@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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "remove": "Remove"
3
+ }
@@ -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
  }
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "الإجراءات"
91
91
  },
92
+ "Tag": {
93
+ "remove": "إزالة"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} أسطر"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Aktionen"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Entfernen"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} Zeilen"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Actions"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Remove"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} lines"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Acciones"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Eliminar"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} líneas"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Actions"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Supprimer"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} lignes"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "क्रियाएं"
91
91
  },
92
+ "Tag": {
93
+ "remove": "हटाएं"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} पंक्तियाँ"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Tindakan"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Hapus"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} baris"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Azioni"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Rimuovi"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} righe"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "アクション"
91
91
  },
92
+ "Tag": {
93
+ "remove": "削除"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} 行"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "작업"
91
91
  },
92
+ "Tag": {
93
+ "remove": "제거"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count}줄"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Acties"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Verwijderen"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} regels"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Akcje"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Usuń"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} wierszy"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Ações"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Remover"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} linhas"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Действия"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Удалить"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} строк"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "การกระทำ"
91
91
  },
92
+ "Tag": {
93
+ "remove": "ลบ"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} บรรทัด"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "İşlemler"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Kaldır"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} satır"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "Hành động"
91
91
  },
92
+ "Tag": {
93
+ "remove": "Xóa"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} dòng"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "操作"
91
91
  },
92
+ "Tag": {
93
+ "remove": "移除"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} 行"
94
97
  },
@@ -89,6 +89,9 @@
89
89
  "StaticDataTable": {
90
90
  "actions": "操作"
91
91
  },
92
+ "Tag": {
93
+ "remove": "移除"
94
+ },
92
95
  "Textarea": {
93
96
  "lines": "{count} 行"
94
97
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjj/nuxt-layer-shadcn-ui",
3
- "version": "0.16.0",
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": "a4d32792ab79adc258207e940a1bdb76488de4d7"
45
+ "gitHead": "50e38d338fe80994bb04b57f1d9865ab830fe289"
46
46
  }