-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialog.stories.ts
More file actions
331 lines (305 loc) · 8.72 KB
/
Copy pathDialog.stories.ts
File metadata and controls
331 lines (305 loc) · 8.72 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import type { Meta, StoryObj } from '@storybook/vue3-vite';
import { ref } from 'vue';
import N8nButton from '@n8n/design-system/components/N8nButton/Button.vue';
import {
N8nDialog,
N8nDialogClose,
N8nDialogHeader,
N8nDialogTitle,
N8nDialogDescription,
N8nDialogFooter,
type DialogProps,
} from '@n8n/design-system/components/N8nDialog';
const meta = {
title: 'Core/Dialog',
// Use N8nDialog as component; docgen may have issues with reka-ui imports but types must match
component: N8nDialog,
parameters: {
docs: {
source: { type: 'dynamic' },
},
},
argTypes: {
size: {
control: { type: 'select' },
options: ['small', 'medium', 'large', 'xlarge', '2xlarge', 'fit', 'full', 'cover'],
},
},
} satisfies Meta<typeof N8nDialog>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
render: (args: DialogProps) => ({
components: {
N8nDialog,
N8nDialogFooter,
N8nDialogClose,
N8nButton,
},
setup() {
const isOpen = ref(false);
return { args, isOpen };
},
template: `
<div style="display: flex; justify-content: center; padding: 40px;">
<N8nButton label="Open Dialog" @click="isOpen = true" />
<N8nDialog v-model:open="isOpen" v-bind="args">
<div style="padding: var(--spacing--sm) 0;">
<p>Dialog content goes here...</p>
</div>
<N8nDialogFooter>
<N8nDialogClose as-child>
<N8nButton type="secondary" label="Cancel" />
</N8nDialogClose>
<N8nButton label="Save changes" />
</N8nDialogFooter>
</N8nDialog>
</div>
`,
}),
args: {
size: 'medium',
header: 'Edit Profile',
description: "Make changes to your profile here. Click save when you're done.",
},
} satisfies Story;
export const Sizes: Story = {
render: () => ({
components: {
N8nDialog,
N8nDialogFooter,
N8nDialogClose,
N8nButton,
},
setup() {
const sizes = ['small', 'medium', 'large', 'xlarge', 'full', 'cover'] as const;
const openDialogs = ref<Record<string, boolean>>({});
const openDialog = (size: string) => {
openDialogs.value[size] = true;
};
return { sizes, openDialogs, openDialog };
},
template: `
<div style="display: flex; gap: 16px; justify-content: center; padding: 40px;">
<template v-for="size in sizes" :key="size">
<N8nButton :label="size" variant="outline" @click="openDialog(size)" />
<N8nDialog
v-model:open="openDialogs[size]"
:size="size"
:header="size + ' Dialog'"
:description="'This dialog has size=' + size"
>
<div style="padding: var(--spacing--sm) 0;">
<p>Content for the {{ size }} dialog size variant.</p>
</div>
<N8nDialogFooter>
<N8nDialogClose as-child>
<N8nButton variant="outline" label="Close" />
</N8nDialogClose>
</N8nDialogFooter>
</N8nDialog>
</template>
</div>
`,
}),
args: {},
} satisfies Story;
export const WithoutCloseButton: Story = {
render: (args: DialogProps) => ({
components: {
N8nDialog,
N8nDialogFooter,
N8nDialogClose,
N8nButton,
},
setup() {
const isOpen = ref(false);
return { args, isOpen };
},
template: `
<div style="display: flex; justify-content: center; padding: 40px;">
<N8nButton label="Open Dialog" @click="isOpen = true" />
<N8nDialog v-model:open="isOpen" v-bind="args">
<N8nDialogFooter>
<N8nDialogClose as-child>
<N8nButton variant="outline" label="Cancel" />
</N8nDialogClose>
<N8nButton label="Confirm" />
</N8nDialogFooter>
</N8nDialog>
</div>
`,
}),
args: {
showCloseButton: false,
header: 'No Close Button',
description: "This dialog doesn't have a close button in the top right corner.",
},
} satisfies Story;
export const ScrollableContent: Story = {
render: () => ({
components: {
N8nDialog,
N8nDialogFooter,
N8nDialogClose,
N8nButton,
},
setup() {
const isOpen = ref(false);
return { isOpen };
},
template: `
<div style="display: flex; justify-content: center; padding: 40px;">
<N8nButton label="View Terms" variant="outline" @click="isOpen = true" />
<N8nDialog
v-model:open="isOpen"
header="Terms of Service"
style="max-height: 80vh; display: flex; flex-direction: column;"
>
<div style="flex: 1; overflow-y: auto; padding: var(--spacing--sm);">
<p v-for="i in 20" :key="i" style="margin-bottom: var(--spacing--sm);">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</p>
</div>
<N8nDialogFooter>
<N8nDialogClose as-child>
<N8nButton variant="outline" label="Decline" />
</N8nDialogClose>
<N8nButton label="Accept" />
</N8nDialogFooter>
</N8nDialog>
</div>
`,
}),
args: {},
} satisfies Story;
export const AccessibilityFallback: Story = {
render: (args: DialogProps) => ({
components: {
N8nDialog,
N8nDialogFooter,
N8nDialogClose,
N8nButton,
},
setup() {
const isOpen = ref(false);
return { args, isOpen };
},
template: `
<div style="display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 40px;">
<p style="max-width: 500px; text-align: center; color: var(--color--text--tint-1);">
This dialog uses <code>ariaLabel</code> and <code>ariaDescription</code> props instead of
<code>N8nDialogTitle</code> and <code>N8nDialogDescription</code> components.
The title and description are visually hidden but accessible to screen readers.
</p>
<N8nButton label="Open Dialog" @click="isOpen = true" />
<N8nDialog v-model:open="isOpen" v-bind="args">
<div style="padding: var(--spacing--sm) 0;">
<p style="font-weight: var(--font-weight--bold); margin-bottom: var(--spacing--xs);">
Custom Visual Title
</p>
<p>
This dialog has no visible DialogTitle or DialogDescription components,
but screen readers will announce "Delete Confirmation" as the title
and the description text for accessibility.
</p>
</div>
<N8nDialogFooter>
<N8nDialogClose as-child>
<N8nButton type="secondary" label="Cancel" />
</N8nDialogClose>
<N8nButton type="danger" label="Delete" />
</N8nDialogFooter>
</N8nDialog>
</div>
`,
}),
args: {
ariaLabel: 'Delete Confirmation',
ariaDescription: 'Are you sure you want to delete this item? This action cannot be undone.',
},
} satisfies Story;
export const AccessibilityFallbackTitleOnly: Story = {
render: (args: DialogProps) => ({
components: {
N8nDialog,
N8nDialogFooter,
N8nDialogClose,
N8nButton,
},
setup() {
const isOpen = ref(false);
return { args, isOpen };
},
template: `
<div style="display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 40px;">
<p style="max-width: 500px; text-align: center; color: var(--color--text--tint-1);">
This dialog only uses the <code>ariaLabel</code> prop for an accessible title.
Useful for simple confirmation dialogs or icon-only interfaces.
</p>
<N8nButton label="Quick Action" variant="outline" @click="isOpen = true" />
<N8nDialog v-model:open="isOpen" v-bind="args" size="small">
<div style="text-align: center; padding: var(--spacing--md) 0;">
<p>Complete this action?</p>
</div>
<N8nDialogFooter>
<N8nDialogClose as-child>
<N8nButton type="secondary" label="No" />
</N8nDialogClose>
<N8nButton label="Yes" />
</N8nDialogFooter>
</N8nDialog>
</div>
`,
}),
args: {
ariaLabel: 'Confirm Action',
},
} satisfies Story;
/**
* You can use child components for custom header layouts instead of the header/description props.
*/
export const CustomHeader: Story = {
render: () => ({
components: {
N8nDialog,
N8nDialogHeader,
N8nDialogTitle,
N8nDialogDescription,
N8nDialogFooter,
N8nDialogClose,
N8nButton,
},
setup() {
const isOpen = ref(false);
return { isOpen };
},
template: `
<div style="display: flex; justify-content: center; padding: 40px;">
<N8nButton label="Open Dialog" @click="isOpen = true" />
<N8nDialog v-model:open="isOpen">
<N8nDialogHeader>
<N8nDialogTitle>Custom Header Layout</N8nDialogTitle>
<N8nDialogDescription>
Use child components when you need more control over the header layout,
such as adding icons, badges, or custom styling.
</N8nDialogDescription>
</N8nDialogHeader>
<div style="padding: var(--spacing--sm) 0;">
<p>Dialog content goes here...</p>
</div>
<N8nDialogFooter>
<N8nDialogClose as-child>
<N8nButton type="secondary" label="Cancel" />
</N8nDialogClose>
<N8nButton label="Save" />
</N8nDialogFooter>
</N8nDialog>
</div>
`,
}),
args: {},
} satisfies Story;