@papernote/ui 1.5.0 → 1.7.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.
Files changed (37) hide show
  1. package/README.md +3 -3
  2. package/dist/components/ActionBar.d.ts +112 -0
  3. package/dist/components/ActionBar.d.ts.map +1 -0
  4. package/dist/components/DataGrid.d.ts +182 -0
  5. package/dist/components/DataGrid.d.ts.map +1 -0
  6. package/dist/components/FormulaAutocomplete.d.ts +29 -0
  7. package/dist/components/FormulaAutocomplete.d.ts.map +1 -0
  8. package/dist/components/Modal.d.ts +29 -1
  9. package/dist/components/Modal.d.ts.map +1 -1
  10. package/dist/components/PageHeader.d.ts +86 -0
  11. package/dist/components/PageHeader.d.ts.map +1 -0
  12. package/dist/components/Select.d.ts +2 -0
  13. package/dist/components/Select.d.ts.map +1 -1
  14. package/dist/components/index.d.ts +8 -0
  15. package/dist/components/index.d.ts.map +1 -1
  16. package/dist/index.d.ts +419 -3
  17. package/dist/index.esm.js +2533 -350
  18. package/dist/index.esm.js.map +1 -1
  19. package/dist/index.js +2543 -348
  20. package/dist/index.js.map +1 -1
  21. package/dist/styles.css +81 -0
  22. package/dist/utils/formulaDefinitions.d.ts +25 -0
  23. package/dist/utils/formulaDefinitions.d.ts.map +1 -0
  24. package/package.json +1 -1
  25. package/src/components/ActionBar.stories.tsx +246 -0
  26. package/src/components/ActionBar.tsx +242 -0
  27. package/src/components/DataGrid.stories.tsx +356 -0
  28. package/src/components/DataGrid.tsx +1025 -0
  29. package/src/components/FormulaAutocomplete.tsx +417 -0
  30. package/src/components/Modal.stories.tsx +205 -0
  31. package/src/components/Modal.tsx +38 -1
  32. package/src/components/PageHeader.stories.tsx +198 -0
  33. package/src/components/PageHeader.tsx +217 -0
  34. package/src/components/Select.tsx +121 -7
  35. package/src/components/Sidebar.tsx +2 -2
  36. package/src/components/index.ts +36 -0
  37. package/src/utils/formulaDefinitions.ts +1228 -0
