This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathva-button-icon.tsx
More file actions
110 lines (99 loc) · 2.72 KB
/
va-button-icon.tsx
File metadata and controls
110 lines (99 loc) · 2.72 KB
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
import {
Component,
Event,
EventEmitter,
Host,
h,
Listen,
Prop,
Element,
} from '@stencil/core';
import classnames from 'classnames';
import { i18next } from '../..';
/**
* @componentName Button - Icon
* @nativeHandler onClick
* @maturityCategory caution
* @maturityLevel available
* @guidanceHref button/button-icon
*/
@Component({
tag: 'va-button-icon',
styleUrl: 'va-button-icon.scss',
shadow: true,
})
export class VaButtonIcon {
@Element() el: HTMLElement;
/**
* If `true`, the component-library-analytics event is disabled.
*/
@Prop() disableAnalytics?: boolean = false;
/**
* The aria-label of the component.
*/
@Prop() label?: string; // could use this.el.getAttribute('aria-label') but this is more explicit
/**
* The type of button this will render as, currently a limited number of options
*/
private buttonTypeMap = {
// eslint-disable-next-line i18next/no-literal-string
'change-file': { icon: 'attach_file', text: 'Change File' },
// eslint-disable-next-line i18next/no-literal-string
'delete': { icon: 'delete', text: 'Delete' },
// eslint-disable-next-line i18next/no-literal-string
'cancel': { icon: 'cancel', text: 'Cancel' },
// eslint-disable-next-line i18next/no-literal-string
'expand': { icon: 'add', text: i18next.t('expand-all') },
// eslint-disable-next-line i18next/no-literal-string
'collapse': { icon: 'remove', text: i18next.t('collapse-all') },
};
@Prop({reflect: true}) buttonType: keyof typeof this.buttonTypeMap;
/**
* The event used to track usage of the component.
*/
@Event({
bubbles: true,
composed: true,
eventName: 'component-library-analytics',
})
componentLibraryAnalytics: EventEmitter;
@Listen('click')
handleClick(_: MouseEvent): void {
if (!this.disableAnalytics) {
const detail = {
componentName: 'va-button',
action: 'click',
details: {
// eslint-disable-next-line i18next/no-literal-string
type: 'tertiary',
label: this.buttonTypeMap[this.buttonType].text,
},
};
this.componentLibraryAnalytics.emit(detail);
}
}
render() {
const { label, buttonType } = this;
const buttonClass = classnames({
'usa-button': true,
'va-button-icon--destructive':
buttonType === 'cancel' || buttonType === 'delete',
});
return (
<Host>
<button
class={buttonClass}
aria-label={label}
type="button"
part="button"
>
<va-icon
icon={this.buttonTypeMap[buttonType].icon}
size={2}
></va-icon>
{this.buttonTypeMap[buttonType].text}
</button>
</Host>
);
}
}