@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,41 @@
1
+ import { render, screen, act, fireEvent } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { ToastProvider, useToast } from './Toast';
4
+
5
+ const ToastTrigger = ({ message = 'Test toast', variant = 'info' as const }) => {
6
+ const { showToast } = useToast();
7
+ return <button onClick={() => showToast(message, variant)}>Show Toast</button>;
8
+ };
9
+
10
+ const setup = (props = {}) =>
11
+ render(
12
+ <ToastProvider>
13
+ <ToastTrigger {...props} />
14
+ </ToastProvider>,
15
+ );
16
+
17
+ describe('Toast', () => {
18
+ it('shows a toast when showToast is called', async () => {
19
+ const user = userEvent.setup();
20
+ setup({ message: 'Hello toast' });
21
+ await user.click(screen.getByRole('button'));
22
+ expect(screen.getByText('Hello toast')).toBeInTheDocument();
23
+ });
24
+
25
+ it('removes the toast after 5 seconds', () => {
26
+ vi.useFakeTimers();
27
+ setup({ message: 'Timed toast' });
28
+ act(() => { fireEvent.click(screen.getByRole('button')); });
29
+ expect(screen.getByText('Timed toast')).toBeInTheDocument();
30
+ act(() => { vi.advanceTimersByTime(5100); });
31
+ expect(screen.queryByText('Timed toast')).not.toBeInTheDocument();
32
+ vi.useRealTimers();
33
+ });
34
+
35
+ it('throws when useToast is used outside ToastProvider', () => {
36
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
37
+ const Bad = () => { useToast(); return null; };
38
+ expect(() => render(<Bad />)).toThrow('useToast must be used within a ToastProvider');
39
+ errorSpy.mockRestore();
40
+ });
41
+ });
@@ -0,0 +1,57 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { ToastProvider, useToast } from './Toast';
3
+ import { Button } from '../Button/Button';
4
+
5
+ const meta = {
6
+ title: 'Interaction/Toast',
7
+ component: ToastProvider,
8
+ tags: ['autodocs'],
9
+ } satisfies Meta<typeof ToastProvider>;
10
+
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+
14
+ const ToastDemo = ({ variant }: { variant?: 'success' | 'error' | 'info' }) => {
15
+ const { showToast } = useToast();
16
+ return (
17
+ <Button onClick={() => showToast(`This is a ${variant ?? 'info'} toast`, variant ?? 'info')}>
18
+ Show {variant ?? 'info'} toast
19
+ </Button>
20
+ );
21
+ };
22
+
23
+ export const Success: Story = {
24
+ render: () => (
25
+ <ToastProvider>
26
+ <ToastDemo variant="success" />
27
+ </ToastProvider>
28
+ ),
29
+ };
30
+
31
+ export const Error: Story = {
32
+ render: () => (
33
+ <ToastProvider>
34
+ <ToastDemo variant="error" />
35
+ </ToastProvider>
36
+ ),
37
+ };
38
+
39
+ export const Info: Story = {
40
+ render: () => (
41
+ <ToastProvider>
42
+ <ToastDemo variant="info" />
43
+ </ToastProvider>
44
+ ),
45
+ };
46
+
47
+ export const AllVariants: Story = {
48
+ render: () => (
49
+ <ToastProvider>
50
+ <div style={{ display: 'flex', gap: '8px' }}>
51
+ <ToastDemo variant="success" />
52
+ <ToastDemo variant="error" />
53
+ <ToastDemo variant="info" />
54
+ </div>
55
+ </ToastProvider>
56
+ ),
57
+ };
@@ -0,0 +1,64 @@
1
+ import { useState, useEffect, createContext, useContext, ReactNode, useCallback, useMemo } from 'react';
2
+ import css from './Toast.module.css';
3
+ import { cn } from '@boostdev/design-system-foundation';
4
+
5
+ type ToastVariant = 'success' | 'error' | 'info';
6
+
7
+ interface Toast {
8
+ id: string;
9
+ message: string;
10
+ variant: ToastVariant;
11
+ }
12
+
13
+ interface ToastContextType {
14
+ showToast: (message: string, variant: ToastVariant) => void;
15
+ }
16
+
17
+ const ToastContext = createContext<ToastContextType | undefined>(undefined);
18
+
19
+ export function ToastProvider({ children }: { children: ReactNode }) {
20
+ const [toasts, setToasts] = useState<Toast[]>([]);
21
+
22
+ const showToast = useCallback((message: string, variant: ToastVariant) => {
23
+ const id = Math.random().toString(36).substring(2, 9);
24
+ setToasts(prev => [...prev, { id, message, variant }]);
25
+ }, []);
26
+
27
+ const removeToast = useCallback((id: string) => {
28
+ setToasts(prev => prev.filter(toast => toast.id !== id));
29
+ }, []);
30
+
31
+ const value = useMemo(() => ({ showToast }), [showToast]);
32
+
33
+ return (
34
+ <ToastContext.Provider value={value}>
35
+ {children}
36
+ <div className={css.toastContainer}>
37
+ {toasts.map(toast => (
38
+ <ToastItem
39
+ key={toast.id}
40
+ toast={toast}
41
+ onRemove={() => removeToast(toast.id)}
42
+ />
43
+ ))}
44
+ </div>
45
+ </ToastContext.Provider>
46
+ );
47
+ }
48
+
49
+ function ToastItem({ toast, onRemove }: { toast: Toast; onRemove: () => void }) {
50
+ useEffect(() => {
51
+ const timer = setTimeout(onRemove, 5000);
52
+ return () => clearTimeout(timer);
53
+ }, [onRemove]);
54
+
55
+ return <div className={cn(css.toast, css[`--variant_${toast.variant}`])}>{toast.message}</div>;
56
+ }
57
+
58
+ export function useToast() {
59
+ const context = useContext(ToastContext);
60
+ if (!context) {
61
+ throw new Error('useToast must be used within a ToastProvider');
62
+ }
63
+ return context;
64
+ }
@@ -0,0 +1 @@
1
+ export { ToastProvider, useToast } from './Toast';
@@ -0,0 +1,61 @@
1
+ @layer component {
2
+ .checkboxGroup {
3
+ --inputSize: calc(var(--space_s) * 2);
4
+
5
+ display: flex;
6
+ flex-direction: column;
7
+ margin-block-end: var(--space_m);
8
+ }
9
+
10
+ .inputWrapper {
11
+ display: flex;
12
+ align-items: stretch;
13
+ gap: var(--space_xs);
14
+ }
15
+
16
+ .checkbox {
17
+ margin-block-start: 0.25em;
18
+ width: var(--inputSize);
19
+ height: var(--inputSize);
20
+ border: 1px solid var(--color_border);
21
+ border-radius: var(--border_radius--xs);
22
+ appearance: none;
23
+ background-color: var(--color_bg);
24
+ cursor: pointer;
25
+ position: relative;
26
+ transition: background-color 0.3s ease, border-color 0.3s ease;
27
+ }
28
+
29
+ .checkbox:checked {
30
+ background-color: var(--color_green);
31
+ border-color: var(--color_green);
32
+ box-shadow: 0 0 0 2px var(--color_green);
33
+ }
34
+
35
+ .checkbox:checked::after {
36
+ content: '';
37
+ position: absolute;
38
+ left: 0.6em;
39
+ top: 0.2em;
40
+ width: 0.5em;
41
+ height: 1em;
42
+ border: solid var(--color_on-green);
43
+ border-width: 0 2px 2px 0;
44
+ transform: rotate(45deg);
45
+ }
46
+
47
+ .checkbox:focus {
48
+ outline: none;
49
+ border-color: var(--color_interactive);
50
+ box-shadow: 0 0 0 2px var(--color_green);
51
+ }
52
+
53
+ .checkboxError {
54
+ border-color: var(--color_error);
55
+ }
56
+
57
+ .checkboxError:focus {
58
+ border-color: var(--color_error);
59
+ box-shadow: 0 0 0 2px rgb(from var(--color_error) r g b / 20%);
60
+ }
61
+ }
@@ -0,0 +1,39 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { Checkbox } from './Checkbox';
4
+
5
+ describe('Checkbox', () => {
6
+ it('renders with a label', () => {
7
+ render(<Checkbox label="Accept terms" name="terms" />);
8
+ expect(screen.getByLabelText('Accept terms')).toBeInTheDocument();
9
+ });
10
+
11
+ it('renders a checkbox input', () => {
12
+ render(<Checkbox label="Opt in" name="optin" />);
13
+ expect(screen.getByRole('checkbox')).toBeInTheDocument();
14
+ });
15
+
16
+ it('can be toggled', async () => {
17
+ const user = userEvent.setup();
18
+ render(<Checkbox label="Toggle" name="toggle" />);
19
+ const checkbox = screen.getByRole('checkbox');
20
+ expect(checkbox).not.toBeChecked();
21
+ await user.click(checkbox);
22
+ expect(checkbox).toBeChecked();
23
+ });
24
+
25
+ it('shows an error message', () => {
26
+ render(<Checkbox label="Accept" name="accept" error="Required" />);
27
+ expect(screen.getByText('Required')).toBeInTheDocument();
28
+ });
29
+
30
+ it('shows a hint message', () => {
31
+ render(<Checkbox label="Subscribe" name="sub" hint="Weekly updates" />);
32
+ expect(screen.getByText('Weekly updates')).toBeInTheDocument();
33
+ });
34
+
35
+ it('is disabled when disabled prop is set', () => {
36
+ render(<Checkbox label="Disabled" name="disabled" disabled />);
37
+ expect(screen.getByRole('checkbox')).toBeDisabled();
38
+ });
39
+ });
@@ -0,0 +1,17 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Checkbox } from './Checkbox';
3
+
4
+ const meta = {
5
+ title: 'Form/Checkbox',
6
+ component: Checkbox,
7
+ tags: ['autodocs'],
8
+ } satisfies Meta<typeof Checkbox>;
9
+
10
+ export default meta;
11
+ type Story = StoryObj<typeof meta>;
12
+
13
+ export const Default: Story = { args: { label: 'Accept terms', name: 'terms' } };
14
+ export const Checked: Story = { args: { label: 'Checked', name: 'checked', defaultChecked: true } };
15
+ export const WithError: Story = { args: { label: 'Required', name: 'required', error: 'This field is required' } };
16
+ export const WithHint: Story = { args: { label: 'Subscribe', name: 'subscribe', hint: 'Receive weekly updates' } };
17
+ export const Disabled: Story = { args: { label: 'Disabled', name: 'disabled', disabled: true } };
@@ -0,0 +1,39 @@
1
+ import { InputHTMLAttributes, useId } from 'react';
2
+ import css from './Checkbox.module.css';
3
+ import { Message } from '../atoms/Message';
4
+ import { Label } from '../atoms/Label';
5
+ import { cn } from '@boostdev/design-system-foundation';
6
+ import { InputContainer } from '../atoms/InputContainer';
7
+
8
+ interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
9
+ label: string;
10
+ name: string;
11
+ error?: string;
12
+ hint?: string;
13
+ className?: string;
14
+ }
15
+
16
+ export function Checkbox({ label, name, error, hint, className, ...props }: CheckboxProps) {
17
+ const id = name + useId();
18
+ const hintId = id + 'hint';
19
+ const errorId = id + 'error';
20
+ const describedBy = !!error ? errorId : hintId;
21
+
22
+ return (
23
+ <InputContainer className={cn(css.checkboxGroup, className)}>
24
+ <div className={css.inputWrapper}>
25
+ <input
26
+ aria-describedby={describedBy}
27
+ type="checkbox"
28
+ id={id}
29
+ name={name}
30
+ className={`${css.checkbox} ${error ? css.checkboxError : ''}`}
31
+ {...props}
32
+ />
33
+ <Label id={id} label={label} />
34
+ </div>
35
+ <Message inputId={id} type="error" message={error} />
36
+ <Message inputId={id} type="hint" message={hint} />
37
+ </InputContainer>
38
+ );
39
+ }
@@ -0,0 +1 @@
1
+ export { Checkbox } from './Checkbox';
@@ -0,0 +1,104 @@
1
+ @layer component {
2
+ .formGroup {
3
+ display: flex;
4
+ flex-direction: column;
5
+ }
6
+
7
+ .inputWrapper {
8
+ position: relative;
9
+ display: flex;
10
+ align-items: center;
11
+ }
12
+
13
+ .input {
14
+ --combobox_border-color: var(--color_on-bg);
15
+ --combobox_focus-ring: 0 0 0 2px rgb(from var(--color_interactive) r g b / 20%);
16
+
17
+ appearance: none;
18
+ width: 100%;
19
+ font-family: var(--font_family--body);
20
+ font-size: var(--font_size--body);
21
+ padding: var(--space_s);
22
+ padding-inline-end: var(--space_xxl);
23
+ border: 1px solid var(--combobox_border-color);
24
+ border-radius: var(--border_radius--xs);
25
+ background-color: var(--color_bg);
26
+ color: var(--color_on-bg);
27
+ transition: var(--animation_transition);
28
+ }
29
+
30
+ .input:focus {
31
+ --combobox_border-color: var(--color_interactive);
32
+
33
+ outline: none;
34
+ box-shadow: var(--combobox_focus-ring);
35
+ }
36
+
37
+ .input:disabled {
38
+ opacity: 0.5;
39
+ cursor: not-allowed;
40
+ }
41
+
42
+ .inputError {
43
+ --combobox_border-color: var(--color_error);
44
+ }
45
+
46
+ .inputError:focus {
47
+ --combobox_focus-ring: 0 0 0 2px rgb(from var(--color_error) r g b / 20%);
48
+ }
49
+
50
+ .chevron {
51
+ position: absolute;
52
+ inset-inline-end: var(--space_s);
53
+ display: flex;
54
+ align-items: center;
55
+ pointer-events: none;
56
+ color: var(--color_on-bg);
57
+ }
58
+
59
+ .chevron svg {
60
+ width: 1rem;
61
+ height: 1rem;
62
+ }
63
+
64
+ .listbox {
65
+ position: absolute;
66
+ top: calc(100% + var(--space_xxs));
67
+ left: 0;
68
+ right: 0;
69
+ z-index: var(--z-index_dropdown);
70
+ max-height: 15rem;
71
+ overflow-y: auto;
72
+ list-style: none;
73
+ margin: 0;
74
+ padding: var(--space_xxs) 0;
75
+ border-radius: var(--border_radius--xs);
76
+ border: 1px solid var(--color_bg--subtle);
77
+ background-color: var(--color_bg);
78
+ box-shadow: var(--shadow_m);
79
+ }
80
+
81
+ .option {
82
+ display: flex;
83
+ align-items: center;
84
+ padding: var(--space_xs) var(--space_m);
85
+ font-size: var(--font_size--body);
86
+ color: var(--color_on-bg);
87
+ cursor: pointer;
88
+ transition: var(--animation_transition);
89
+ }
90
+
91
+ .option.--highlighted {
92
+ background-color: var(--color_bg--subtle);
93
+ color: var(--color_interactive);
94
+ }
95
+
96
+ .option.--selected {
97
+ font-weight: var(--font_weight--semibold);
98
+ }
99
+
100
+ .option.--disabled {
101
+ opacity: 0.4;
102
+ cursor: not-allowed;
103
+ }
104
+ }
@@ -0,0 +1,81 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { Combobox } from './Combobox';
4
+
5
+ const options = [
6
+ { value: 'nl', label: 'Netherlands' },
7
+ { value: 'be', label: 'Belgium' },
8
+ { value: 'de', label: 'Germany' },
9
+ { value: 'fr', label: 'France', disabled: true },
10
+ ];
11
+
12
+ describe('Combobox', () => {
13
+ it('renders with a label', () => {
14
+ render(<Combobox label="Country" name="country" options={options} />);
15
+ expect(screen.getByLabelText('Country')).toBeInTheDocument();
16
+ });
17
+
18
+ it('renders an input with role="combobox"', () => {
19
+ render(<Combobox label="Country" name="country" options={options} />);
20
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
21
+ });
22
+
23
+ it('opens the listbox on focus', async () => {
24
+ const user = userEvent.setup();
25
+ render(<Combobox label="Country" name="country" options={options} />);
26
+ await user.click(screen.getByRole('combobox'));
27
+ expect(screen.getByRole('listbox')).toBeInTheDocument();
28
+ });
29
+
30
+ it('filters options as the user types', async () => {
31
+ const user = userEvent.setup();
32
+ render(<Combobox label="Country" name="country" options={options} />);
33
+ await user.type(screen.getByRole('combobox'), 'Be');
34
+ expect(screen.getByRole('option', { name: 'Belgium' })).toBeInTheDocument();
35
+ expect(screen.queryByRole('option', { name: 'Netherlands' })).not.toBeInTheDocument();
36
+ });
37
+
38
+ it('selects an option on click and closes the listbox', async () => {
39
+ const user = userEvent.setup();
40
+ const onChange = vi.fn();
41
+ render(<Combobox label="Country" name="country" options={options} onChange={onChange} />);
42
+ await user.click(screen.getByRole('combobox'));
43
+ await user.click(screen.getByRole('option', { name: 'Netherlands' }));
44
+ expect(onChange).toHaveBeenCalledWith('nl');
45
+ expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
46
+ expect(screen.getByRole('combobox')).toHaveValue('Netherlands');
47
+ });
48
+
49
+ it('selects highlighted option with Enter key', async () => {
50
+ const user = userEvent.setup();
51
+ const onChange = vi.fn();
52
+ render(<Combobox label="Country" name="country" options={options} onChange={onChange} />);
53
+ await user.click(screen.getByRole('combobox'));
54
+ await user.keyboard('{ArrowDown}');
55
+ await user.keyboard('{Enter}');
56
+ expect(onChange).toHaveBeenCalledOnce();
57
+ });
58
+
59
+ it('closes the listbox on Escape', async () => {
60
+ const user = userEvent.setup();
61
+ render(<Combobox label="Country" name="country" options={options} />);
62
+ await user.click(screen.getByRole('combobox'));
63
+ await user.keyboard('{Escape}');
64
+ expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
65
+ });
66
+
67
+ it('shows an error message', () => {
68
+ render(<Combobox label="Country" name="country" options={options} error="Required" />);
69
+ expect(screen.getByText('Required')).toBeInTheDocument();
70
+ });
71
+
72
+ it('shows a hint message', () => {
73
+ render(<Combobox label="Country" name="country" options={options} hint="Start typing to search" />);
74
+ expect(screen.getByText('Start typing to search')).toBeInTheDocument();
75
+ });
76
+
77
+ it('marks the combobox as aria-invalid when there is an error', () => {
78
+ render(<Combobox label="Country" name="country" options={options} error="Required" />);
79
+ expect(screen.getByRole('combobox')).toHaveAttribute('aria-invalid', 'true');
80
+ });
81
+ });
@@ -0,0 +1,25 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Combobox } from './Combobox';
3
+
4
+ const options = [
5
+ { value: 'nl', label: 'Netherlands' },
6
+ { value: 'be', label: 'Belgium' },
7
+ { value: 'de', label: 'Germany' },
8
+ { value: 'fr', label: 'France' },
9
+ { value: 'es', label: 'Spain' },
10
+ { value: 'it', label: 'Italy' },
11
+ { value: 'pt', label: 'Portugal', disabled: true },
12
+ ];
13
+
14
+ const meta = {
15
+ title: 'Form/Combobox',
16
+ component: Combobox,
17
+ tags: ['autodocs'],
18
+ } satisfies Meta<typeof Combobox>;
19
+
20
+ export default meta;
21
+ type Story = StoryObj<typeof meta>;
22
+
23
+ export const Default: Story = { args: { label: 'Country', name: 'country', options, placeholder: 'Search…' } };
24
+ export const WithError: Story = { args: { label: 'Country', name: 'country', options, error: 'Please select a valid country' } };
25
+ export const WithHint: Story = { args: { label: 'Country', name: 'country', options, hint: 'Start typing to filter options' } };