Last active
June 27, 2022 15:52
-
-
Save fireflysemantics/f3411ff601763a11c9a47fad2cf3b9ac to your computer and use it in GitHub Desktop.
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
import { | |
Component, | |
ChangeDetectionStrategy, | |
HostListener, | |
} from '@angular/core'; | |
import { | |
trigger, | |
state, | |
style, | |
animate, | |
transition, | |
} from '@angular/animations'; | |
@Component({ | |
selector: 'my-app', | |
template: `<mat-icon | |
[@animationTrigger]="state" | |
aria-hidden="false" | |
aria-label="Chevron Animation" | |
>expand_circle_down</mat-icon> | |
`, | |
styleUrls: ['./app.component.css'], | |
animations: [ | |
trigger('animationTrigger', [ | |
state( | |
'expanded', | |
style({ | |
transform: 'rotate(180deg)', | |
}) | |
), | |
transition('collapsed => expanded', animate('300ms ease-in')), | |
transition('expanded => collapsed', animate('300ms ease-out')), | |
]), | |
], | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
}) | |
export class AppComponent { | |
public isExpanded = false; | |
@HostListener('click') | |
@HostListener('keydown.enter') | |
@HostListener('keydown.space') | |
public toggle() { | |
this.isExpanded = !this.isExpanded; | |
} | |
get state(): string { | |
return this.isExpanded ? 'expanded' : 'collapsed'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment