-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use Angular Animations to animate flyout * support additional placement options * fix alignment issues with nav-bar
- Loading branch information
Showing
6 changed files
with
133 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,44 @@ | ||
import { NgClass } from '@angular/common'; | ||
import { | ||
Component, | ||
ElementRef, | ||
Renderer2, | ||
contentChild, | ||
inject, | ||
input, | ||
signal, | ||
viewChild | ||
} from '@angular/core'; | ||
import { animate, state, style, transition, trigger } from '@angular/animations'; | ||
import { NgClass, NgTemplateOutlet } from '@angular/common'; | ||
import { Component, input, signal } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-flyout', | ||
templateUrl: './flyout.component.html', | ||
styleUrls: ['./flyout.component.scss'], | ||
standalone: true, | ||
imports: [NgClass] | ||
imports: [NgClass, NgTemplateOutlet], | ||
animations: [ | ||
trigger('flyInOutVertical', [ | ||
state('false', style({ height: '0' })), | ||
transition('false => true', [animate('500ms ease-in', style({ height: '*' }))]), | ||
transition('true => false', [animate('500ms ease-in', style({ height: '0' }))]) | ||
]), | ||
trigger('flyInOutHorizontal', [ | ||
state('false', style({ width: '0' })), | ||
transition('false => true', [animate('500ms ease-in', style({ width: '*' }))]), | ||
transition('true => false', [animate('500ms ease-in', style({ width: '0' }))]) | ||
]) | ||
] | ||
}) | ||
export class FlyoutComponent { | ||
readonly #renderer = inject(Renderer2); | ||
|
||
readonly container = viewChild.required<ElementRef>('flyoutContentContainer'); | ||
readonly content = contentChild.required<ElementRef>('flyoutContent'); | ||
|
||
readonly label = input(''); | ||
readonly placement = input<'left' | 'right' | 'top' | 'bottom'>('right'); | ||
readonly placement = input< | ||
| 'top' | ||
| 'bottom' | ||
| 'left-top' | ||
| 'left-bottom' | ||
| 'right-top' | ||
| 'right-bottom' | ||
| 'top-left' | ||
| 'top-right' | ||
| 'bottom-left' | ||
| 'bottom-right' | ||
>('right-top'); | ||
|
||
readonly isOpen = signal(false); | ||
|
||
toggle() { | ||
if (this.content() && this.container()) { | ||
if (this.placement() === 'top' || this.placement() === 'bottom') { | ||
if (this.isOpen()) { | ||
this.#renderer.setStyle(this.container().nativeElement, 'height', 0); | ||
} else { | ||
this.#renderer.setStyle( | ||
this.container().nativeElement, | ||
'height', | ||
`${this.content().nativeElement.clientHeight}px` | ||
); | ||
} | ||
} else { | ||
if (this.isOpen()) { | ||
this.#renderer.setStyle(this.container().nativeElement, 'width', 0); | ||
} else { | ||
this.#renderer.setStyle( | ||
this.container().nativeElement, | ||
'width', | ||
`${this.content().nativeElement.clientWidth}px` | ||
); | ||
} | ||
} | ||
|
||
this.isOpen.set(!this.isOpen()); | ||
} | ||
this.isOpen.set(!this.isOpen()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters