Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu: make trigger button float when button with isFloating is slotted #3215

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@ import { Component } from '@angular/core';

const config = {
selector: 'cookbook-menu-custom-button-example',
template: `<kirby-menu>
template: `<kirby-menu [title]="'Title'" [subtitle]="'This is a message where we can put absolutely anything we want.'">
<button
kirby-button
type="button"
[attentionLevel]="'3'"
[isFloating]="true"
>
<kirby-icon [name]="'menu-outline'"></kirby-icon>
<kirby-icon [name]="'add'"></kirby-icon>
</button>
<kirby-item>
<h3>Action 1</h3>
</kirby-item>
<kirby-item [selectable]="true">
<h3>Action 1</h3>
</kirby-item>
<kirby-divider></kirby-divider>
<kirby-item [selectable]="true">
<h3>Action 2</h3>
</kirby-item>
<kirby-divider></kirby-divider>
<kirby-item [selectable]="true">
<h3>Action 3 lorem ipsum something wow yes</h3>
</kirby-item>
<kirby-divider></kirby-divider>
<kirby-item [selectable]="true">
<h3>Action 4</h3>
</kirby-item>
<kirby-divider></kirby-divider>
<kirby-item [selectable]="true">
<h3>Action 5</h3>
</kirby-item>
</kirby-menu>`,
};

Expand Down
1 change: 1 addition & 0 deletions libs/designsystem/button/src/button.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ $button-margin: utils.size('xxxs');

:host-context(kirby-page-actions),
:host-context(kirby-action-group),
:host-context(kirby-menu),
:host-context(.kirby-modal ion-header ion-toolbar ion-buttons) {
margin: 0;
}
Expand Down
11 changes: 10 additions & 1 deletion libs/designsystem/menu/src/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@
[closeOnSelect]="closeOnSelect"
[autoPlacement]="autoPlacement"
[shift]="shift"
[offset]="_offset"
[ngStyle]="{
minWidth: minWidth ? minWidth + 'px' : null
}"
class="menu-popover"
>
<ng-content select="kirby-item"></ng-content>
<kirby-card-header
*ngIf="title || subtitle"
[title]="title"
[subtitle]="subtitle"
[isTitleBold]="true"
>
<ng-content></ng-content>
</kirby-card-header>
<ng-content select="kirby-item,kirby-divider"></ng-content>
</kirby-card>
6 changes: 6 additions & 0 deletions libs/designsystem/menu/src/menu.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ $max-screen-width-small: 460px;

:host {
position: relative;

&.floating-action-button {
position: fixed;
bottom: utils.size('s');
right: utils.size('s');
}
}

.button-container {
Expand Down
20 changes: 16 additions & 4 deletions libs/designsystem/menu/src/menu.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { CommonModule } from '@angular/common';
import {
AfterContentInit,
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ContentChild,
ElementRef,
HostBinding,
Input,
NgZone,
OnDestroy,
Expand Down Expand Up @@ -34,7 +36,7 @@ import { EventListenerDisposeFn } from '@kirbydesign/designsystem/types';
styleUrls: ['./menu.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MenuComponent implements AfterViewInit, OnDestroy {
export class MenuComponent implements AfterViewInit, OnDestroy, AfterContentInit {
constructor(
private cdf: ChangeDetectorRef,
private elementRef: ElementRef<HTMLElement>,
Expand Down Expand Up @@ -66,26 +68,32 @@ export class MenuComponent implements AfterViewInit, OnDestroy {

@Input() public shift: boolean = true;

@Input() public title: string;

@Input() public subtitle: string;

/**
* The minimum width of the menu. If not set, the default width is 240px
*/
@Input() public minWidth: number;

@HostBinding('class.floating-action-button') private isFloatingActionButton;

@ViewChild('buttonContainer', { read: ElementRef })
public buttonContainerElement: ElementRef<HTMLElement> | undefined;

@ViewChild('defaultButton', { read: ElementRef })
public defaultButtonElement: ElementRef<HTMLElement> | undefined;

@ContentChild(ButtonComponent, { read: ElementRef }) public userProvidedButton:
| ElementRef<HTMLElement>
| undefined;
@ContentChild(ButtonComponent) public userProvidedButton: ButtonComponent | undefined;

@ViewChild(FloatingDirective)
private floatingDirective: FloatingDirective;

public FloatingOffset: typeof FloatingOffset = FloatingOffset;

public _offset = FloatingOffset.small;

private scrollListenerDisposeFn: EventListenerDisposeFn;

public ngAfterViewInit(): void {
Expand All @@ -102,6 +110,10 @@ export class MenuComponent implements AfterViewInit, OnDestroy {
});
}

public ngAfterContentInit(): void {
this.isFloatingActionButton = this.userProvidedButton?.isFloating;
}

ngOnDestroy(): void {
this.scrollListenerDisposeFn?.();
}
Expand Down
Loading