-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTwDismissableBadge.vue
101 lines (95 loc) · 2.08 KB
/
TwDismissableBadge.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<script setup lang="ts">
import { nanoid } from 'nanoid'
const props = defineProps({
id: {
type: String,
required: false,
default: '',
},
backgroundColor: {
type: String,
required: false,
default: 'blue-100',
},
darkBackgroundColor: {
type: String,
required: false,
default: 'blue-800',
},
textColor: {
type: String,
required: false,
default: 'blue-800',
},
darkTextColor: {
type: String,
required: false,
default: 'blue-100',
},
fontSize: {
type: String,
required: false,
default: 'base',
},
fontWeight: {
type: String,
required: false,
default: 'normal',
},
rounded: {
type: Boolean,
required: false,
default: true,
},
buttonHoverBackgroundColor: {
type: String,
required: false,
default: 'blue-200',
},
buttonDarkHoverBackgroundColor: {
type: String,
required: false,
default: 'blue-900',
},
})
const emit = defineEmits(['removed'])
const { t } = useI18n()
const computedId = toRef(props, 'id')
if (computedId.value.length === 0) {
computedId.value = nanoid()
}
const remove = (e: Event) => emit('removed', e)
</script>
<template>
<span
:id="computedId"
class="inline-flex items-center py-1 px-2"
:class="[
`bg-${backgroundColor}`,
`dark:bg-${darkBackgroundColor}`,
`text-${textColor}`,
`dark:text-${darkTextColor}`,
`text-${fontSize}`,
`font-${fontWeight}`,
rounded ? 'rounded-sm' : '',
]"
>
<slot />
<button
type="button"
class="bg-transparent inline-flex items-center p-0.5 ml-2"
:class="[
`hover:bg-${buttonHoverBackgroundColor}`,
`dark:hover:bg-${buttonDarkHoverBackgroundColor}`,
`text-${fontSize}`,
rounded ? 'rounded-sm' : '',
]"
:data-dismiss-target="`#${computedId}`"
:aria-label="t('button.remove')"
@click="remove"
>
<Icon icon="bi:x" :class="`text-${textColor} dark:text-${darkTextColor}`" />
<span class="sr-only">{{ t('button.remove') }}</span>
</button>
</span>
</template>