@ds-mo/ui 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/dist/components/Accordion/Accordion.d.ts +29 -0
  2. package/dist/components/Accordion/Accordion.d.ts.map +1 -0
  3. package/dist/components/Accordion/index.d.ts +3 -0
  4. package/dist/components/Accordion/index.d.ts.map +1 -0
  5. package/dist/components/Badge/Badge.d.ts +18 -0
  6. package/dist/components/Badge/Badge.d.ts.map +1 -0
  7. package/dist/components/Badge/index.d.ts +3 -0
  8. package/dist/components/Badge/index.d.ts.map +1 -0
  9. package/dist/components/Banner/Banner.d.ts +16 -0
  10. package/dist/components/Banner/Banner.d.ts.map +1 -0
  11. package/dist/components/Banner/index.d.ts +3 -0
  12. package/dist/components/Banner/index.d.ts.map +1 -0
  13. package/dist/components/Breadcrumb/Breadcrumb.d.ts +15 -0
  14. package/dist/components/Breadcrumb/Breadcrumb.d.ts.map +1 -0
  15. package/dist/components/Breadcrumb/index.d.ts +3 -0
  16. package/dist/components/Breadcrumb/index.d.ts.map +1 -0
  17. package/dist/components/Button/Button.d.ts +85 -0
  18. package/dist/components/Button/Button.d.ts.map +1 -0
  19. package/dist/components/Button/index.d.ts +3 -0
  20. package/dist/components/Button/index.d.ts.map +1 -0
  21. package/dist/components/ButtonGroup/ButtonGroup.d.ts +26 -0
  22. package/dist/components/ButtonGroup/ButtonGroup.d.ts.map +1 -0
  23. package/dist/components/ButtonGroup/index.d.ts +3 -0
  24. package/dist/components/ButtonGroup/index.d.ts.map +1 -0
  25. package/dist/components/Card/Card.d.ts +20 -0
  26. package/dist/components/Card/Card.d.ts.map +1 -0
  27. package/dist/components/Card/index.d.ts +3 -0
  28. package/dist/components/Card/index.d.ts.map +1 -0
  29. package/dist/components/Checkbox/Checkbox.d.ts +18 -0
  30. package/dist/components/Checkbox/Checkbox.d.ts.map +1 -0
  31. package/dist/components/Checkbox/index.d.ts +3 -0
  32. package/dist/components/Checkbox/index.d.ts.map +1 -0
  33. package/dist/components/Divider/Divider.d.ts +9 -0
  34. package/dist/components/Divider/Divider.d.ts.map +1 -0
  35. package/dist/components/Divider/index.d.ts +3 -0
  36. package/dist/components/Divider/index.d.ts.map +1 -0
  37. package/dist/components/EmptyState/EmptyState.d.ts +9 -0
  38. package/dist/components/EmptyState/EmptyState.d.ts.map +1 -0
  39. package/dist/components/EmptyState/index.d.ts +3 -0
  40. package/dist/components/EmptyState/index.d.ts.map +1 -0
  41. package/dist/components/ErrorBoundary/ErrorBoundary.d.ts +18 -0
  42. package/dist/components/ErrorBoundary/ErrorBoundary.d.ts.map +1 -0
  43. package/dist/components/ErrorBoundary/index.d.ts +3 -0
  44. package/dist/components/ErrorBoundary/index.d.ts.map +1 -0
  45. package/dist/components/Fade/Fade.d.ts +11 -0
  46. package/dist/components/Fade/Fade.d.ts.map +1 -0
  47. package/dist/components/Fade/index.d.ts +3 -0
  48. package/dist/components/Fade/index.d.ts.map +1 -0
  49. package/dist/components/Field/Field.d.ts +9 -0
  50. package/dist/components/Field/Field.d.ts.map +1 -0
  51. package/dist/components/Field/index.d.ts +3 -0
  52. package/dist/components/Field/index.d.ts.map +1 -0
  53. package/dist/components/Header/Header.d.ts +12 -0
  54. package/dist/components/Header/Header.d.ts.map +1 -0
  55. package/dist/components/Header/index.d.ts +3 -0
  56. package/dist/components/Header/index.d.ts.map +1 -0
  57. package/dist/components/Input/Input.d.ts +27 -0
  58. package/dist/components/Input/Input.d.ts.map +1 -0
  59. package/dist/components/Input/index.d.ts +3 -0
  60. package/dist/components/Input/index.d.ts.map +1 -0
  61. package/dist/components/LabelWrap/LabelWrap.d.ts +27 -0
  62. package/dist/components/LabelWrap/LabelWrap.d.ts.map +1 -0
  63. package/dist/components/LabelWrap/index.d.ts +2 -0
  64. package/dist/components/LabelWrap/index.d.ts.map +1 -0
  65. package/dist/components/Loader/Loader.d.ts +33 -0
  66. package/dist/components/Loader/Loader.d.ts.map +1 -0
  67. package/dist/components/Loader/index.d.ts +3 -0
  68. package/dist/components/Loader/index.d.ts.map +1 -0
  69. package/dist/components/Menu/DestructiveMenuItem.d.ts +12 -0
  70. package/dist/components/Menu/DestructiveMenuItem.d.ts.map +1 -0
  71. package/dist/components/Menu/Menu.d.ts +55 -0
  72. package/dist/components/Menu/Menu.d.ts.map +1 -0
  73. package/dist/components/Menu/MenuItem.d.ts +33 -0
  74. package/dist/components/Menu/MenuItem.d.ts.map +1 -0
  75. package/dist/components/Menu/index.d.ts +7 -0
  76. package/dist/components/Menu/index.d.ts.map +1 -0
  77. package/dist/components/Modal/Modal.d.ts +15 -0
  78. package/dist/components/Modal/Modal.d.ts.map +1 -0
  79. package/dist/components/Modal/index.d.ts +3 -0
  80. package/dist/components/Modal/index.d.ts.map +1 -0
  81. package/dist/components/Pagination/Pagination.d.ts +16 -0
  82. package/dist/components/Pagination/Pagination.d.ts.map +1 -0
  83. package/dist/components/Pagination/index.d.ts +3 -0
  84. package/dist/components/Pagination/index.d.ts.map +1 -0
  85. package/dist/components/Radio/Radio.d.ts +35 -0
  86. package/dist/components/Radio/Radio.d.ts.map +1 -0
  87. package/dist/components/Radio/index.d.ts +3 -0
  88. package/dist/components/Radio/index.d.ts.map +1 -0
  89. package/dist/components/Scrollbar/Scrollbar.d.ts +13 -0
  90. package/dist/components/Scrollbar/Scrollbar.d.ts.map +1 -0
  91. package/dist/components/Scrollbar/index.d.ts +3 -0
  92. package/dist/components/Scrollbar/index.d.ts.map +1 -0
  93. package/dist/components/Select/Select.d.ts +22 -0
  94. package/dist/components/Select/Select.d.ts.map +1 -0
  95. package/dist/components/Select/index.d.ts +3 -0
  96. package/dist/components/Select/index.d.ts.map +1 -0
  97. package/dist/components/Sidebar/Sidebar.d.ts +15 -0
  98. package/dist/components/Sidebar/Sidebar.d.ts.map +1 -0
  99. package/dist/components/Sidebar/SidebarItem.d.ts +14 -0
  100. package/dist/components/Sidebar/SidebarItem.d.ts.map +1 -0
  101. package/dist/components/Sidebar/SidebarSection.d.ts +10 -0
  102. package/dist/components/Sidebar/SidebarSection.d.ts.map +1 -0
  103. package/dist/components/Sidebar/index.d.ts +7 -0
  104. package/dist/components/Sidebar/index.d.ts.map +1 -0
  105. package/dist/components/Skeleton/Skeleton.d.ts +17 -0
  106. package/dist/components/Skeleton/Skeleton.d.ts.map +1 -0
  107. package/dist/components/Skeleton/index.d.ts +3 -0
  108. package/dist/components/Skeleton/index.d.ts.map +1 -0
  109. package/dist/components/Slider/Slider.d.ts +16 -0
  110. package/dist/components/Slider/Slider.d.ts.map +1 -0
  111. package/dist/components/Slider/index.d.ts +3 -0
  112. package/dist/components/Slider/index.d.ts.map +1 -0
  113. package/dist/components/Surface/Surface.d.ts +59 -0
  114. package/dist/components/Surface/Surface.d.ts.map +1 -0
  115. package/dist/components/Surface/index.d.ts +3 -0
  116. package/dist/components/Surface/index.d.ts.map +1 -0
  117. package/dist/components/Tab/Tab.d.ts +21 -0
  118. package/dist/components/Tab/Tab.d.ts.map +1 -0
  119. package/dist/components/Tab/index.d.ts +3 -0
  120. package/dist/components/Tab/index.d.ts.map +1 -0
  121. package/dist/components/TabGroup/TabGroup.d.ts +26 -0
  122. package/dist/components/TabGroup/TabGroup.d.ts.map +1 -0
  123. package/dist/components/TabGroup/index.d.ts +3 -0
  124. package/dist/components/TabGroup/index.d.ts.map +1 -0
  125. package/dist/components/Table/Table.d.ts +46 -0
  126. package/dist/components/Table/Table.d.ts.map +1 -0
  127. package/dist/components/Table/index.d.ts +3 -0
  128. package/dist/components/Table/index.d.ts.map +1 -0
  129. package/dist/components/Tag/Tag.d.ts +38 -0
  130. package/dist/components/Tag/Tag.d.ts.map +1 -0
  131. package/dist/components/Tag/index.d.ts +3 -0
  132. package/dist/components/Tag/index.d.ts.map +1 -0
  133. package/dist/components/Text/Text.d.ts +41 -0
  134. package/dist/components/Text/Text.d.ts.map +1 -0
  135. package/dist/components/Text/index.d.ts +3 -0
  136. package/dist/components/Text/index.d.ts.map +1 -0
  137. package/dist/components/Toast/Toast.d.ts +33 -0
  138. package/dist/components/Toast/Toast.d.ts.map +1 -0
  139. package/dist/components/Toast/index.d.ts +3 -0
  140. package/dist/components/Toast/index.d.ts.map +1 -0
  141. package/dist/components/Toggle/Toggle.d.ts +17 -0
  142. package/dist/components/Toggle/Toggle.d.ts.map +1 -0
  143. package/dist/components/Toggle/index.d.ts +3 -0
  144. package/dist/components/Toggle/index.d.ts.map +1 -0
  145. package/dist/components/ToggleButton/ToggleButton.d.ts +35 -0
  146. package/dist/components/ToggleButton/ToggleButton.d.ts.map +1 -0
  147. package/dist/components/ToggleButton/index.d.ts +3 -0
  148. package/dist/components/ToggleButton/index.d.ts.map +1 -0
  149. package/dist/components/ToggleButtonGroup/ToggleButtonGroup.d.ts +24 -0
  150. package/dist/components/ToggleButtonGroup/ToggleButtonGroup.d.ts.map +1 -0
  151. package/dist/components/ToggleButtonGroup/index.d.ts +3 -0
  152. package/dist/components/ToggleButtonGroup/index.d.ts.map +1 -0
  153. package/dist/components/Tooltip/Tooltip.d.ts +17 -0
  154. package/dist/components/Tooltip/Tooltip.d.ts.map +1 -0
  155. package/dist/components/Tooltip/index.d.ts +3 -0
  156. package/dist/components/Tooltip/index.d.ts.map +1 -0
  157. package/dist/index.css +1 -1
  158. package/dist/index.d.ts +82 -969
  159. package/dist/index.d.ts.map +1 -0
  160. package/dist/index.js +1641 -1165
  161. package/dist/index.js.map +1 -1
  162. package/dist/r/badge.json +1 -1
  163. package/dist/r/banner.json +2 -2
  164. package/dist/r/loader.json +2 -2
  165. package/dist/r/menu.json +4 -4
  166. package/dist/r/select.json +1 -1
  167. package/dist/r/tab-group.json +1 -1
  168. package/dist/r/tab.json +1 -1
  169. package/dist/r/toast.json +1 -1
  170. package/dist/r/toggle.json +1 -1
  171. package/dist/types/icons.d.ts +14 -0
  172. package/dist/types/icons.d.ts.map +1 -0
  173. package/dist/types/index.d.ts +2 -0
  174. package/dist/types/index.d.ts.map +1 -0
  175. package/dist/utils/cn.d.ts +5 -0
  176. package/dist/utils/cn.d.ts.map +1 -0
  177. package/dist/utils/css-tokens.d.ts +11 -0
  178. package/dist/utils/css-tokens.d.ts.map +1 -0
  179. package/package.json +17 -12
  180. package/src/components/Accordion/Accordion.tsx +10 -1
  181. package/src/components/Badge/Badge.stories.tsx +32 -0
  182. package/src/components/Badge/Badge.tsx +19 -2
  183. package/src/components/Banner/Banner.module.css +38 -0
  184. package/src/components/Banner/Banner.tsx +34 -4
  185. package/src/components/Button/Button.mdx +143 -0
  186. package/src/components/Button/Button.stories.tsx +1 -1
  187. package/src/components/Button/Button.tsx +42 -11
  188. package/src/components/Checkbox/Checkbox.tsx +6 -3
  189. package/src/components/Field/Field.tsx +20 -7
  190. package/src/components/Input/Input.module.css +21 -0
  191. package/src/components/Input/Input.tsx +62 -21
  192. package/src/components/Loader/Loader.module.css +17 -0
  193. package/src/components/Loader/Loader.stories.tsx +9 -0
  194. package/src/components/Loader/Loader.tsx +42 -20
  195. package/src/components/Menu/DestructiveMenuItem.tsx +59 -6
  196. package/src/components/Menu/Menu.tsx +160 -11
  197. package/src/components/Menu/MenuItem.module.css +2 -0
  198. package/src/components/Menu/MenuItem.tsx +48 -5
  199. package/src/components/Modal/Modal.tsx +81 -4
  200. package/src/components/Radio/Radio.tsx +117 -29
  201. package/src/components/Scrollbar/Scrollbar.module.css +5 -0
  202. package/src/components/Scrollbar/Scrollbar.tsx +18 -4
  203. package/src/components/Select/Select.tsx +139 -9
  204. package/src/components/Sidebar/Sidebar.module.css +7 -0
  205. package/src/components/Sidebar/Sidebar.tsx +102 -4
  206. package/src/components/Slider/Slider.module.css +5 -1
  207. package/src/components/Slider/Slider.stories.tsx +25 -0
  208. package/src/components/Slider/Slider.tsx +4 -4
  209. package/src/components/Tab/Tab.tsx +32 -2
  210. package/src/components/TabGroup/TabGroup.stories.tsx +46 -15
  211. package/src/components/TabGroup/TabGroup.tsx +77 -10
  212. package/src/components/Table/Table.module.css +10 -0
  213. package/src/components/Table/Table.tsx +58 -29
  214. package/src/components/Tag/Tag.tsx +5 -2
  215. package/src/components/Toast/Toast.tsx +44 -8
  216. package/src/components/Toggle/Toggle.tsx +23 -22
  217. package/src/components/Tooltip/Tooltip.tsx +42 -6
