forked from appuniversum/ember-appuniversum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathau-badge.gts
54 lines (48 loc) · 1.29 KB
/
au-badge.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
import Component from '@glimmer/component';
import AuIcon, { type AuIconSignature } from './au-icon';
export interface AuBadgeSignature {
Args: {
icon?: AuIconSignature['Args']['icon'];
iconVisible?: boolean;
number?: number;
size?: 'small';
skin?: 'action' | 'border' | 'brand' | 'error' | 'success' | 'warning';
};
Element: HTMLSpanElement;
}
const SKIN_CLASSES = {
border: 'au-c-badge--border',
action: 'au-c-badge--action',
brand: 'au-c-badge--brand',
success: 'au-c-badge--success',
warning: 'au-c-badge--warning',
error: 'au-c-badge--error',
default: 'au-c-badge--default',
};
export default class AuBadge extends Component<AuBadgeSignature> {
get skin() {
if (!this.args.skin) {
return SKIN_CLASSES.default;
}
const skin = SKIN_CLASSES[this.args.skin];
return skin ? skin : SKIN_CLASSES.default;
}
get size() {
if (this.args.size === 'small') return 'au-c-badge--small';
return '';
}
<template>
<span
class="au-c-badge {{this.skin}} {{this.size}}"
aria-hidden={{if @iconVisible "false" "true"}}
...attributes
>
{{#if @icon}}
<AuIcon @icon={{@icon}} />
{{/if}}
{{#if @number}}
<span class="au-c-badge__number">{{@number}}</span>
{{/if}}
</span>
</template>
}