@bjj/nuxt-layer-shadcn-ui 0.16.0 → 0.17.0
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/AsyncDataTable/index.stories.ts +43 -0
- package/app/components/ui/AsyncDataTable/index.vue +2 -0
- package/app/components/ui/AsyncDataTable/types.ts +2 -0
- package/app/components/ui/DataTable/index.stories.ts +46 -0
- package/app/components/ui/DataTable/index.vue +19 -5
- package/app/components/ui/DataTable/types.ts +2 -0
- package/app/components/ui/StaticDataTable/index.stories.ts +43 -0
- package/app/components/ui/StaticDataTable/index.vue +2 -0
- package/app/components/ui/StaticDataTable/types.ts +2 -0
- 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
|
@@ -92,6 +92,7 @@ const meta = {
|
|
|
92
92
|
showPagination: { control: 'boolean' },
|
|
93
93
|
selectable: { control: 'boolean' },
|
|
94
94
|
rowSelectable: { control: false },
|
|
95
|
+
selectOnRowClick: { control: 'boolean' },
|
|
95
96
|
clickable: { control: 'boolean' },
|
|
96
97
|
hoverable: { control: 'boolean' },
|
|
97
98
|
batchActions: { control: 'object' },
|
|
@@ -109,6 +110,7 @@ const meta = {
|
|
|
109
110
|
showPagination: true,
|
|
110
111
|
selectable: false,
|
|
111
112
|
rowSelectable: undefined,
|
|
113
|
+
selectOnRowClick: false,
|
|
112
114
|
clickable: false,
|
|
113
115
|
hoverable: true,
|
|
114
116
|
batchActions: [],
|
|
@@ -173,6 +175,47 @@ export const WithBatchActions: Story = {
|
|
|
173
175
|
}),
|
|
174
176
|
}
|
|
175
177
|
|
|
178
|
+
/** `selectOnRowClick` lets a click anywhere on a row toggle its selection, not just the checkbox cell. */
|
|
179
|
+
export const SelectOnRowClick: Story = {
|
|
180
|
+
parameters: {
|
|
181
|
+
...noControls,
|
|
182
|
+
docs: {
|
|
183
|
+
source: {
|
|
184
|
+
code: `
|
|
185
|
+
<template>
|
|
186
|
+
<AsyncDataTable
|
|
187
|
+
:columns="columns"
|
|
188
|
+
:fetchMethod="mockFetch"
|
|
189
|
+
v-model:selection="selection"
|
|
190
|
+
selectable
|
|
191
|
+
selectOnRowClick
|
|
192
|
+
/>
|
|
193
|
+
</template>
|
|
194
|
+
`.trim(),
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
render: () => ({
|
|
199
|
+
components: { AsyncDataTable },
|
|
200
|
+
setup () {
|
|
201
|
+
const selection = ref<User[]>([])
|
|
202
|
+
return { columns, mockFetch, selection }
|
|
203
|
+
},
|
|
204
|
+
template: `
|
|
205
|
+
<AsyncDataTable
|
|
206
|
+
:columns="columns"
|
|
207
|
+
:fetchMethod="mockFetch"
|
|
208
|
+
v-model:selection="selection"
|
|
209
|
+
selectable
|
|
210
|
+
selectOnRowClick
|
|
211
|
+
/>
|
|
212
|
+
<div class="mt-2 text-sm text-muted-foreground">
|
|
213
|
+
Selected: {{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
|
|
214
|
+
</div>
|
|
215
|
+
`,
|
|
216
|
+
}),
|
|
217
|
+
}
|
|
218
|
+
|
|
176
219
|
/** `rowSelectable` locks individual rows out of selection: their checkbox is disabled and "select all" skips them. */
|
|
177
220
|
export const DisabledRows: Story = {
|
|
178
221
|
parameters: {
|
|
@@ -18,6 +18,7 @@ const props = withDefaults(defineProps<AsyncDataTableProps<TData>>(), {
|
|
|
18
18
|
showPagination: true,
|
|
19
19
|
selectable: false,
|
|
20
20
|
rowSelectable: undefined,
|
|
21
|
+
selectOnRowClick: false,
|
|
21
22
|
clickable: false,
|
|
22
23
|
hoverable: true,
|
|
23
24
|
batchActions: () => [],
|
|
@@ -338,6 +339,7 @@ onMounted(() => {
|
|
|
338
339
|
:loading
|
|
339
340
|
:selectionMode="showSelectionColumn ? 'multiple' : undefined"
|
|
340
341
|
:rowSelectable
|
|
342
|
+
:selectOnRowClick
|
|
341
343
|
:clickable
|
|
342
344
|
:hoverable
|
|
343
345
|
:sortBy="sortState.sortBy"
|
|
@@ -46,6 +46,8 @@ export interface AsyncDataTableProps<T = Record<string, any>> {
|
|
|
46
46
|
selectable?: boolean
|
|
47
47
|
/** Per-row selection gate; `index` is relative to the current page. Rows returning false get a disabled checkbox and are skipped by "select all". */
|
|
48
48
|
rowSelectable?: DataTableRowSelectable<T>
|
|
49
|
+
/** Whether clicking anywhere on a row toggles its selection. Default: false — selection toggles only from the selection cell, leaving row clicks to `@rowClick`. */
|
|
50
|
+
selectOnRowClick?: boolean
|
|
49
51
|
/** Whether rows are clickable (shows pointer cursor and pairs with `@rowClick`) */
|
|
50
52
|
clickable?: boolean
|
|
51
53
|
/** Row hover highlight. Default: true. Turn it off where the cells hold form controls — a tinted row reads as "not editable" there. Selected and active rows keep their highlight either way. */
|
|
@@ -79,6 +79,7 @@ const meta = {
|
|
|
79
79
|
argTypes: {
|
|
80
80
|
selectionMode: { control: 'select', options: [ undefined, 'single', 'multiple' ]},
|
|
81
81
|
rowSelectable: { control: false },
|
|
82
|
+
selectOnRowClick: { control: 'boolean' },
|
|
82
83
|
loading: { control: 'boolean' },
|
|
83
84
|
clickable: { control: 'boolean' },
|
|
84
85
|
hoverable: { control: 'boolean' },
|
|
@@ -87,6 +88,7 @@ const meta = {
|
|
|
87
88
|
args: {
|
|
88
89
|
selectionMode: undefined,
|
|
89
90
|
rowSelectable: undefined,
|
|
91
|
+
selectOnRowClick: false,
|
|
90
92
|
loading: false,
|
|
91
93
|
clickable: false,
|
|
92
94
|
hoverable: true,
|
|
@@ -530,6 +532,50 @@ export const DisabledRows: Story = {
|
|
|
530
532
|
}),
|
|
531
533
|
}
|
|
532
534
|
|
|
535
|
+
/** `selectOnRowClick` lets a click anywhere on a row toggle its selection, not just the checkbox cell. */
|
|
536
|
+
export const SelectOnRowClick: Story = {
|
|
537
|
+
parameters: {
|
|
538
|
+
...noControls,
|
|
539
|
+
docs: {
|
|
540
|
+
source: {
|
|
541
|
+
code: `
|
|
542
|
+
<template>
|
|
543
|
+
<DataTable
|
|
544
|
+
:data="data"
|
|
545
|
+
:columns="columns"
|
|
546
|
+
selectionMode="multiple"
|
|
547
|
+
selectOnRowClick
|
|
548
|
+
v-model:selection="selection"
|
|
549
|
+
/>
|
|
550
|
+
</template>
|
|
551
|
+
`.trim(),
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
render: () => ({
|
|
556
|
+
components: { DataTable: DataTable as any },
|
|
557
|
+
setup () {
|
|
558
|
+
const selection = ref<User[]>([])
|
|
559
|
+
return { data: sampleData, basicColumns, selection }
|
|
560
|
+
},
|
|
561
|
+
template: `
|
|
562
|
+
<div class="w-full">
|
|
563
|
+
<DataTable
|
|
564
|
+
:data="data"
|
|
565
|
+
:columns="basicColumns"
|
|
566
|
+
selectionMode="multiple"
|
|
567
|
+
selectOnRowClick
|
|
568
|
+
v-model:selection="selection"
|
|
569
|
+
/>
|
|
570
|
+
<div class="mt-2 text-sm text-muted-foreground">
|
|
571
|
+
Click anywhere on a row — Selected:
|
|
572
|
+
{{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
|
|
573
|
+
</div>
|
|
574
|
+
</div>
|
|
575
|
+
`,
|
|
576
|
+
}),
|
|
577
|
+
}
|
|
578
|
+
|
|
533
579
|
export const FrozenColumns: Story = {
|
|
534
580
|
parameters: {
|
|
535
581
|
...noControls,
|
|
@@ -23,6 +23,7 @@ const props = withDefaults(defineProps<DataTableProps<TData>>(), {
|
|
|
23
23
|
columns: () => [],
|
|
24
24
|
selectionMode: undefined,
|
|
25
25
|
rowSelectable: undefined,
|
|
26
|
+
selectOnRowClick: false,
|
|
26
27
|
sortBy: undefined,
|
|
27
28
|
sortOrder: undefined,
|
|
28
29
|
loading: false,
|
|
@@ -100,9 +101,12 @@ function isRowSelected (row: TData): boolean {
|
|
|
100
101
|
return toRaw(selection.value) === toRaw(row)
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
//
|
|
104
|
+
// Whether a click on the row body toggles the row's selection.
|
|
105
|
+
const rowClickSelects = computed(() => showSelectionColumn.value && props.selectOnRowClick)
|
|
106
|
+
|
|
107
|
+
// Both row-click selection and the `clickable` contract make a row respond to a click.
|
|
104
108
|
function isRowClickable (row: TData, index: number): boolean {
|
|
105
|
-
return props.clickable || (
|
|
109
|
+
return props.clickable || (rowClickSelects.value && isRowSelectable(row, index))
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
function isRowActive (row: TData): boolean {
|
|
@@ -124,7 +128,13 @@ function toggleRow (row: TData, index: number) {
|
|
|
124
128
|
|
|
125
129
|
function onRowClick (row: TData, index: number, event: MouseEvent) {
|
|
126
130
|
emit('rowClick', row, index, event)
|
|
127
|
-
if (
|
|
131
|
+
if (rowClickSelects.value) toggleRow(row, index)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// The whole selection cell is the hit target, not just the 16px checkbox.
|
|
135
|
+
// A click on the checkbox itself is already handled by its own update event.
|
|
136
|
+
function onSelectionCellClick (row: TData, index: number, event: MouseEvent) {
|
|
137
|
+
if (event.target === event.currentTarget) toggleRow(row, index)
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
// -- Sorting --
|
|
@@ -440,10 +450,14 @@ defineExpose({
|
|
|
440
450
|
<!-- Selection cell: stop click to prevent double toggle with row click -->
|
|
441
451
|
<TableCell
|
|
442
452
|
v-if="showSelectionColumn"
|
|
443
|
-
:class="cn(
|
|
453
|
+
:class="cn(
|
|
454
|
+
stickyLeftClass,
|
|
455
|
+
selectionColumnClass,
|
|
456
|
+
isRowSelectable(row, index) && 'cursor-pointer',
|
|
457
|
+
)"
|
|
444
458
|
:style="selectionColumnStyle"
|
|
445
459
|
:data-shadow="selectionColumnShadowDir"
|
|
446
|
-
@click.stop
|
|
460
|
+
@click.stop="onSelectionCellClick(row, index, $event)"
|
|
447
461
|
>
|
|
448
462
|
<Checkbox
|
|
449
463
|
:modelValue="isRowSelected(row)"
|
|
@@ -46,6 +46,8 @@ export interface DataTableProps<T = Record<string, any>> {
|
|
|
46
46
|
selectionMode?: DataTableSelectionMode
|
|
47
47
|
/** Per-row selection gate. Rows returning false get a disabled checkbox and ignore row-click selection; a selection they already hold is left untouched. */
|
|
48
48
|
rowSelectable?: DataTableRowSelectable<T>
|
|
49
|
+
/** Whether clicking anywhere on a row toggles its selection. Default: false — selection toggles only from the selection cell, leaving row clicks to `@rowClick`. */
|
|
50
|
+
selectOnRowClick?: boolean
|
|
49
51
|
/** Row to highlight as active. Independent from selection; uses the same highlight style. */
|
|
50
52
|
active?: T | null
|
|
51
53
|
/** Current sort field */
|
|
@@ -78,6 +78,7 @@ const meta = {
|
|
|
78
78
|
showPagination: { control: 'boolean' },
|
|
79
79
|
selectable: { control: 'boolean' },
|
|
80
80
|
rowSelectable: { control: false },
|
|
81
|
+
selectOnRowClick: { control: 'boolean' },
|
|
81
82
|
clickable: { control: 'boolean' },
|
|
82
83
|
hoverable: { control: 'boolean' },
|
|
83
84
|
batchActions: { control: 'object' },
|
|
@@ -94,6 +95,7 @@ const meta = {
|
|
|
94
95
|
showPagination: true,
|
|
95
96
|
selectable: false,
|
|
96
97
|
rowSelectable: undefined,
|
|
98
|
+
selectOnRowClick: false,
|
|
97
99
|
clickable: false,
|
|
98
100
|
hoverable: true,
|
|
99
101
|
batchActions: [],
|
|
@@ -155,6 +157,47 @@ export const WithBatchActions: Story = {
|
|
|
155
157
|
}),
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
/** `selectOnRowClick` lets a click anywhere on a row toggle its selection, not just the checkbox cell. */
|
|
161
|
+
export const SelectOnRowClick: Story = {
|
|
162
|
+
parameters: {
|
|
163
|
+
...noControls,
|
|
164
|
+
docs: {
|
|
165
|
+
source: {
|
|
166
|
+
code: `
|
|
167
|
+
<template>
|
|
168
|
+
<StaticDataTable
|
|
169
|
+
:data="users"
|
|
170
|
+
:columns="columns"
|
|
171
|
+
v-model:selection="selection"
|
|
172
|
+
selectable
|
|
173
|
+
selectOnRowClick
|
|
174
|
+
/>
|
|
175
|
+
</template>
|
|
176
|
+
`.trim(),
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
render: () => ({
|
|
181
|
+
components: { StaticDataTable },
|
|
182
|
+
setup () {
|
|
183
|
+
const selection = ref<User[]>([])
|
|
184
|
+
return { users: allUsers, columns, selection }
|
|
185
|
+
},
|
|
186
|
+
template: `
|
|
187
|
+
<StaticDataTable
|
|
188
|
+
:data="users"
|
|
189
|
+
:columns="columns"
|
|
190
|
+
v-model:selection="selection"
|
|
191
|
+
selectable
|
|
192
|
+
selectOnRowClick
|
|
193
|
+
/>
|
|
194
|
+
<div class="mt-2 text-sm text-muted-foreground">
|
|
195
|
+
Selected: {{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
|
|
196
|
+
</div>
|
|
197
|
+
`,
|
|
198
|
+
}),
|
|
199
|
+
}
|
|
200
|
+
|
|
158
201
|
/** `rowSelectable` locks individual rows out of selection: their checkbox is disabled and "select all" skips them. */
|
|
159
202
|
export const DisabledRows: Story = {
|
|
160
203
|
parameters: {
|
|
@@ -17,6 +17,7 @@ const props = withDefaults(defineProps<StaticDataTableProps<TData>>(), {
|
|
|
17
17
|
showPagination: true,
|
|
18
18
|
selectable: false,
|
|
19
19
|
rowSelectable: undefined,
|
|
20
|
+
selectOnRowClick: false,
|
|
20
21
|
clickable: false,
|
|
21
22
|
hoverable: true,
|
|
22
23
|
batchActions: () => [],
|
|
@@ -205,6 +206,7 @@ function onSortOrderUpdate (value: number | null) {
|
|
|
205
206
|
:columns="columns"
|
|
206
207
|
:selectionMode="showSelectionColumn ? 'multiple' : undefined"
|
|
207
208
|
:rowSelectable="rowSelectable"
|
|
209
|
+
:selectOnRowClick="selectOnRowClick"
|
|
208
210
|
:clickable="clickable"
|
|
209
211
|
:hoverable="hoverable"
|
|
210
212
|
:sortBy="sortState.sortBy"
|
|
@@ -30,6 +30,8 @@ export interface StaticDataTableProps<T = Record<string, any>> {
|
|
|
30
30
|
selectable?: boolean
|
|
31
31
|
/** Per-row selection gate; `index` is relative to the current page. Rows returning false get a disabled checkbox and are skipped by "select all". */
|
|
32
32
|
rowSelectable?: DataTableRowSelectable<T>
|
|
33
|
+
/** Whether clicking anywhere on a row toggles its selection. Default: false — selection toggles only from the selection cell, leaving row clicks to `@rowClick`. */
|
|
34
|
+
selectOnRowClick?: boolean
|
|
33
35
|
/** Whether rows are clickable (shows pointer cursor and pairs with `@rowClick`) */
|
|
34
36
|
clickable?: boolean
|
|
35
37
|
/** Row hover highlight. Default: true. Turn it off where the cells hold form controls — a tinted row reads as "not editable" there. Selected and active rows keep their highlight either way. */
|
|
@@ -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.
|
|
3
|
+
"version": "0.17.0",
|
|
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": "baefb8dd7a1d57a9a3b34fe53bda45a845153b2c"
|
|
46
46
|
}
|