@@ -30,12 +30,50 @@
30
30
  .bannerBody {
31
31
  padding: var(--dimension-space-075);
32
32
  min-height: var(--dimension-size-400);
33
+ display: flex;
34
+ align-items: flex-start;
35
+ gap: var(--dimension-space-075);
33
36
  }
34
37
 
35
38
  .message {
36
39
  color: var(--banner-content);
37
40
  line-height: var(--typography-lineheight-md);
38
41
  display: block;
42
+ flex: 1;
43
+ min-width: 0;
44
+ }
45
+
46
+ .dismiss {
47
+ background: none;
48
+ border: none;
49
+ margin: 0;
50
+ padding: var(--dimension-space-025);
51
+ color: var(--banner-content);
52
+ cursor: pointer;
53
+ display: inline-flex;
54
+ align-items: center;
55
+ justify-content: center;
56
+ flex-shrink: 0;
57
+ border-radius: var(--dimension-radius-050);
58
+ position: relative;
59
+ }
60
+
61
+ .dismiss::before {
62
+ content: '';
63
+ position: absolute;
64
+ inset: 0;
65
+ border-radius: inherit;
66
+ background-color: transparent;
67
+ transition: var(--effect-transition-interaction-background-short-2);
68
+ pointer-events: none;
69
+ }
70
+
71
+ .dismiss:hover::before { background-color: var(--color-interaction-hover); }
72
+ .dismiss:active::before { background-color: var(--color-interaction-pressed); }
73
+
74
+ .dismiss:focus-visible {
75
+ outline: var(--dimension-stroke-width-025) solid var(--color-interaction-focus);
76
+ outline-offset: var(--dimension-stroke-width-015);
39
77
  }
