Skip to content

Commit 3cf4d09

Browse files
author
issayah
committed
Form tag script setup conversion Be careful!READPR
1 parent c0b9506 commit 3cf4d09

File tree

3 files changed

+204
-136
lines changed

3 files changed

+204
-136
lines changed

src/components/BFormTags/BFormTag.vue

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,50 @@
2121
}"
2222
:aria-controls="id"
2323
:aria-describedby="taglabelId"
24-
@click="$emit('remove', tagText)"
24+
@click="emit('remove', tagText)"
2525
></button>
2626
</component>
2727
</template>
2828

2929
<script setup lang="ts">
30-
import {computed, useSlots} from 'vue'
31-
import useId from '../../composables/useId'
32-
33-
const props = defineProps({
34-
disabled: {type: Boolean, default: false},
35-
id: {type: String},
36-
noRemove: {type: Boolean, default: false},
37-
pill: {type: Boolean, default: false},
38-
removeLabel: {type: String, default: 'Remove tag'},
39-
tag: {type: String, default: 'span'},
40-
title: {type: String},
41-
variant: {type: String, default: 'secondary'},
30+
// import type {BFormTagEmits, BFormTagProps} from '@/types/components'
31+
import {computed, useSlots, VNodeNormalizedChildren} from 'vue'
32+
import useId from '@/composables/useId'
33+
import type {ColorVariant} from '@/types'
34+
35+
interface BFormTagProps {
36+
id?: string
37+
title?: string
38+
disabled?: boolean
39+
noRemove?: boolean
40+
pill?: boolean
41+
removeLabel?: string
42+
tag?: string
43+
variant?: ColorVariant
44+
}
45+
46+
const props = withDefaults(defineProps<BFormTagProps>(), {
47+
disabled: false,
48+
noRemove: false,
49+
pill: false,
50+
removeLabel: 'Remove tag',
51+
tag: 'span',
52+
variant: 'secondary',
4253
})
4354
44-
defineEmits(['remove'])
55+
interface BFormTagEmits {
56+
(e: 'remove', value?: VNodeNormalizedChildren): void
57+
}
58+
59+
const emit = defineEmits<BFormTagEmits>()
4560
4661
const slots = useSlots()
4762
48-
const tagText = computed(() => slots.default?.()[0].children || props.title)
63+
const tagText = computed<string>(
64+
() => (slots.default?.()[0].children?.toString() || props.title) ?? ''
65+
)
4966
const computedId = useId(props.id)
50-
const taglabelId = computed(() => `${computedId.value}taglabel__`)
67+
const taglabelId = computed<string>(() => `${computedId.value}taglabel__`)
5168
5269
const classes = computed(() => [
5370
`bg-${props.variant}`,

0 commit comments

Comments
 (0)