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

add tooltip support #155

Closed
wants to merge 1 commit into from
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
28 changes: 20 additions & 8 deletions projects/fab-speed-dial/src/lib/fab-speed-dial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ViewEncapsulation,
} from '@angular/core';
import {MatButton} from '@angular/material/button';
import {MatTooltip} from '@angular/material/tooltip';
import {CommonModule, DOCUMENT} from '@angular/common';
import {forkJoin, fromEvent, Subscription} from 'rxjs';
import {take} from 'rxjs/operators';
Expand All @@ -36,6 +37,7 @@ export class EcoFabSpeedDialActionsComponent implements AfterContentInit {
private _parent: EcoFabSpeedDialComponent;

@ContentChildren(MatButton) private _buttons!: QueryList<MatButton>;
@ContentChildren(MatTooltip) private _tooltips!: QueryList<MatTooltip>;

/**
* Whether the min-fab button exist in DOM
Expand Down Expand Up @@ -97,15 +99,15 @@ export class EcoFabSpeedDialActionsComponent implements AfterContentInit {
this.changeElementStyle(hostElement, 'opacity', '1');
this.changeElementStyle(hostElement, 'transform', transform);
});
}, 50); // Be sure that *ngIf can show elements before trying to animate them
}

private resetAnimationState(): void {
clearTimeout(this.showMiniFabAnimation);
if (this.hideMiniFab) {
this.hideMiniFab.unsubscribe();
this.hideMiniFab = null;
}
setTimeout(() => {
this._tooltips.forEach(tooltip => {
if (this.miniFabVisible) {
tooltip.show();
}
});
}, 500);
}, 50); // Be sure that *ngIf can show elements before trying to animate them
}

public hide(): void {
Expand All @@ -115,6 +117,8 @@ export class EcoFabSpeedDialActionsComponent implements AfterContentInit {

this.resetAnimationState();

this._tooltips.map(tooltip => tooltip.hide());

const obs = this._buttons.map((button, i) => {
let opacity = '1';
let transitionDelay = 0;
Expand All @@ -141,6 +145,14 @@ export class EcoFabSpeedDialActionsComponent implements AfterContentInit {
this.hideMiniFab = forkJoin(obs).subscribe(() => (this.miniFabVisible = false));
}

private resetAnimationState(): void {
clearTimeout(this.showMiniFabAnimation);
if (this.hideMiniFab) {
this.hideMiniFab.unsubscribe();
this.hideMiniFab = null;
}
}

private getTranslateFunction(value: string): string {
const dir = this._parent.direction;
const translateFn = dir === 'up' || dir === 'down' ? 'translateY' : 'translateX';
Expand Down
51 changes: 45 additions & 6 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
<mat-radio-button value="right">Right</mat-radio-button>
</mat-radio-group>
</p>
<p>
Tooltip position:
<mat-radio-group [(ngModel)]="tooltipPosition" name="tooltipPosition">
<mat-radio-button value="after">After</mat-radio-button>
<mat-radio-button value="before">Before</mat-radio-button>
<mat-radio-button value="above">Above</mat-radio-button>
<mat-radio-button value="below">Below</mat-radio-button>
</mat-radio-group>
</p>
<p>
Animation Mode:
<mat-radio-group [(ngModel)]="animationMode" name="animationMode">
Expand Down Expand Up @@ -46,13 +55,28 @@
</eco-fab-speed-dial-trigger>

<eco-fab-speed-dial-actions>
<button mat-mini-fab (click)="doAction('action1')">
<button
mat-mini-fab
matTooltip="Search"
[matTooltipPosition]="tooltipPosition"
(click)="doAction('action1')"
>
<mat-icon>search</mat-icon>
</button>
<button mat-mini-fab (click)="doAction('action2')">
<button
mat-mini-fab
matTooltip="Edit"
[matTooltipPosition]="tooltipPosition"
(click)="doAction('action2')"
>
<mat-icon>edit</mat-icon>
</button>
<button mat-mini-fab (click)="doAction('action3')">
<button
mat-mini-fab
matTooltip="Home"
[matTooltipPosition]="tooltipPosition"
(click)="doAction('action3')"
>
<mat-icon>home</mat-icon>
</button>
</eco-fab-speed-dial-actions>
Expand All @@ -76,13 +100,28 @@
</eco-fab-speed-dial-trigger>

<eco-fab-speed-dial-actions>
<button mat-mini-fab (click)="doAction('action1')">
<button
mat-mini-fab
matTooltip="Search"
[matTooltipPosition]="tooltipPosition"
(click)="doAction('action1')"
>
<mat-icon>add</mat-icon>
</button>
<button mat-mini-fab (click)="doAction('action2')">
<button
mat-mini-fab
matTooltip="Edit"
[matTooltipPosition]="tooltipPosition"
(click)="doAction('action2')"
>
<mat-icon>edit</mat-icon>
</button>
<button mat-mini-fab (click)="doAction('action3')">
<button
mat-mini-fab
matTooltip="Menu"
[matTooltipPosition]="tooltipPosition"
(click)="doAction('action3')"
>
<mat-icon>menu</mat-icon>
</button>
</eco-fab-speed-dial-actions>
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Component} from '@angular/core';
import {TooltipPosition} from '@angular/material/tooltip';
import {AnimationMode, Direction} from '@ecodev/fab-speed-dial';

@Component({
Expand All @@ -15,6 +16,7 @@ export class AppComponent {
public spin = false;
public direction: Direction = 'up';
public animationMode: AnimationMode = 'fling';
public tooltipPosition: TooltipPosition = 'after';

public get fixed(): boolean {
return this._fixed;
Expand Down