@boostdev/design-system-components 0.1.1

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 (233) hide show
  1. package/AGENTS.md +72 -0
  2. package/README.md +396 -0
  3. package/dist/index.cjs +2273 -0
  4. package/dist/index.css +2543 -0
  5. package/dist/index.d.cts +453 -0
  6. package/dist/index.d.ts +453 -0
  7. package/dist/index.js +2221 -0
  8. package/package.json +143 -0
  9. package/src/components/interaction/Button/Button.module.css +136 -0
  10. package/src/components/interaction/Button/Button.spec.tsx +50 -0
  11. package/src/components/interaction/Button/Button.stories.tsx +43 -0
  12. package/src/components/interaction/Button/Button.tsx +68 -0
  13. package/src/components/interaction/Button/index.ts +1 -0
  14. package/src/components/interaction/Command/Command.module.css +128 -0
  15. package/src/components/interaction/Command/Command.spec.tsx +60 -0
  16. package/src/components/interaction/Command/Command.stories.tsx +35 -0
  17. package/src/components/interaction/Command/Command.tsx +161 -0
  18. package/src/components/interaction/Command/index.ts +2 -0
  19. package/src/components/interaction/Dialog/Dialog.module.css +39 -0
  20. package/src/components/interaction/Dialog/Dialog.spec.tsx +43 -0
  21. package/src/components/interaction/Dialog/Dialog.stories.tsx +36 -0
  22. package/src/components/interaction/Dialog/Dialog.tsx +42 -0
  23. package/src/components/interaction/Dialog/index.ts +1 -0
  24. package/src/components/interaction/Drawer/Drawer.module.css +98 -0
  25. package/src/components/interaction/Drawer/Drawer.spec.tsx +43 -0
  26. package/src/components/interaction/Drawer/Drawer.stories.tsx +46 -0
  27. package/src/components/interaction/Drawer/Drawer.tsx +71 -0
  28. package/src/components/interaction/Drawer/index.ts +1 -0
  29. package/src/components/interaction/DropdownMenu/DropdownMenu.module.css +68 -0
  30. package/src/components/interaction/DropdownMenu/DropdownMenu.spec.tsx +74 -0
  31. package/src/components/interaction/DropdownMenu/DropdownMenu.stories.tsx +68 -0
  32. package/src/components/interaction/DropdownMenu/DropdownMenu.tsx +137 -0
  33. package/src/components/interaction/DropdownMenu/index.ts +1 -0
  34. package/src/components/interaction/Popover/Popover.module.css +39 -0
  35. package/src/components/interaction/Popover/Popover.spec.tsx +72 -0
  36. package/src/components/interaction/Popover/Popover.stories.tsx +47 -0
  37. package/src/components/interaction/Popover/Popover.tsx +78 -0
  38. package/src/components/interaction/Popover/index.ts +1 -0
  39. package/src/components/interaction/Rating/Rating.module.css +16 -0
  40. package/src/components/interaction/Rating/Rating.spec.tsx +30 -0
  41. package/src/components/interaction/Rating/Rating.stories.tsx +29 -0
  42. package/src/components/interaction/Rating/Rating.tsx +30 -0
  43. package/src/components/interaction/Rating/index.ts +1 -0
  44. package/src/components/interaction/Toast/Toast.module.css +48 -0
  45. package/src/components/interaction/Toast/Toast.spec.tsx +41 -0
  46. package/src/components/interaction/Toast/Toast.stories.tsx +57 -0
  47. package/src/components/interaction/Toast/Toast.tsx +64 -0
  48. package/src/components/interaction/Toast/index.ts +1 -0
  49. package/src/components/interaction/form/Checkbox/Checkbox.module.css +61 -0
  50. package/src/components/interaction/form/Checkbox/Checkbox.spec.tsx +39 -0
  51. package/src/components/interaction/form/Checkbox/Checkbox.stories.tsx +17 -0
  52. package/src/components/interaction/form/Checkbox/Checkbox.tsx +39 -0
  53. package/src/components/interaction/form/Checkbox/index.ts +1 -0
  54. package/src/components/interaction/form/Combobox/Combobox.module.css +104 -0
  55. package/src/components/interaction/form/Combobox/Combobox.spec.tsx +81 -0
  56. package/src/components/interaction/form/Combobox/Combobox.stories.tsx +25 -0
  57. package/src/components/interaction/form/Combobox/Combobox.tsx +182 -0
  58. package/src/components/interaction/form/Combobox/index.ts +1 -0
  59. package/src/components/interaction/form/FileInput/FileInput.module.css +79 -0
  60. package/src/components/interaction/form/FileInput/FileInput.spec.tsx +53 -0
  61. package/src/components/interaction/form/FileInput/FileInput.stories.tsx +17 -0
  62. package/src/components/interaction/form/FileInput/FileInput.tsx +99 -0
  63. package/src/components/interaction/form/FileInput/index.ts +1 -0
  64. package/src/components/interaction/form/FormInput/FormInput.module.css +37 -0
  65. package/src/components/interaction/form/FormInput/FormInput.spec.tsx +43 -0
  66. package/src/components/interaction/form/FormInput/FormInput.stories.tsx +17 -0
  67. package/src/components/interaction/form/FormInput/FormInput.tsx +47 -0
  68. package/src/components/interaction/form/FormInput/index.ts +1 -0
  69. package/src/components/interaction/form/NumberInput/NumberInput.module.css +78 -0
  70. package/src/components/interaction/form/NumberInput/NumberInput.spec.tsx +49 -0
  71. package/src/components/interaction/form/NumberInput/NumberInput.stories.tsx +17 -0
  72. package/src/components/interaction/form/NumberInput/NumberInput.tsx +106 -0
  73. package/src/components/interaction/form/NumberInput/index.ts +1 -0
  74. package/src/components/interaction/form/Radio/Radio.module.css +62 -0
  75. package/src/components/interaction/form/Radio/Radio.spec.tsx +38 -0
  76. package/src/components/interaction/form/Radio/Radio.stories.tsx +26 -0
  77. package/src/components/interaction/form/Radio/Radio.tsx +39 -0
  78. package/src/components/interaction/form/Radio/index.ts +1 -0
  79. package/src/components/interaction/form/Select/Select.module.css +64 -0
  80. package/src/components/interaction/form/Select/Select.spec.tsx +61 -0
  81. package/src/components/interaction/form/Select/Select.stories.tsx +24 -0
  82. package/src/components/interaction/form/Select/Select.tsx +72 -0
  83. package/src/components/interaction/form/Select/index.ts +1 -0
  84. package/src/components/interaction/form/Slider/Slider.module.css +99 -0
  85. package/src/components/interaction/form/Slider/Slider.spec.tsx +53 -0
  86. package/src/components/interaction/form/Slider/Slider.stories.tsx +18 -0
  87. package/src/components/interaction/form/Slider/Slider.tsx +71 -0
  88. package/src/components/interaction/form/Slider/index.ts +1 -0
  89. package/src/components/interaction/form/Switch/Switch.module.css +114 -0
  90. package/src/components/interaction/form/Switch/Switch.spec.tsx +48 -0
  91. package/src/components/interaction/form/Switch/Switch.stories.tsx +31 -0
  92. package/src/components/interaction/form/Switch/Switch.tsx +54 -0
  93. package/src/components/interaction/form/Switch/index.ts +1 -0
  94. package/src/components/interaction/form/Textarea/Textarea.module.css +44 -0
  95. package/src/components/interaction/form/Textarea/Textarea.spec.tsx +53 -0
  96. package/src/components/interaction/form/Textarea/Textarea.stories.tsx +18 -0
  97. package/src/components/interaction/form/Textarea/Textarea.tsx +44 -0
  98. package/src/components/interaction/form/Textarea/index.ts +1 -0
  99. package/src/components/interaction/form/atoms/InputContainer.module.css +9 -0
  100. package/src/components/interaction/form/atoms/InputContainer.tsx +9 -0
  101. package/src/components/interaction/form/atoms/Label.module.css +10 -0
  102. package/src/components/interaction/form/atoms/Label.tsx +15 -0
  103. package/src/components/interaction/form/atoms/Message.module.css +11 -0
  104. package/src/components/interaction/form/atoms/Message.tsx +17 -0
  105. package/src/components/layout/ButtonGroup/ButtonGroup.module.css +59 -0
  106. package/src/components/layout/ButtonGroup/ButtonGroup.spec.tsx +20 -0
  107. package/src/components/layout/ButtonGroup/ButtonGroup.stories.tsx +28 -0
  108. package/src/components/layout/ButtonGroup/ButtonGroup.tsx +17 -0
  109. package/src/components/layout/ButtonGroup/index.ts +1 -0
  110. package/src/components/layout/Card/Card.module.css +72 -0
  111. package/src/components/layout/Card/Card.spec.tsx +33 -0
  112. package/src/components/layout/Card/Card.stories.tsx +32 -0
  113. package/src/components/layout/Card/Card.tsx +45 -0
  114. package/src/components/layout/Card/index.ts +1 -0
  115. package/src/components/layout/IconWrapper/IconWrapper.module.css +24 -0
  116. package/src/components/layout/IconWrapper/IconWrapper.spec.tsx +19 -0
  117. package/src/components/layout/IconWrapper/IconWrapper.stories.tsx +22 -0
  118. package/src/components/layout/IconWrapper/IconWrapper.tsx +14 -0
  119. package/src/components/layout/IconWrapper/index.ts +1 -0
  120. package/src/components/layout/SectionHeader/SectionHeader.module.css +75 -0
  121. package/src/components/layout/SectionHeader/SectionHeader.spec.tsx +31 -0
  122. package/src/components/layout/SectionHeader/SectionHeader.stories.tsx +21 -0
  123. package/src/components/layout/SectionHeader/SectionHeader.tsx +32 -0
  124. package/src/components/layout/SectionHeader/index.ts +1 -0
  125. package/src/components/ui/Accordion/Accordion.module.css +87 -0
  126. package/src/components/ui/Accordion/Accordion.spec.tsx +78 -0
  127. package/src/components/ui/Accordion/Accordion.stories.tsx +34 -0
  128. package/src/components/ui/Accordion/Accordion.tsx +82 -0
  129. package/src/components/ui/Accordion/index.ts +1 -0
  130. package/src/components/ui/Alert/Alert.module.css +91 -0
  131. package/src/components/ui/Alert/Alert.spec.tsx +63 -0
  132. package/src/components/ui/Alert/Alert.stories.tsx +53 -0
  133. package/src/components/ui/Alert/Alert.tsx +54 -0
  134. package/src/components/ui/Alert/index.ts +1 -0
  135. package/src/components/ui/Avatar/Avatar.module.css +42 -0
  136. package/src/components/ui/Avatar/Avatar.spec.tsx +49 -0
  137. package/src/components/ui/Avatar/Avatar.stories.tsx +44 -0
  138. package/src/components/ui/Avatar/Avatar.tsx +45 -0
  139. package/src/components/ui/Avatar/index.ts +1 -0
  140. package/src/components/ui/Badge/Badge.module.css +46 -0
  141. package/src/components/ui/Badge/Badge.spec.tsx +19 -0
  142. package/src/components/ui/Badge/Badge.stories.tsx +29 -0
  143. package/src/components/ui/Badge/Badge.tsx +13 -0
  144. package/src/components/ui/Badge/index.ts +1 -0
  145. package/src/components/ui/Breadcrumb/Breadcrumb.module.css +50 -0
  146. package/src/components/ui/Breadcrumb/Breadcrumb.spec.tsx +44 -0
  147. package/src/components/ui/Breadcrumb/Breadcrumb.stories.tsx +48 -0
  148. package/src/components/ui/Breadcrumb/Breadcrumb.tsx +41 -0
  149. package/src/components/ui/Breadcrumb/index.ts +1 -0
  150. package/src/components/ui/Calendar/Calendar.module.css +120 -0
  151. package/src/components/ui/Calendar/Calendar.spec.tsx +64 -0
  152. package/src/components/ui/Calendar/Calendar.stories.tsx +59 -0
  153. package/src/components/ui/Calendar/Calendar.tsx +184 -0
  154. package/src/components/ui/Calendar/index.ts +1 -0
  155. package/src/components/ui/Carousel/Carousel.module.css +66 -0
  156. package/src/components/ui/Carousel/Carousel.spec.tsx +29 -0
  157. package/src/components/ui/Carousel/Carousel.stories.tsx +30 -0
  158. package/src/components/ui/Carousel/Carousel.tsx +64 -0
  159. package/src/components/ui/Carousel/index.ts +1 -0
  160. package/src/components/ui/DescriptionList/DescriptionList.module.css +43 -0
  161. package/src/components/ui/DescriptionList/DescriptionList.spec.tsx +31 -0
  162. package/src/components/ui/DescriptionList/DescriptionList.stories.tsx +21 -0
  163. package/src/components/ui/DescriptionList/DescriptionList.tsx +30 -0
  164. package/src/components/ui/DescriptionList/index.ts +1 -0
  165. package/src/components/ui/Link/Link.module.css +64 -0
  166. package/src/components/ui/Link/Link.spec.tsx +43 -0
  167. package/src/components/ui/Link/Link.stories.tsx +55 -0
  168. package/src/components/ui/Link/Link.tsx +42 -0
  169. package/src/components/ui/Link/index.ts +1 -0
  170. package/src/components/ui/Loading/Loading.module.css +33 -0
  171. package/src/components/ui/Loading/Loading.spec.tsx +19 -0
  172. package/src/components/ui/Loading/Loading.stories.tsx +27 -0
  173. package/src/components/ui/Loading/Loading.tsx +15 -0
  174. package/src/components/ui/Loading/index.ts +1 -0
  175. package/src/components/ui/NotificationBanner/NotificationBanner.module.css +79 -0
  176. package/src/components/ui/NotificationBanner/NotificationBanner.spec.tsx +42 -0
  177. package/src/components/ui/NotificationBanner/NotificationBanner.stories.tsx +30 -0
  178. package/src/components/ui/NotificationBanner/NotificationBanner.tsx +45 -0
  179. package/src/components/ui/NotificationBanner/index.ts +1 -0
  180. package/src/components/ui/Pagination/Pagination.module.css +78 -0
  181. package/src/components/ui/Pagination/Pagination.spec.tsx +67 -0
  182. package/src/components/ui/Pagination/Pagination.stories.tsx +40 -0
  183. package/src/components/ui/Pagination/Pagination.tsx +87 -0
  184. package/src/components/ui/Pagination/index.ts +1 -0
  185. package/src/components/ui/Progress/Progress.module.css +51 -0
  186. package/src/components/ui/Progress/Progress.spec.tsx +55 -0
  187. package/src/components/ui/Progress/Progress.stories.tsx +30 -0
  188. package/src/components/ui/Progress/Progress.tsx +43 -0
  189. package/src/components/ui/Progress/index.ts +1 -0
  190. package/src/components/ui/ProgressCircle/ProgressCircle.module.css +40 -0
  191. package/src/components/ui/ProgressCircle/ProgressCircle.spec.tsx +34 -0
  192. package/src/components/ui/ProgressCircle/ProgressCircle.stories.tsx +18 -0
  193. package/src/components/ui/ProgressCircle/ProgressCircle.tsx +75 -0
  194. package/src/components/ui/ProgressCircle/index.ts +1 -0
  195. package/src/components/ui/Separator/Separator.module.css +23 -0
  196. package/src/components/ui/Separator/Separator.spec.tsx +30 -0
  197. package/src/components/ui/Separator/Separator.stories.tsx +40 -0
  198. package/src/components/ui/Separator/Separator.tsx +21 -0
  199. package/src/components/ui/Separator/index.ts +1 -0
  200. package/src/components/ui/Skeleton/Skeleton.module.css +24 -0
  201. package/src/components/ui/Skeleton/Skeleton.spec.tsx +19 -0
  202. package/src/components/ui/Skeleton/Skeleton.stories.tsx +25 -0
  203. package/src/components/ui/Skeleton/Skeleton.tsx +12 -0
  204. package/src/components/ui/Skeleton/index.ts +1 -0
  205. package/src/components/ui/SkipLink/SkipLink.module.css +30 -0
  206. package/src/components/ui/SkipLink/SkipLink.spec.tsx +24 -0
  207. package/src/components/ui/SkipLink/SkipLink.stories.tsx +24 -0
  208. package/src/components/ui/SkipLink/SkipLink.tsx +14 -0
  209. package/src/components/ui/SkipLink/index.ts +1 -0
  210. package/src/components/ui/Table/Table.module.css +111 -0
  211. package/src/components/ui/Table/Table.spec.tsx +69 -0
  212. package/src/components/ui/Table/Table.stories.tsx +53 -0
  213. package/src/components/ui/Table/Table.tsx +98 -0
  214. package/src/components/ui/Table/index.ts +1 -0
  215. package/src/components/ui/Tabs/Tabs.module.css +61 -0
  216. package/src/components/ui/Tabs/Tabs.spec.tsx +91 -0
  217. package/src/components/ui/Tabs/Tabs.stories.tsx +59 -0
  218. package/src/components/ui/Tabs/Tabs.tsx +100 -0
  219. package/src/components/ui/Tabs/index.ts +1 -0
  220. package/src/components/ui/Tooltip/Tooltip.module.css +69 -0
  221. package/src/components/ui/Tooltip/Tooltip.spec.tsx +46 -0
  222. package/src/components/ui/Tooltip/Tooltip.stories.tsx +69 -0
  223. package/src/components/ui/Tooltip/Tooltip.tsx +38 -0
  224. package/src/components/ui/Tooltip/index.ts +1 -0
  225. package/src/components/ui/Typography/Typography.module.css +41 -0
  226. package/src/components/ui/Typography/Typography.spec.tsx +39 -0
  227. package/src/components/ui/Typography/Typography.stories.tsx +31 -0
  228. package/src/components/ui/Typography/Typography.tsx +28 -0
  229. package/src/components/ui/Typography/index.ts +1 -0
  230. package/src/css/index.css +55 -0
  231. package/src/index.ts +54 -0
  232. package/src/test/setup.ts +1 -0
  233. package/src/typings.d.ts +4 -0
