-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathau-card.gts
291 lines (267 loc) · 7.58 KB
/
au-card.gts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import { hash } from '@ember/helper';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import AuBadge from './au-badge';
import AuButton from './au-button';
import AuContent, { type AuContentSignature } from './au-content';
import AuIcon, { type AuIconSignature } from './au-icon';
import { AddIcon } from './icons/add';
import { NavDownIcon } from './icons/nav-down';
import { NavUpIcon } from './icons/nav-up';
import { RemoveIcon } from './icons/remove';
export interface AuCardSignature {
Args: {
divided?: boolean;
expandable?: boolean;
flex?: boolean;
isExpanded?: boolean;
isOpenInitially?: boolean;
manualControl?: boolean;
openSection?: () => void;
size?: 'small' | 'tiny' | 'flush';
shadow?: boolean;
standOut?: boolean;
textCenter?: boolean;
};
Blocks: {
default: [
{
header?: typeof Header;
content?: typeof Content;
footer?: typeof Footer;
},
];
};
Element: HTMLElement;
}
export default class AuCard extends Component<AuCardSignature> {
@tracked isExpanded = false;
constructor(owner: unknown, args: AuCardSignature['Args']) {
super(owner, args);
if (this.args.isOpenInitially) {
this.isExpanded = true;
}
}
get sectionOpen() {
if (this.args.manualControl) {
return this.args.isExpanded;
} else {
return this.isExpanded;
}
}
get size() {
if (this.args.size == 'small') return 'au-c-card--padding-small';
if (this.args.size == 'tiny') return 'au-c-card--padding-tiny';
if (this.args.size == 'flush') return '';
else return 'au-c-card--padding';
}
get flex() {
if (this.args.flex) return 'au-c-card--flex';
return '';
}
get expandable() {
if (this.args.expandable) return 'au-c-card--expandable';
return '';
}
get shadow() {
if (this.args.shadow) return 'au-c-card--shadow';
return '';
}
get divided() {
if (this.args.divided) return 'au-c-card--divided';
return '';
}
get textCenter() {
if (this.args.textCenter) return 'au-c-card--text-center';
return '';
}
get standOut() {
if (this.args.standOut) return 'au-c-card--standout';
return '';
}
@action
openSection() {
if (this.args.manualControl) {
this.args.openSection?.();
} else {
this.isExpanded = !this.isExpanded;
}
}
<template>
<article
class="au-c-card au-c-card--fill
{{this.size}}
{{this.flex}}
{{this.expandable}}
{{this.shadow}}
{{this.divided}}
{{this.textCenter}}
{{this.standOut}}"
...attributes
>
{{#if this.expandable}}
{{#if this.shadow}}
<div
class="au-c-card__clickable"
role="button"
{{on "click" this.openSection}}
{{! template-lint-disable require-presentational-children}}
{{! this triggers a false positive for components: https://github.com/ember-template-lint/ember-template-lint/issues/2334}}
>
<AuButton
@skin="link"
class="au-c-card__toggle"
aria-hidden="true"
focusable="false"
aria-expanded={{if this.sectionOpen "true" "false"}}
>
{{#if this.sectionOpen}}
<AuIcon
@icon={{RemoveIcon}}
@size="large"
@ariaHidden={{true}}
/>
<span class="au-u-hidden-visually au-c-card__toggle-false">
Verberg
</span>
{{else}}
<AuIcon @icon={{AddIcon}} @size="large" @ariaHidden={{true}} />
<span class="au-u-hidden-visually au-c-card__toggle-true">
Toon
</span>
{{/if}}
</AuButton>
{{yield (hash header=Header)}}
</div>
{{else}}
<div
class="au-c-card__clickable"
role="button"
{{on "click" this.openSection}}
{{! template-lint-disable require-presentational-children}}
{{! this triggers a false positive for components: https://github.com/ember-template-lint/ember-template-lint/issues/2334}}
>
{{yield (hash header=Header)}}
<AuButton
@skin="link"
class="au-c-card__toggle"
aria-hidden="true"
focusable="false"
aria-expanded={{if this.sectionOpen "true" "false"}}
>
{{#if this.sectionOpen}}
<AuIcon
@icon={{NavUpIcon}}
@size="large"
@ariaHidden={{true}}
/>
<span class="au-u-hidden-visually au-c-card__toggle-false">
Verberg
</span>
{{else}}
<AuIcon
@icon={{NavDownIcon}}
@size="large"
@ariaHidden={{true}}
/>
<span class="au-u-hidden-visually au-c-card__toggle-true">
Toon
</span>
{{/if}}
</AuButton>
</div>
{{/if}}
{{#if this.sectionOpen}}
<div tabindex="0">
{{yield (hash content=Content)}}
</div>
{{/if}}
{{else}}
{{yield (hash header=Header)}}
{{yield (hash content=Content)}}
{{/if}}
{{yield (hash footer=Footer)}}
</article>
</template>
}
interface HeaderSignature {
Args: {
badgeIcon?: AuIconSignature['Args']['icon'];
badgeNumber?: number;
badgeSize?: 'small';
badgeSkin?: 'border' | 'action' | 'brand' | 'success' | 'warning' | 'error';
};
Blocks: {
default: [];
};
Element: HTMLDivElement;
}
class Header extends Component<HeaderSignature> {
get badgeSkin() {
if (this.args.badgeSkin == 'border') return 'au-c-badge--border';
if (this.args.badgeSkin == 'action') return 'au-c-badge--action';
if (this.args.badgeSkin == 'brand') return 'au-c-badge--brand';
if (this.args.badgeSkin == 'success') return 'au-c-badge--success';
if (this.args.badgeSkin == 'warning') return 'au-c-badge--warning';
if (this.args.badgeSkin == 'error') return 'au-c-badge--error';
return 'au-c-badge--default';
}
get badgeSize() {
if (this.args.badgeSize == 'small') return 'au-c-badge--small';
return '';
}
<template>
<div class="au-c-card__header" ...attributes>
{{#if @badgeIcon}}
<AuBadge
@size={{@badgeSize}}
@skin={{@badgeSkin}}
@icon={{@badgeIcon}}
/>
{{else if @badgeNumber}}
<AuBadge
@size={{@badgeSize}}
@skin={{@badgeSkin}}
@number={{@badgeNumber}}
/>
{{/if}}
{{#if (has-block)}}
<div>
{{yield}}
</div>
{{/if}}
</div>
</template>
}
interface ContentSignature {
Blocks: {
default: [];
};
Element: AuContentSignature['Element'];
}
class Content extends Component<ContentSignature> {
<template>
{{#if (has-block)}}
<AuContent class="au-c-card__content" ...attributes>
{{yield}}
</AuContent>
{{/if}}
</template>
}
interface FooterSignature {
Blocks: {
default: [];
};
Element: AuContentSignature['Element'];
}
class Footer extends Component<FooterSignature> {
<template>
{{#if (has-block)}}
<AuContent class="au-c-card__footer" ...attributes>
{{yield}}
</AuContent>
{{/if}}
</template>
}