-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathdialog.stories.js
375 lines (363 loc) · 11.1 KB
/
dialog.stories.js
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import { withUnderlayWrapper } from "@spectrum-css/preview/decorators";
import { disableDefaultModes } from "@spectrum-css/preview/modes";
import { size } from "@spectrum-css/preview/types";
import { Template as Table } from "@spectrum-css/table/stories/template.js";
import { Template as Steplist } from "@spectrum-css/steplist/stories/template.js";
import { Template as Typography } from "@spectrum-css/typography/stories/template.js";
import metadata from "../dist/metadata.json";
import packageJson from "../package.json";
import { DialogFullscreen, DialogFullscreenTakeover, DialogGroup } from "./dialog.test.js";
import { Template } from "./template.js";
/**
* A dialog displays important information that users need to acknowledge. They appear over the interface and block further interactions. Standard dialogs are the most frequent type of dialogs. They appear in the center of the screen over the interface and should be used for moderately complex tasks. Takeover dialogs are large types of dialogs. They use the totality of the screen and should be used for modal experiences with complex workflows.
*
* The alert variants that were previously a part of Dialog were moved to their own component, [alert dialog](/docs/components-alert-dialog--docs).
*
* ## Usage with modal component
* When a dialog component is used in tandem with a [modal](/docs/components-modal--docs), implementations should set `--mod-modal-background-color` to `transparent`. This will prevent any background color used in the modal from peeking through from behind the dialog at the rounded corners, allowing the dialog's background color to take precedence.
*
*/
export default {
title: "Dialog",
component: "Dialog",
argTypes: {
size: size(["s", "m", "l"]),
heading: {
name: "Heading",
description: "Title for the dialog.",
type: { name: "string" },
table: {
type: { summary: "string" },
category: "Content",
},
control: { type: "text" },
},
header: {
name: "Additional header content",
description: "Controls header content.",
type: { name: "string" },
table: {
type: { summary: "string" },
category: "Content",
},
control: { type: "text" },
},
content: { table: { disable: true } },
hasFooter: {
name: "Has footer",
description: "Adds a footer to the dialog, containing the button group, checkbox, and footer text. Currently only supported in the default layout.",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Content",
},
control: "boolean",
},
footer: {
name: "Footer text",
description: "Text content of the dialog footer. Represents the checkbox label if a checkbox is present, or stands alone if there is no checkbox. Currently only supported in the default layout.",
type: { name: "string" },
table: {
type: { summary: "string" },
category: "Content",
},
control: { type: "text" },
if: { arg: "hasFooter", truthy: true, },
},
hasCheckbox: {
name: "Has checkbox",
description: "Adds a checkbox to the footer content. Currently only supported in the default layout.",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Content",
},
control: { type: "boolean" },
if: { arg: "hasFooter", truthy: true, },
},
layout: {
name: "Layout",
type: { name: "string" },
defaultValue: "Default",
table: {
type: { summary: "string" },
category: "Component",
defaultValue: { summary: "Default" },
disable: true,
},
options: ["default", "fullscreen", "fullscreenTakeover"],
control: "select",
},
isDismissible: {
name: "Dismissible",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Component",
},
control: "boolean",
if: { arg: "layout", eq: "default" },
},
showModal: {
name: "Wrap the dialog in a modal",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "Component",
},
control: "boolean",
},
hasHeroImage: {
name: "Has hero image",
type: { name: "boolean" },
description: "Adds a cover image to the header of a dialog.",
table: {
type: { summary: "boolean" },
category: "Content",
},
control: "boolean",
if: { arg: "layout", eq: "default" },
},
heroImageUrl: {
name: "Hero Image",
type: { name: "string" },
description: "Select a cover image for the hero section of a dialog.",
defaultValue: "example-card-portrait.png",
table: {
type: { summary: "string" },
category: "Content",
defaultValue: { summary: "example-card-portrait.png" },
},
control: { type: "file", accept: ".svg,.png,.jpg,.jpeg,.webc" },
if: { arg: "hasHeroImage", truthy: true },
},
},
args: {
rootClass: "spectrum-Dialog",
hasFooter: true,
footer: "Do not show this message again.",
isDismissible: false,
isOpen: true,
showModal: false,
size: "m",
layout: "default",
hasCheckbox: true,
hasHeroImage: false,
},
parameters: {
actions: {
handles: [],
},
docs: {
story: {
// TODO: restore `inline: false,`
height: "500px",
},
},
design: {
type: "figma",
url: "https://www.figma.com/design/Mngz9H7WZLbrCvGQf3GnsY/S2-%2F-Desktop?node-id=839-1128",
},
packageJson,
metadata,
layout: "fullscreen",
},
decorators: [
withUnderlayWrapper,
],
tags: ["migrated"],
};
const ExampleContent = "Standard dialog description. This should briefly communicate any additional information or context about the standard dialog title, to help users make one of the decisions offered by the buttons. Make it no more than a few short sentences.";
/**
* The default size for dialog is medium. The default dialog also has a checkbox in the footer.
*/
export const Default = DialogGroup.bind({});
Default.args = {
heading: "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
header: "* Required",
showModal: true,
content: [
(passthroughs, context) => Typography({
semantics: "body",
size: "m",
content: [ ExampleContent ],
...passthroughs,
}, context),
],
};
// ********* DOCS ONLY ********* //
export const DefaultSmall = Template.bind({});
DefaultSmall.tags = ["!dev"];
DefaultSmall.storyName = "Dialog - small",
DefaultSmall.parameters = {
chromatic: { disableSnapshot: true },
};
DefaultSmall.args = {
...Default.args,
size: "s",
};
export const DefaultLarge = Template.bind({});
DefaultLarge.tags = ["!dev"];
DefaultLarge.storyName = "Dialog - large",
DefaultLarge.parameters = {
chromatic: { disableSnapshot: true },
};
DefaultLarge.args = {
...Default.args,
size: "l",
};
/**
* A dialog that can be dismissed without taking an action.
*/
export const Dismissible = Template.bind({});
Dismissible.tags = ["!dev"];
Dismissible.parameters = {
chromatic: { disableSnapshot: true },
};
Dismissible.args = {
...Default.args,
isDismissible: true,
};
/**
* Dialogs can have a hero or cover image header.
*/
export const WithHero = Template.bind({});
WithHero.tags = ["!dev"];
WithHero.storyName = "With hero image";
WithHero.parameters = {
docs: {
story: {
height: "650px",
},
},
chromatic: { disableSnapshot: true },
};
WithHero.args = {
...Default.args,
hasHeroImage: true,
};
/**
* The content inside the body area can scroll when necessary.
*/
export const WithScroll = Template.bind({});
WithScroll.args = {
...Default.args,
content: [ ExampleContent, ExampleContent, ExampleContent, ExampleContent ],
customStyles: {
"max-block-size": "400px",
}
};
WithScroll.storyName = "Scrollable";
WithScroll.tags = ["!dev"];
WithScroll.parameters = {
chromatic: { disableSnapshot: true },
};
/**
* The fullscreen variant shows a large dialog background, only revealing a small portion of the page around the outside of the dialog, behind an overlay. The size of the dialog varies with the size of the screen, in both width and height.
*
* Fullscreen dialogs do not support a close button, and are not dismissible.
*
* Implementations may swap out the extra header content and body content for other components, like the [steplist](/docs/components-steplist--docs) and [table](/docs/components-table--docs) seen in this example. Components in the extra header content area will be centered.
*/
export const Fullscreen = DialogFullscreen.bind({});
Fullscreen.args = {
...Default.args,
header:[
(passthroughs, context) => Steplist({
...passthroughs,
items: [
{
label: "Enter records",
isComplete: true,
},
{
label: "Confirmation",
isComplete: true,
},
{
label: "Summary",
isSelected: true,
},
],
}, context),
],
content: [
(passthroughs, context) => Table({
...passthroughs,
showThumbnails: true,
rowItems: [
{
cellContent: ["Table Row Alpha", "Test", "2"],
},
{
cellContent: ["Table Row Bravo", "Test", "28"],
},
{
cellContent: [
"Table Row Charlie. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.",
"Test",
"23",
],
},
{
cellContent: ["Table Row Delta", "Test", "7"],
},
{
cellContent: ["Summary Row", "", "60"],
isSummaryRow: true,
},
],
}, context),
],
layout: "fullscreen",
hasFooter: false,
};
Fullscreen.parameters = {
chromatic: { disableSnapshot: true },
design: {
type: "figma",
url: "https://www.figma.com/design/Mngz9H7WZLbrCvGQf3GnsY/S2-%2F-Desktop?node-id=61935-5399",
}
};
// TODO: Because storybook doesn't support for multiple conditionals, we've removed the hasFooter
// arg from the control table for the fullscreen and fullscreenTakeover stories only. Ideally, we
// could have some of our controls display when more than one arg is met to avoid custom argTypes.
// For instance, hasCheckbox would appear when layout: "default", AND footer is truthy.
// https://github.com/storybookjs/storybook/discussions/18542
Fullscreen.argTypes = {
hasFooter: { table: { disable: true, } },
header: { table: { disable: true, } },
};
/**
* The fullscreen takeover variant is similar to the fullscreen variant except that the background covers the entire screen. The page behind the dialog is not visible. This variant should be reserved for workflows where displaying a second dialog on top of the first one is to be expected.
*
* Fullscreen takeover dialogs do not support a close button, and are not dismissible.
*/
export const FullscreenTakeover = DialogFullscreenTakeover.bind({});
FullscreenTakeover.storyName = "Fullscreen takeover";
FullscreenTakeover.parameters = {
chromatic: { disableSnapshot: true },
design: {
type: "figma",
url: "https://www.figma.com/design/Mngz9H7WZLbrCvGQf3GnsY/S2-%2F-Desktop?node-id=61935-5399",
}
};
FullscreenTakeover.args = {
...Default.args,
layout: "fullscreenTakeover",
hasFooter: false,
content: [ ExampleContent, ExampleContent, ExampleContent, ExampleContent, ExampleContent, ExampleContent, ExampleContent, ExampleContent ],
};
FullscreenTakeover.argTypes = {
hasFooter: { table: { disable: true, } },
};
// ********* VRT ONLY ********* //
export const WithForcedColors = Default.bind({});
WithForcedColors.args = Default.args;
WithForcedColors.tags = ["!autodocs", "!dev"];
WithForcedColors.parameters = {
chromatic: {
forcedColors: "active",
modes: disableDefaultModes,
},
};