5
5
</template >
6
6
7
7
<script lang="ts">
8
+ import {resolveBooleanish } from ' ../../utils'
8
9
import {computed , defineComponent , PropType } from ' vue'
9
- import type {ButtonVariant , InputSize , LinkTarget } from ' ../../types'
10
+ import type {Booleanish , ButtonVariant , InputSize , LinkTarget } from ' ../../types'
10
11
import {BLINK_PROPS } from ' ../BLink/BLink.vue'
11
12
12
13
export default defineComponent ({
13
14
props: {
14
15
... BLINK_PROPS ,
15
- active: {type: Boolean , default: false },
16
- disabled: {type: Boolean , default: false },
16
+ active: {type: Boolean as PropType < Booleanish > , default: false },
17
+ disabled: {type: Boolean as PropType < Booleanish > , default: false },
17
18
href: {type: String , required: false },
18
- pill: {type: Boolean , default: false },
19
- pressed: {type: Boolean , default: null },
19
+ pill: {type: Boolean as PropType < Booleanish > , default: false },
20
+ pressed: {type: Boolean as PropType < Booleanish > , default: null },
20
21
rel: {type: String , default: null },
21
22
size: {type: String as PropType <InputSize >},
22
- squared: {type: Boolean , default: false },
23
+ squared: {type: Boolean as PropType < Booleanish > , default: false },
23
24
tag: {type: String , default: ' button' },
24
25
target: {type: String as PropType <LinkTarget >, default: ' _self' },
25
26
type: {type: String , default: ' button' },
26
27
variant: {type: String as PropType <ButtonVariant >, default: ' secondary' },
27
28
},
28
29
emits: [' click' , ' update:pressed' ],
29
30
setup(props , {emit }) {
31
+ const activeBoolean = computed (() => resolveBooleanish (props .active ))
32
+ const disabledBoolean = computed (() => resolveBooleanish (props .disabled ))
33
+ const pillBoolean = computed (() => resolveBooleanish (props .pill ))
34
+ const pressedBoolean = computed (() => resolveBooleanish (props .pressed ))
35
+ const squaredBoolean = computed (() => resolveBooleanish (props .squared ))
36
+
30
37
// TODO none of these are computed values. Meaning they will not react if any of these are changed?
31
- const isToggle = props . pressed !== null
38
+ const isToggle = pressedBoolean . value !== null
32
39
const isButton = props .tag === ' button' && ! props .href && ! props .to
33
40
const isLink = !! (props .href || props .to )
34
41
const isBLink = !! props .to
@@ -37,17 +44,17 @@ export default defineComponent({
37
44
const classes = computed (() => ({
38
45
[` btn-${props .variant } ` ]: props .variant ,
39
46
[` btn-${props .size } ` ]: props .size ,
40
- ' active' : props . active || props . pressed ,
41
- ' rounded-pill' : props . pill ,
42
- ' rounded-0' : props . squared ,
43
- ' disabled' : props . disabled ,
47
+ ' active' : activeBoolean . value || pressedBoolean . value ,
48
+ ' rounded-pill' : pillBoolean . value ,
49
+ ' rounded-0' : squaredBoolean . value ,
50
+ ' disabled' : disabledBoolean . value ,
44
51
}))
45
52
46
53
const attrs = computed (() => ({
47
- ' aria-disabled' : nonStandardTag ? String (props . disabled ) : null ,
48
- ' aria-pressed' : isToggle ? String (props . pressed ) : null ,
54
+ ' aria-disabled' : nonStandardTag ? String (disabledBoolean . value ) : null ,
55
+ ' aria-pressed' : isToggle ? String (pressedBoolean . value ) : null ,
49
56
' autocomplete' : isToggle ? ' off' : null ,
50
- ' disabled' : isButton ? props . disabled : null ,
57
+ ' disabled' : isButton ? disabledBoolean . value : null ,
51
58
' href' : props .href ,
52
59
' rel' : isLink ? props .rel : null ,
53
60
' role' : nonStandardTag || isLink ? ' button' : null ,
@@ -70,14 +77,14 @@ export default defineComponent({
70
77
})
71
78
72
79
const clicked = (e : MouseEvent ): void => {
73
- if (props . disabled ) {
80
+ if (disabledBoolean . value ) {
74
81
e .preventDefault ()
75
82
e .stopPropagation ()
76
83
return
77
84
}
78
85
emit (' click' , e )
79
86
if (isToggle ) {
80
- emit (' update:pressed' , ! props . pressed )
87
+ emit (' update:pressed' , ! pressedBoolean . value )
81
88
}
82
89
}
83
90
0 commit comments