2323</template >
2424
2525<script lang="ts">
26- import { kebabCase } from " lodash" ;
27- import { ref , computed , defineComponent , PropType } from " vue" ;
28- import { BUTTON_VARIANTS as VARIANTS , ICON_SIZES , ICONS } from " ../constants" ;
29-
30- type ButtonSize = " small" | " medium" | " large" | " sm" | " md" | " lg" ;
26+ import { kebabCase } from ' lodash' ;
27+ import type { PropType } from ' vue' ;
28+ import { ref , computed , defineComponent } from ' vue' ;
29+ import type {
30+ BUTTON_VARIANTS as VARIANTS ,
31+ ICON_SIZES ,
32+ ICONS ,
33+ } from ' ../constants' ;
34+ import useLogEvent from ' @/hooks/useLogEvent' ;
35+
36+ type ButtonSize = ' small' | ' medium' | ' large' | ' sm' | ' md' | ' lg' ;
3137type IconSize = typeof ICON_SIZES [number ];
3238
3339export default defineComponent ({
34- name: " BaseButton" ,
40+ name: ' BaseButton' ,
3541
3642 props: {
3743 action: {
@@ -48,51 +54,51 @@ export default defineComponent({
4854 },
4955 text: {
5056 type: String ,
51- default: " " ,
57+ default: ' ' ,
5258 },
5359 alt: {
5460 type: String ,
55- default: " button" ,
61+ default: ' button' ,
5662 },
5763 title: {
5864 type: String ,
59- default: " " ,
65+ default: ' ' ,
6066 },
6167 ccuEvent: {
6268 type: String ,
63- default: " " ,
69+ default: ' ' ,
6470 },
6571 size: {
6672 type: String as PropType <ButtonSize >,
67- default: " " ,
73+ default: ' ' ,
6874 },
6975 icon: {
7076 type: String ,
71- default: " " ,
77+ default: ' ' ,
7278 },
7379 ccuIcon: {
7480 type: String as PropType <typeof ICONS [keyof typeof ICONS ]>,
75- default: " " ,
81+ default: ' ' ,
7682 },
7783 iconSize: {
7884 type: String as PropType <IconSize >,
79- default: " " ,
85+ default: ' ' ,
8086 },
8187 suffixIcon: {
8288 type: String as PropType <typeof ICONS [keyof typeof ICONS ]>,
83- default: " " ,
89+ default: ' ' ,
8490 },
8591 selector: {
8692 type: String ,
87- default: " " ,
93+ default: ' ' ,
8894 },
8995 variant: {
9096 type: String as PropType <typeof VARIANTS [keyof typeof VARIANTS ]>,
91- default: " " ,
97+ default: ' ' ,
9298 },
9399 type: {
94100 type: String ,
95- default: " " ,
101+ default: ' ' ,
96102 },
97103 },
98104
@@ -103,28 +109,28 @@ export default defineComponent({
103109 const buttonTitle = computed (() => props .text || props .alt || props .title );
104110
105111 const buttonSelector = computed (
106- () => props .selector || ` js-${kebabCase (buttonTitle .value )} `
112+ () => props .selector || ` js-${kebabCase (buttonTitle .value )} ` ,
107113 );
108114
109115 const styles = computed (() => {
110116 const styleObject = {
111- " large text-h3 font-h3" : [" large" , " lg " ].includes (props .size ),
112- " medium text-sans text-h4 font-h4" : [" medium" , " md " ].includes (
113- props .size
117+ ' large text-h3 font-h3' : [' large' , ' lg ' ].includes (props .size ),
118+ ' medium text-sans text-h4 font-h4' : [' medium' , ' md ' ].includes (
119+ props .size ,
114120 ),
115- " small text-bodysm font-bodysm" : [" small" , " sm " ].includes (props .size ),
121+ ' small text-bodysm font-bodysm' : [' small' , ' sm ' ].includes (props .size ),
116122 disabled: props .disabled ,
117123 // **** DEPRECATED ****
118- primary: props .type === " primary" ,
119- danger: props .type === " danger" ,
120- warning: props .type === " warning" ,
121- link: props .type === " link" ,
122- bare: props .type === " bare" ,
124+ primary: props .type === ' primary' ,
125+ danger: props .type === ' danger' ,
126+ warning: props .type === ' warning' ,
127+ link: props .type === ' link' ,
128+ bare: props .type === ' bare' ,
123129 // **************
124130 flex: true ,
125- " items-center" : true ,
126- " justify-center" : true ,
127- " base-button" : true ,
131+ ' items-center' : true ,
132+ ' justify-center' : true ,
133+ ' base-button' : true ,
128134 };
129135 if (props .variant ) {
130136 styleObject [props .variant ] = true ;
@@ -135,7 +141,7 @@ export default defineComponent({
135141
136142 const timeout = async () => {
137143 await delay (5000 );
138- return Promise . reject () ;
144+ throw undefined ;
139145 };
140146
141147 const performAction = async () => {
@@ -145,11 +151,9 @@ export default defineComponent({
145151 if (props .action ) {
146152 await Promise .race ([props .action (), timeout ()]);
147153 }
148- } catch (e ) {
149- // TODO: expose method for handling button exceptions
150154 } finally {
151- // const { logEvent } = useLogEvent();
152- // logEvent(props.ccuEvent);
155+ const { logEvent } = useLogEvent ();
156+ logEvent (props .ccuEvent );
153157 loading .value = false ;
154158 }
155159 };
0 commit comments