@@ -0,0 +1,417 @@
1
+ import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import {
4
+ FORMULA_DEFINITIONS,
5
+ searchFormulas,
6
+ getFormula,
7
+ FORMULA_CATEGORIES,
8
+ FormulaDefinition,
9
+ FormulaCategory,
10
+ } from '../utils/formulaDefinitions';
11
+
12
+ export interface FormulaAutocompleteProps {
13
+ /** Current input value */
14
+ value: string;
15
+ /** Callback when value changes */
16
+ onChange: (value: string) => void;
17
+ /** Callback when editing is complete */
18
+ onComplete: () => void;
19
+ /** Callback to cancel editing */
20
+ onCancel: () => void;
21
+ /** Position for the dropdown */
22
+ anchorRect: DOMRect | null;
23
+ /** Auto focus the input */
24
+ autoFocus?: boolean;
25
+ /** Custom class name */
26
+ className?: string;
27
+ }
28
+
29
+ interface FormulaHint {
30
+ formula: FormulaDefinition;
31
+ currentParamIndex: number;
32
+ }
33
+
34
+ /**
35
+ * FormulaAutocomplete - Input with formula intellisense
36
+ *
37
+ * Features:
38
+ * - Autocomplete dropdown when typing after '='
39
+ * - Function signature hints while typing parameters
40
+ * - Category-based browsing
41
+ * - Keyboard navigation
42
+ */
43
+ const FormulaAutocomplete: React.FC<FormulaAutocompleteProps> = ({
44
+ value,
45
+ onChange,
46
+ onComplete,
47
+ onCancel,
48
+ anchorRect,
49
+ autoFocus = true,
50
+ className = '',
51
+ }) => {
52
+ const inputRef = useRef<HTMLInputElement>(null);
53
+ const dropdownRef = useRef<HTMLDivElement>(null);
54
+ const [selectedIndex, setSelectedIndex] = useState(0);
55
+ const [showDropdown, setShowDropdown] = useState(false);
56
+ const [showHint, setShowHint] = useState(false);
57
+ const [hint, setHint] = useState<FormulaHint | null>(null);
58
+ const [activeCategory, setActiveCategory] = useState<FormulaCategory | null>(null);
59
+
60
+ // Parse the current formula context
61
+ const formulaContext = useMemo(() => {
62
+ if (!value.startsWith('=')) {
63
+ return { isFormula: false, query: '', inFunction: false, functionName: '', paramIndex: 0 };
64
+ }
65
+
66
+ const formulaText = value.substring(1);
67
+
68
+ // Check if we're typing a function name (before opening paren)
69
+ const functionMatch = formulaText.match(/^([A-Z]+)$/i);
70
+ if (functionMatch) {
71
+ return {
72
+ isFormula: true,
73
+ query: functionMatch[1].toUpperCase(),
74
+ inFunction: false,
75
+ functionName: '',
76
+ paramIndex: 0,
77
+ };
78
+ }
79
+
80
+ // Check if we're inside a function (after opening paren)
81
+ const insideFunctionMatch = formulaText.match(/^([A-Z]+)\((.*)$/i);
82
+ if (insideFunctionMatch) {
83
+ const functionName = insideFunctionMatch[1].toUpperCase();
84
+ const params = insideFunctionMatch[2];
85
+
86
+ // Count commas to determine parameter index (accounting for nested parens)
87
+ let paramIndex = 0;
88
+ let parenDepth = 0;
89
+ for (const char of params) {
90
+ if (char === '(') parenDepth++;
91
+ else if (char === ')') parenDepth--;
92
+ else if (char === ',' && parenDepth === 0) paramIndex++;
93
+ }
94
+
95
+ return {
96
+ isFormula: true,
97
+ query: '',
98
+ inFunction: true,
99
+ functionName,
100
+ paramIndex,
101
+ };
102
+ }
103
+
104
+ // Just '=' or other expression
105
+ return {
106
+ isFormula: true,
107
+ query: formulaText.toUpperCase(),
108
+ inFunction: false,
109
+ functionName: '',
110
+ paramIndex: 0,
111
+ };
112
+ }, [value]);
113
+
114
+ // Get matching formulas for dropdown
115
+ const matchingFormulas = useMemo(() => {
116
+ if (!formulaContext.isFormula || formulaContext.inFunction) return [];
117
+
118
+ if (activeCategory) {
119
+ const categoryFormulas = FORMULA_DEFINITIONS.filter(f => f.category === activeCategory);
120
+ if (formulaContext.query) {
121
+ return categoryFormulas.filter(f => f.name.startsWith(formulaContext.query));
122
+ }
123
+ return categoryFormulas;
124
+ }
125
+
126
+ if (formulaContext.query) {
127
+ return searchFormulas(formulaContext.query);
128
+ }
129
+
130
+ // Show all formulas grouped by first letter when just '='
131
+ return FORMULA_DEFINITIONS.slice(0, 20); // Show first 20 as default
132
+ }, [formulaContext, activeCategory]);
133
+
134
+ // Update hint when inside a function
135
+ useEffect(() => {
136
+ if (formulaContext.inFunction && formulaContext.functionName) {
137
+ const formula = getFormula(formulaContext.functionName);
138
+ if (formula) {
139
+ setHint({
140
+ formula,
141
+ currentParamIndex: formulaContext.paramIndex,
142
+ });
143
+ setShowHint(true);
144
+ setShowDropdown(false);
145
+ } else {
146
+ setShowHint(false);
147
+ setHint(null);
148
+ }
149
+ } else if (formulaContext.isFormula && !formulaContext.inFunction) {
150
+ setShowDropdown(true);
151
+ setShowHint(false);
152
+ setHint(null);
153
+ } else {
154
+ setShowDropdown(false);
155
+ setShowHint(false);
156
+ setHint(null);
157
+ }
158
+ }, [formulaContext]);
159
+
160
+ // Reset selected index when matches change
161
+ useEffect(() => {
162
+ setSelectedIndex(0);
163
+ }, [matchingFormulas.length]);
164
+
165
+ // Auto-focus
166
+ useEffect(() => {
167
+ if (autoFocus && inputRef.current) {
168
+ inputRef.current.focus();
169
+ inputRef.current.select();
170
+ }
171
+ }, [autoFocus]);
172
+
173
+ // Scroll selected item into view
174
+ useEffect(() => {
175
+ if (dropdownRef.current && showDropdown) {
176
+ const selectedItem = dropdownRef.current.querySelector(`[data-index="${selectedIndex}"]`);
177
+ if (selectedItem) {
178
+ selectedItem.scrollIntoView({ block: 'nearest' });
179
+ }
180
+ }
181
+ }, [selectedIndex, showDropdown]);
182
+
183
+ // Handle keyboard navigation
184
+ const handleKeyDown = useCallback(
185
+ (e: React.KeyboardEvent) => {
186
+ if (showDropdown && matchingFormulas.length > 0) {
187
+ switch (e.key) {
188
+ case 'ArrowDown':
189
+ e.preventDefault();
190
+ setSelectedIndex((prev) => Math.min(prev + 1, matchingFormulas.length - 1));
191
+ break;
192
+ case 'ArrowUp':
193
+ e.preventDefault();
194
+ setSelectedIndex((prev) => Math.max(prev - 1, 0));
195
+ break;
196
+ case 'Tab':
197
+ case 'Enter':
198
+ e.preventDefault();
199
+ insertFormula(matchingFormulas[selectedIndex]);
200
+ break;
201
+ case 'Escape':
202
+ e.preventDefault();
203
+ if (showDropdown) {
204
+ setShowDropdown(false);
205
+ } else {
206
+ onCancel();
207
+ }
208
+ break;
209
+ }
210
+ } else {
211
+ if (e.key === 'Enter') {
212
+ e.preventDefault();
213
+ onComplete();
214
+ } else if (e.key === 'Escape') {
215
+ e.preventDefault();
216
+ onCancel();
217
+ }
218
+ }
219
+ },
220
+ [showDropdown, matchingFormulas, selectedIndex, onComplete, onCancel]
221
+ );
222
+
223
+ // Insert selected formula
224
+ const insertFormula = useCallback(
225
+ (formula: FormulaDefinition) => {
226
+ // Replace the current query with the formula name and open paren
227
+ const newValue = `=${formula.name}(`;
228
+ onChange(newValue);
229
+ setShowDropdown(false);
230
+ inputRef.current?.focus();
231
+ },
232
+ [onChange]
233
+ );
234
+
235
+ // Calculate dropdown position
236
+ const dropdownPosition = useMemo(() => {
237
+ if (!anchorRect) return { top: 0, left: 0 };
238
+ return {
239
+ top: anchorRect.bottom + 2,
240
+ left: anchorRect.left,
241
+ };
242
+ }, [anchorRect]);
243
+
244
+ // Prevent blur when clicking inside dropdown
245
+ const handleDropdownMouseDown = useCallback((e: React.MouseEvent) => {
246
+ e.preventDefault(); // Prevents input from losing focus
247
+ }, []);
248
+
249
+ // Render parameter hint
250
+ const renderHint = () => {
251
+ if (!showHint || !hint) return null;
252
+
253
+ return createPortal(
254
+ <div
255
+ className="fixed z-[9999] bg-white border border-stone-200 rounded-lg shadow-lg p-3 max-w-md"
256
+ style={{
257
+ top: dropdownPosition.top,
258
+ left: dropdownPosition.left,
259
+ }}
260
+ onMouseDown={handleDropdownMouseDown}
261
+ >
262
+ {/* Function name and syntax */}
263
+ <div className="font-mono text-sm mb-2">
264
+ <span className="text-primary-600 font-semibold">{hint.formula.name}</span>
265
+ <span className="text-ink-500">(</span>
266
+ {hint.formula.parameters.map((param, idx) => (
267
+ <span key={param.name}>
268
+ {idx > 0 && <span className="text-ink-500">, </span>}
269
+ <span
270
+ className={`${
271
+ idx === hint.currentParamIndex
272
+ ? 'bg-primary-100 text-primary-700 px-1 rounded font-semibold'
273
+ : param.optional
274
+ ? 'text-ink-400'
275
+ : 'text-ink-600'
276
+ }`}
277
+ >
278
+ {param.optional ? `[${param.name}]` : param.name}
279
+ </span>
280
+ </span>
281
+ ))}
282
+ <span className="text-ink-500">)</span>
283
+ </div>
284
+
285
+ {/* Description */}
286
+ <div className="text-xs text-ink-600 mb-2">{hint.formula.description}</div>
287
+
288
+ {/* Current parameter description */}
289
+ {hint.formula.parameters[hint.currentParamIndex] && (
290
+ <div className="text-xs bg-paper-50 p-2 rounded border border-stone-100">
291
+ <span className="font-semibold text-primary-600">
292
+ {hint.formula.parameters[hint.currentParamIndex].name}:
293
+ </span>{' '}
294
+ <span className="text-ink-600">
295
+ {hint.formula.parameters[hint.currentParamIndex].description}
296
+ </span>
297
+ </div>
298
+ )}
299
+ </div>,
300
+ document.body
301
+ );
302
+ };
303
+
304
+ // Render autocomplete dropdown
305
+ const renderDropdown = () => {
306
+ if (!showDropdown || matchingFormulas.length === 0) return null;
307
+
308
+ return createPortal(
309
+ <div
310
+ ref={dropdownRef}
311
+ className="fixed z-[9999] bg-white border border-stone-200 rounded-lg shadow-lg overflow-hidden"
312
+ style={{
313
+ top: dropdownPosition.top,
314
+ left: dropdownPosition.left,
315
+ minWidth: 320,
316
+ maxWidth: 450,
317
+ maxHeight: 300,
318
+ }}
319
+ onMouseDown={handleDropdownMouseDown}
320
+ >
321
+ {/* Category tabs */}
322
+ <div className="flex flex-wrap gap-1 p-2 border-b border-stone-100 bg-paper-50">
323
+ <button
324
+ className={`px-2 py-1 text-xs rounded ${
325
+ activeCategory === null
326
+ ? 'bg-primary-500 text-white'
327
+ : 'bg-white text-ink-600 hover:bg-stone-100'
328
+ }`}
329
+ onClick={() => {
330
+ setActiveCategory(null);
331
+ inputRef.current?.focus();
332
+ }}
333
+ >
334
+ All
335
+ </button>
336
+ {FORMULA_CATEGORIES.map((cat) => (
337
+ <button
338
+ key={cat}
339
+ className={`px-2 py-1 text-xs rounded ${
340
+ activeCategory === cat
341
+ ? 'bg-primary-500 text-white'
342
+ : 'bg-white text-ink-600 hover:bg-stone-100'
343
+ }`}
344
+ onClick={() => {
345
+ setActiveCategory(cat);
346
+ inputRef.current?.focus();
347
+ }}
348
+ >
349
+ {cat}
350
+ </button>
351
+ ))}
352
+ </div>
353
+
354
+ {/* Formula list */}
355
+ <div className="overflow-y-auto" style={{ maxHeight: 220 }}>
356
+ {matchingFormulas.map((formula, index) => (
357
+ <div
358
+ key={formula.name}
359
+ data-index={index}
360
+ className={`px-3 py-2 cursor-pointer border-b border-stone-50 ${
361
+ index === selectedIndex ? 'bg-primary-50' : 'hover:bg-paper-50'
362
+ }`}
363
+ onClick={() => insertFormula(formula)}
364
+ onMouseEnter={() => setSelectedIndex(index)}
365
+ >
366
+ <div className="flex items-center gap-2">
367
+ <span className="font-mono font-semibold text-primary-600 text-sm">
368
+ {formula.name}
369
+ </span>
370
+ <span className="text-xs text-ink-400 bg-stone-100 px-1.5 py-0.5 rounded">
371
+ {formula.category}
372
+ </span>
373
+ </div>
374
+ <div className="text-xs text-ink-500 mt-0.5 truncate">{formula.description}</div>
375
+ <div className="font-mono text-xs text-ink-400 mt-0.5">{formula.syntax}</div>
376
+ </div>
377
+ ))}
378
+ </div>
379
+
380
+ {/* Footer hint */}
381
+ <div className="px-3 py-1.5 bg-paper-50 border-t border-stone-100 text-xs text-ink-400">
382
+ <span className="font-medium">↑↓</span> navigate
383
+ <span className="mx-2">·</span>
384
+ <span className="font-medium">Tab/Enter</span> insert
385
+ <span className="mx-2">·</span>
386
+ <span className="font-medium">Esc</span> close
387
+ </div>
388
+ </div>,
389
+ document.body
390
+ );
391
+ };
392
+
393
+ return (
394
+ <>
395
+ <input
396
+ ref={inputRef}
397
+ type="text"
398
+ value={value}
399
+ onChange={(e) => onChange(e.target.value)}
400
+ onKeyDown={handleKeyDown}
401
+ onBlur={() => {
402
+ // Delay to allow click on dropdown
403
+ setTimeout(() => {
404
+ setShowDropdown(false);
405
+ setShowHint(false);
406
+ }, 150);
407
+ }}
408
+ className={`w-full h-full border-none outline-none bg-transparent font-mono text-sm ${className}`}
409
+ style={{ margin: '-4px', padding: '4px' }}
410
+ />
411
+ {renderDropdown()}
412
+ {renderHint()}
413
+ </>
414
+ );
415
+ };
416
+
417
+ export default FormulaAutocomplete;
@@ -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
 
@@ -531,3 +546,193 @@ export const MobileFullScreen: Story = {
531
546
  );
532
547
  },
533
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
+ };
@@ -12,6 +12,10 @@ export interface ModalProps {
12
12
  showCloseButton?: boolean;
13
13
  /** Animation variant for modal entrance (default: 'scale') */
14
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;
15
19
 
16
20
  // Mobile behavior props
17
21
  /** Mobile display mode: 'auto' uses BottomSheet on mobile, 'modal' always uses modal, 'sheet' always uses BottomSheet */
@@ -48,6 +52,30 @@ const sizeClasses = {
48
52
  * </Modal>
49
53
  * ```
50
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
+ *
51
79
  * @example Force modal on mobile
52
80
  * ```tsx
53
81
  * <Modal
@@ -81,6 +109,8 @@ export default function Modal({
81
109
  size = 'md',
82
110
  showCloseButton = true,
83
111
  animation = 'scale',
112
+ scrollable = false,
113
+ maxHeight,
84
114
  mobileMode = 'auto',
85
115
  mobileHeight = 'lg',
86
116
  mobileShowHandle = true,
@@ -200,7 +230,14 @@ export default function Modal({
200
230
  </div>
201
231
 
202
232
  {/* Content */}
203
- <div className="px-6 py-4">{children}</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>
204
241
  </div>
205
242
  </div>
206
243
  );