40
78
 
41
79
  .floatingPosition {
@@ -1,5 +1,6 @@
1
1
  import React, { useState, useEffect, useCallback, useRef } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
+ import { Cross } from '@ds-mo/icons';
3
4
  import { Surface } from '@/components/Surface';
4
5
  import { Text } from '@/components/Text';
5
6
  import { getCssTimeMs } from '@/utils/css-tokens';
@@ -22,6 +23,8 @@ export interface BannerProps {
22
23
  className?: string;
23
24
  floating?: boolean;
24
25
  onDismiss?: () => void;
26
+ /** Accessible label for the dismiss button. Defaults to "Dismiss". */
27
+ dismissLabel?: string;
25
28
  }
26
29
 
27
30
  const getContentColorVar = (intent: BannerIntent, contrast: BannerContrast): string => {
@@ -38,6 +41,7 @@ export const Banner: React.FC<BannerProps> = ({
38
41
  className = '',
39
42
  floating = false,
40
43
  onDismiss,
44
+ dismissLabel = 'Dismiss',
41
45
  }) => {
42
46
  const toastDurationMs = getCssTimeMs('--effect-animation-delay-long-2', TOAST_DURATION_FALLBACK_MS);
43
47
  const messageColor = getContentColorVar(intent, contrast);
@@ -45,18 +49,28 @@ export const Banner: React.FC<BannerProps> = ({
45
49
  const dismissTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
46
50
  const closeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
47
51
 
48
- const scheduleDismiss = useCallback(() => {
52
+ const beginClose = useCallback(() => {
49
53
  if (dismissTimerRef.current) clearTimeout(dismissTimerRef.current);
50
54
  if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
51
- dismissTimerRef.current = setTimeout(() => {
52
- dismissTimerRef.current = null;
55
+ dismissTimerRef.current = null;
56
+ if (floating) {
53
57
  setIsClosing(true);
54
58
  closeTimerRef.current = setTimeout(() => {
55
59
  closeTimerRef.current = null;
56
60
  onDismiss?.();
57
61
  }, FADE_OUT_DURATION_MS);
62
+ } else {
63
+ onDismiss?.();
64
+ }
65
+ }, [floating, onDismiss]);
66
+
67
+ const scheduleDismiss = useCallback(() => {
68
+ if (dismissTimerRef.current) clearTimeout(dismissTimerRef.current);
69
+ dismissTimerRef.current = setTimeout(() => {
70
+ dismissTimerRef.current = null;
71
+ beginClose();
58
72
  }, toastDurationMs);
59
- }, [onDismiss, toastDurationMs]);
73
+ }, [beginClose, toastDurationMs]);
60
74
 
61
75
  useEffect(() => {
62
76
  if (floating && message) scheduleDismiss();
@@ -66,10 +80,16 @@ export const Banner: React.FC<BannerProps> = ({
66
80
  };
67
81
  }, [floating, message, scheduleDismiss]);
68
82
 
83
+ const isAssertive = intent === 'negative';
84
+ const role = isAssertive ? 'alert' : 'status';
85
+ const ariaLive = isAssertive ? undefined : 'polite';
86
+
69
87
  const content = (
70
88
  <div
71
89
  className={`${styles.bannerWrapper} ${className}`.trim()}
72
90
  style={{ '--banner-content': messageColor } as React.CSSProperties}
91
+ role={role}
92
+ aria-live={ariaLive}
73
93
  >
74
94
  <Surface
75
95
  elevation={floating ? 'floating' : 'elevated'}
@@ -87,6 +107,16 @@ export const Banner: React.FC<BannerProps> = ({
87
107
  <Text variant="text-body-medium" as="span" className={styles.message}>
88
108
  {message}
89
109
  </Text>
110
+ {onDismiss && (
111
+ <button
112
+ type="button"
113
+ className={styles.dismiss}
114
+ onClick={beginClose}
115
+ aria-label={dismissLabel}
116
+ >
117
+ <Cross size={16} />
118
+ </button>
119
+ )}
90
120
  </div>
91
121
  </Surface>
92
122
  </div>
@@ -0,0 +1,143 @@
1
+ import { Meta, Title, Subtitle, Canvas, Controls, Primary } from '@storybook/addon-docs/blocks';
2
+ import * as ButtonStories from './Button.stories';
3
+
4
+ <Meta of={ButtonStories} />
5
+
6
+ <Title />
7
+
8
+ <Subtitle>
9
+ Buttons trigger actions. They are the primary way users commit to a decision —
10
+ saving a record, opening a dialog, navigating somewhere meaningful.
11
+ </Subtitle>
12
+
13
+ A button should make its purpose obvious from its label, its visual weight, and
14
+ its position on the page. The right button in the right place is invisible — it
15
+ just feels like the next step. The wrong button competes for attention and slows
16
+ the user down.
17
+
18
+ ## Playground
19
+
20
+ Use the controls below to explore every prop the component accepts. This is the
21
+ fastest way to understand how `variant`, `intent`, `contrast`, and `elevation`
22
+ combine.
23
+
24
+ <Primary />
25
+
26
+ <Controls />
27
+
28
+ ## When to use
29
+
30
+ Reach for a button when the user needs to perform an **action** — submit a form,
31
+ delete a record, open a panel, run a process. If the user is navigating between
32
+ pages or sections, prefer a link instead. Buttons are for verbs; links are for
33
+ nouns.
34
+
35
+ A page should have **one** clearly dominant button. If two actions look equally
36
+ important, the user has to stop and read both before deciding — which is exactly
37
+ the moment of friction good hierarchy avoids.
38
+
39
+ ## Variants
40
+
41
+ `primary` is filled and carries the strongest visual weight. Use it for the one
42
+ action you most want the user to take on a given screen.
43
+
44
+ `secondary` is a softer treatment for actions that matter but should not compete
45
+ with the primary action. Use `elevation="none"` to get the ghost treatment for
46
+ tertiary actions like cancel, dismiss, or inline controls.
47
+
48
+ <Canvas of={ButtonStories.Variants} />
49
+
50
+ > **Do** pair one `primary` with one or more `secondary` buttons in a form footer.
51
+ >
52
+ > **Don't** stack two `primary` buttons next to each other — only one action can
53
+ > be the primary one.
54
+
55
+ ## Intent
56
+
57
+ Intent communicates the **meaning** of the action through color. Most buttons
58
+ should use `brand` (the default) or `neutral`. Reserve semantic intents for
59
+ moments when the meaning genuinely matches.
60
+
61
+ <Canvas of={ButtonStories.Intents} />
62
+
63
+ - `brand` — the default for primary calls-to-action
64
+ - `neutral` — for actions that should not draw color, like filters or toolbar controls
65
+ - `negative` — for destructive actions (delete, remove, discard)
66
+ - `positive` — for confirmations of a successful state, used sparingly
67
+ - `warning` / `caution` — for actions that need a moment of pause
68
+ - `ai` — reserved for AI-generated or AI-triggering actions
69
+ - `none` — inverted styling for use on colored or dark surfaces
70
+
71
+ > **Don't** use `negative` intent for a cancel button. Cancel is not destructive;
72
+ > it is the absence of an action. Use `secondary` with no intent.
73
+
74
+ ## Sizes
75
+
76
+ Pick a size from the surrounding density, not the importance of the action.
77
+ Forms and dialogs use `md`. Compact toolbars and table rows use `sm` or `xs`.
78
+ Hero sections and marketing surfaces can use `lg`.
79
+
80
+ <Canvas of={ButtonStories.Sizes} />
81
+
82
+ ## Icons
83
+
84
+ A leading icon can clarify a button's purpose at a glance — but only when the
85
+ icon's meaning is unambiguous. If you have to think about which icon to pick,
86
+ the label alone is doing a better job.
87
+
88
+ <Canvas of={ButtonStories.IconAndLabel} />
89
+
90
+ Icon-only buttons must always have an `aria-label`. Without it, screen readers
91
+ announce nothing meaningful, and keyboard users lose all context.
92
+
93
+ <Canvas of={ButtonStories.IconOnly} />
94
+
95
+ ## States
96
+
97
+ Buttons have several states that communicate progress or availability:
98
+
99
+ - `inactive` — the action is not currently available, but may become available
100
+ - `loading` — the action is in flight; prevents double-submission
101
+ - `rounded` — pill-shaped variant for filter chips and compact actions
102
+
103
+ <Canvas of={ButtonStories.Loading} />
104
+
105
+ <Canvas of={ButtonStories.Inactive} />
106
+
107
+ > **Do** use `loading` for any async action that takes longer than ~200ms.
108
+ > Without it, users will click again, often submitting twice.
109
+
110
+ ## Full width
111
+
112
+ Use `fullWidth` inside narrow containers like mobile sheets, side panels, or
113
+ form footers where the button should fill the available width. Avoid full-width
114
+ buttons on wide desktop layouts — they read as banner CTAs and feel heavy.
115
+
116
+ <Canvas of={ButtonStories.FullWidth} />
117
+
118
+ ## On colored surfaces
119
+
120
+ When a button sits on a colored or dark surface, set the `background` prop so
121
+ the button can adapt its contrast to remain legible. The `BackgroundContext`
122
+ story below demonstrates every variant against every supported surface.
123
+
124
+ <Canvas of={ButtonStories.BackgroundContext} />
125
+
126
+ ## Accessibility
127
+
128
+ - Every button must have a discernible name — either visible text in `label` or
129
+ an `aria-label` for icon-only buttons.
130
+ - The `inactive` state is **not** the same as the HTML `disabled` attribute.
131
+ `inactive` keeps the button focusable and announceable; truly disabled buttons
132
+ vanish from the tab order and frustrate users who can't tell why an action
133
+ isn't working.
134
+ - Touch targets meet the 24×24 CSS pixel minimum at all sizes; `xs` is intended
135
+ for dense desktop UIs and should not be used on mobile.
136
+
137
+ ## Full reference matrix
138
+
139
+ The matrix below renders every meaningful combination of `variant`, `intent`,
140
+ `contrast`, `elevation`, `size`, and state on a single canvas. Use it as a
141
+ visual regression reference when changing tokens or styles.
142
+
143
+ <Canvas of={ButtonStories.Matrix} />
@@ -66,7 +66,7 @@ const ELEVATIONS: ButtonElevation[] = ['elevated', 'flat', 'none', 'floating'];
66
66
 
67
67
  const col: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 8, alignItems: 'flex-start' };
68
68
  const row: React.CSSProperties = { display: 'flex', gap: 8, alignItems: 'center' };
69
- const lbl = (text: string): React.CSSProperties => ({ fontSize: 10, fontFamily: 'monospace', color: '#888', minWidth: 80, flexShrink: 0 });
69
+ const lbl = (_text: string): React.CSSProperties => ({ fontSize: 10, fontFamily: 'monospace', color: '#888', minWidth: 80, flexShrink: 0 });
70
70
  const section = (text: string) => (
71
71
  <div style={{ fontSize: 11, fontWeight: 600, letterSpacing: '0.05em', textTransform: 'uppercase', color: '#555', marginTop: 8 }}>
72
72
  {text}
@@ -14,13 +14,11 @@ export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg';
14
14
  export type ButtonContrast = 'strong' | 'bold' | 'medium' | 'faint';
15
15
  export type ButtonBackground = 'faint' | 'medium' | 'bold' | 'strong' | 'always-dark';
16
16
 
17
- export interface ButtonProps {
17
+ interface ButtonBaseProps {
18
18
  /** Polymorphic element type. Defaults to 'button'. */
19
19
  as?: React.ElementType;
20
20
  /** Visual variant. Defaults to 'primary'. */
21
21
  variant?: ButtonVariant;
22
- /** Label text. */
23
- label?: string;
24
22
  /** Leading icon component from @ds-mo/icons. */
25
23
  icon?: IconComponent;
26
24
  /** Semantic intent. Defaults to 'brand'. */
@@ -67,12 +65,24 @@ export interface ButtonProps {
67
65
  inactive?: boolean;
68
66
  type?: 'button' | 'submit' | 'reset';
69
67
  id?: string;
70
- 'aria-label'?: string;
71
68
  href?: string;
72
69
  target?: string;
73
70
  rel?: string;
74
71
  }
75
72
 
73
+ /**
74
+ * Accessible-name requirement: a Button must expose text via `label`,
75
+ * `aria-label`, or `aria-labelledby`. Icon-only buttons that omit all three
76
+ * fail at the call site (TypeScript), with a runtime warning as a soft
77
+ * fallback for callers that bypass the type system.
78
+ */
79
+ type ButtonAccessibleNameProps =
80
+ | { label: string; 'aria-label'?: string; 'aria-labelledby'?: string }
81
+ | { label?: string; 'aria-label': string; 'aria-labelledby'?: string }
82
+ | { label?: string; 'aria-label'?: string; 'aria-labelledby': string };
83
+
84
+ export type ButtonProps = ButtonBaseProps & ButtonAccessibleNameProps;
85
+
76
86
  const ICON_SIZE_MAP: Record<ButtonSize, number> = { xs: 12, sm: 16, md: 20, lg: 24 };
77
87
 
78
88
  const TEXT_STYLE_MAP: Record<ButtonSize, string> = {
@@ -84,8 +94,8 @@ const TEXT_STYLE_MAP: Record<ButtonSize, string> = {
84
94
 
85
95
 
86
96
  export const Button = forwardRef<HTMLElement, ButtonProps>(
87
- (
88
- {
97
+ (props, ref) => {
98
+ const {
89
99
  as,
90
100
  variant = 'primary',
91
101
  label,
@@ -109,14 +119,16 @@ export const Button = forwardRef<HTMLElement, ButtonProps>(
109
119
  type = 'button',
110
120
  id,
111
121
  'aria-label': ariaLabel,
122
+ 'aria-labelledby': ariaLabelledBy,
112
123
  href,
113
124
  target,
114
125
  rel,
115
- },
116
- ref
117
- ) => {
126
+ } = props;
127
+
118
128
  const Component = (as ?? 'button') as React.ElementType;
119
129
  const isButton = !as || as === 'button';
130
+ const isLink = as === 'a';
131
+ const isCustomInteractive = !isButton && !isLink;
120
132
  const isInteractive = !inactive && !loading;
121
133
 
122
134
  const hasIcon = !!Icon;
@@ -153,7 +165,11 @@ export const Button = forwardRef<HTMLElement, ButtonProps>(
153
165
  className,
154
166
  );
155
167
 
156
- const resolvedAriaLabel = ariaLabel || label || 'button';
168
+ if (isIconOnly && !ariaLabel && !ariaLabelledBy) {
169
+ console.warn(
170
+ '[@ds-mo/ui Button] Icon-only Button is missing an accessible name. Provide `label`, `aria-label`, or `aria-labelledby`.'
171
+ );
172
+ }
157
173
 
158
174
  const extraProps: Record<string, unknown> = {};
159
175
  if (isButton) {
@@ -164,6 +180,19 @@ export const Button = forwardRef<HTMLElement, ButtonProps>(
164
180
  if (target) extraProps.target = target;
165
181
  if (rel) extraProps.rel = rel;
166
182
 
183
+ if (isCustomInteractive) {
184
+ extraProps.role = 'button';
185
+ extraProps.tabIndex = isInteractive ? 0 : -1;
186
+ if (isInteractive) {
187
+ extraProps.onKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {
188
+ if (e.key === 'Enter' || e.key === ' ') {
189
+ e.preventDefault();
190
+ (e.currentTarget as HTMLElement).click();
191
+ }
192
+ };
193
+ }
194
+ }
195
+
167
196
  return (
168
197
  <Component
169
198
  ref={ref}
@@ -173,7 +202,9 @@ export const Button = forwardRef<HTMLElement, ButtonProps>(
173
202
  onClick={isInteractive ? onClick : undefined}
174
203
  onMouseEnter={isInteractive ? onMouseEnter : undefined}
175
204
  onMouseLeave={isInteractive ? onMouseLeave : undefined}
176
- aria-label={resolvedAriaLabel}
205
+ aria-label={ariaLabel}
206
+ aria-labelledby={ariaLabelledBy}
207
+ aria-disabled={inactive || loading || undefined}
177
208
  aria-busy={loading || undefined}
178
209
  {...extraProps}
179
210
  >
@@ -1,4 +1,4 @@
1
- import React, { forwardRef } from 'react';
1
+ import React, { forwardRef, useId } from 'react';
2
2
  import { cn } from '@/utils/cn';
3
3
  import { Text } from '@/components/Text';
4
4
  import type { IconComponent } from '@/types/icons';
@@ -34,6 +34,7 @@ export const Checkbox = forwardRef<HTMLDivElement, CheckboxProps>(
34
34
  },
35
35
  ref
36
36
  ) => {
37
+ const labelId = useId();
37
38
  const handleClick = () => {
38
39
  if (!inactive) onChange?.(!checked);
39
40
  };
@@ -46,7 +47,9 @@ export const Checkbox = forwardRef<HTMLDivElement, CheckboxProps>(
46
47
  ref={ref}
47
48
  role="checkbox"
48
49
  aria-checked={indeterminate ? 'mixed' : checked}
49
- aria-inactive={inactive}
50
+ aria-disabled={inactive || undefined}
51
+ aria-labelledby={labelId}
52
+ data-inactive={inactive || undefined}
50
53
  tabIndex={inactive ? -1 : 0}
51
54
  className={cn(styles.checkbox, inactive && styles.inactive, className)}
52
55
  onClick={handleClick}
@@ -57,7 +60,7 @@ export const Checkbox = forwardRef<HTMLDivElement, CheckboxProps>(
57
60
  {(checked || indeterminate) && <span className={styles.checkmark}>{indeterminate ? '−' : '✓'}</span>}
58
61
  </span>
59
62
  )}
60
- <Text variant="text-body-medium" as="span" color="inherit">
63
+ <Text id={labelId} variant="text-body-medium" as="span" color="inherit">
61
64
  {label}
62
65
  </Text>
63
66
  </div>
@@ -1,4 +1,4 @@
1
- import React, { forwardRef } from 'react';
1
+ import React, { forwardRef, useId, isValidElement, cloneElement } from 'react';
2
2
  import { cn } from '@/utils/cn';
3
3
  import { Text } from '@/components/Text';
4
4
  import styles from './Field.module.css';
@@ -11,12 +11,25 @@ export interface FieldProps {
11
11
  }
12
12
 
13
13
  export const Field = forwardRef<HTMLDivElement, FieldProps>(
14
- ({ label, children, id, className }, ref) => (
15
- <div ref={ref} className={cn(styles.field, className)}>
16
- <Text variant="text-body-small-emphasis" as="label" htmlFor={id}>{label}</Text>
17
- {children}
18
- </div>
19
- )
14
+ ({ label, children, id, className }, ref) => {
15
+ const generatedId = useId();
16
+ const fieldId = id ?? generatedId;
17
+
18
+ let content = children;
19
+ if (isValidElement(children)) {
20
+ const childProps = children.props as { id?: string };
21
+ if (childProps.id === undefined) {
22
+ content = cloneElement(children as React.ReactElement<{ id?: string }>, { id: fieldId });
23
+ }
24
+ }
25
+
26
+ return (
27
+ <div ref={ref} className={cn(styles.field, className)}>
28
+ <Text variant="text-body-small-emphasis" as="label" htmlFor={fieldId}>{label}</Text>
29
+ {content}
30
+ </div>
31
+ );
32
+ }
20
33
  );
21
34
 
22
35
  Field.displayName = 'Field';
@@ -1,3 +1,10 @@
1
+ .container {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: var(--dimension-space-050);
5
+ width: 100%;
6
+ }
7
+
1
8
  .wrapper {
2
9
  width: 100%;
3
10
  height: var(--dimension-size-400);
@@ -13,6 +20,20 @@
13
20
  box-shadow: inset 0 0 0 1.25px var(--color-foreground-bold-brand);
14
21
  }
15
22
 
23
+ .wrapperError {
24
+ box-shadow: inset 0 0 0 1.25px var(--color-border-bold-negative);
25
+ }
26
+
27
+ .wrapperError:focus-within {
28
+ box-shadow: inset 0 0 0 1.25px var(--color-border-bold-negative);
29
+ }
30
+
31
+ .errorText {
32
+ font-size: var(--typography-fontsize-sm);
33
+ line-height: var(--typography-lineheight-sm);
34
+ color: var(--color-foreground-bold-negative);
35
+ }
36
+
16
37
  .row {
17
38
  display: flex;
18
39
  align-items: center;
@@ -1,4 +1,4 @@
1
- import React, { forwardRef } from 'react';
1
+ import React, { forwardRef, useEffect, useId } from 'react';
2
2
  import { cn } from '@/utils/cn';
3
3
  import type { IconComponent } from '@/types/icons';
4
4
  import styles from './Input.module.css';
@@ -20,8 +20,19 @@ export interface InputProps {
20
20
  /** Icon for clear button (search type). */
21
21
  clearIcon?: IconComponent;
22
22
  'aria-label'?: string;
23
+ 'aria-labelledby'?: string;
24
+ 'aria-describedby'?: string;
25
+ /** Marks the input as invalid; sets `aria-invalid` and applies error styling. */
26
+ error?: boolean;
27
+ /** Message rendered below the input when `error` is true; auto-linked via `aria-describedby`. */
28
+ errorMessage?: string;
23
29
  }
24
30
 
31
+ const isDevEnv = (): boolean => {
32
+ const meta = import.meta as { env?: { DEV?: boolean } };
33
+ return Boolean(meta.env?.DEV);
34
+ };
35
+
25
36
  export const Input = forwardRef<HTMLDivElement, InputProps>(
26
37
  (
27
38
  {
@@ -37,37 +48,67 @@ export const Input = forwardRef<HTMLDivElement, InputProps>(
37
48
  suffix,
38
49
  clearIcon: ClearIcon,
39
50
  'aria-label': ariaLabel,
51
+ 'aria-labelledby': ariaLabelledBy,
52
+ 'aria-describedby': ariaDescribedBy,
53
+ error = false,
54
+ errorMessage,
40
55
  },
41
56
  ref
42
57
  ) => {
58
+ const reactId = useId();
59
+ const errorId = `${reactId}-error`;
43
60
  const showClear = type === 'search' && value.length > 0 && !inactive;
61
+ const showErrorMessage = error && Boolean(errorMessage);
62
+
63
+ const describedBy =
64
+ [ariaDescribedBy, showErrorMessage ? errorId : undefined].filter(Boolean).join(' ') ||
65
+ undefined;
66
+
67
+ useEffect(() => {
68
+ if (!isDevEnv()) return;
69
+ if (!id && !ariaLabel && !ariaLabelledBy) {
70
+ console.warn(
71
+ '[@ds-mo/ui] <Input> is missing an accessible name. Provide one of: `id` (paired with a <label htmlFor>), `aria-label`, or `aria-labelledby`.'
72
+ );
73
+ }
74
+ }, [id, ariaLabel, ariaLabelledBy]);
44
75
 
45
76
  const handleClear = () => {
46
77
  onChange({ target: { value: '' } } as React.ChangeEvent<HTMLInputElement>);
47
78
  };
48
79
 
49
80
  return (
50
- <div ref={ref} className={cn(styles.wrapper, className)}>
51
- <div className={styles.row}>
52
- <input
53
- type={type}
54
- id={id}
55
- value={value}
56
- onChange={onChange}
57
- onKeyDown={onKeyDown}
58
- placeholder={placeholder}
59
- className={styles.input}
60
- autoFocus={autoFocus}
61
- disabled={inactive}
62
- aria-label={ariaLabel}
63
- />
64
- {showClear && (
65
- <button type="button" className={styles.clearButton} onClick={handleClear} aria-label="Clear">
66
- {ClearIcon ? <ClearIcon size={16} /> : <span aria-hidden>&times;</span>}
67
- </button>
68
- )}
69
- {suffix && <div className={styles.suffix}>{suffix}</div>}
81
+ <div className={styles.container}>
82
+ <div ref={ref} className={cn(styles.wrapper, error && styles.wrapperError, className)}>
83
+ <div className={styles.row}>
84
+ <input
85
+ type={type}
86
+ id={id}
87
+ value={value}
88
+ onChange={onChange}
89
+ onKeyDown={onKeyDown}
90
+ placeholder={placeholder}
91
+ className={styles.input}
92
+ autoFocus={autoFocus}
93
+ disabled={inactive}
94
+ aria-label={ariaLabel}
95
+ aria-labelledby={ariaLabelledBy}
96
+ aria-describedby={describedBy}
97
+ aria-invalid={error || undefined}
98
+ />
99
+ {showClear && (
100
+ <button type="button" className={styles.clearButton} onClick={handleClear} aria-label="Clear">
101
+ {ClearIcon ? <ClearIcon size={16} /> : <span aria-hidden>&times;</span>}
102
+ </button>
103
+ )}
104
+ {suffix && <div className={styles.suffix}>{suffix}</div>}
105
+ </div>
70
106
  </div>
107
+ {showErrorMessage && (
108
+ <div id={errorId} role="alert" className={styles.errorText}>
109
+ {errorMessage}
110
+ </div>
111
+ )}
71
112
  </div>
72
113
  );
73
114
  }
@@ -3,6 +3,23 @@
3
3
  animation: spin 0.75s linear infinite;
4
4
  }
5
5
 
6
+ .status {
7
+ display: inline-flex;
8
+ align-items: center;
9
+ }
10
+
11
+ .visuallyHidden {
12
+ position: absolute;
13
+ width: 1px;
14
+ height: 1px;
15
+ padding: 0;
16
+ margin: -1px;
17
+ overflow: hidden;
18
+ clip: rect(0, 0, 0, 0);
19
+ white-space: nowrap;
20
+ border: 0;
21
+ }
22
+
6
23
  @keyframes spin {
7
24
  from { transform: rotate(0deg); }
8
25
  to { transform: rotate(360deg); }
@@ -14,6 +14,15 @@ type Story = StoryObj<typeof Loader>;
14
14
 
15
15
  export const Default: Story = {};
16
16
 
17
+ /**
18
+ * Standalone usage with an accessible label. Wraps the spinner in a
19
+ * `role="status"` live region and renders a visually-hidden label so
20
+ * screen readers announce the loading state on mount.
21
+ */
22
+ export const WithLabel: Story = {
23
+ args: { label: 'Loading' },
24
+ };
25
+
17
26
  /** Shows how stroke weight scales naturally with size — same as icon strokes. */
18
27
  export const Sizes: Story = {
19
28
  render: () => (