forked from tomalaforge/angular-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpandable-card.ts
66 lines (62 loc) · 1.76 KB
/
expandable-card.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
import {
ChangeDetectionStrategy,
Component,
output,
signal,
} from '@angular/core';
@Component({
selector: 'app-expandable-card',
template: `
<button
class="text-fg-subtle hover:bg-button-secondary-bg-hover active:bg-button-secondary-bg-active focus:outline-button-border-highlight flex w-fit items-center gap-1 py-2 focus:outline focus:outline-2 focus:outline-offset-1"
(click)="toggleExpansion()"
data-cy="expandable-panel-toggle">
@if (isExpanded()) {
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-4 w-4">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m19.5 8.25-7.5 7.5-7.5-7.5" />
</svg>
} @else {
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-4 w-4">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m8.25 4.5 7.5 7.5-7.5 7.5" />
</svg>
}
<ng-content select="[title]" />
</button>
<div
class="overflow-hidden transition-[max-height] duration-500"
[class.max-h-0]="!isExpanded()"
[class.max-h-[1000px]]="isExpanded()">
<ng-content />
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
class: 'flex flex-col gap-2 ',
},
})
export class ExpandableCard {
public isExpanded = signal(false);
expanded = output<boolean>();
toggleExpansion(): void {
this.isExpanded.update((isExpanded) => !isExpanded);
this.expanded.emit(this.isExpanded());
}
}