@@ -0,0 +1,161 @@
1
+ import { useState, useEffect, useRef, useId, KeyboardEvent, useMemo } from 'react';
2
+ import css from './Command.module.css';
3
+ import { cn } from '@boostdev/design-system-foundation';
4
+
5
+ export interface CommandItem {
6
+ id: string;
7
+ label: string;
8
+ description?: string;
9
+ group?: string;
10
+ shortcut?: string;
11
+ onSelect: () => void;
12
+ }
13
+
14
+ interface CommandProps {
15
+ isOpen: boolean;
16
+ onClose: () => void;
17
+ items: CommandItem[];
18
+ placeholder?: string;
19
+ className?: string;
20
+ }
21
+
22
+ export function Command({
23
+ isOpen,
24
+ onClose,
25
+ items,
26
+ placeholder = 'Search commands…',
27
+ className,
28
+ }: Readonly<CommandProps>) {
29
+ const [query, setQuery] = useState('');
30
+ const [activeIndex, setActiveIndex] = useState(0);
31
+ const dialogRef = useRef<HTMLDialogElement>(null);
32
+ const inputRef = useRef<HTMLInputElement>(null);
33
+ const listboxId = useId();
34
+
35
+ const filtered = useMemo(() => {
36
+ const q = query.toLowerCase().trim();
37
+ return q ? items.filter(item =>
38
+ item.label.toLowerCase().includes(q) ||
39
+ item.description?.toLowerCase().includes(q)
40
+ ) : items;
41
+ }, [query, items]);
42
+
43
+ const groups = useMemo(() => {
44
+ const map = new Map<string, CommandItem[]>();
45
+ filtered.forEach(item => {
46
+ const g = item.group ?? '';
47
+ const list = map.get(g) ?? [];
48
+ list.push(item);
49
+ map.set(g, list);
50
+ });
51
+ return map;
52
+ }, [filtered]);
53
+
54
+ useEffect(() => {
55
+ const dialog = dialogRef.current;
56
+ if (!dialog) return;
57
+ if (isOpen) {
58
+ dialog.showModal();
59
+ setQuery('');
60
+ setActiveIndex(0);
61
+ setTimeout(() => inputRef.current?.focus(), 0);
62
+ } else if (dialog.open) {
63
+ dialog.close();
64
+ }
65
+ }, [isOpen]);
66
+
67
+ useEffect(() => {
68
+ setActiveIndex(0);
69
+ }, [query]);
70
+
71
+ const handleCancel = (e: React.SyntheticEvent) => {
72
+ e.preventDefault();
73
+ onClose();
74
+ };
75
+
76
+ const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
77
+ if (e.key === 'ArrowDown') {
78
+ e.preventDefault();
79
+ setActiveIndex(i => Math.min(i + 1, filtered.length - 1));
80
+ } else if (e.key === 'ArrowUp') {
81
+ e.preventDefault();
82
+ setActiveIndex(i => Math.max(i - 1, 0));
83
+ } else if (e.key === 'Enter') {
84
+ e.preventDefault();
85
+ filtered[activeIndex]?.onSelect();
86
+ onClose();
87
+ } else if (e.key === 'Escape') {
88
+ onClose();
89
+ }
90
+ };
91
+
92
+ const selectItem = (item: CommandItem) => {
93
+ item.onSelect();
94
+ onClose();
95
+ };
96
+
97
+ return (
98
+ <dialog
99
+ ref={dialogRef}
100
+ className={cn(css.dialog, className)}
101
+ aria-label="Command palette"
102
+ onCancel={handleCancel}
103
+ >
104
+ <div className={css.palette} onKeyDown={handleKeyDown}>
105
+ <div className={css.searchRow}>
106
+ <svg aria-hidden="true" className={css.searchIcon} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
107
+ <circle cx="11" cy="11" r="8" />
108
+ <path strokeLinecap="round" d="M21 21l-4.35-4.35" />
109
+ </svg>
110
+ <input
111
+ ref={inputRef}
112
+ type="search"
113
+ role="combobox"
114
+ aria-expanded={filtered.length > 0}
115
+ aria-controls={listboxId}
116
+ aria-autocomplete="list"
117
+ aria-activedescendant={filtered[activeIndex] ? `cmd-${filtered[activeIndex].id}` : undefined}
118
+ className={css.search}
119
+ placeholder={placeholder}
120
+ value={query}
121
+ onChange={e => setQuery(e.target.value)}
122
+ />
123
+ <kbd className={css.escHint}>Esc</kbd>
124
+ </div>
125
+
126
+ {filtered.length > 0 ? (
127
+ <ul id={listboxId} role="listbox" className={css.list} aria-label="Commands">
128
+ {Array.from(groups.entries()).map(([group, groupItems]) => (
129
+ <li key={group} role="presentation">
130
+ {group && <div className={css.group} role="presentation">{group}</div>}
131
+ <ul role="group" aria-label={group || undefined} className={css.groupList}>
132
+ {groupItems.map(item => {
133
+ const flatIndex = filtered.indexOf(item);
134
+ const isActive = flatIndex === activeIndex;
135
+ return (
136
+ <li
137
+ key={item.id}
138
+ id={`cmd-${item.id}`}
139
+ role="option"
140
+ aria-selected={isActive}
141
+ className={cn(css.item, isActive && css.itemActive)}
142
+ onPointerDown={e => e.preventDefault()}
143
+ onClick={() => selectItem(item)}
144
+ >
145
+ <span className={css.itemLabel}>{item.label}</span>
146
+ {item.description && <span className={css.itemDesc}>{item.description}</span>}
147
+ {item.shortcut && <kbd className={css.shortcut}>{item.shortcut}</kbd>}
148
+ </li>
149
+ );
150
+ })}
151
+ </ul>
152
+ </li>
153
+ ))}
154
+ </ul>
155
+ ) : (
156
+ <div className={css.empty} aria-live="polite">No results for &ldquo;{query}&rdquo;</div>
157
+ )}
158
+ </div>
159
+ </dialog>
160
+ );
161
+ }
@@ -0,0 +1,2 @@
1
+ export { Command } from './Command';
2
+ export type { CommandItem } from './Command';
@@ -0,0 +1,39 @@
1
+ @layer component {
2
+ .dialog {
3
+ display: grid;
4
+ gap: var(--grid_gap);
5
+ font-size: var(--font_size--body--s);
6
+ border: 2px solid currentcolor;
7
+ background-color: var(--color_grey--subtle);
8
+ color: var(--color_on-grey--subtle);
9
+ border-radius: var(--border_radius--m);
10
+ padding: var(--space_l);
11
+ overflow: visible;
12
+ max-width: 90svw;
13
+ }
14
+
15
+ .closeForm {
16
+ position: absolute;
17
+ inset-block-start: -1em;
18
+ inset-inline-end: -1em;
19
+ }
20
+
21
+ .closeButton {
22
+ all: unset;
23
+ width: 2em;
24
+ height: 2em;
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: center;
28
+ border-radius: 50%;
29
+ background-color: var(--color_bg);
30
+ color: var(--color_on-bg);
31
+ border: 2px solid currentcolor;
32
+ cursor: pointer;
33
+ }
34
+
35
+ .closeButton svg {
36
+ width: 1.25em;
37
+ height: 1.25em;
38
+ }
39
+ }
@@ -0,0 +1,43 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { Dialog } from './Dialog';
4
+
5
+ beforeEach(() => {
6
+ // jsdom doesn't implement showModal/close — mock them and simulate the open attribute
7
+ HTMLDialogElement.prototype.showModal = vi.fn(function (this: HTMLDialogElement) {
8
+ this.setAttribute('open', '');
9
+ });
10
+ HTMLDialogElement.prototype.close = vi.fn(function (this: HTMLDialogElement) {
11
+ this.removeAttribute('open');
12
+ });
13
+ });
14
+
15
+ describe('Dialog', () => {
16
+ it('renders children', () => {
17
+ render(<Dialog isVisible><p>Dialog content</p></Dialog>);
18
+ expect(screen.getByText('Dialog content')).toBeInTheDocument();
19
+ });
20
+
21
+ it('calls showModal when isVisible becomes true', () => {
22
+ render(<Dialog isVisible><span>Content</span></Dialog>);
23
+ expect(HTMLDialogElement.prototype.showModal).toHaveBeenCalled();
24
+ });
25
+
26
+ it('renders a close button with aria-label', () => {
27
+ render(<Dialog isVisible><span>Content</span></Dialog>);
28
+ expect(screen.getByRole('button', { name: /close dialog/i })).toBeInTheDocument();
29
+ });
30
+
31
+ it('calls handleClose when close button is clicked', async () => {
32
+ const user = userEvent.setup();
33
+ const handleClose = vi.fn();
34
+ render(<Dialog isVisible handleClose={handleClose}><span>Content</span></Dialog>);
35
+ await user.click(screen.getByRole('button', { name: /close dialog/i }));
36
+ expect(handleClose).toHaveBeenCalled();
37
+ });
38
+
39
+ it('does not call showModal when isVisible is false', () => {
40
+ render(<Dialog isVisible={false}><span>Content</span></Dialog>);
41
+ expect(HTMLDialogElement.prototype.showModal).not.toHaveBeenCalled();
42
+ });
43
+ });
@@ -0,0 +1,36 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { useState } from 'react';
3
+ import { Dialog } from './Dialog';
4
+ import { Button } from '../Button/Button';
5
+
6
+ const meta = {
7
+ title: 'Interaction/Dialog',
8
+ component: Dialog,
9
+ tags: ['autodocs'],
10
+ } satisfies Meta<typeof Dialog>;
11
+
12
+ export default meta;
13
+ type Story = StoryObj<typeof meta>;
14
+
15
+ export const Default: Story = {
16
+ args: {
17
+ isVisible: true,
18
+ children: <p>This is dialog content.</p>,
19
+ },
20
+ };
21
+
22
+ export const Interactive: Story = {
23
+ render: () => {
24
+ const [open, setOpen] = useState(false);
25
+ return (
26
+ <>
27
+ <Button onClick={() => setOpen(true)}>Open Dialog</Button>
28
+ <Dialog isVisible={open} handleClose={() => setOpen(false)}>
29
+ <h2>Dialog Title</h2>
30
+ <p>This is the dialog body content.</p>
31
+ <Button onClick={() => setOpen(false)}>Close</Button>
32
+ </Dialog>
33
+ </>
34
+ );
35
+ },
36
+ };
@@ -0,0 +1,42 @@
1
+ import { ReactNode, useEffect, useRef } from 'react';
2
+ import css from './Dialog.module.css';
3
+ import { cn } from '@boostdev/design-system-foundation';
4
+
5
+ interface DialogProps {
6
+ children: ReactNode;
7
+ className?: string;
8
+ isVisible?: boolean;
9
+ handleClose?: () => void;
10
+ }
11
+
12
+ export function Dialog({ children, isVisible = false, className, handleClose }: DialogProps) {
13
+ const dialogRef = useRef<HTMLDialogElement | null>(null);
14
+
15
+ useEffect(() => {
16
+ const dialog = dialogRef.current;
17
+ if (!dialog) return;
18
+ if (isVisible) {
19
+ dialog.showModal();
20
+ } else if (dialog.open) {
21
+ dialog.close();
22
+ }
23
+ }, [isVisible]);
24
+
25
+ return (
26
+ <dialog ref={dialogRef} className={cn(className, css.dialog)}>
27
+ <form method="dialog" className={css.closeForm}>
28
+ <button
29
+ type="submit"
30
+ className={css.closeButton}
31
+ onClick={handleClose}
32
+ aria-label="Close dialog"
33
+ >
34
+ <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
35
+ <path strokeLinecap="round" strokeLinejoin="round" d="M18 6L6 18M6 6l12 12" />
36
+ </svg>
37
+ </button>
38
+ </form>
39
+ {children}
40
+ </dialog>
41
+ );
42
+ }
@@ -0,0 +1 @@
1
+ export { Dialog } from './Dialog';
@@ -0,0 +1,98 @@
1
+ @layer component {
2
+ .drawer {
3
+ position: fixed;
4
+ inset: 0;
5
+ margin: 0;
6
+ padding: 0;
7
+ width: 100%;
8
+ max-width: 100%;
9
+ height: 100%;
10
+ max-height: 100%;
11
+ border: none;
12
+ background: transparent;
13
+ overflow: hidden;
14
+ }
15
+
16
+ .drawer::backdrop {
17
+ background: rgb(0 0 0 / 50%);
18
+ }
19
+
20
+ .panel {
21
+ position: absolute;
22
+ inset-block: 0;
23
+ display: flex;
24
+ flex-direction: column;
25
+ width: min(28rem, 90vw);
26
+ height: 100%;
27
+ background-color: var(--color_bg);
28
+ color: var(--color_on-bg);
29
+ box-shadow: var(--shadow_xl);
30
+ overflow: hidden;
31
+ transition: transform var(--animation_transition-duration) var(--animation_easing);
32
+ }
33
+
34
+ .--side_right .panel {
35
+ inset-inline-end: 0;
36
+ }
37
+
38
+ .--side_left .panel {
39
+ inset-inline-start: 0;
40
+ }
41
+
42
+ .header {
43
+ display: flex;
44
+ align-items: center;
45
+ justify-content: space-between;
46
+ padding: var(--space_m) var(--space_l);
47
+ border-block-end: 1px solid var(--color_bg--subtle);
48
+ flex-shrink: 0;
49
+ }
50
+
51
+ .title {
52
+ margin: 0;
53
+ font-size: var(--font_size--heading--s);
54
+ font-weight: var(--font_weight--semibold);
55
+ line-height: var(--font_line-height--heading);
56
+ }
57
+
58
+ .closeButton {
59
+ all: unset;
60
+ display: flex;
61
+ align-items: center;
62
+ justify-content: center;
63
+ width: 2rem;
64
+ height: 2rem;
65
+ border-radius: 50%;
66
+ cursor: pointer;
67
+ color: var(--color_on-bg);
68
+ transition: var(--animation_transition);
69
+ }
70
+
71
+ .closeButton svg {
72
+ width: 1.25rem;
73
+ height: 1.25rem;
74
+ }
75
+
76
+ .closeButton:focus-visible {
77
+ outline: var(--outline_default);
78
+ outline-offset: var(--outline_offset);
79
+ }
80
+
81
+ @media (hover: hover) and (pointer: fine) {
82
+ .closeButton:hover {
83
+ background-color: var(--color_bg--subtle);
84
+ }
85
+ }
86
+
87
+ .body {
88
+ flex: 1;
89
+ overflow-y: auto;
90
+ padding: var(--space_l);
91
+ }
92
+
93
+ @media (prefers-reduced-motion: reduce) {
94
+ .panel {
95
+ transition: none;
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,43 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { Drawer } from './Drawer';
4
+
5
+ // jsdom doesn't implement showModal/close, mock them
6
+ beforeEach(() => {
7
+ HTMLDialogElement.prototype.showModal = vi.fn().mockImplementation(function (this: HTMLDialogElement) {
8
+ this.setAttribute('open', '');
9
+ });
10
+ HTMLDialogElement.prototype.close = vi.fn().mockImplementation(function (this: HTMLDialogElement) {
11
+ this.removeAttribute('open');
12
+ });
13
+ });
14
+
15
+ describe('Drawer', () => {
16
+ it('renders title when open', () => {
17
+ render(<Drawer isOpen title="Settings" onClose={() => {}}>Content</Drawer>);
18
+ expect(screen.getByText('Settings')).toBeInTheDocument();
19
+ });
20
+
21
+ it('renders children content', () => {
22
+ render(<Drawer isOpen title="Menu" onClose={() => {}}>Navigation items</Drawer>);
23
+ expect(screen.getByText('Navigation items')).toBeInTheDocument();
24
+ });
25
+
26
+ it('calls onClose when close button clicked', async () => {
27
+ const onClose = vi.fn();
28
+ render(<Drawer isOpen title="Menu" onClose={onClose}>Content</Drawer>);
29
+ await userEvent.click(screen.getByRole('button', { name: 'Close drawer' }));
30
+ expect(onClose).toHaveBeenCalledOnce();
31
+ });
32
+
33
+ it('shows the dialog when isOpen is true', () => {
34
+ render(<Drawer isOpen title="Open" onClose={() => {}}>Body</Drawer>);
35
+ expect(HTMLDialogElement.prototype.showModal).toHaveBeenCalled();
36
+ });
37
+
38
+ it('closes the dialog when isOpen is false', () => {
39
+ const { rerender } = render(<Drawer isOpen title="Test" onClose={() => {}}>Body</Drawer>);
40
+ rerender(<Drawer isOpen={false} title="Test" onClose={() => {}}>Body</Drawer>);
41
+ expect(HTMLDialogElement.prototype.close).toHaveBeenCalled();
42
+ });
43
+ });
@@ -0,0 +1,46 @@
1
+ import { useState } from 'react';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import { Drawer } from './Drawer';
4
+
5
+ const meta = {
6
+ title: 'Interaction/Drawer',
7
+ component: Drawer,
8
+ tags: ['autodocs'],
9
+ } satisfies Meta<typeof Drawer>;
10
+
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+
14
+ export const Right: Story = {
15
+ render: () => {
16
+ const [open, setOpen] = useState(false);
17
+ return (
18
+ <>
19
+ <button type="button" onClick={() => setOpen(true)}>Open right drawer</button>
20
+ <Drawer isOpen={open} onClose={() => setOpen(false)} title="Settings" side="right">
21
+ <p>Drawer content goes here. You can put any React content inside.</p>
22
+ </Drawer>
23
+ </>
24
+ );
25
+ },
26
+ };
27
+
28
+ export const Left: Story = {
29
+ render: () => {
30
+ const [open, setOpen] = useState(false);
31
+ return (
32
+ <>
33
+ <button type="button" onClick={() => setOpen(true)}>Open left drawer</button>
34
+ <Drawer isOpen={open} onClose={() => setOpen(false)} title="Navigation" side="left">
35
+ <nav>
36
+ <ul>
37
+ <li><a href="#">Home</a></li>
38
+ <li><a href="#">About</a></li>
39
+ <li><a href="#">Contact</a></li>
40
+ </ul>
41
+ </nav>
42
+ </Drawer>
43
+ </>
44
+ );
45
+ },
46
+ };
@@ -0,0 +1,71 @@
1
+ import { ReactNode, useEffect, useRef } from 'react';
2
+ import css from './Drawer.module.css';
3
+ import { cn } from '@boostdev/design-system-foundation';
4
+
5
+ interface DrawerProps {
6
+ isOpen: boolean;
7
+ onClose: () => void;
8
+ title: string;
9
+ children: ReactNode;
10
+ side?: 'left' | 'right';
11
+ className?: string;
12
+ }
13
+
14
+ export function Drawer({
15
+ isOpen,
16
+ onClose,
17
+ title,
18
+ children,
19
+ side = 'right',
20
+ className,
21
+ }: Readonly<DrawerProps>) {
22
+ const dialogRef = useRef<HTMLDialogElement>(null);
23
+
24
+ useEffect(() => {
25
+ const dialog = dialogRef.current;
26
+ if (!dialog) return;
27
+ if (isOpen) {
28
+ dialog.showModal();
29
+ } else if (dialog.open) {
30
+ dialog.close();
31
+ }
32
+ }, [isOpen]);
33
+
34
+ // Close on backdrop click
35
+ const handleClick = (e: React.MouseEvent<HTMLDialogElement>) => {
36
+ if (e.target === dialogRef.current) onClose();
37
+ };
38
+
39
+ // Close on Escape (dialog handles it natively, but we sync state)
40
+ const handleCancel = (e: React.SyntheticEvent) => {
41
+ e.preventDefault();
42
+ onClose();
43
+ };
44
+
45
+ return (
46
+ <dialog
47
+ ref={dialogRef}
48
+ className={cn(css.drawer, css[`--side_${side}`], className)}
49
+ aria-label={title}
50
+ onClick={handleClick}
51
+ onCancel={handleCancel}
52
+ >
53
+ <div className={css.panel}>
54
+ <div className={css.header}>
55
+ <h2 className={css.title}>{title}</h2>
56
+ <button
57
+ type="button"
58
+ className={css.closeButton}
59
+ onClick={onClose}
60
+ aria-label="Close drawer"
61
+ >
62
+ <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
63
+ <path strokeLinecap="round" strokeLinejoin="round" d="M18 6L6 18M6 6l12 12" />
64
+ </svg>
65
+ </button>
66
+ </div>
67
+ <div className={css.body}>{children}</div>
68
+ </div>
69
+ </dialog>
70
+ );
71
+ }
@@ -0,0 +1 @@
1
+ export { Drawer } from './Drawer';
@@ -0,0 +1,68 @@
1
+ @layer component {
2
+ .wrapper {
3
+ position: relative;
4
+ display: inline-flex;
5
+ }
6
+
7
+ .menu {
8
+ position: absolute;
9
+ top: calc(100% + var(--space_xxs));
10
+ z-index: var(--z-index_dropdown);
11
+ min-width: 10rem;
12
+ padding: var(--space_xxs) 0;
13
+ border-radius: var(--border_radius--s);
14
+ border: 1px solid var(--color_bg--subtle);
15
+ background-color: var(--color_bg);
16
+ box-shadow: var(--shadow_m);
17
+ list-style: none;
18
+ margin: 0;
19
+ }
20
+
21
+ .--placement_bottom-start { left: 0; }
22
+ .--placement_bottom-end { right: 0; }
23
+
24
+ .separator {
25
+ border: none;
26
+ border-top: 1px solid var(--color_bg--subtle);
27
+ margin: var(--space_xxs) 0;
28
+ }
29
+
30
+ .item {
31
+ all: unset;
32
+ display: flex;
33
+ align-items: center;
34
+ gap: var(--space_xs);
35
+ width: 100%;
36
+ padding: var(--space_xs) var(--space_m);
37
+ font-family: var(--font_family--body);
38
+ font-size: var(--font_size--body);
39
+ color: var(--color_on-bg);
40
+ cursor: pointer;
41
+ box-sizing: border-box;
42
+ transition: var(--animation_transition);
43
+ }
44
+
45
+ .item:disabled {
46
+ opacity: 0.4;
47
+ cursor: not-allowed;
48
+ }
49
+
50
+ .item:focus-visible {
51
+ outline: var(--outline_default);
52
+ outline-offset: calc(var(--outline_offset) * -1);
53
+ border-radius: var(--border_radius--xs);
54
+ }
55
+
56
+ @media (hover: hover) and (pointer: fine) {
57
+ .item:not(:disabled):hover {
58
+ background-color: var(--color_bg--subtle);
59
+ color: var(--color_interactive);
60
+ }
61
+ }
62
+
63
+ .icon {
64
+ display: flex;
65
+ align-items: center;
66
+ flex-shrink: 0;
67
+ }
68
+ }