@latte-macchiat-io/latte-vanilla-components 0.0.185 → 0.0.186

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.
@@ -0,0 +1,408 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { useState } from 'react';
3
+ import { Modal } from './Modal';
4
+ import { Button } from '../Button/Button';
5
+ import { Section } from '../Section/Section';
6
+
7
+ const meta: Meta<typeof Modal> = {
8
+ title: 'Interactive Components/Modal',
9
+ component: Modal,
10
+ parameters: {
11
+ layout: 'fullscreen',
12
+ docs: {
13
+ description: {
14
+ component: `
15
+ The Modal component provides an accessible, animated modal dialog with various customization options.
16
+
17
+ ## Features
18
+ - Accessible (ARIA compliant, focus management)
19
+ - Animated entrance/exit
20
+ - Multiple sizes (small, medium, large, fullscreen)
21
+ - Centered or top-aligned positioning
22
+ - Backdrop click to close (optional)
23
+ - Escape key to close (optional)
24
+ - Close button (optional)
25
+ - Body scroll lock when open
26
+ - TypeScript support
27
+
28
+ ## Accessibility
29
+ - Traps focus within the modal
30
+ - Restores focus to trigger element on close
31
+ - Supports keyboard navigation
32
+ - ARIA attributes for screen readers
33
+ `,
34
+ },
35
+ },
36
+ },
37
+ tags: ['autodocs'],
38
+ argTypes: {
39
+ isOpen: {
40
+ control: 'boolean',
41
+ description: 'Controls whether the modal is visible',
42
+ },
43
+ size: {
44
+ control: 'select',
45
+ options: ['small', 'medium', 'large', 'fullscreen'],
46
+ description: 'Size of the modal dialog',
47
+ },
48
+ centered: {
49
+ control: 'boolean',
50
+ description: 'Whether to center the modal vertically',
51
+ },
52
+ showCloseButton: {
53
+ control: 'boolean',
54
+ description: 'Whether to show the close button',
55
+ },
56
+ closeOnBackdropClick: {
57
+ control: 'boolean',
58
+ description: 'Whether clicking the backdrop closes the modal',
59
+ },
60
+ closeOnEscape: {
61
+ control: 'boolean',
62
+ description: 'Whether pressing Escape closes the modal',
63
+ },
64
+ },
65
+ };
66
+
67
+ export default meta;
68
+ type Story = StoryObj<typeof Modal>;
69
+
70
+ // Interactive Modal Example
71
+ const InteractiveModal = ({ size = 'medium', centered = true, ...args }: any) => {
72
+ const [isOpen, setIsOpen] = useState(false);
73
+
74
+ return (
75
+ <Section>
76
+ <Button variant="primary" onClick={() => setIsOpen(true)}>
77
+ Open Modal
78
+ </Button>
79
+ <Modal
80
+ isOpen={isOpen}
81
+ onClose={() => setIsOpen(false)}
82
+ size={size}
83
+ centered={centered}
84
+ {...args}
85
+ >
86
+ <div style={{ padding: '2rem' }}>
87
+ <h2>Modal Title</h2>
88
+ <p>This is the modal content. You can put any React components here.</p>
89
+ <div style={{ marginTop: '2rem', display: 'flex', gap: '1rem' }}>
90
+ <Button variant="primary" onClick={() => setIsOpen(false)}>
91
+ Confirm
92
+ </Button>
93
+ <Button variant="secondary" onClick={() => setIsOpen(false)}>
94
+ Cancel
95
+ </Button>
96
+ </div>
97
+ </div>
98
+ </Modal>
99
+ </Section>
100
+ );
101
+ };
102
+
103
+ export const Default: Story = {
104
+ render: (args) => <InteractiveModal {...args} />,
105
+ args: {
106
+ size: 'medium',
107
+ centered: true,
108
+ showCloseButton: true,
109
+ closeOnBackdropClick: true,
110
+ closeOnEscape: true,
111
+ },
112
+ };
113
+
114
+ export const Small: Story = {
115
+ render: (args) => <InteractiveModal {...args} size="small" />,
116
+ parameters: {
117
+ docs: {
118
+ description: {
119
+ story: 'Small modal size, perfect for confirmations and quick actions.',
120
+ },
121
+ },
122
+ },
123
+ };
124
+
125
+ export const Medium: Story = {
126
+ render: (args) => <InteractiveModal {...args} size="medium" />,
127
+ parameters: {
128
+ docs: {
129
+ description: {
130
+ story: 'Medium modal size, the default and most commonly used size.',
131
+ },
132
+ },
133
+ },
134
+ };
135
+
136
+ export const Large: Story = {
137
+ render: (args) => <InteractiveModal {...args} size="large" />,
138
+ parameters: {
139
+ docs: {
140
+ description: {
141
+ story: 'Large modal size, good for forms and detailed content.',
142
+ },
143
+ },
144
+ },
145
+ };
146
+
147
+ export const Fullscreen: Story = {
148
+ render: (args) => <InteractiveModal {...args} size="fullscreen" />,
149
+ parameters: {
150
+ docs: {
151
+ description: {
152
+ story: 'Fullscreen modal that takes up the entire viewport.',
153
+ },
154
+ },
155
+ },
156
+ };
157
+
158
+ export const TopAligned: Story = {
159
+ render: (args) => <InteractiveModal {...args} centered={false} />,
160
+ parameters: {
161
+ docs: {
162
+ description: {
163
+ story: 'Modal aligned to the top of the viewport instead of centered.',
164
+ },
165
+ },
166
+ },
167
+ };
168
+
169
+ export const NoCloseButton: Story = {
170
+ render: (args) => <InteractiveModal {...args} showCloseButton={false} />,
171
+ parameters: {
172
+ docs: {
173
+ description: {
174
+ story: 'Modal without the close button - must be closed programmatically.',
175
+ },
176
+ },
177
+ },
178
+ };
179
+
180
+ export const NoBackdropClose: Story = {
181
+ render: (args) => <InteractiveModal {...args} closeOnBackdropClick={false} />,
182
+ parameters: {
183
+ docs: {
184
+ description: {
185
+ story: 'Modal that cannot be closed by clicking the backdrop.',
186
+ },
187
+ },
188
+ },
189
+ };
190
+
191
+ export const ConfirmationDialog: Story = {
192
+ render: () => {
193
+ const [isOpen, setIsOpen] = useState(false);
194
+
195
+ return (
196
+ <Section>
197
+ <Button variant="destructive" onClick={() => setIsOpen(true)}>
198
+ Delete Item
199
+ </Button>
200
+ <Modal
201
+ isOpen={isOpen}
202
+ onClose={() => setIsOpen(false)}
203
+ size="small"
204
+ centered={true}
205
+ >
206
+ <div style={{ padding: '2rem', textAlign: 'center' }}>
207
+ <h3 style={{ color: 'var(--latte-colors-error)', marginBottom: '1rem' }}>
208
+ Delete Confirmation
209
+ </h3>
210
+ <p style={{ marginBottom: '2rem' }}>
211
+ Are you sure you want to delete this item? This action cannot be undone.
212
+ </p>
213
+ <div style={{ display: 'flex', gap: '1rem', justifyContent: 'center' }}>
214
+ <Button variant="destructive" onClick={() => setIsOpen(false)}>
215
+ Delete
216
+ </Button>
217
+ <Button variant="secondary" onClick={() => setIsOpen(false)}>
218
+ Cancel
219
+ </Button>
220
+ </div>
221
+ </div>
222
+ </Modal>
223
+ </Section>
224
+ );
225
+ },
226
+ parameters: {
227
+ docs: {
228
+ description: {
229
+ story: 'A real-world example of a confirmation dialog for destructive actions.',
230
+ },
231
+ },
232
+ },
233
+ };
234
+
235
+ export const FormModal: Story = {
236
+ render: () => {
237
+ const [isOpen, setIsOpen] = useState(false);
238
+
239
+ return (
240
+ <Section>
241
+ <Button variant="primary" onClick={() => setIsOpen(true)}>
242
+ Add New User
243
+ </Button>
244
+ <Modal
245
+ isOpen={isOpen}
246
+ onClose={() => setIsOpen(false)}
247
+ size="medium"
248
+ centered={true}
249
+ >
250
+ <div style={{ padding: '2rem' }}>
251
+ <h2 style={{ marginBottom: '2rem' }}>Add New User</h2>
252
+ <form style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
253
+ <div>
254
+ <label style={{ display: 'block', marginBottom: '0.5rem', fontWeight: '500' }}>
255
+ Name
256
+ </label>
257
+ <input
258
+ type="text"
259
+ style={{
260
+ width: '100%',
261
+ padding: '0.75rem',
262
+ border: '1px solid var(--latte-colors-border)',
263
+ borderRadius: 'var(--latte-radii-md)',
264
+ fontSize: 'var(--latte-fontSizes-md)'
265
+ }}
266
+ />
267
+ </div>
268
+ <div>
269
+ <label style={{ display: 'block', marginBottom: '0.5rem', fontWeight: '500' }}>
270
+ Email
271
+ </label>
272
+ <input
273
+ type="email"
274
+ style={{
275
+ width: '100%',
276
+ padding: '0.75rem',
277
+ border: '1px solid var(--latte-colors-border)',
278
+ borderRadius: 'var(--latte-radii-md)',
279
+ fontSize: 'var(--latte-fontSizes-md)'
280
+ }}
281
+ />
282
+ </div>
283
+ <div>
284
+ <label style={{ display: 'block', marginBottom: '0.5rem', fontWeight: '500' }}>
285
+ Role
286
+ </label>
287
+ <select
288
+ style={{
289
+ width: '100%',
290
+ padding: '0.75rem',
291
+ border: '1px solid var(--latte-colors-border)',
292
+ borderRadius: 'var(--latte-radii-md)',
293
+ fontSize: 'var(--latte-fontSizes-md)'
294
+ }}
295
+ >
296
+ <option>User</option>
297
+ <option>Admin</option>
298
+ <option>Moderator</option>
299
+ </select>
300
+ </div>
301
+ <div style={{ marginTop: '2rem', display: 'flex', gap: '1rem', justifyContent: 'flex-end' }}>
302
+ <Button variant="secondary" onClick={() => setIsOpen(false)}>
303
+ Cancel
304
+ </Button>
305
+ <Button variant="primary" onClick={() => setIsOpen(false)}>
306
+ Add User
307
+ </Button>
308
+ </div>
309
+ </form>
310
+ </div>
311
+ </Modal>
312
+ </Section>
313
+ );
314
+ },
315
+ parameters: {
316
+ docs: {
317
+ description: {
318
+ story: 'A practical example of using a modal for form input.',
319
+ },
320
+ },
321
+ },
322
+ };
323
+
324
+ export const ImageGallery: Story = {
325
+ render: () => {
326
+ const [isOpen, setIsOpen] = useState(false);
327
+ const [selectedImage, setSelectedImage] = useState(0);
328
+
329
+ const images = [
330
+ 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&h=600&fit=crop',
331
+ 'https://images.unsplash.com/photo-1519904981063-b0cf448d479e?w=800&h=600&fit=crop',
332
+ 'https://images.unsplash.com/photo-1454391304352-2bf4678b1a7a?w=800&h=600&fit=crop',
333
+ ];
334
+
335
+ const openImage = (index: number) => {
336
+ setSelectedImage(index);
337
+ setIsOpen(true);
338
+ };
339
+
340
+ return (
341
+ <Section>
342
+ <h3>Click an image to view in modal:</h3>
343
+ <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: '1rem', marginTop: '1rem' }}>
344
+ {images.map((src, index) => (
345
+ <img
346
+ key={index}
347
+ src={src}
348
+ alt={`Gallery ${index + 1}`}
349
+ style={{
350
+ width: '100%',
351
+ height: '150px',
352
+ objectFit: 'cover',
353
+ borderRadius: 'var(--latte-radii-md)',
354
+ cursor: 'pointer'
355
+ }}
356
+ onClick={() => openImage(index)}
357
+ />
358
+ ))}
359
+ </div>
360
+ <Modal
361
+ isOpen={isOpen}
362
+ onClose={() => setIsOpen(false)}
363
+ size="large"
364
+ centered={true}
365
+ >
366
+ <div style={{ padding: '1rem' }}>
367
+ <img
368
+ src={images[selectedImage]}
369
+ alt={`Gallery ${selectedImage + 1}`}
370
+ style={{
371
+ width: '100%',
372
+ height: 'auto',
373
+ borderRadius: 'var(--latte-radii-md)'
374
+ }}
375
+ />
376
+ <div style={{
377
+ marginTop: '1rem',
378
+ display: 'flex',
379
+ justifyContent: 'space-between',
380
+ alignItems: 'center'
381
+ }}>
382
+ <Button
383
+ variant="ghost"
384
+ onClick={() => setSelectedImage((prev) => (prev > 0 ? prev - 1 : images.length - 1))}
385
+ >
386
+ ← Previous
387
+ </Button>
388
+ <span>Image {selectedImage + 1} of {images.length}</span>
389
+ <Button
390
+ variant="ghost"
391
+ onClick={() => setSelectedImage((prev) => (prev < images.length - 1 ? prev + 1 : 0))}
392
+ >
393
+ Next →
394
+ </Button>
395
+ </div>
396
+ </div>
397
+ </Modal>
398
+ </Section>
399
+ );
400
+ },
401
+ parameters: {
402
+ docs: {
403
+ description: {
404
+ story: 'An example of using modals for image galleries with navigation.',
405
+ },
406
+ },
407
+ },
408
+ };
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
2
 
3
3
  import { Nav } from '../../index';
4
4
 
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
2
 
3
3
  import { NavLegal } from '../../index';
4
4