alert-dialog.stories.tsx
11.4 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
import * as React from 'react';
import * as AlertDialog from '@radix-ui/react-alert-dialog';
import styles from './alert-dialog.stories.module.css';
export default { title: 'Components/AlertDialog' };
export const Styled = () => (
<AlertDialog.Root>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlay} />
<AlertDialog.Content className={styles.content}>
<AlertDialog.Title className={styles.title}>Are you sure?</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
This will do a very dangerous thing. Thar be dragons!
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>yolo, do it</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>maybe not</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
);
export const Controlled = () => {
const [open, setOpen] = React.useState(false);
const [housePurchased, setHousePurchased] = React.useState(false);
return (
<div>
<div>
<img src="https://i.ibb.co/K54hsKt/house.jpg" alt="a large white house with a red roof" />
</div>
<AlertDialog.Root open={open} onOpenChange={setOpen}>
<AlertDialog.Trigger
onClick={(e) => {
if (housePurchased) {
e.preventDefault();
setHousePurchased(false);
}
}}
>
{housePurchased ? 'You bought the house! Sell it!' : 'Buy this house'}
</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlay} />
<AlertDialog.Content className={styles.content}>
<AlertDialog.Title>Are you sure?</AlertDialog.Title>
<AlertDialog.Description>
Houses are very expensive and it looks like you only have €20 in the bank. Maybe
consult with a financial advisor?
</AlertDialog.Description>
<AlertDialog.Action className={styles.action} onClick={() => setHousePurchased(true)}>
buy it anyway
</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>
good point, I'll reconsider
</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
</div>
);
};
export const Chromatic = () => (
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(4, 1fr)',
gridTemplateRows: 'repeat(2, 1fr)',
height: '100vh',
}}
>
<div>
<h1>Uncontrolled</h1>
<h2>Closed</h2>
<AlertDialog.Root>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlay} />
<AlertDialog.Content className={styles.chromaticContent}>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
<h2>Open</h2>
<AlertDialog.Root defaultOpen>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay
className={styles.overlay}
style={{ left: 0, bottom: '50%', width: '25%' }}
/>
<AlertDialog.Content
className={styles.chromaticContent}
style={{ top: '25%', left: '12%' }}
>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
</div>
<div>
<h1>Uncontrolled with reordered parts</h1>
<h2>Closed</h2>
<AlertDialog.Root>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlay} />
<AlertDialog.Content className={styles.chromaticContent}>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
</AlertDialog.Root>
<h2>Open</h2>
<AlertDialog.Root defaultOpen>
<AlertDialog.Portal>
<AlertDialog.Overlay
className={styles.overlay}
style={{ left: '25%', bottom: '50%', width: '25%' }}
/>
<AlertDialog.Content
className={styles.chromaticContent}
style={{ top: '25%', left: '37%' }}
>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
</AlertDialog.Root>
</div>
<div>
<h1>Controlled</h1>
<h2>Closed</h2>
<AlertDialog.Root open={false}>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlay} />
<AlertDialog.Content className={styles.chromaticContent}>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
<h2>Open</h2>
<AlertDialog.Root open>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay
className={styles.overlay}
style={{ left: '50%', bottom: '50%', width: '25%' }}
/>
<AlertDialog.Content
className={styles.chromaticContent}
style={{ top: '25%', left: '62%' }}
>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
</div>
<div>
<h1>Controlled with reordered parts</h1>
<h2>Closed</h2>
<AlertDialog.Root open={false}>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlay} />
<AlertDialog.Content className={styles.chromaticContent}>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
</AlertDialog.Root>
<h2>Open</h2>
<AlertDialog.Root open>
<AlertDialog.Portal>
<AlertDialog.Overlay
className={styles.overlay}
style={{ left: '75%', bottom: '50%', width: '25%' }}
/>
<AlertDialog.Content
className={styles.chromaticContent}
style={{ top: '25%', left: '88%' }}
>
<AlertDialog.Title className={styles.title}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.description}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.action}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancel}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
<AlertDialog.Trigger className={styles.trigger}>delete everything</AlertDialog.Trigger>
</AlertDialog.Root>
</div>
<div>
<h1>State attributes</h1>
<h2>Closed</h2>
<AlertDialog.Root>
<AlertDialog.Trigger className={styles.triggerAttr}>delete everything</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlayAttr} />
<AlertDialog.Content className={styles.contentAttr}>
<AlertDialog.Title className={styles.titleAttr}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.descriptionAttr}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.actionAttr}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancelAttr}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
<h2>Open</h2>
<AlertDialog.Root defaultOpen>
<AlertDialog.Trigger className={styles.triggerAttr}>delete everything</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay className={styles.overlayAttr} style={{ top: '50%' }} />
<AlertDialog.Content className={styles.contentAttr} style={{ top: '75%' }}>
<AlertDialog.Title className={styles.titleAttr}>Title</AlertDialog.Title>
<AlertDialog.Description className={styles.descriptionAttr}>
Description
</AlertDialog.Description>
<AlertDialog.Action className={styles.actionAttr}>Confirm</AlertDialog.Action>
<AlertDialog.Cancel className={styles.cancelAttr}>Cancel</AlertDialog.Cancel>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
</div>
</div>
);
Chromatic.parameters = { chromatic: { disable: false } };