|
21 | 21 | }" |
22 | 22 | :aria-controls="id" |
23 | 23 | :aria-describedby="taglabelId" |
24 | | - @click="$emit('remove', tagText)" |
| 24 | + @click="emit('remove', tagText)" |
25 | 25 | ></button> |
26 | 26 | </component> |
27 | 27 | </template> |
28 | 28 |
|
29 | 29 | <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', |
42 | 53 | }) |
43 | 54 |
|
44 | | -defineEmits(['remove']) |
| 55 | +interface BFormTagEmits { |
| 56 | + (e: 'remove', value?: VNodeNormalizedChildren): void |
| 57 | +} |
| 58 | +
|
| 59 | +const emit = defineEmits<BFormTagEmits>() |
45 | 60 |
|
46 | 61 | const slots = useSlots() |
47 | 62 |
|
48 | | -const tagText = computed(() => slots.default?.()[0].children || props.title) |
| 63 | +const tagText = computed<string>( |
| 64 | + () => (slots.default?.()[0].children?.toString() || props.title) ?? '' |
| 65 | +) |
49 | 66 | const computedId = useId(props.id) |
50 | | -const taglabelId = computed(() => `${computedId.value}taglabel__`) |
| 67 | +const taglabelId = computed<string>(() => `${computedId.value}taglabel__`) |
51 | 68 |
|
52 | 69 | const classes = computed(() => [ |
53 | 70 | `bg-${props.variant}`, |
|
0 commit comments