Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 21a1102

Browse files
feat(popover): animations, scroll and resize handling
1 parent ad0cf96 commit 21a1102

17 files changed

+314
-163
lines changed

projects/core/src/lib/popover/popover-element.directive.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ export class PopoverElementDirective implements AfterViewInit {
1212

1313
@Input('fivPopover.show') set show(visible: boolean) {
1414
this._show = visible;
15-
16-
if (this.show) {
17-
this.fivPopover.openElementRef(this.el);
18-
} else if (this.fivPopover.overlay && this.fivPopover.overlay.open) {
19-
this.fivPopover.close();
20-
}
15+
setTimeout(() => {
16+
if (this.show) {
17+
this.fivPopover.open(this.el);
18+
} else if (this.fivPopover.overlay && this.fivPopover.overlay.open) {
19+
this.fivPopover.close();
20+
}
21+
}, 0);
2122
}
2223
get show() {
2324
return this._show;
@@ -28,7 +29,7 @@ export class PopoverElementDirective implements AfterViewInit {
2829
open() {
2930
this.show = true;
3031
}
31-
hide() {
32+
close() {
3233
this.show = false;
3334
}
3435

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
tween,
3+
transform,
4+
scale,
5+
fadeIn,
6+
easeOutSine,
7+
beforeStyle,
8+
fadeOut,
9+
easeInSine
10+
} from '@fivethree/ngx-rxjs-animations';
11+
import { ElementRef } from '@angular/core';
12+
import { zip } from 'rxjs';
13+
import { PopoverPosition } from './popover.types';
14+
15+
export const scaleIn = (target, easing, duration) =>
16+
tween(easing, duration).pipe(transform(target, scale(0, 1)));
17+
18+
export const animIn = (
19+
element: ElementRef,
20+
position: PopoverPosition,
21+
duration: number
22+
) =>
23+
zip(
24+
fadeIn(element, easeOutSine, duration),
25+
scaleIn(element, easeOutSine, duration).pipe(
26+
beforeStyle(
27+
element,
28+
'transform-origin',
29+
`${position.vertical === 'top' ? 'bottom' : 'top'} ${
30+
position.horizontal === 'left' ? 'right' : 'left'
31+
}`
32+
)
33+
)
34+
);
35+
36+
export const animOut = (element: ElementRef, duration: number) =>
37+
fadeOut(element, easeInSine, duration);
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<fiv-overlay>
2-
<div *ngIf="backdrop" class="fiv-popover-backdrop" (click)="close()">
2+
<div *ngIf="backdrop && !hidden" [ngClass]="classes" class="fiv-popover-backdrop" (click)="close()">
33
</div>
4-
<div class="popover-container" [style]="containerStyles">
5-
<ng-content>
6-
</ng-content>
7-
<svg *ngIf="arrow && !overlaysTarget" class="arrow" [style]="svgStyles">
8-
<polygon [attr.points]="triangle" />
9-
</svg>
4+
<div *ngIf="!hidden" [ngClass]="classes" class="popover-container" [style]="containerStyles">
5+
<div #animation *ngIf="overlay?.open" class="animation-container" anim [anim.in]="animationIn">
6+
<ng-content>
7+
</ng-content>
8+
<svg *ngIf="arrow && !overlaysTarget" class="arrow" [style]="svgStyles">
9+
<polygon [attr.points]="triangle" />
10+
</svg>
11+
</div>
12+
1013
</div>
1114

1215
</fiv-overlay>

projects/core/src/lib/popover/popover.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
display: block;
88
}
99

10+
.animation-container {
11+
height: 100%;
12+
position: relative;
13+
}
14+
1015
svg.arrow {
1116
position: absolute;
1217
fill: var(--ion-item-background);

0 commit comments

Comments
 (0)