@bjj/nuxt-layer-shadcn-ui 0.11.17 → 0.12.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/AlertDialog/index.stories.ts +60 -0
- package/app/components/ui/AlertDialog/index.vue +36 -11
- package/app/components/ui/Drawer/index.stories.ts +2 -0
- package/app/components/ui/Drawer/index.vue +43 -16
- package/app/components/ui/Drawer/types.ts +1 -0
- package/app/components/ui/Modal/index.stories.ts +2 -0
- package/app/components/ui/Modal/index.vue +45 -18
- package/app/components/ui/Modal/types.ts +1 -0
- package/app/composables/useDialog.ts +15 -12
- package/package.json +2 -2
|
@@ -150,6 +150,66 @@ async function handleDestroy () {
|
|
|
150
150
|
}),
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
export const BeforeClose: Story = {
|
|
154
|
+
parameters: {
|
|
155
|
+
...noControls,
|
|
156
|
+
docs: {
|
|
157
|
+
source: {
|
|
158
|
+
code: `
|
|
159
|
+
<script setup lang="ts">
|
|
160
|
+
const { destroy } = useDialog()
|
|
161
|
+
const result = ref('')
|
|
162
|
+
|
|
163
|
+
async function handleDelete () {
|
|
164
|
+
const ok = await destroy({
|
|
165
|
+
title: 'Delete Item',
|
|
166
|
+
message: 'This will call the API before closing.',
|
|
167
|
+
beforeClose: async (action) => {
|
|
168
|
+
// Only intercept confirm; cancel / close stay instant.
|
|
169
|
+
if (action !== 'confirm') return
|
|
170
|
+
// Returning a Promise keeps the dialog open and shows loading until it settles.
|
|
171
|
+
await new Promise((resolve) => setTimeout(resolve, 1500))
|
|
172
|
+
},
|
|
173
|
+
})
|
|
174
|
+
result.value = \`destroy → \${ok}\`
|
|
175
|
+
}
|
|
176
|
+
</script>
|
|
177
|
+
|
|
178
|
+
<template>
|
|
179
|
+
<Button variant="destructive" @click="handleDelete">Delete with async</Button>
|
|
180
|
+
<div v-if="result">Result: {{ result }}</div>
|
|
181
|
+
</template>
|
|
182
|
+
`.trim(),
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
render: () => ({
|
|
187
|
+
components: { Button },
|
|
188
|
+
setup () {
|
|
189
|
+
const { destroy } = useDialog()
|
|
190
|
+
const result = ref('')
|
|
191
|
+
async function handleDelete () {
|
|
192
|
+
const ok = await destroy({
|
|
193
|
+
title: 'Delete Item',
|
|
194
|
+
message: 'This will call the API before closing.',
|
|
195
|
+
beforeClose: async action => {
|
|
196
|
+
if (action !== 'confirm') return
|
|
197
|
+
await new Promise(resolve => setTimeout(resolve, 1500))
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
result.value = `destroy → ${ok}`
|
|
201
|
+
}
|
|
202
|
+
return { handleDelete, result }
|
|
203
|
+
},
|
|
204
|
+
template: `
|
|
205
|
+
<div class="space-y-4">
|
|
206
|
+
<Button variant="destructive" @click="handleDelete">Delete with async</Button>
|
|
207
|
+
<div v-if="result" class="rounded-md bg-muted p-4 text-sm">Result: {{ result }}</div>
|
|
208
|
+
</div>
|
|
209
|
+
`,
|
|
210
|
+
}),
|
|
211
|
+
}
|
|
212
|
+
|
|
153
213
|
export const MultiDialog: Story = {
|
|
154
214
|
parameters: {
|
|
155
215
|
...noControls,
|
|
@@ -1,28 +1,53 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
const { current, isOpen, isActive, close, onClosed } = useDialogState()
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const modalProps = computed<Record<string, unknown> | undefined>(() => {
|
|
5
|
+
const options = current.value?.options as Record<string, unknown> | undefined
|
|
6
|
+
if (!options) return undefined
|
|
7
|
+
// `content` (string | VNode | HTMLElement) wins over the `message` shorthand;
|
|
8
|
+
// strip `message` so it never leaks onto the DOM as an unknown attribute.
|
|
9
|
+
const { message, ...rest } = options
|
|
10
|
+
return { ...rest, content: rest.content ?? message }
|
|
11
|
+
})
|
|
12
|
+
|
|
5
13
|
const isDestructive = computed(() => {
|
|
6
14
|
const type = current.value?.options.type
|
|
7
15
|
return type === 'danger' || type === 'error'
|
|
8
16
|
})
|
|
17
|
+
// danger/error dialogs get a destructive confirm button unless overridden
|
|
18
|
+
const confirmVariant = computed(
|
|
19
|
+
() => current.value?.options.confirmVariant ?? (isDestructive.value ? 'destructive' : undefined),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
// Modal's `@close` fires only after `beforeClose` allows it, but carries no
|
|
23
|
+
// action — so we remember the intent and resolve on the actual close. `@open`
|
|
24
|
+
// resets it per dialog: each one defaults to a cancel (X / Esc / outside click).
|
|
25
|
+
let confirmed = false
|
|
26
|
+
function onOpen () {
|
|
27
|
+
confirmed = false
|
|
28
|
+
}
|
|
29
|
+
function onConfirm () {
|
|
30
|
+
confirmed = true
|
|
31
|
+
}
|
|
32
|
+
function onCancel () {
|
|
33
|
+
confirmed = false
|
|
34
|
+
}
|
|
35
|
+
function onClose () {
|
|
36
|
+
close(confirmed)
|
|
37
|
+
}
|
|
9
38
|
</script>
|
|
10
39
|
|
|
11
40
|
<template>
|
|
12
41
|
<Modal
|
|
13
42
|
v-if="isActive"
|
|
43
|
+
v-bind="modalProps"
|
|
14
44
|
data-alert-dialog
|
|
15
45
|
:visible="isOpen"
|
|
16
|
-
:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
:confirmText="current?.options.acceptLabel || undefined"
|
|
22
|
-
:confirmVariant="isDestructive ? 'destructive' : 'default'"
|
|
23
|
-
@confirm="close(true)"
|
|
24
|
-
@cancel="close(false)"
|
|
25
|
-
@close="close(false)"
|
|
46
|
+
:confirmVariant="confirmVariant"
|
|
47
|
+
@open="onOpen"
|
|
48
|
+
@confirm="onConfirm"
|
|
49
|
+
@cancel="onCancel"
|
|
50
|
+
@close="onClose"
|
|
26
51
|
@closed="onClosed"
|
|
27
52
|
/>
|
|
28
53
|
</template>
|
|
@@ -16,6 +16,7 @@ const meta = {
|
|
|
16
16
|
argTypes: {
|
|
17
17
|
visible: { control: 'boolean' },
|
|
18
18
|
loading: { control: 'boolean' },
|
|
19
|
+
confirmLoading: { control: 'boolean' },
|
|
19
20
|
disabled: { control: 'boolean' },
|
|
20
21
|
confirmDisabled: { control: 'boolean' },
|
|
21
22
|
modal: { control: 'boolean' },
|
|
@@ -36,6 +37,7 @@ const meta = {
|
|
|
36
37
|
args: {
|
|
37
38
|
visible: false,
|
|
38
39
|
loading: false,
|
|
40
|
+
confirmLoading: false,
|
|
39
41
|
disabled: false,
|
|
40
42
|
confirmDisabled: false,
|
|
41
43
|
modal: true,
|
|
@@ -57,7 +57,11 @@ const resolvedCancelText = computed(
|
|
|
57
57
|
|
|
58
58
|
const sheetOpen = ref(props.visible ?? false)
|
|
59
59
|
const internalLoading = ref(false)
|
|
60
|
-
|
|
60
|
+
// The confirm action is in progress: either the consumer-driven `confirmLoading`
|
|
61
|
+
// prop or an internal async `beforeClose`. This blocks closing and disables the
|
|
62
|
+
// footer/close controls. The `loading` prop is separate — it only dims the
|
|
63
|
+
// content behind a translucent overlay.
|
|
64
|
+
const confirmInProgress = computed(() => internalLoading.value || props.confirmLoading)
|
|
61
65
|
|
|
62
66
|
watch(() => props.visible, value => {
|
|
63
67
|
if (value !== undefined) sheetOpen.value = value
|
|
@@ -70,7 +74,7 @@ watch(sheetOpen, value => {
|
|
|
70
74
|
})
|
|
71
75
|
|
|
72
76
|
function onOpenUpdate (value: boolean) {
|
|
73
|
-
if (!value &&
|
|
77
|
+
if (!value && confirmInProgress.value) return
|
|
74
78
|
if (value) sheetOpen.value = true
|
|
75
79
|
else handleClose('cancel')
|
|
76
80
|
}
|
|
@@ -161,18 +165,41 @@ const contentClass = computed(() =>
|
|
|
161
165
|
</template>
|
|
162
166
|
|
|
163
167
|
<!-- Content -->
|
|
164
|
-
<
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
<div
|
|
169
|
-
:inert="isLoading || disabled || undefined"
|
|
170
|
-
:class="[ isLoading || disabled ? 'opacity-50' : undefined ]"
|
|
171
|
-
class="p-4"
|
|
168
|
+
<div class="min-h-0 relative flex-1">
|
|
169
|
+
<ScrollArea
|
|
170
|
+
fadeMask
|
|
171
|
+
class="h-full"
|
|
172
172
|
>
|
|
173
|
-
<
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
<div
|
|
174
|
+
:inert="loading || disabled || confirmInProgress || undefined"
|
|
175
|
+
:class="[ disabled ? 'opacity-50' : undefined ]"
|
|
176
|
+
class="p-4"
|
|
177
|
+
>
|
|
178
|
+
<slot />
|
|
179
|
+
</div>
|
|
180
|
+
</ScrollArea>
|
|
181
|
+
|
|
182
|
+
<!-- Content loading overlay -->
|
|
183
|
+
<Transition
|
|
184
|
+
enterActiveClass="transition-opacity duration-200"
|
|
185
|
+
leaveActiveClass="transition-opacity duration-200"
|
|
186
|
+
enterFromClass="opacity-0"
|
|
187
|
+
leaveToClass="opacity-0"
|
|
188
|
+
>
|
|
189
|
+
<div
|
|
190
|
+
v-if="loading"
|
|
191
|
+
class="
|
|
192
|
+
inset-0 bg-popover/60 absolute z-30 flex items-center
|
|
193
|
+
justify-center
|
|
194
|
+
"
|
|
195
|
+
>
|
|
196
|
+
<Icon
|
|
197
|
+
name="loader-circle"
|
|
198
|
+
class="size-6 animate-spin text-muted-foreground"
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
</Transition>
|
|
202
|
+
</div>
|
|
176
203
|
|
|
177
204
|
<!-- Footer -->
|
|
178
205
|
<SheetFooter
|
|
@@ -189,7 +216,7 @@ const contentClass = computed(() =>
|
|
|
189
216
|
v-if="showCancel"
|
|
190
217
|
class="min-w-24"
|
|
191
218
|
:variant="cancelVariant"
|
|
192
|
-
:disabled="
|
|
219
|
+
:disabled="confirmInProgress"
|
|
193
220
|
@click="onCancel"
|
|
194
221
|
>
|
|
195
222
|
{{ resolvedCancelText }}
|
|
@@ -197,7 +224,7 @@ const contentClass = computed(() =>
|
|
|
197
224
|
<Button
|
|
198
225
|
:class="showCancel ? 'min-w-24' : 'min-w-32'"
|
|
199
226
|
:variant="confirmVariant"
|
|
200
|
-
:loading="
|
|
227
|
+
:loading="confirmInProgress"
|
|
201
228
|
:disabled="disabled || confirmDisabled"
|
|
202
229
|
@click="onConfirm"
|
|
203
230
|
>
|
|
@@ -209,7 +236,7 @@ const contentClass = computed(() =>
|
|
|
209
236
|
|
|
210
237
|
<SheetClose
|
|
211
238
|
v-if="showClose"
|
|
212
|
-
:disabled="
|
|
239
|
+
:disabled="confirmInProgress"
|
|
213
240
|
class="
|
|
214
241
|
top-3 right-3 size-8 text-muted-foreground ring-offset-background
|
|
215
242
|
hover:bg-accent/50 hover:text-foreground
|
|
@@ -15,6 +15,7 @@ const meta = {
|
|
|
15
15
|
argTypes: {
|
|
16
16
|
visible: { control: 'boolean' },
|
|
17
17
|
loading: { control: 'boolean' },
|
|
18
|
+
confirmLoading: { control: 'boolean' },
|
|
18
19
|
disabled: { control: 'boolean' },
|
|
19
20
|
confirmDisabled: { control: 'boolean' },
|
|
20
21
|
modal: { control: 'boolean' },
|
|
@@ -33,6 +34,7 @@ const meta = {
|
|
|
33
34
|
args: {
|
|
34
35
|
visible: false,
|
|
35
36
|
loading: false,
|
|
37
|
+
confirmLoading: false,
|
|
36
38
|
disabled: false,
|
|
37
39
|
confirmDisabled: false,
|
|
38
40
|
modal: true,
|
|
@@ -58,7 +58,11 @@ const resolvedCancelText = computed(
|
|
|
58
58
|
|
|
59
59
|
const dialogOpen = ref(props.visible ?? false)
|
|
60
60
|
const internalLoading = ref(false)
|
|
61
|
-
|
|
61
|
+
// The confirm action is in progress: either the consumer-driven `confirmLoading`
|
|
62
|
+
// prop or an internal async `beforeClose`. This blocks closing and disables the
|
|
63
|
+
// footer/close controls. The `loading` prop is separate — it only dims the
|
|
64
|
+
// content behind a translucent overlay.
|
|
65
|
+
const confirmInProgress = computed(() => internalLoading.value || props.confirmLoading)
|
|
62
66
|
|
|
63
67
|
watch(() => props.visible, value => {
|
|
64
68
|
if (value !== undefined) dialogOpen.value = value
|
|
@@ -71,7 +75,7 @@ watch(dialogOpen, value => {
|
|
|
71
75
|
})
|
|
72
76
|
|
|
73
77
|
function onOpenUpdate (value: boolean) {
|
|
74
|
-
if (!value &&
|
|
78
|
+
if (!value && confirmInProgress.value) return
|
|
75
79
|
if (value) dialogOpen.value = true
|
|
76
80
|
else handleClose('cancel')
|
|
77
81
|
}
|
|
@@ -166,20 +170,43 @@ const contentClass = computed(() =>
|
|
|
166
170
|
</template>
|
|
167
171
|
|
|
168
172
|
<!-- Content -->
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
<div class="my-5 min-h-16 relative">
|
|
174
|
+
<ScrollArea
|
|
175
|
+
fadeMask
|
|
176
|
+
class="max-h-[60vh]"
|
|
177
|
+
>
|
|
178
|
+
<ModalContent
|
|
179
|
+
:type="type"
|
|
180
|
+
:content="content"
|
|
181
|
+
:inert="loading || disabled || confirmInProgress || undefined"
|
|
182
|
+
:class="[ disabled ? 'opacity-50' : undefined ]"
|
|
183
|
+
class="p-1"
|
|
184
|
+
>
|
|
185
|
+
<slot />
|
|
186
|
+
</ModalContent>
|
|
187
|
+
</ScrollArea>
|
|
188
|
+
|
|
189
|
+
<!-- Content loading overlay -->
|
|
190
|
+
<Transition
|
|
191
|
+
enterActiveClass="transition-opacity duration-200"
|
|
192
|
+
leaveActiveClass="transition-opacity duration-200"
|
|
193
|
+
enterFromClass="opacity-0"
|
|
194
|
+
leaveToClass="opacity-0"
|
|
179
195
|
>
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
196
|
+
<div
|
|
197
|
+
v-if="loading"
|
|
198
|
+
class="
|
|
199
|
+
inset-0 rounded-md bg-popover/60 absolute z-30 flex items-center
|
|
200
|
+
justify-center
|
|
201
|
+
"
|
|
202
|
+
>
|
|
203
|
+
<Icon
|
|
204
|
+
name="loader-circle"
|
|
205
|
+
class="size-6 animate-spin text-muted-foreground"
|
|
206
|
+
/>
|
|
207
|
+
</div>
|
|
208
|
+
</Transition>
|
|
209
|
+
</div>
|
|
183
210
|
|
|
184
211
|
<!-- Footer -->
|
|
185
212
|
<DialogFooter
|
|
@@ -201,7 +228,7 @@ const contentClass = computed(() =>
|
|
|
201
228
|
v-if="showCancel"
|
|
202
229
|
class="min-w-32"
|
|
203
230
|
:variant="cancelVariant"
|
|
204
|
-
:disabled="
|
|
231
|
+
:disabled="confirmInProgress"
|
|
205
232
|
@click="onCancel"
|
|
206
233
|
>
|
|
207
234
|
{{ resolvedCancelText }}
|
|
@@ -209,7 +236,7 @@ const contentClass = computed(() =>
|
|
|
209
236
|
<Button
|
|
210
237
|
:class="showCancel ? 'min-w-32' : 'min-w-48'"
|
|
211
238
|
:variant="confirmVariant"
|
|
212
|
-
:loading="
|
|
239
|
+
:loading="confirmInProgress"
|
|
213
240
|
:disabled="disabled || confirmDisabled"
|
|
214
241
|
@click="onConfirm"
|
|
215
242
|
>
|
|
@@ -221,7 +248,7 @@ const contentClass = computed(() =>
|
|
|
221
248
|
|
|
222
249
|
<DialogClose
|
|
223
250
|
v-if="showClose"
|
|
224
|
-
:disabled="
|
|
251
|
+
:disabled="confirmInProgress"
|
|
225
252
|
class="
|
|
226
253
|
top-3 right-3 size-8 text-muted-foreground ring-offset-background
|
|
227
254
|
hover:bg-accent/50 hover:text-foreground
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ModalProps } from '../components/ui/Modal/types'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
rejectLabel?: string
|
|
3
|
+
/**
|
|
4
|
+
* Imperative dialog options, aligned with `<Modal>` props (minus `visible`,
|
|
5
|
+
* which the queue manages). Anything Modal accepts — `beforeClose`, `loading`,
|
|
6
|
+
* `confirmVariant`, `class`, … — works here too.
|
|
7
|
+
*/
|
|
8
|
+
export interface DialogOptions extends Omit<ModalProps, 'visible'> {
|
|
9
|
+
/** Plain-text body shorthand. Overridden by `content` when both are set. */
|
|
10
|
+
message?: string
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
interface DialogQueueItem {
|
|
@@ -16,7 +15,11 @@ interface DialogQueueItem {
|
|
|
16
15
|
resolve: (value: boolean) => void
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
// shallowReactive (not reactive): aligning DialogOptions with ModalProps pulls in
|
|
19
|
+
// recursive types (ClassValue) and VNode, which blow past TS's depth limit under
|
|
20
|
+
// deep ref-unwrapping. Queue items are written once and read whole, so array-level
|
|
21
|
+
// reactivity is all we need.
|
|
22
|
+
const dialogQueue = shallowReactive<DialogQueueItem[]>([])
|
|
20
23
|
const isOpen = ref(false)
|
|
21
24
|
const mountedInstances = ref<symbol[]>([])
|
|
22
25
|
|
|
@@ -41,7 +44,7 @@ export function useDialog () {
|
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
const alert = (options: DialogOptions): Promise<void> => {
|
|
44
|
-
return showDialog({ ...options,
|
|
47
|
+
return showDialog({ ...options, showCancel: false }).then(() => {})
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
const destroy = (options: DialogOptions): Promise<boolean> => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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": "d0be46c15352780f0de931b64735b4abceb5067f"
|
|
46
46
|
}
|