@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,182 @@
1
+ import {
2
+ ChangeEvent,
3
+ KeyboardEvent,
4
+ ReactNode,
5
+ useEffect,
6
+ useId,
7
+ useRef,
8
+ useState,
9
+ } from 'react';
10
+ import css from './Combobox.module.css';
11
+ import { cn } from '@boostdev/design-system-foundation';
12
+ import { InputContainer } from '../atoms/InputContainer';
13
+ import { Label } from '../atoms/Label';
14
+ import { Message } from '../atoms/Message';
15
+
16
+ interface ComboboxOption {
17
+ value: string;
18
+ label: string;
19
+ disabled?: boolean;
20
+ }
21
+
22
+ interface ComboboxProps {
23
+ label: ReactNode;
24
+ name: string;
25
+ options: ComboboxOption[];
26
+ placeholder?: string;
27
+ value?: string;
28
+ onChange?: (value: string) => void;
29
+ error?: string;
30
+ hint?: string;
31
+ className?: string;
32
+ }
33
+
34
+ export function Combobox({
35
+ label,
36
+ name,
37
+ options,
38
+ placeholder,
39
+ value,
40
+ onChange,
41
+ error,
42
+ hint,
43
+ className,
44
+ }: Readonly<ComboboxProps>) {
45
+ const id = name + useId();
46
+ const listboxId = id + 'listbox';
47
+ const hintId = id + 'hint';
48
+ const errorId = id + 'error';
49
+ const describedBy = error ? errorId : hintId;
50
+
51
+ const selectedOption = options.find(o => o.value === value);
52
+ const [inputValue, setInputValue] = useState(selectedOption?.label ?? '');
53
+ const [isOpen, setIsOpen] = useState(false);
54
+ const [highlightedIndex, setHighlightedIndex] = useState(-1);
55
+
56
+ const containerRef = useRef<HTMLDivElement>(null);
57
+ const inputRef = useRef<HTMLInputElement>(null);
58
+
59
+ const filtered = options.filter(o =>
60
+ o.label.toLowerCase().includes(inputValue.toLowerCase())
61
+ );
62
+
63
+ const getOptionId = (index: number) => `${id}-option-${index}`;
64
+
65
+ useEffect(() => {
66
+ if (!isOpen) return;
67
+ const handlePointerDown = (e: PointerEvent) => {
68
+ if (!containerRef.current?.contains(e.target as Node)) setIsOpen(false);
69
+ };
70
+ document.addEventListener('pointerdown', handlePointerDown);
71
+ return () => document.removeEventListener('pointerdown', handlePointerDown);
72
+ }, [isOpen]);
73
+
74
+ const selectOption = (option: ComboboxOption) => {
75
+ setInputValue(option.label);
76
+ setIsOpen(false);
77
+ setHighlightedIndex(-1);
78
+ onChange?.(option.value);
79
+ };
80
+
81
+ const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
82
+ setInputValue(e.target.value);
83
+ setIsOpen(true);
84
+ setHighlightedIndex(-1);
85
+ };
86
+
87
+ const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
88
+ const enabledIndexes = filtered
89
+ .map((opt, i) => ({ opt, i }))
90
+ .filter(({ opt }) => !opt.disabled)
91
+ .map(({ i }) => i);
92
+
93
+ if (e.key === 'ArrowDown') {
94
+ e.preventDefault();
95
+ if (!isOpen) { setIsOpen(true); return; }
96
+ const pos = enabledIndexes.indexOf(highlightedIndex);
97
+ setHighlightedIndex(enabledIndexes[(pos + 1) % enabledIndexes.length] ?? 0);
98
+ } else if (e.key === 'ArrowUp') {
99
+ e.preventDefault();
100
+ const pos = enabledIndexes.indexOf(highlightedIndex);
101
+ setHighlightedIndex(
102
+ enabledIndexes[(pos - 1 + enabledIndexes.length) % enabledIndexes.length] ?? 0
103
+ );
104
+ } else if (e.key === 'Enter') {
105
+ e.preventDefault();
106
+ if (highlightedIndex >= 0 && filtered[highlightedIndex]) {
107
+ selectOption(filtered[highlightedIndex]);
108
+ }
109
+ } else if (e.key === 'Escape') {
110
+ setIsOpen(false);
111
+ setHighlightedIndex(-1);
112
+ } else if (e.key === 'Tab') {
113
+ setIsOpen(false);
114
+ }
115
+ };
116
+
117
+ return (
118
+ <InputContainer className={cn(css.formGroup, className)}>
119
+ <Label id={id} label={label} />
120
+ <div ref={containerRef} className={css.inputWrapper}>
121
+ <input
122
+ ref={inputRef}
123
+ id={id}
124
+ name={name}
125
+ type="text"
126
+ role="combobox"
127
+ aria-expanded={isOpen}
128
+ aria-haspopup="listbox"
129
+ aria-autocomplete="list"
130
+ aria-controls={listboxId}
131
+ aria-activedescendant={highlightedIndex >= 0 ? getOptionId(highlightedIndex) : undefined}
132
+ aria-invalid={!!error}
133
+ aria-describedby={describedBy}
134
+ autoComplete="off"
135
+ placeholder={placeholder}
136
+ value={inputValue}
137
+ className={cn(css.input, error ? css.inputError : undefined)}
138
+ onChange={handleInputChange}
139
+ onKeyDown={handleKeyDown}
140
+ onFocus={() => setIsOpen(true)}
141
+ />
142
+ <span className={css.chevron} aria-hidden="true">
143
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
144
+ <path strokeLinecap="round" strokeLinejoin="round" d="M6 9l6 6 6-6" />
145
+ </svg>
146
+ </span>
147
+ {isOpen && filtered.length > 0 && (
148
+ <ul
149
+ id={listboxId}
150
+ role="listbox"
151
+ aria-label={String(label)}
152
+ className={css.listbox}
153
+ >
154
+ {filtered.map((option, index) => (
155
+ <li
156
+ key={option.value}
157
+ id={getOptionId(index)}
158
+ role="option"
159
+ aria-selected={option.value === value}
160
+ aria-disabled={option.disabled}
161
+ className={cn(
162
+ css.option,
163
+ index === highlightedIndex ? css['--highlighted'] : undefined,
164
+ option.value === value ? css['--selected'] : undefined,
165
+ option.disabled ? css['--disabled'] : undefined,
166
+ )}
167
+ onPointerDown={e => {
168
+ e.preventDefault();
169
+ if (!option.disabled) selectOption(option);
170
+ }}
171
+ >
172
+ {option.label}
173
+ </li>
174
+ ))}
175
+ </ul>
176
+ )}
177
+ </div>
178
+ <Message inputId={id} type="error" message={error} />
179
+ <Message inputId={id} type="hint" message={hint} />
180
+ </InputContainer>
181
+ );
182
+ }
@@ -0,0 +1 @@
1
+ export { Combobox } from './Combobox';
@@ -0,0 +1,79 @@
1
+ @layer component {
2
+ .formGroup {
3
+ display: flex;
4
+ flex-direction: column;
5
+ }
6
+
7
+ .dropZone {
8
+ display: flex;
9
+ flex-direction: column;
10
+ align-items: center;
11
+ justify-content: center;
12
+ gap: var(--space_xs);
13
+ padding: var(--space_l) var(--space_m);
14
+ border: 2px dashed var(--color_on-bg);
15
+ border-radius: var(--border_radius--s);
16
+ cursor: pointer;
17
+ text-align: center;
18
+ transition: var(--animation_transition);
19
+ color: var(--color_on-bg--muted);
20
+ }
21
+
22
+ .dropZone:focus-within {
23
+ outline: var(--outline_default);
24
+ outline-offset: var(--outline_offset);
25
+ border-color: var(--color_interactive);
26
+ }
27
+
28
+ .isDragging {
29
+ border-color: var(--color_interactive);
30
+ background-color: rgb(from var(--color_interactive) r g b / 8%);
31
+ }
32
+
33
+ .hasError {
34
+ border-color: var(--color_error);
35
+ }
36
+
37
+ .isDisabled {
38
+ opacity: 0.5;
39
+ cursor: not-allowed;
40
+ }
41
+
42
+ .icon {
43
+ width: 2rem;
44
+ height: 2rem;
45
+ flex-shrink: 0;
46
+ }
47
+
48
+ .prompt {
49
+ font-size: var(--font_size--body);
50
+ color: var(--color_on-bg--muted);
51
+ }
52
+
53
+ .prompt strong {
54
+ color: var(--color_interactive);
55
+ font-weight: var(--font_weight--semibold);
56
+ }
57
+
58
+ .acceptHint {
59
+ font-size: var(--font_size--body--s);
60
+ color: var(--color_on-bg--muted);
61
+ }
62
+
63
+ .hiddenInput {
64
+ position: absolute;
65
+ width: 1px;
66
+ height: 1px;
67
+ overflow: hidden;
68
+ clip: rect(0, 0, 0, 0);
69
+ white-space: nowrap;
70
+ border: 0;
71
+ }
72
+
73
+ @media (hover: hover) and (pointer: fine) {
74
+ .dropZone:not(.isDisabled):hover {
75
+ border-color: var(--color_interactive);
76
+ background-color: rgb(from var(--color_interactive) r g b / 4%);
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,53 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { FileInput } from './FileInput';
4
+
5
+ describe('FileInput', () => {
6
+ it('renders with label', () => {
7
+ render(<FileInput label="Upload file" name="file" />);
8
+ expect(screen.getByText('Upload file')).toBeInTheDocument();
9
+ });
10
+
11
+ it('renders upload prompt text', () => {
12
+ render(<FileInput label="Upload" name="file" />);
13
+ expect(screen.getByText('Click to upload')).toBeInTheDocument();
14
+ });
15
+
16
+ it('renders file input element', () => {
17
+ render(<FileInput label="Upload" name="file" />);
18
+ // The hidden input is there
19
+ const input = document.querySelector('input[type="file"]');
20
+ expect(input).toBeInTheDocument();
21
+ });
22
+
23
+ it('accepts multiple files when multiple is true', () => {
24
+ render(<FileInput label="Upload" name="file" multiple />);
25
+ const input = document.querySelector('input[type="file"]');
26
+ expect(input).toHaveAttribute('multiple');
27
+ });
28
+
29
+ it('shows error message', () => {
30
+ render(<FileInput label="Upload" name="file" error="File required" />);
31
+ expect(screen.getByText('File required')).toBeInTheDocument();
32
+ });
33
+
34
+ it('shows hint message', () => {
35
+ render(<FileInput label="Upload" name="file" hint="Max 5MB" />);
36
+ expect(screen.getByText('Max 5MB')).toBeInTheDocument();
37
+ });
38
+
39
+ it('marks input as invalid when error present', () => {
40
+ render(<FileInput label="Upload" name="file" error="Required" />);
41
+ const input = document.querySelector('input[type="file"]');
42
+ expect(input).toHaveAttribute('aria-invalid', 'true');
43
+ });
44
+
45
+ it('calls onChange when file is selected', async () => {
46
+ const onChange = vi.fn();
47
+ render(<FileInput label="Upload" name="file" onChange={onChange} />);
48
+ const file = new File(['hello'], 'hello.txt', { type: 'text/plain' });
49
+ const input = document.querySelector('input[type="file"]') as HTMLInputElement;
50
+ await userEvent.upload(input, file);
51
+ expect(onChange).toHaveBeenCalledOnce();
52
+ });
53
+ });
@@ -0,0 +1,17 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { FileInput } from './FileInput';
3
+
4
+ const meta = {
5
+ title: 'Form/FileInput',
6
+ component: FileInput,
7
+ tags: ['autodocs'],
8
+ } satisfies Meta<typeof FileInput>;
9
+
10
+ export default meta;
11
+ type Story = StoryObj<typeof meta>;
12
+
13
+ export const Default: Story = { args: { label: 'Upload file', name: 'file' } };
14
+ export const WithAccept: Story = { args: { label: 'Upload image', name: 'image', accept: 'image/png, image/jpeg', hint: 'PNG or JPG only' } };
15
+ export const Multiple: Story = { args: { label: 'Upload documents', name: 'docs', multiple: true, hint: 'You can select multiple files' } };
16
+ export const WithError: Story = { args: { label: 'Upload', name: 'file', error: 'Please upload a valid file' } };
17
+ export const Disabled: Story = { args: { label: 'Upload', name: 'file', disabled: true } };
@@ -0,0 +1,99 @@
1
+ import { useId, useRef, useState, DragEvent, ChangeEvent } from 'react';
2
+ import css from './FileInput.module.css';
3
+ import { Label } from '../atoms/Label';
4
+ import { Message } from '../atoms/Message';
5
+ import { InputContainer } from '../atoms/InputContainer';
6
+ import { cn } from '@boostdev/design-system-foundation';
7
+
8
+ interface FileInputProps {
9
+ label: string;
10
+ name: string;
11
+ accept?: string;
12
+ multiple?: boolean;
13
+ disabled?: boolean;
14
+ error?: string;
15
+ hint?: string;
16
+ onChange?: (files: FileList | null) => void;
17
+ className?: string;
18
+ }
19
+
20
+ export function FileInput({
21
+ label,
22
+ name,
23
+ accept,
24
+ multiple = false,
25
+ disabled = false,
26
+ error,
27
+ hint,
28
+ onChange,
29
+ className,
30
+ }: Readonly<FileInputProps>) {
31
+ const uid = name + useId();
32
+ const hintId = uid + 'hint';
33
+ const errorId = uid + 'error';
34
+ const describedBy = error ? errorId : hintId;
35
+ const inputRef = useRef<HTMLInputElement>(null);
36
+ const [isDragging, setIsDragging] = useState(false);
37
+ const [fileNames, setFileNames] = useState<string[]>([]);
38
+
39
+ const handleFiles = (files: FileList | null) => {
40
+ if (!files) return;
41
+ setFileNames(Array.from(files).map(f => f.name));
42
+ onChange?.(files);
43
+ };
44
+
45
+ const handleChange = (e: ChangeEvent<HTMLInputElement>) => handleFiles(e.target.files);
46
+
47
+ const handleDrop = (e: DragEvent<HTMLLabelElement>) => {
48
+ e.preventDefault();
49
+ setIsDragging(false);
50
+ if (disabled) return;
51
+ handleFiles(e.dataTransfer.files);
52
+ };
53
+
54
+ const handleDragOver = (e: DragEvent<HTMLLabelElement>) => {
55
+ e.preventDefault();
56
+ if (!disabled) setIsDragging(true);
57
+ };
58
+
59
+ const handleDragLeave = () => setIsDragging(false);
60
+
61
+ return (
62
+ <InputContainer className={cn(css.formGroup, className)}>
63
+ <Label id={uid} label={label} />
64
+ <label
65
+ htmlFor={uid}
66
+ className={cn(css.dropZone, isDragging && css.isDragging, error && css.hasError, disabled && css.isDisabled)}
67
+ onDrop={handleDrop}
68
+ onDragOver={handleDragOver}
69
+ onDragLeave={handleDragLeave}
70
+ >
71
+ <svg aria-hidden="true" className={css.icon} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
72
+ <path strokeLinecap="round" strokeLinejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5" />
73
+ </svg>
74
+ <span className={css.prompt}>
75
+ {fileNames.length > 0
76
+ ? fileNames.join(', ')
77
+ : <><strong>Click to upload</strong> or drag and drop</>
78
+ }
79
+ </span>
80
+ {accept && <span className={css.acceptHint}>{accept}</span>}
81
+ <input
82
+ ref={inputRef}
83
+ id={uid}
84
+ type="file"
85
+ name={name}
86
+ accept={accept}
87
+ multiple={multiple}
88
+ disabled={disabled}
89
+ aria-invalid={!!error}
90
+ aria-describedby={describedBy}
91
+ className={css.hiddenInput}
92
+ onChange={handleChange}
93
+ />
94
+ </label>
95
+ <Message inputId={uid} type="error" message={error} />
96
+ <Message inputId={uid} type="hint" message={hint} />
97
+ </InputContainer>
98
+ );
99
+ }
@@ -0,0 +1 @@
1
+ export { FileInput } from './FileInput';
@@ -0,0 +1,37 @@
1
+ @layer component {
2
+ .formGroup {
3
+ --labelPosition: 0; /* Used for positioning */
4
+
5
+ display: flex;
6
+ flex-direction: column;
7
+ }
8
+
9
+ .input {
10
+ /* Component tokens — override from a parent context or inline style */
11
+ --input_border-color: var(--color_on-bg);
12
+ --input_radius: var(--border_radius--xs);
13
+ --input_focus-ring: 0 0 0 2px rgb(from var(--color_interactive) r g b / 20%);
14
+
15
+ font-family: var(--font_family--body);
16
+ font-size: var(--font_size--body);
17
+ padding: var(--space_s);
18
+ border: 1px solid var(--input_border-color);
19
+ border-radius: var(--input_radius);
20
+ transition: var(--animation_transition)
21
+ }
22
+
23
+ .input:focus {
24
+ --input_border-color: var(--color_interactive);
25
+
26
+ outline: none;
27
+ box-shadow: var(--input_focus-ring);
28
+ }
29
+
30
+ .inputError {
31
+ --input_border-color: var(--color_error);
32
+ }
33
+
34
+ .inputError:focus {
35
+ --input_focus-ring: 0 0 0 2px rgb(from var(--color_error) r g b / 20%);
36
+ }
37
+ }
@@ -0,0 +1,43 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { FormInput } from './FormInput';
4
+
5
+ describe('FormInput', () => {
6
+ it('renders the label', () => {
7
+ render(<FormInput label="Email" name="email" />);
8
+ expect(screen.getByLabelText('Email')).toBeInTheDocument();
9
+ });
10
+
11
+ it('renders the input', () => {
12
+ render(<FormInput label="Name" name="name" />);
13
+ expect(screen.getByRole('textbox')).toBeInTheDocument();
14
+ });
15
+
16
+ it('shows an error message when error prop is set', () => {
17
+ render(<FormInput label="Email" name="email" error="Invalid email" />);
18
+ expect(screen.getByText('Invalid email')).toBeInTheDocument();
19
+ });
20
+
21
+ it('marks input as aria-invalid when error is set', () => {
22
+ render(<FormInput label="Email" name="email" error="Required" />);
23
+ expect(screen.getByRole('textbox')).toHaveAttribute('aria-invalid', 'true');
24
+ });
25
+
26
+ it('shows a hint message when hint prop is set', () => {
27
+ render(<FormInput label="Username" name="username" hint="Min 3 chars" />);
28
+ expect(screen.getByText('Min 3 chars')).toBeInTheDocument();
29
+ });
30
+
31
+ it('accepts typed input', async () => {
32
+ const user = userEvent.setup();
33
+ render(<FormInput label="Name" name="name" />);
34
+ const input = screen.getByRole('textbox');
35
+ await user.type(input, 'hello');
36
+ expect(input).toHaveValue('hello');
37
+ });
38
+
39
+ it('is disabled when disabled prop is set', () => {
40
+ render(<FormInput label="Name" name="name" disabled />);
41
+ expect(screen.getByRole('textbox')).toBeDisabled();
42
+ });
43
+ });
@@ -0,0 +1,17 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { FormInput } from './FormInput';
3
+
4
+ const meta = {
5
+ title: 'Form/FormInput',
6
+ component: FormInput,
7
+ tags: ['autodocs'],
8
+ } satisfies Meta<typeof FormInput>;
9
+
10
+ export default meta;
11
+ type Story = StoryObj<typeof meta>;
12
+
13
+ export const Default: Story = { args: { label: 'Email', name: 'email', placeholder: 'you@example.com' } };
14
+ export const WithError: Story = { args: { label: 'Email', name: 'email', error: 'Invalid email address', value: 'bad', onChange: () => {} } };
15
+ export const WithHint: Story = { args: { label: 'Username', name: 'username', hint: 'At least 3 characters', placeholder: 'Enter username' } };
16
+ export const Disabled: Story = { args: { label: 'Disabled', name: 'disabled', disabled: true, value: 'Read only value', onChange: () => {} } };
17
+ export const Required: Story = { args: { label: 'Required Field', name: 'required', required: true, placeholder: 'Required' } };
@@ -0,0 +1,47 @@
1
+ import { InputHTMLAttributes, useId, ReactNode } from 'react';
2
+ import css from './FormInput.module.css';
3
+ import { Label } from '../atoms/Label';
4
+ import { Message } from '../atoms/Message';
5
+ import { cn } from '@boostdev/design-system-foundation';
6
+ import { InputContainer } from '../atoms/InputContainer';
7
+
8
+ interface FormInputProps extends InputHTMLAttributes<HTMLInputElement> {
9
+ label: ReactNode;
10
+ name: string;
11
+ ariaLabel?: string;
12
+ error?: string;
13
+ hint?: string;
14
+ className?: string;
15
+ }
16
+
17
+ export function FormInput({
18
+ label,
19
+ name,
20
+ ariaLabel,
21
+ error,
22
+ hint,
23
+ className,
24
+ ...props
25
+ }: FormInputProps) {
26
+ const id = name + useId();
27
+ const hintId = id + 'hint';
28
+ const errorId = id + 'error';
29
+ const describedBy = !!error ? errorId : hintId;
30
+
31
+ return (
32
+ <InputContainer className={cn(css.formGroup, className)}>
33
+ <Label id={id} label={label} />
34
+ <input
35
+ aria-invalid={!!error}
36
+ aria-describedby={describedBy}
37
+ aria-label={ariaLabel}
38
+ id={id}
39
+ name={name}
40
+ className={`${css.input} ${error ? css.inputError : ''}`}
41
+ {...props}
42
+ />
43
+ <Message inputId={id} type="error" message={error} />
44
+ <Message inputId={id} type="hint" message={hint} />
45
+ </InputContainer>
46
+ );
47
+ }
@@ -0,0 +1 @@
1
+ export { FormInput } from './FormInput';
@@ -0,0 +1,78 @@
1
+ @layer component {
2
+ .formGroup {
3
+ display: flex;
4
+ flex-direction: column;
5
+ }
6
+
7
+ .inputRow {
8
+ display: flex;
9
+ align-items: stretch;
10
+ border: 1px solid var(--color_on-bg);
11
+ border-radius: var(--border_radius--xs);
12
+ overflow: hidden;
13
+ transition: var(--animation_transition);
14
+ }
15
+
16
+ .inputRow:focus-within {
17
+ border-color: var(--color_interactive);
18
+ box-shadow: 0 0 0 2px rgb(from var(--color_interactive) r g b / 20%);
19
+ }
20
+
21
+ .input {
22
+ flex: 1;
23
+ border: none;
24
+ outline: none;
25
+ font-family: var(--font_family--body);
26
+ font-size: var(--font_size--body);
27
+ text-align: center;
28
+ padding: var(--space_s);
29
+ background: transparent;
30
+ color: var(--color_on-bg);
31
+ min-width: 0;
32
+ appearance: textfield;
33
+ }
34
+
35
+ .input::-webkit-inner-spin-button,
36
+ .input::-webkit-outer-spin-button {
37
+ appearance: none;
38
+ }
39
+
40
+ .inputError {
41
+ border-color: var(--color_error);
42
+ }
43
+
44
+ .inputError:focus-within {
45
+ border-color: var(--color_error);
46
+ box-shadow: 0 0 0 2px rgb(from var(--color_error) r g b / 20%);
47
+ }
48
+
49
+ .stepper {
50
+ all: unset;
51
+ display: flex;
52
+ align-items: center;
53
+ justify-content: center;
54
+ padding: var(--space_xs);
55
+ background-color: var(--color_bg--subtle);
56
+ color: var(--color_on-bg);
57
+ cursor: pointer;
58
+ transition: var(--animation_transition);
59
+ flex-shrink: 0;
60
+ }
61
+
62
+ .stepper svg {
63
+ width: 1rem;
64
+ height: 1rem;
65
+ }
66
+
67
+ .stepper:disabled {
68
+ opacity: 0.4;
69
+ cursor: not-allowed;
70
+ }
71
+
72
+ @media (hover: hover) and (pointer: fine) {
73
+ .stepper:not(:disabled):hover {
74
+ background-color: var(--color_bg--subtle);
75
+ opacity: 0.7;
76
+ }
77
+ }
78
+ }