@bjj/nuxt-layer-shadcn-ui 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/components/ui/Tag/en.json +3 -0
- package/app/components/ui/Tag/index.stories.ts +145 -0
- package/app/components/ui/Tag/index.vue +40 -0
- package/app/components/ui/Tag/types.ts +4 -0
- package/i18n/messages/ar.json +3 -0
- package/i18n/messages/de.json +3 -0
- package/i18n/messages/en.json +3 -0
- package/i18n/messages/es.json +3 -0
- package/i18n/messages/fr.json +3 -0
- package/i18n/messages/hi.json +3 -0
- package/i18n/messages/id.json +3 -0
- package/i18n/messages/it.json +3 -0
- package/i18n/messages/ja.json +3 -0
- package/i18n/messages/ko.json +3 -0
- package/i18n/messages/nl.json +3 -0
- package/i18n/messages/pl.json +3 -0
- package/i18n/messages/pt.json +3 -0
- package/i18n/messages/ru.json +3 -0
- package/i18n/messages/th.json +3 -0
- package/i18n/messages/tr.json +3 -0
- package/i18n/messages/vi.json +3 -0
- package/i18n/messages/zh-CN.json +3 -0
- package/i18n/messages/zh-TW.json +3 -0
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3'
|
|
2
2
|
import type { TagColor, TagSize, TagVariant } from './types'
|
|
3
|
+
import EventLog from '#storybook/EventLog.vue'
|
|
3
4
|
import Tag from './index.vue'
|
|
4
5
|
|
|
5
6
|
const colors: TagColor[] = [ 'default', 'primary', 'success', 'info', 'help', 'warn', 'danger' ]
|
|
@@ -13,11 +14,15 @@ const meta = {
|
|
|
13
14
|
color: { control: 'select', options: colors },
|
|
14
15
|
variant: { control: 'select', options: variants },
|
|
15
16
|
size: { control: 'select', options: sizes },
|
|
17
|
+
closable: { control: 'boolean' },
|
|
18
|
+
closeLabel: { control: 'text' },
|
|
16
19
|
},
|
|
17
20
|
args: {
|
|
18
21
|
color: 'default',
|
|
19
22
|
variant: 'soft',
|
|
20
23
|
size: 'md',
|
|
24
|
+
closable: false,
|
|
25
|
+
closeLabel: '',
|
|
21
26
|
},
|
|
22
27
|
render: args => ({
|
|
23
28
|
components: { Tag },
|
|
@@ -142,3 +147,143 @@ export const VariantColorMatrix: Story = {
|
|
|
142
147
|
`,
|
|
143
148
|
}),
|
|
144
149
|
}
|
|
150
|
+
|
|
151
|
+
export const Closable: Story = {
|
|
152
|
+
parameters: noControls,
|
|
153
|
+
args: {
|
|
154
|
+
closable: true,
|
|
155
|
+
closeLabel: 'Remove filter',
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const ClosableSizes: Story = {
|
|
160
|
+
parameters: {
|
|
161
|
+
...noControls,
|
|
162
|
+
docs: {
|
|
163
|
+
source: {
|
|
164
|
+
code: `
|
|
165
|
+
<template>
|
|
166
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
167
|
+
<Tag v-for="s in sizes" :key="s" :size="s" closable>{{ s }}</Tag>
|
|
168
|
+
</div>
|
|
169
|
+
</template>
|
|
170
|
+
`.trim(),
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
render: () => ({
|
|
175
|
+
components: { Tag },
|
|
176
|
+
setup: () => ({ sizes }),
|
|
177
|
+
template: `
|
|
178
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
179
|
+
<Tag v-for="s in sizes" :key="s" :size="s" closable>{{ s }}</Tag>
|
|
180
|
+
</div>
|
|
181
|
+
`,
|
|
182
|
+
}),
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export const ClosableVariantColorMatrix: Story = {
|
|
186
|
+
parameters: {
|
|
187
|
+
...noControls,
|
|
188
|
+
docs: {
|
|
189
|
+
source: {
|
|
190
|
+
code: `
|
|
191
|
+
<template>
|
|
192
|
+
<div class="space-y-3">
|
|
193
|
+
<div v-for="v in variants" :key="v" class="flex flex-wrap items-center gap-3">
|
|
194
|
+
<span class="w-20 text-sm text-muted-foreground">{{ v }}</span>
|
|
195
|
+
<Tag v-for="c in colors" :key="c" :color="c" :variant="v" closable>{{ c }}</Tag>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
</template>
|
|
199
|
+
`.trim(),
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
render: () => ({
|
|
204
|
+
components: { Tag },
|
|
205
|
+
setup: () => ({ colors, variants }),
|
|
206
|
+
template: `
|
|
207
|
+
<div class="space-y-3">
|
|
208
|
+
<div v-for="v in variants" :key="v" class="flex flex-wrap items-center gap-3">
|
|
209
|
+
<span class="w-20 text-sm text-muted-foreground">{{ v }}</span>
|
|
210
|
+
<Tag v-for="c in colors" :key="c" :color="c" :variant="v" closable>{{ c }}</Tag>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
`,
|
|
214
|
+
}),
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export const EventHandling: Story = {
|
|
218
|
+
parameters: {
|
|
219
|
+
...noControls,
|
|
220
|
+
docs: {
|
|
221
|
+
source: {
|
|
222
|
+
code: `
|
|
223
|
+
<script setup lang="ts">
|
|
224
|
+
const filters = ref([ 'Status: Active', 'Plan: Pro', 'Region: Tokyo' ])
|
|
225
|
+
|
|
226
|
+
function remove (name: string) {
|
|
227
|
+
filters.value = filters.value.filter(f => f !== name)
|
|
228
|
+
}
|
|
229
|
+
</script>
|
|
230
|
+
|
|
231
|
+
<template>
|
|
232
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
233
|
+
<Tag
|
|
234
|
+
v-for="name in filters"
|
|
235
|
+
:key="name"
|
|
236
|
+
color="info"
|
|
237
|
+
class="rounded-full"
|
|
238
|
+
closable
|
|
239
|
+
:close-label="'Remove ' + name"
|
|
240
|
+
@close="remove(name)"
|
|
241
|
+
>
|
|
242
|
+
{{ name }}
|
|
243
|
+
</Tag>
|
|
244
|
+
</div>
|
|
245
|
+
</template>
|
|
246
|
+
`.trim(),
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
render: () => ({
|
|
251
|
+
components: { Tag, EventLog },
|
|
252
|
+
setup () {
|
|
253
|
+
const initial = [ 'Status: Active', 'Plan: Pro', 'Region: Tokyo' ]
|
|
254
|
+
const filters = ref([ ...initial ])
|
|
255
|
+
const remove = (name: string) => {
|
|
256
|
+
filters.value = filters.value.filter(f => f !== name)
|
|
257
|
+
}
|
|
258
|
+
const reset = () => {
|
|
259
|
+
filters.value = [ ...initial ]
|
|
260
|
+
}
|
|
261
|
+
return { filters, remove, reset }
|
|
262
|
+
},
|
|
263
|
+
template: `
|
|
264
|
+
<EventLog v-slot="{ record }">
|
|
265
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
266
|
+
<Tag
|
|
267
|
+
v-for="name in filters"
|
|
268
|
+
:key="name"
|
|
269
|
+
color="info"
|
|
270
|
+
class="rounded-full"
|
|
271
|
+
closable
|
|
272
|
+
:close-label="'Remove ' + name"
|
|
273
|
+
@close="record('close', name); remove(name)"
|
|
274
|
+
>
|
|
275
|
+
{{ name }}
|
|
276
|
+
</Tag>
|
|
277
|
+
<button
|
|
278
|
+
v-if="!filters.length"
|
|
279
|
+
type="button"
|
|
280
|
+
class="text-sm text-muted-foreground underline"
|
|
281
|
+
@click="reset"
|
|
282
|
+
>
|
|
283
|
+
Reset
|
|
284
|
+
</button>
|
|
285
|
+
</div>
|
|
286
|
+
</EventLog>
|
|
287
|
+
`,
|
|
288
|
+
}),
|
|
289
|
+
}
|
|
@@ -106,17 +106,44 @@ const tagVariants = cva(
|
|
|
106
106
|
},
|
|
107
107
|
)
|
|
108
108
|
|
|
109
|
+
// Remove button: sized from the tag's own size so it fits the text line
|
|
110
|
+
// without touching the tag's padding. The negative end margin pulls it into
|
|
111
|
+
// the padding by a fixed amount, offsetting the whitespace around the × glyph
|
|
112
|
+
// so both sides look even whatever padding the tag has. Colors derive from
|
|
113
|
+
// `currentColor`, so hover / focus follow every color × variant combination.
|
|
114
|
+
const closeClass = `
|
|
115
|
+
-me-1 inline-flex shrink-0 cursor-pointer items-center justify-center
|
|
116
|
+
rounded-full
|
|
117
|
+
opacity-60 transition
|
|
118
|
+
hover:bg-current/15 hover:opacity-100
|
|
119
|
+
focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-current/50
|
|
120
|
+
focus-visible:outline-none
|
|
121
|
+
`
|
|
122
|
+
|
|
123
|
+
const closeSizes = {
|
|
124
|
+
sm: { button: 'size-3.5', icon: 'size-2.5' },
|
|
125
|
+
md: { button: 'size-4', icon: 'size-3' },
|
|
126
|
+
} as const
|
|
127
|
+
|
|
109
128
|
const props = withDefaults(defineProps<TagProps>(), {
|
|
110
129
|
color: 'default',
|
|
111
130
|
variant: 'soft',
|
|
112
131
|
size: 'md',
|
|
132
|
+
closable: false,
|
|
133
|
+
closeLabel: undefined,
|
|
113
134
|
class: undefined,
|
|
114
135
|
})
|
|
115
136
|
|
|
137
|
+
const emit = defineEmits<{
|
|
138
|
+
close: [event: MouseEvent]
|
|
139
|
+
}>()
|
|
140
|
+
|
|
116
141
|
defineSlots<{
|
|
117
142
|
default?: () => any
|
|
118
143
|
}>()
|
|
119
144
|
|
|
145
|
+
const T = useTranslations('components.ui.Tag')
|
|
146
|
+
|
|
120
147
|
const mergedClass = computed(() =>
|
|
121
148
|
cn(tagVariants({ color: props.color, variant: props.variant, size: props.size }), props.class),
|
|
122
149
|
)
|
|
@@ -125,5 +152,18 @@ const mergedClass = computed(() =>
|
|
|
125
152
|
<template>
|
|
126
153
|
<span :class="mergedClass">
|
|
127
154
|
<slot />
|
|
155
|
+
<button
|
|
156
|
+
v-if="closable"
|
|
157
|
+
type="button"
|
|
158
|
+
data-slot="tag-close"
|
|
159
|
+
:class="[ closeClass, closeSizes[size].button ]"
|
|
160
|
+
:aria-label="closeLabel || T('remove')"
|
|
161
|
+
@click="emit('close', $event)"
|
|
162
|
+
>
|
|
163
|
+
<Icon
|
|
164
|
+
name="x"
|
|
165
|
+
:class="closeSizes[size].icon"
|
|
166
|
+
/>
|
|
167
|
+
</button>
|
|
128
168
|
</span>
|
|
129
169
|
</template>
|
|
@@ -6,5 +6,9 @@ export interface TagProps {
|
|
|
6
6
|
color?: TagColor
|
|
7
7
|
variant?: TagVariant
|
|
8
8
|
size?: TagSize
|
|
9
|
+
/** Render a remove (×) button after the content; clicking it emits `close`. */
|
|
10
|
+
closable?: boolean
|
|
11
|
+
/** Accessible name of the remove button. Defaults to the localized "Remove". */
|
|
12
|
+
closeLabel?: string
|
|
9
13
|
class?: ClassValue
|
|
10
14
|
}
|
package/i18n/messages/ar.json
CHANGED
package/i18n/messages/de.json
CHANGED
package/i18n/messages/en.json
CHANGED
package/i18n/messages/es.json
CHANGED
package/i18n/messages/fr.json
CHANGED
package/i18n/messages/hi.json
CHANGED
package/i18n/messages/id.json
CHANGED
package/i18n/messages/it.json
CHANGED
package/i18n/messages/ja.json
CHANGED
package/i18n/messages/ko.json
CHANGED
package/i18n/messages/nl.json
CHANGED
package/i18n/messages/pl.json
CHANGED
package/i18n/messages/pt.json
CHANGED
package/i18n/messages/ru.json
CHANGED
package/i18n/messages/th.json
CHANGED
package/i18n/messages/tr.json
CHANGED
package/i18n/messages/vi.json
CHANGED
package/i18n/messages/zh-CN.json
CHANGED
package/i18n/messages/zh-TW.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Nuxt layer providing shadcn-vue based UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"vue-i18n": "^11",
|
|
43
43
|
"vue-router": "^4 || ^5"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "50e38d338fe80994bb04b57f1d9865ab830fe289"
|
|
46
46
|
}
|