Skip to content

Commit 83785cc

Browse files
committed
feat: bbutton booleanish added
1 parent 3a43866 commit 83785cc

File tree

1 file changed

+23
-16
lines changed
  • packages/bootstrap-vue-3/src/components/BButton

1 file changed

+23
-16
lines changed

packages/bootstrap-vue-3/src/components/BButton/BButton.vue

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@
55
</template>
66

77
<script lang="ts">
8+
import {resolveBooleanish} from '../../utils'
89
import {computed, defineComponent, PropType} from 'vue'
9-
import type {ButtonVariant, InputSize, LinkTarget} from '../../types'
10+
import type {Booleanish, ButtonVariant, InputSize, LinkTarget} from '../../types'
1011
import {BLINK_PROPS} from '../BLink/BLink.vue'
1112
1213
export default defineComponent({
1314
props: {
1415
...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},
1718
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},
2021
rel: {type: String, default: null},
2122
size: {type: String as PropType<InputSize>},
22-
squared: {type: Boolean, default: false},
23+
squared: {type: Boolean as PropType<Booleanish>, default: false},
2324
tag: {type: String, default: 'button'},
2425
target: {type: String as PropType<LinkTarget>, default: '_self'},
2526
type: {type: String, default: 'button'},
2627
variant: {type: String as PropType<ButtonVariant>, default: 'secondary'},
2728
},
2829
emits: ['click', 'update:pressed'],
2930
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+
3037
// 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
3239
const isButton = props.tag === 'button' && !props.href && !props.to
3340
const isLink = !!(props.href || props.to)
3441
const isBLink = !!props.to
@@ -37,17 +44,17 @@ export default defineComponent({
3744
const classes = computed(() => ({
3845
[`btn-${props.variant}`]: props.variant,
3946
[`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,
4451
}))
4552
4653
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,
4956
'autocomplete': isToggle ? 'off' : null,
50-
'disabled': isButton ? props.disabled : null,
57+
'disabled': isButton ? disabledBoolean.value : null,
5158
'href': props.href,
5259
'rel': isLink ? props.rel : null,
5360
'role': nonStandardTag || isLink ? 'button' : null,
@@ -70,14 +77,14 @@ export default defineComponent({
7077
})
7178
7279
const clicked = (e: MouseEvent): void => {
73-
if (props.disabled) {
80+
if (disabledBoolean.value) {
7481
e.preventDefault()
7582
e.stopPropagation()
7683
return
7784
}
7885
emit('click', e)
7986
if (isToggle) {
80-
emit('update:pressed', !props.pressed)
87+
emit('update:pressed', !pressedBoolean.value)
8188
}
8289
}
8390

0 commit comments

Comments
 (0)