-
Notifications
You must be signed in to change notification settings - Fork 949
/
stacked-examples.component.ts
70 lines (62 loc) · 2.09 KB
/
stacked-examples.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Component, Input, OnInit } from '@angular/core';
import { NgdExampleView } from '../../enum.example-view';
import { NgdAnalytics } from '../../../@theme/services';
import { animate, animation, keyframes, style, transition, trigger, useAnimation } from '@angular/animations';
export const pulse = animation(
animate(
'{{ timing }}s {{ delay }}s',
keyframes([
style({ transform: 'scale3d(1, 1, 1)' }),
style({ transform: 'scale3d({{ scale }}, {{ scale }}, {{ scale }})' }),
style({ transform: 'scale3d(1, 1, 1)' }),
]),
),
{ params: { scale: 1.02, timing: 0.5, delay: 0 } },
);
@Component({
selector: 'ngd-stacked-example-block',
template: `
<div *ngIf="isLiveExample">
<ngd-live-example-block [hidden]="!isLive"
[@exampleState]="isLive ? 'live': 'code'"
[content]="content"
hasViewSwitch="true"
(changeView)="changeView($event)">
</ngd-live-example-block>
<ngd-tabbed-example-block [hidden]="isLive"
[@exampleState]="isLive ? 'live': 'code'"
[content]="content"
hasViewSwitch="true"
(changeView)="changeView($event)">
</ngd-tabbed-example-block>
</div>
<div *ngIf="!isLiveExample">
<ngd-overview-example [example]="content">
</ngd-overview-example>
</div>
`,
animations: [
trigger('exampleState', [
transition('live => code', [
useAnimation(pulse),
]),
transition('code => live', [
useAnimation(pulse),
]),
]),
],
})
export class NgdStackedExampleComponent implements OnInit {
@Input() content: any;
isLive = true;
isLiveExample: boolean;
ngOnInit(): void {
this.isLiveExample = this.content.hasOwnProperty('id');
}
constructor(private analytics: NgdAnalytics) {
}
changeView(view: NgdExampleView) {
this.analytics.trackEvent('changeExampleView', view);
this.isLive = view === NgdExampleView.LIVE;
}
}