@papernote/ui 1.3.1 → 1.6.0
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/dist/components/ActionBar.d.ts +112 -0
- package/dist/components/ActionBar.d.ts.map +1 -0
- package/dist/components/BottomNavigation.d.ts +98 -0
- package/dist/components/BottomNavigation.d.ts.map +1 -0
- package/dist/components/Checkbox.d.ts +2 -0
- package/dist/components/Checkbox.d.ts.map +1 -1
- package/dist/components/CheckboxList.d.ts +81 -0
- package/dist/components/CheckboxList.d.ts.map +1 -0
- package/dist/components/Chip.d.ts +92 -1
- package/dist/components/Chip.d.ts.map +1 -1
- package/dist/components/ConfirmDialog.d.ts +43 -1
- package/dist/components/ConfirmDialog.d.ts.map +1 -1
- package/dist/components/DataTable.d.ts +10 -1
- package/dist/components/DataTable.d.ts.map +1 -1
- package/dist/components/DataTableCardView.d.ts +99 -0
- package/dist/components/DataTableCardView.d.ts.map +1 -0
- package/dist/components/ExpandablePanel.d.ts +142 -0
- package/dist/components/ExpandablePanel.d.ts.map +1 -0
- package/dist/components/FloatingActionButton.d.ts +98 -0
- package/dist/components/FloatingActionButton.d.ts.map +1 -0
- package/dist/components/Input.d.ts +45 -1
- package/dist/components/Input.d.ts.map +1 -1
- package/dist/components/MobileHeader.d.ts +98 -0
- package/dist/components/MobileHeader.d.ts.map +1 -0
- package/dist/components/MobileLayout.d.ts +121 -0
- package/dist/components/MobileLayout.d.ts.map +1 -0
- package/dist/components/Modal.d.ts +78 -1
- package/dist/components/Modal.d.ts.map +1 -1
- package/dist/components/PageHeader.d.ts +86 -0
- package/dist/components/PageHeader.d.ts.map +1 -0
- package/dist/components/PullToRefresh.d.ts +87 -0
- package/dist/components/PullToRefresh.d.ts.map +1 -0
- package/dist/components/QueryTransparency.d.ts +1 -1
- package/dist/components/QueryTransparency.d.ts.map +1 -1
- package/dist/components/SearchableList.d.ts +83 -0
- package/dist/components/SearchableList.d.ts.map +1 -0
- package/dist/components/Select.d.ts +16 -2
- package/dist/components/Select.d.ts.map +1 -1
- package/dist/components/Sidebar.d.ts +40 -1
- package/dist/components/Sidebar.d.ts.map +1 -1
- package/dist/components/SwipeActions.d.ts +93 -0
- package/dist/components/SwipeActions.d.ts.map +1 -0
- package/dist/components/Switch.d.ts +1 -0
- package/dist/components/Switch.d.ts.map +1 -1
- package/dist/components/Textarea.d.ts +13 -0
- package/dist/components/Textarea.d.ts.map +1 -1
- package/dist/components/index.d.ts +31 -3
- package/dist/components/index.d.ts.map +1 -1
- package/dist/context/MobileContext.d.ts +168 -0
- package/dist/context/MobileContext.d.ts.map +1 -0
- package/dist/hooks/useResponsive.d.ts +158 -0
- package/dist/hooks/useResponsive.d.ts.map +1 -0
- package/dist/index.d.ts +1871 -51
- package/dist/index.esm.js +3025 -196
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3063 -194
- package/dist/index.js.map +1 -1
- package/dist/styles.css +434 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ActionBar.stories.tsx +246 -0
- package/src/components/ActionBar.tsx +242 -0
- package/src/components/BottomNavigation.stories.tsx +142 -0
- package/src/components/BottomNavigation.tsx +225 -0
- package/src/components/Checkbox.stories.tsx +162 -0
- package/src/components/Checkbox.tsx +22 -6
- package/src/components/CheckboxList.stories.tsx +311 -0
- package/src/components/CheckboxList.tsx +433 -0
- package/src/components/Chip.stories.tsx +389 -0
- package/src/components/Chip.tsx +182 -3
- package/src/components/ConfirmDialog.tsx +56 -4
- package/src/components/DataTable.tsx +60 -1
- package/src/components/DataTableCardView.stories.tsx +307 -0
- package/src/components/DataTableCardView.tsx +419 -0
- package/src/components/ExpandablePanel.stories.tsx +620 -0
- package/src/components/ExpandablePanel.tsx +383 -0
- package/src/components/FloatingActionButton.stories.tsx +197 -0
- package/src/components/FloatingActionButton.tsx +301 -0
- package/src/components/Grid.stories.tsx +16 -16
- package/src/components/Input.stories.tsx +214 -0
- package/src/components/Input.tsx +81 -4
- package/src/components/MobileHeader.stories.tsx +205 -0
- package/src/components/MobileHeader.tsx +233 -0
- package/src/components/MobileLayout.stories.tsx +338 -0
- package/src/components/MobileLayout.tsx +313 -0
- package/src/components/Modal.stories.tsx +388 -0
- package/src/components/Modal.tsx +122 -4
- package/src/components/PageHeader.stories.tsx +198 -0
- package/src/components/PageHeader.tsx +217 -0
- package/src/components/PullToRefresh.stories.tsx +321 -0
- package/src/components/PullToRefresh.tsx +294 -0
- package/src/components/QueryTransparency.tsx +1 -1
- package/src/components/SearchableList.stories.tsx +437 -0
- package/src/components/SearchableList.tsx +326 -0
- package/src/components/Select.stories.tsx +190 -0
- package/src/components/Select.tsx +353 -137
- package/src/components/Sidebar.tsx +193 -10
- package/src/components/SwipeActions.stories.tsx +327 -0
- package/src/components/SwipeActions.tsx +387 -0
- package/src/components/Switch.stories.tsx +158 -0
- package/src/components/Switch.tsx +12 -3
- package/src/components/Textarea.tsx +31 -1
- package/src/components/index.ts +69 -3
- package/src/context/MobileContext.tsx +296 -0
- package/src/hooks/useResponsive.ts +360 -0
- package/src/types/index.ts +4 -0
- package/tailwind.config.js +56 -1
|
@@ -96,6 +96,21 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
96
96
|
defaultValue: { summary: 'true' },
|
|
97
97
|
},
|
|
98
98
|
},
|
|
99
|
+
scrollable: {
|
|
100
|
+
control: 'boolean',
|
|
101
|
+
description: 'Enable automatic scrolling for content that exceeds viewport height. Applies max-height: calc(100vh - 200px) and overflow-y: auto.',
|
|
102
|
+
table: {
|
|
103
|
+
type: { summary: 'boolean' },
|
|
104
|
+
defaultValue: { summary: 'false' },
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
maxHeight: {
|
|
108
|
+
control: 'text',
|
|
109
|
+
description: 'Maximum height of the modal content area (e.g., "70vh", "500px"). Enables overflow-y: auto when set.',
|
|
110
|
+
table: {
|
|
111
|
+
type: { summary: 'string' },
|
|
112
|
+
},
|
|
113
|
+
},
|
|
99
114
|
},
|
|
100
115
|
} satisfies Meta<typeof Modal>;
|
|
101
116
|
|
|
@@ -348,3 +363,376 @@ export const TextSelectionTest: Story = {
|
|
|
348
363
|
);
|
|
349
364
|
},
|
|
350
365
|
};
|
|
366
|
+
|
|
367
|
+
// Mobile-optimized stories
|
|
368
|
+
export const MobileSlideUp: Story = {
|
|
369
|
+
parameters: {
|
|
370
|
+
viewport: { defaultViewport: 'mobile1' },
|
|
371
|
+
docs: {
|
|
372
|
+
description: {
|
|
373
|
+
story: 'On mobile devices, slide-up animation feels natural like a native bottom sheet, ideal for mobile modals.',
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
render: () => {
|
|
378
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
379
|
+
return (
|
|
380
|
+
<>
|
|
381
|
+
<Button onClick={() => setIsOpen(true)}>Open Mobile Modal</Button>
|
|
382
|
+
<Modal
|
|
383
|
+
isOpen={isOpen}
|
|
384
|
+
onClose={() => setIsOpen(false)}
|
|
385
|
+
title="Mobile Modal"
|
|
386
|
+
animation="slide-up"
|
|
387
|
+
size="lg"
|
|
388
|
+
>
|
|
389
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
|
390
|
+
<p>This modal slides up from the bottom, which feels natural on mobile devices.</p>
|
|
391
|
+
<Input
|
|
392
|
+
label="Email"
|
|
393
|
+
type="email"
|
|
394
|
+
inputMode="email"
|
|
395
|
+
enterKeyHint="next"
|
|
396
|
+
size="lg"
|
|
397
|
+
placeholder="you@example.com"
|
|
398
|
+
/>
|
|
399
|
+
</div>
|
|
400
|
+
<ModalFooter>
|
|
401
|
+
<Button variant="ghost" onClick={() => setIsOpen(false)}>Cancel</Button>
|
|
402
|
+
<Button variant="primary" onClick={() => setIsOpen(false)}>Save</Button>
|
|
403
|
+
</ModalFooter>
|
|
404
|
+
</Modal>
|
|
405
|
+
</>
|
|
406
|
+
);
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
export const MobileFormModal: Story = {
|
|
411
|
+
parameters: {
|
|
412
|
+
viewport: { defaultViewport: 'mobile1' },
|
|
413
|
+
docs: {
|
|
414
|
+
description: {
|
|
415
|
+
story: 'Mobile form modal with touch-friendly inputs (size="lg") and appropriate keyboard hints.',
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
render: () => {
|
|
420
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
421
|
+
return (
|
|
422
|
+
<>
|
|
423
|
+
<Button onClick={() => setIsOpen(true)}>Add Contact</Button>
|
|
424
|
+
<Modal
|
|
425
|
+
isOpen={isOpen}
|
|
426
|
+
onClose={() => setIsOpen(false)}
|
|
427
|
+
title="Add New Contact"
|
|
428
|
+
animation="slide-up"
|
|
429
|
+
size="lg"
|
|
430
|
+
>
|
|
431
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
|
432
|
+
<Input
|
|
433
|
+
label="Full Name"
|
|
434
|
+
size="lg"
|
|
435
|
+
enterKeyHint="next"
|
|
436
|
+
placeholder="John Smith"
|
|
437
|
+
required
|
|
438
|
+
/>
|
|
439
|
+
<Input
|
|
440
|
+
label="Phone Number"
|
|
441
|
+
type="tel"
|
|
442
|
+
inputMode="tel"
|
|
443
|
+
enterKeyHint="next"
|
|
444
|
+
size="lg"
|
|
445
|
+
placeholder="(555) 123-4567"
|
|
446
|
+
/>
|
|
447
|
+
<Input
|
|
448
|
+
label="Email"
|
|
449
|
+
type="email"
|
|
450
|
+
inputMode="email"
|
|
451
|
+
enterKeyHint="done"
|
|
452
|
+
size="lg"
|
|
453
|
+
placeholder="john@example.com"
|
|
454
|
+
/>
|
|
455
|
+
</div>
|
|
456
|
+
<ModalFooter>
|
|
457
|
+
<Button variant="ghost" size="lg" onClick={() => setIsOpen(false)}>Cancel</Button>
|
|
458
|
+
<Button variant="primary" size="lg" onClick={() => setIsOpen(false)}>Save Contact</Button>
|
|
459
|
+
</ModalFooter>
|
|
460
|
+
</Modal>
|
|
461
|
+
</>
|
|
462
|
+
);
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
export const MobileConfirmation: Story = {
|
|
467
|
+
parameters: {
|
|
468
|
+
viewport: { defaultViewport: 'mobile1' },
|
|
469
|
+
docs: {
|
|
470
|
+
description: {
|
|
471
|
+
story: 'Small confirmation modal on mobile with scale animation and touch-friendly buttons.',
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
render: () => {
|
|
476
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
477
|
+
return (
|
|
478
|
+
<>
|
|
479
|
+
<Button variant="danger" onClick={() => setIsOpen(true)}>Delete Item</Button>
|
|
480
|
+
<Modal
|
|
481
|
+
isOpen={isOpen}
|
|
482
|
+
onClose={() => setIsOpen(false)}
|
|
483
|
+
title="Delete Item?"
|
|
484
|
+
animation="scale"
|
|
485
|
+
size="sm"
|
|
486
|
+
>
|
|
487
|
+
<p style={{ marginBottom: '1rem' }}>
|
|
488
|
+
Are you sure you want to delete this item? This action cannot be undone.
|
|
489
|
+
</p>
|
|
490
|
+
<ModalFooter>
|
|
491
|
+
<Button variant="ghost" size="lg" onClick={() => setIsOpen(false)}>Cancel</Button>
|
|
492
|
+
<Button variant="danger" size="lg" onClick={() => setIsOpen(false)}>Delete</Button>
|
|
493
|
+
</ModalFooter>
|
|
494
|
+
</Modal>
|
|
495
|
+
</>
|
|
496
|
+
);
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
export const MobileFullScreen: Story = {
|
|
501
|
+
parameters: {
|
|
502
|
+
viewport: { defaultViewport: 'mobile1' },
|
|
503
|
+
docs: {
|
|
504
|
+
description: {
|
|
505
|
+
story: 'Full-screen modal on mobile for complex content that needs maximum space.',
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
render: () => {
|
|
510
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
511
|
+
return (
|
|
512
|
+
<>
|
|
513
|
+
<Button onClick={() => setIsOpen(true)}>View Details</Button>
|
|
514
|
+
<Modal
|
|
515
|
+
isOpen={isOpen}
|
|
516
|
+
onClose={() => setIsOpen(false)}
|
|
517
|
+
title="Product Details"
|
|
518
|
+
animation="slide-up"
|
|
519
|
+
size="full"
|
|
520
|
+
>
|
|
521
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
|
522
|
+
<div style={{ backgroundColor: '#f5f5f4', padding: '3rem', borderRadius: '0.5rem', textAlign: 'center' }}>
|
|
523
|
+
[Product Image]
|
|
524
|
+
</div>
|
|
525
|
+
<h3 style={{ fontSize: '1.25rem', fontWeight: 600 }}>Product Name</h3>
|
|
526
|
+
<p style={{ color: '#666' }}>$99.99</p>
|
|
527
|
+
<p>
|
|
528
|
+
This is a detailed product description that takes advantage of the full-screen
|
|
529
|
+
modal on mobile devices to show comprehensive information.
|
|
530
|
+
</p>
|
|
531
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
|
|
532
|
+
<h4 style={{ fontWeight: 600 }}>Features:</h4>
|
|
533
|
+
<ul style={{ marginLeft: '1.5rem' }}>
|
|
534
|
+
<li>Feature 1</li>
|
|
535
|
+
<li>Feature 2</li>
|
|
536
|
+
<li>Feature 3</li>
|
|
537
|
+
</ul>
|
|
538
|
+
</div>
|
|
539
|
+
</div>
|
|
540
|
+
<ModalFooter>
|
|
541
|
+
<Button variant="ghost" size="lg" onClick={() => setIsOpen(false)}>Close</Button>
|
|
542
|
+
<Button variant="primary" size="lg" onClick={() => setIsOpen(false)}>Add to Cart</Button>
|
|
543
|
+
</ModalFooter>
|
|
544
|
+
</Modal>
|
|
545
|
+
</>
|
|
546
|
+
);
|
|
547
|
+
},
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
// Scrollable content stories
|
|
551
|
+
export const Scrollable: Story = {
|
|
552
|
+
parameters: {
|
|
553
|
+
docs: {
|
|
554
|
+
description: {
|
|
555
|
+
story: 'Modal with `scrollable` prop enables automatic overflow handling for long content. The content area gets a max-height of `calc(100vh - 200px)` and becomes scrollable.',
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
render: () => {
|
|
560
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
561
|
+
return (
|
|
562
|
+
<>
|
|
563
|
+
<Button onClick={() => setIsOpen(true)}>Open Scrollable Modal</Button>
|
|
564
|
+
<Modal
|
|
565
|
+
isOpen={isOpen}
|
|
566
|
+
onClose={() => setIsOpen(false)}
|
|
567
|
+
title="Terms and Conditions"
|
|
568
|
+
scrollable
|
|
569
|
+
size="lg"
|
|
570
|
+
>
|
|
571
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
|
572
|
+
<h4 style={{ fontWeight: 600 }}>1. Introduction</h4>
|
|
573
|
+
<p>
|
|
574
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor
|
|
575
|
+
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
|
576
|
+
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
|
577
|
+
</p>
|
|
578
|
+
<h4 style={{ fontWeight: 600 }}>2. User Responsibilities</h4>
|
|
579
|
+
<p>
|
|
580
|
+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
|
581
|
+
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
|
|
582
|
+
culpa qui officia deserunt mollit anim id est laborum.
|
|
583
|
+
</p>
|
|
584
|
+
<h4 style={{ fontWeight: 600 }}>3. Privacy Policy</h4>
|
|
585
|
+
<p>
|
|
586
|
+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
|
|
587
|
+
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
|
|
588
|
+
veritatis et quasi architecto beatae vitae dicta sunt explicabo.
|
|
589
|
+
</p>
|
|
590
|
+
<h4 style={{ fontWeight: 600 }}>4. Data Collection</h4>
|
|
591
|
+
<p>
|
|
592
|
+
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed
|
|
593
|
+
quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
|
|
594
|
+
</p>
|
|
595
|
+
<h4 style={{ fontWeight: 600 }}>5. Service Terms</h4>
|
|
596
|
+
<p>
|
|
597
|
+
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
|
|
598
|
+
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et
|
|
599
|
+
dolore magnam aliquam quaerat voluptatem.
|
|
600
|
+
</p>
|
|
601
|
+
<h4 style={{ fontWeight: 600 }}>6. Liability</h4>
|
|
602
|
+
<p>
|
|
603
|
+
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit
|
|
604
|
+
laboriosam, nisi ut aliquid ex ea commodi consequatur.
|
|
605
|
+
</p>
|
|
606
|
+
<h4 style={{ fontWeight: 600 }}>7. Termination</h4>
|
|
607
|
+
<p>
|
|
608
|
+
Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil
|
|
609
|
+
molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur.
|
|
610
|
+
</p>
|
|
611
|
+
<h4 style={{ fontWeight: 600 }}>8. Amendments</h4>
|
|
612
|
+
<p>
|
|
613
|
+
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis
|
|
614
|
+
praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias
|
|
615
|
+
excepturi sint occaecati cupiditate non provident.
|
|
616
|
+
</p>
|
|
617
|
+
</div>
|
|
618
|
+
<ModalFooter>
|
|
619
|
+
<Button variant="ghost" onClick={() => setIsOpen(false)}>Decline</Button>
|
|
620
|
+
<Button variant="primary" onClick={() => setIsOpen(false)}>Accept</Button>
|
|
621
|
+
</ModalFooter>
|
|
622
|
+
</Modal>
|
|
623
|
+
</>
|
|
624
|
+
);
|
|
625
|
+
},
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
export const CustomMaxHeight: Story = {
|
|
629
|
+
parameters: {
|
|
630
|
+
docs: {
|
|
631
|
+
description: {
|
|
632
|
+
story: 'Modal with custom `maxHeight` prop for precise control over content area height. Useful when you want a specific height constraint rather than the default scrollable behavior.',
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
},
|
|
636
|
+
render: () => {
|
|
637
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
638
|
+
return (
|
|
639
|
+
<>
|
|
640
|
+
<Button onClick={() => setIsOpen(true)}>Open Modal (maxHeight: 300px)</Button>
|
|
641
|
+
<Modal
|
|
642
|
+
isOpen={isOpen}
|
|
643
|
+
onClose={() => setIsOpen(false)}
|
|
644
|
+
title="Document Preview"
|
|
645
|
+
maxHeight="300px"
|
|
646
|
+
size="lg"
|
|
647
|
+
>
|
|
648
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
|
649
|
+
<p>This modal has a fixed maximum height of 300px for the content area.</p>
|
|
650
|
+
<p>
|
|
651
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor
|
|
652
|
+
incididunt ut labore et dolore magna aliqua.
|
|
653
|
+
</p>
|
|
654
|
+
<p>
|
|
655
|
+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
|
656
|
+
aliquip ex ea commodo consequat.
|
|
657
|
+
</p>
|
|
658
|
+
<p>
|
|
659
|
+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
|
|
660
|
+
eu fugiat nulla pariatur.
|
|
661
|
+
</p>
|
|
662
|
+
<p>
|
|
663
|
+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
|
|
664
|
+
deserunt mollit anim id est laborum.
|
|
665
|
+
</p>
|
|
666
|
+
<p>
|
|
667
|
+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
|
|
668
|
+
doloremque laudantium.
|
|
669
|
+
</p>
|
|
670
|
+
</div>
|
|
671
|
+
<ModalFooter>
|
|
672
|
+
<Button variant="ghost" onClick={() => setIsOpen(false)}>Close</Button>
|
|
673
|
+
<Button variant="primary" onClick={() => setIsOpen(false)}>Download</Button>
|
|
674
|
+
</ModalFooter>
|
|
675
|
+
</Modal>
|
|
676
|
+
</>
|
|
677
|
+
);
|
|
678
|
+
},
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
export const ScrollableWithViewportHeight: Story = {
|
|
682
|
+
parameters: {
|
|
683
|
+
docs: {
|
|
684
|
+
description: {
|
|
685
|
+
story: 'Modal with `maxHeight="70vh"` - a common pattern for modals that should take up most of the viewport but leave some breathing room.',
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
render: () => {
|
|
690
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
691
|
+
const items = Array.from({ length: 50 }, (_, i) => ({
|
|
692
|
+
id: i + 1,
|
|
693
|
+
name: `Item ${i + 1}`,
|
|
694
|
+
description: `Description for item ${i + 1}`,
|
|
695
|
+
}));
|
|
696
|
+
|
|
697
|
+
return (
|
|
698
|
+
<>
|
|
699
|
+
<Button onClick={() => setIsOpen(true)}>Open Data Table Modal (70vh)</Button>
|
|
700
|
+
<Modal
|
|
701
|
+
isOpen={isOpen}
|
|
702
|
+
onClose={() => setIsOpen(false)}
|
|
703
|
+
title="Select Items"
|
|
704
|
+
maxHeight="70vh"
|
|
705
|
+
size="xl"
|
|
706
|
+
>
|
|
707
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
|
|
708
|
+
<p style={{ color: '#666', marginBottom: '0.5rem' }}>
|
|
709
|
+
Select items from the list below. The content area is limited to 70% of viewport height.
|
|
710
|
+
</p>
|
|
711
|
+
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
|
|
712
|
+
<thead>
|
|
713
|
+
<tr style={{ borderBottom: '2px solid #e5e5e4' }}>
|
|
714
|
+
<th style={{ textAlign: 'left', padding: '0.75rem 0.5rem', fontWeight: 600 }}>ID</th>
|
|
715
|
+
<th style={{ textAlign: 'left', padding: '0.75rem 0.5rem', fontWeight: 600 }}>Name</th>
|
|
716
|
+
<th style={{ textAlign: 'left', padding: '0.75rem 0.5rem', fontWeight: 600 }}>Description</th>
|
|
717
|
+
</tr>
|
|
718
|
+
</thead>
|
|
719
|
+
<tbody>
|
|
720
|
+
{items.map((item) => (
|
|
721
|
+
<tr key={item.id} style={{ borderBottom: '1px solid #e5e5e4' }}>
|
|
722
|
+
<td style={{ padding: '0.5rem' }}>{item.id}</td>
|
|
723
|
+
<td style={{ padding: '0.5rem' }}>{item.name}</td>
|
|
724
|
+
<td style={{ padding: '0.5rem' }}>{item.description}</td>
|
|
725
|
+
</tr>
|
|
726
|
+
))}
|
|
727
|
+
</tbody>
|
|
728
|
+
</table>
|
|
729
|
+
</div>
|
|
730
|
+
<ModalFooter>
|
|
731
|
+
<Button variant="ghost" onClick={() => setIsOpen(false)}>Cancel</Button>
|
|
732
|
+
<Button variant="primary" onClick={() => setIsOpen(false)}>Select</Button>
|
|
733
|
+
</ModalFooter>
|
|
734
|
+
</Modal>
|
|
735
|
+
</>
|
|
736
|
+
);
|
|
737
|
+
},
|
|
738
|
+
};
|
package/src/components/Modal.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useId } from 'react';
|
|
2
2
|
import { X } from 'lucide-react';
|
|
3
|
+
import { useIsMobile } from '../hooks/useResponsive';
|
|
4
|
+
import BottomSheet from './BottomSheet';
|
|
3
5
|
|
|
4
6
|
export interface ModalProps {
|
|
5
7
|
isOpen: boolean;
|
|
@@ -10,6 +12,18 @@ export interface ModalProps {
|
|
|
10
12
|
showCloseButton?: boolean;
|
|
11
13
|
/** Animation variant for modal entrance (default: 'scale') */
|
|
12
14
|
animation?: 'scale' | 'slide-up' | 'slide-down' | 'fade' | 'none';
|
|
15
|
+
/** Enable automatic scrolling for content that exceeds viewport height */
|
|
16
|
+
scrollable?: boolean;
|
|
17
|
+
/** Maximum height of the modal content area (e.g., '70vh', '500px') */
|
|
18
|
+
maxHeight?: string;
|
|
19
|
+
|
|
20
|
+
// Mobile behavior props
|
|
21
|
+
/** Mobile display mode: 'auto' uses BottomSheet on mobile, 'modal' always uses modal, 'sheet' always uses BottomSheet */
|
|
22
|
+
mobileMode?: 'auto' | 'modal' | 'sheet';
|
|
23
|
+
/** Height preset for BottomSheet on mobile (default: 'lg') */
|
|
24
|
+
mobileHeight?: 'sm' | 'md' | 'lg' | 'full';
|
|
25
|
+
/** Show drag handle on BottomSheet (default: true) */
|
|
26
|
+
mobileShowHandle?: boolean;
|
|
13
27
|
}
|
|
14
28
|
|
|
15
29
|
const sizeClasses = {
|
|
@@ -20,6 +34,73 @@ const sizeClasses = {
|
|
|
20
34
|
full: 'max-w-7xl',
|
|
21
35
|
};
|
|
22
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Modal - Adaptive dialog component
|
|
39
|
+
*
|
|
40
|
+
* On desktop, renders as a centered modal dialog.
|
|
41
|
+
* On mobile (when mobileMode='auto'), automatically renders as a BottomSheet
|
|
42
|
+
* for better touch interaction and visibility.
|
|
43
|
+
*
|
|
44
|
+
* @example Basic modal
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <Modal isOpen={isOpen} onClose={handleClose} title="Edit User">
|
|
47
|
+
* <form>...</form>
|
|
48
|
+
* <ModalFooter>
|
|
49
|
+
* <Button onClick={handleClose}>Cancel</Button>
|
|
50
|
+
* <Button variant="primary" onClick={handleSave}>Save</Button>
|
|
51
|
+
* </ModalFooter>
|
|
52
|
+
* </Modal>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example Scrollable modal for long content
|
|
56
|
+
* ```tsx
|
|
57
|
+
* <Modal
|
|
58
|
+
* isOpen={isOpen}
|
|
59
|
+
* onClose={handleClose}
|
|
60
|
+
* title="Terms and Conditions"
|
|
61
|
+
* scrollable
|
|
62
|
+
* >
|
|
63
|
+
* {longContent}
|
|
64
|
+
* </Modal>
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example Modal with custom max height
|
|
68
|
+
* ```tsx
|
|
69
|
+
* <Modal
|
|
70
|
+
* isOpen={isOpen}
|
|
71
|
+
* onClose={handleClose}
|
|
72
|
+
* title="Document Preview"
|
|
73
|
+
* maxHeight="70vh"
|
|
74
|
+
* >
|
|
75
|
+
* {documentContent}
|
|
76
|
+
* </Modal>
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Force modal on mobile
|
|
80
|
+
* ```tsx
|
|
81
|
+
* <Modal
|
|
82
|
+
* isOpen={isOpen}
|
|
83
|
+
* onClose={handleClose}
|
|
84
|
+
* title="Settings"
|
|
85
|
+
* mobileMode="modal"
|
|
86
|
+
* >
|
|
87
|
+
* ...
|
|
88
|
+
* </Modal>
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Always use BottomSheet
|
|
92
|
+
* ```tsx
|
|
93
|
+
* <Modal
|
|
94
|
+
* isOpen={isOpen}
|
|
95
|
+
* onClose={handleClose}
|
|
96
|
+
* title="Select Option"
|
|
97
|
+
* mobileMode="sheet"
|
|
98
|
+
* mobileHeight="md"
|
|
99
|
+
* >
|
|
100
|
+
* ...
|
|
101
|
+
* </Modal>
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
23
104
|
export default function Modal({
|
|
24
105
|
isOpen,
|
|
25
106
|
onClose,
|
|
@@ -28,13 +109,26 @@ export default function Modal({
|
|
|
28
109
|
size = 'md',
|
|
29
110
|
showCloseButton = true,
|
|
30
111
|
animation = 'scale',
|
|
112
|
+
scrollable = false,
|
|
113
|
+
maxHeight,
|
|
114
|
+
mobileMode = 'auto',
|
|
115
|
+
mobileHeight = 'lg',
|
|
116
|
+
mobileShowHandle = true,
|
|
31
117
|
}: ModalProps) {
|
|
32
118
|
const modalRef = useRef<HTMLDivElement>(null);
|
|
33
119
|
const mouseDownOnBackdrop = useRef(false);
|
|
34
120
|
const titleId = useId();
|
|
121
|
+
const isMobile = useIsMobile();
|
|
35
122
|
|
|
36
|
-
//
|
|
123
|
+
// Determine if we should use BottomSheet
|
|
124
|
+
const useBottomSheet =
|
|
125
|
+
mobileMode === 'sheet' ||
|
|
126
|
+
(mobileMode === 'auto' && isMobile);
|
|
127
|
+
|
|
128
|
+
// Handle escape key (only for modal mode, BottomSheet handles its own)
|
|
37
129
|
useEffect(() => {
|
|
130
|
+
if (useBottomSheet) return; // BottomSheet handles escape
|
|
131
|
+
|
|
38
132
|
const handleEscape = (e: KeyboardEvent) => {
|
|
39
133
|
if (e.key === 'Escape' && isOpen) {
|
|
40
134
|
onClose();
|
|
@@ -50,7 +144,7 @@ export default function Modal({
|
|
|
50
144
|
document.removeEventListener('keydown', handleEscape);
|
|
51
145
|
document.body.style.overflow = 'unset';
|
|
52
146
|
};
|
|
53
|
-
}, [isOpen, onClose]);
|
|
147
|
+
}, [isOpen, onClose, useBottomSheet]);
|
|
54
148
|
|
|
55
149
|
// Track if mousedown originated on the backdrop
|
|
56
150
|
const handleBackdropMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
@@ -89,6 +183,23 @@ export default function Modal({
|
|
|
89
183
|
|
|
90
184
|
if (!isOpen) return null;
|
|
91
185
|
|
|
186
|
+
// Render as BottomSheet on mobile
|
|
187
|
+
if (useBottomSheet) {
|
|
188
|
+
return (
|
|
189
|
+
<BottomSheet
|
|
190
|
+
isOpen={isOpen}
|
|
191
|
+
onClose={onClose}
|
|
192
|
+
title={title}
|
|
193
|
+
height={mobileHeight}
|
|
194
|
+
showHandle={mobileShowHandle}
|
|
195
|
+
showCloseButton={showCloseButton}
|
|
196
|
+
>
|
|
197
|
+
{children}
|
|
198
|
+
</BottomSheet>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Render as standard modal on desktop
|
|
92
203
|
return (
|
|
93
204
|
<div
|
|
94
205
|
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-ink-900 bg-opacity-50 backdrop-blur-sm animate-fade-in"
|
|
@@ -119,7 +230,14 @@ export default function Modal({
|
|
|
119
230
|
</div>
|
|
120
231
|
|
|
121
232
|
{/* Content */}
|
|
122
|
-
<div
|
|
233
|
+
<div
|
|
234
|
+
className={`px-6 py-4 ${scrollable || maxHeight ? 'overflow-y-auto' : ''}`}
|
|
235
|
+
style={{
|
|
236
|
+
maxHeight: maxHeight || (scrollable ? 'calc(100vh - 200px)' : undefined),
|
|
237
|
+
}}
|
|
238
|
+
>
|
|
239
|
+
{children}
|
|
240
|
+
</div>
|
|
123
241
|
</div>
|
|
124
242
|
</div>
|
|
125
243
|
);
|
|
@@ -127,7 +245,7 @@ export default function Modal({
|
|
|
127
245
|
|
|
128
246
|
export function ModalFooter({ children }: { children: React.ReactNode }) {
|
|
129
247
|
return (
|
|
130
|
-
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-paper-200 bg-paper-50">
|
|
248
|
+
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-paper-200 bg-paper-50 -mx-6 -mb-4 mt-4 rounded-b-xl">
|
|
131
249
|
{children}
|
|
132
250
|
</div>
|
|
133
251
|
);
|