@duro-app/ui 5.1.0 → 5.2.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 (123) hide show
  1. package/dist/Table-C70zdSkM.js +1419 -0
  2. package/dist/Table-C70zdSkM.js.map +1 -0
  3. package/dist/components/Button/Button.d.ts +11 -2
  4. package/dist/components/Button/Button.d.ts.map +1 -1
  5. package/dist/components/Button/Button.stories.d.ts +1 -0
  6. package/dist/components/Button/Button.stories.d.ts.map +1 -1
  7. package/dist/components/Combobox/Combobox.d.ts +1 -1
  8. package/dist/components/Combobox/Combobox.d.ts.map +1 -1
  9. package/dist/components/Combobox/styles.css.d.ts +0 -64
  10. package/dist/components/Combobox/styles.css.d.ts.map +1 -1
  11. package/dist/components/Dialog/Dialog.d.ts +11 -3
  12. package/dist/components/Dialog/Dialog.d.ts.map +1 -1
  13. package/dist/components/Dialog/Dialog.stories.d.ts +4 -0
  14. package/dist/components/Dialog/Dialog.stories.d.ts.map +1 -1
  15. package/dist/components/Dialog/styles.css.d.ts +1 -0
  16. package/dist/components/Dialog/styles.css.d.ts.map +1 -1
  17. package/dist/components/DragDrop/styles.css.d.ts +10 -2
  18. package/dist/components/DragDrop/styles.css.d.ts.map +1 -1
  19. package/dist/components/Grid/Grid.d.ts +11 -2
  20. package/dist/components/Grid/Grid.d.ts.map +1 -1
  21. package/dist/components/Grid/Grid.stories.d.ts +2 -0
  22. package/dist/components/Grid/Grid.stories.d.ts.map +1 -1
  23. package/dist/components/Input/Input.d.ts +6 -1
  24. package/dist/components/Input/Input.d.ts.map +1 -1
  25. package/dist/components/Input/Input.meta.d.ts.map +1 -1
  26. package/dist/components/Input/Input.stories.d.ts +1 -0
  27. package/dist/components/Input/Input.stories.d.ts.map +1 -1
  28. package/dist/components/Input/styles.css.d.ts +18 -0
  29. package/dist/components/Input/styles.css.d.ts.map +1 -1
  30. package/dist/components/InputGroup/InputGroup.d.ts +6 -1
  31. package/dist/components/InputGroup/InputGroup.d.ts.map +1 -1
  32. package/dist/components/InputGroup/InputGroup.stories.d.ts +1 -0
  33. package/dist/components/InputGroup/InputGroup.stories.d.ts.map +1 -1
  34. package/dist/components/Listbox/Listbox.d.ts +75 -0
  35. package/dist/components/Listbox/Listbox.d.ts.map +1 -0
  36. package/dist/components/Listbox/Listbox.meta.d.ts +3 -0
  37. package/dist/components/Listbox/Listbox.meta.d.ts.map +1 -0
  38. package/dist/components/Listbox/Listbox.stories.d.ts +7 -0
  39. package/dist/components/Listbox/Listbox.stories.d.ts.map +1 -0
  40. package/dist/components/Listbox/styles.css.d.ts +75 -0
  41. package/dist/components/Listbox/styles.css.d.ts.map +1 -0
  42. package/dist/components/Menu/Menu.d.ts +18 -5
  43. package/dist/components/Menu/Menu.d.ts.map +1 -1
  44. package/dist/components/Menu/Menu.meta.d.ts.map +1 -1
  45. package/dist/components/Menu/Menu.stories.d.ts +7 -0
  46. package/dist/components/Menu/Menu.stories.d.ts.map +1 -1
  47. package/dist/components/Menu/MenuContext.d.ts +3 -0
  48. package/dist/components/Menu/MenuContext.d.ts.map +1 -1
  49. package/dist/components/Menu/styles.css.d.ts +24 -15
  50. package/dist/components/Menu/styles.css.d.ts.map +1 -1
  51. package/dist/components/Menu/useMenuRoot.d.ts +14 -1
  52. package/dist/components/Menu/useMenuRoot.d.ts.map +1 -1
  53. package/dist/components/TextLink/TextLink.d.ts +24 -0
  54. package/dist/components/TextLink/TextLink.d.ts.map +1 -0
  55. package/dist/components/TextLink/TextLink.meta.d.ts +3 -0
  56. package/dist/components/TextLink/TextLink.meta.d.ts.map +1 -0
  57. package/dist/components/TextLink/TextLink.stories.d.ts +9 -0
  58. package/dist/components/TextLink/TextLink.stories.d.ts.map +1 -0
  59. package/dist/components/TextLink/styles.css.d.ts +28 -0
  60. package/dist/components/TextLink/styles.css.d.ts.map +1 -0
  61. package/dist/components/ThemeProvider/ThemeProvider.stories.d.ts +1 -0
  62. package/dist/components/ThemeProvider/ThemeProvider.stories.d.ts.map +1 -1
  63. package/dist/components/VisuallyHidden/VisuallyHidden.d.ts +14 -0
  64. package/dist/components/VisuallyHidden/VisuallyHidden.d.ts.map +1 -0
  65. package/dist/components/VisuallyHidden/VisuallyHidden.meta.d.ts +3 -0
  66. package/dist/components/VisuallyHidden/VisuallyHidden.meta.d.ts.map +1 -0
  67. package/dist/components/VisuallyHidden/VisuallyHidden.stories.d.ts +7 -0
  68. package/dist/components/VisuallyHidden/VisuallyHidden.stories.d.ts.map +1 -0
  69. package/dist/docs/FlexGrow.stories.d.ts +7 -0
  70. package/dist/docs/FlexGrow.stories.d.ts.map +1 -0
  71. package/dist/index.css +1 -1
  72. package/dist/index.d.ts +5 -0
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +2943 -2778
  75. package/dist/index.js.map +1 -1
  76. package/dist/index.native.d.ts +1 -0
  77. package/dist/index.native.d.ts.map +1 -1
  78. package/dist/styles/visually-hidden.css.d.ts +6 -0
  79. package/dist/styles/visually-hidden.css.d.ts.map +1 -1
  80. package/dist/table.js +1 -1
  81. package/package.json +2 -2
  82. package/src/components/Button/Button.stories.tsx +41 -0
  83. package/src/components/Button/Button.tsx +16 -1
  84. package/src/components/Combobox/Combobox.tsx +25 -79
  85. package/src/components/Combobox/styles.css.ts +0 -74
  86. package/src/components/Dialog/Dialog.meta.ts +1 -1
  87. package/src/components/Dialog/Dialog.stories.tsx +109 -3
  88. package/src/components/Dialog/Dialog.tsx +63 -9
  89. package/src/components/Dialog/styles.css.ts +2 -0
  90. package/src/components/DragDrop/styles.css.ts +16 -3
  91. package/src/components/Grid/Grid.meta.ts +1 -1
  92. package/src/components/Grid/Grid.stories.tsx +53 -1
  93. package/src/components/Grid/Grid.tsx +23 -11
  94. package/src/components/Input/Input.meta.ts +10 -3
  95. package/src/components/Input/Input.stories.tsx +52 -2
  96. package/src/components/Input/Input.tsx +12 -3
  97. package/src/components/Input/styles.css.ts +29 -0
  98. package/src/components/InputGroup/InputGroup.stories.tsx +20 -0
  99. package/src/components/InputGroup/InputGroup.tsx +20 -2
  100. package/src/components/Listbox/Listbox.meta.ts +52 -0
  101. package/src/components/Listbox/Listbox.stories.tsx +170 -0
  102. package/src/components/Listbox/Listbox.tsx +278 -0
  103. package/src/components/Listbox/styles.css.ts +89 -0
  104. package/src/components/Menu/Menu.meta.ts +2 -1
  105. package/src/components/Menu/Menu.stories.tsx +289 -8
  106. package/src/components/Menu/Menu.tsx +100 -29
  107. package/src/components/Menu/MenuContext.ts +3 -0
  108. package/src/components/Menu/styles.css.ts +31 -15
  109. package/src/components/Menu/useMenuRoot.ts +105 -48
  110. package/src/components/TextLink/TextLink.meta.ts +33 -0
  111. package/src/components/TextLink/TextLink.stories.tsx +63 -0
  112. package/src/components/TextLink/TextLink.tsx +46 -0
  113. package/src/components/TextLink/styles.css.ts +58 -0
  114. package/src/components/ThemeProvider/ThemeProvider.stories.tsx +50 -0
  115. package/src/components/VisuallyHidden/VisuallyHidden.meta.ts +19 -0
  116. package/src/components/VisuallyHidden/VisuallyHidden.stories.tsx +30 -0
  117. package/src/components/VisuallyHidden/VisuallyHidden.tsx +22 -0
  118. package/src/docs/FlexGrow.stories.tsx +83 -0
  119. package/src/index.native.ts +1 -0
  120. package/src/index.ts +5 -0
  121. package/src/styles/visually-hidden.css.ts +8 -0
  122. package/dist/Table-BkrgH0jb.js +0 -1199
  123. package/dist/Table-BkrgH0jb.js.map +0 -1
@@ -64,6 +64,8 @@ export const styles = css.create({
64
64
  flexDirection: 'column',
65
65
  overflow: 'hidden',
66
66
  pointerEvents: 'auto',
67
+ // Focused only as the fallback when it holds nothing focusable.
68
+ outlineStyle: 'none',
67
69
  borderWidth: borders.hairline,
68
70
  borderStyle: 'solid',
69
71
  borderColor: colors.border,
@@ -2,6 +2,8 @@ import {css} from 'react-strict-dom'
2
2
  import {colors} from '@duro-app/tokens/tokens/colors.css'
3
3
  import {radii} from '@duro-app/tokens/tokens/spacing.css'
4
4
  import {duration, easing} from '@duro-app/tokens/tokens/motion.css'
5
+ import {shadows} from '@duro-app/tokens/tokens/shadows.css'
6
+ import {borders} from '@duro-app/tokens/tokens/borders.css'
5
7
 
6
8
  export const styles = css.create({
7
9
  // The item is the drag handle: no browser panning starts on it, so a touch
@@ -30,13 +32,24 @@ export const styles = css.create({
30
32
  transitionTimingFunction: easing.standard,
31
33
  },
32
34
  // Every zone shows it can receive while something is in the air; the one
33
- // under the pointer lights up.
35
+ // under the pointer lights up. Drop-target rings, not focus: keyboard focus
36
+ // stays on outlines, which survive forced-colors mode.
37
+ // Forced-colors mode drops box-shadows and fills; the transparent outline
38
+ // is what it paints instead (in a system colour), so the rings survive.
34
39
  zoneReady: {
35
- boxShadow: `inset 0 0 0 1px ${colors.border}`,
40
+ boxShadow: shadows.dropReady,
41
+ outlineStyle: 'solid',
42
+ outlineWidth: borders.hairline,
43
+ outlineColor: 'transparent',
44
+ outlineOffset: `calc(-1 * ${borders.hairline})`,
36
45
  },
37
46
  zoneOver: {
38
- boxShadow: `inset 0 0 0 2px ${colors.accent}`,
47
+ boxShadow: shadows.dropOver,
39
48
  backgroundColor: colors.infoBg,
49
+ outlineStyle: 'solid',
50
+ outlineWidth: borders.strong,
51
+ outlineColor: 'transparent',
52
+ outlineOffset: `calc(-1 * ${borders.strong})`,
40
53
  },
41
54
  ghost: {
42
55
  position: 'fixed',
@@ -2,7 +2,7 @@ import type {ComponentMeta} from '../component-meta'
2
2
 
3
3
  export const meta: ComponentMeta = {
4
4
  description:
5
- 'Grid layout. Columns are a count (1-6), a list of weights ([1, 2] for one-third / two-thirds), responsive auto-fit via minColumnWidth, or a named split layout (list/detail, nav/content) that collapses to one column on the width of its own container, so it is safe to nest and to place beside a DetailPanel. Weights rather than CSS template strings, so the same props render as CSS grid on web and as a wrapping flex row on native.',
5
+ "Grid layout. Columns are a count (1-6), a list of weights ([1, 2] for one-third / two-thirds), responsive auto-fit via minColumnWidth, or a named split layout (list/detail, nav/content) that collapses to one column on the width of its own container, so it is safe to nest and to place beside a DetailPanel. Weights rather than CSS template strings, so the same props render as CSS grid on web and as a wrapping flex row on native. For a fixed track beside fractions (content + a 320px aside), tracks takes a token track list — tracks={['1fr', 'asideW']} — web only, equal columns on native.",
6
6
  whenToUse: [
7
7
  'Card grids, dashboard layouts, multi-column forms',
8
8
  'Responsive layouts that should auto-adjust column count',
@@ -5,7 +5,8 @@ import {Grid} from './Grid'
5
5
  import {Stack} from '../Stack/Stack'
6
6
  import {colors} from '@duro-app/tokens/tokens/colors.css'
7
7
  import {spacing, radii} from '@duro-app/tokens/tokens/spacing.css'
8
- import {SPACING_KEYS} from '@duro-app/tokens/keys'
8
+ import {SIZES_PX, SPACING_KEYS} from '@duro-app/tokens/keys'
9
+ import {sizes} from '@duro-app/tokens/tokens/sizes.css'
9
10
  import {useContainerQuery} from '../../hooks/useContainerQuery'
10
11
  import {typography} from '@duro-app/tokens/tokens/typography.css'
11
12
  import {borders} from '@duro-app/tokens/tokens/borders.css'
@@ -209,3 +210,54 @@ export const WithContainerQuery: Story = {
209
210
  )
210
211
  },
211
212
  }
213
+
214
+ // A track list with a fixed aside: the content column takes the rest, the
215
+ // aside is sizes.asideW.
216
+ export const TracksWithAside: Story = {
217
+ render: () => (
218
+ <html.div style={trackStyles.frame}>
219
+ <Grid tracks={['1fr', 'asideW']} gap="md">
220
+ <html.div role="region" aria-label="Content" style={trackStyles.cell}>
221
+ Content
222
+ </html.div>
223
+ <html.div role="region" aria-label="Aside" style={trackStyles.cell}>
224
+ Aside
225
+ </html.div>
226
+ </Grid>
227
+ </html.div>
228
+ ),
229
+ play: async ({canvas}) => {
230
+ const aside = canvas.getByRole('region', {name: 'Aside'})
231
+ await expect(aside.getBoundingClientRect().width).toBe(SIZES_PX.asideW)
232
+ const content = canvas.getByRole('region', {name: 'Content'})
233
+ await expect(content.getBoundingClientRect().width).toBeGreaterThan(SIZES_PX.asideW)
234
+ },
235
+ }
236
+
237
+ export const TracksWithMinmax: Story = {
238
+ render: () => (
239
+ <html.div style={trackStyles.frame}>
240
+ <Grid tracks={['minmax(gridColXs, 1fr)', 'minmax(gridColXs, 1fr)', 'minmax(gridColXs, 1fr)']}>
241
+ <html.div style={trackStyles.cell}>One</html.div>
242
+ <html.div style={trackStyles.cell}>Two</html.div>
243
+ <html.div role="region" aria-label="Three" style={trackStyles.cell}>
244
+ Three
245
+ </html.div>
246
+ </Grid>
247
+ </html.div>
248
+ ),
249
+ play: async ({canvas}) => {
250
+ const third = canvas.getByRole('region', {name: 'Three'})
251
+ await expect(third.getBoundingClientRect().width).toBeGreaterThanOrEqual(SIZES_PX.gridColXs)
252
+ },
253
+ }
254
+
255
+ const trackStyles = css.create({
256
+ frame: {
257
+ width: sizes.pageMd,
258
+ },
259
+ cell: {
260
+ padding: spacing.sm,
261
+ backgroundColor: colors.bgCard,
262
+ },
263
+ })
@@ -4,7 +4,7 @@ import {styles} from './styles.css'
4
4
  import {isNative} from '../../platform'
5
5
  import {cellBasis, cellPosition, columnWeights, gridTemplate, type GridColumns} from './columns'
6
6
  import type {SpacingToken} from '@duro-app/tokens/keys'
7
- import {resolveLength, type Length} from '../../shared/length'
7
+ import {resolveLength, resolveTrack, type GridTrack, type Length} from '../../shared/length'
8
8
 
9
9
  export type GridLayout = 'split' | 'split-wide'
10
10
 
@@ -28,6 +28,15 @@ interface GridProps {
28
28
  * rather than when the window does. Wins over `columns` / `minColumnWidth`.
29
29
  */
30
30
  layout?: GridLayout
31
+ /**
32
+ * An explicit track list, for columns that are not all fractions: a size
33
+ * token for a fixed track (`['1fr', 'asideW']`), or `minmax()` /
34
+ * `fit-content()` of tokens and fractions (`'minmax(gridColXs, 1fr)'`).
35
+ * A px is a type error. Web only — on native it falls back to equal
36
+ * columns, one per track. Wins over `columns` / `minColumnWidth`; `layout`
37
+ * wins over it.
38
+ */
39
+ tracks?: readonly GridTrack[]
31
40
  children: ReactNode
32
41
  }
33
42
 
@@ -87,13 +96,14 @@ const cellGapTopMap = {
87
96
  xxxl: styles.cellGapTopXxxl,
88
97
  } as const satisfies Record<SpacingToken, unknown>
89
98
 
90
- export function Grid({gap = 'md', columns, minColumnWidth, layout, children}: GridProps) {
99
+ export function Grid({gap = 'md', columns, minColumnWidth, layout, tracks, children}: GridProps) {
100
+ const hasTracks = tracks !== undefined && tracks.length > 0
91
101
  if (isNative) {
92
102
  return (
93
103
  <NativeGrid
94
104
  gap={gap}
95
- columns={layout ? layoutWeights[layout] : columns}
96
- minColumnWidth={layout ? undefined : minColumnWidth}
105
+ columns={layout ? layoutWeights[layout] : hasTracks ? tracks.map(() => 1) : columns}
106
+ minColumnWidth={layout || hasTracks ? undefined : minColumnWidth}
97
107
  >
98
108
  {children}
99
109
  </NativeGrid>
@@ -102,13 +112,15 @@ export function Grid({gap = 'md', columns, minColumnWidth, layout, children}: Gr
102
112
 
103
113
  const columnStyle = layout
104
114
  ? layoutMap[layout]
105
- : minColumnWidth
106
- ? styles.autoFit(resolveLength(minColumnWidth))
107
- : typeof columns === 'number'
108
- ? columnsMap[columns]
109
- : columns
110
- ? styles.template(gridTemplate(columnWeights(columns) ?? [1]))
111
- : undefined
115
+ : hasTracks
116
+ ? styles.template(tracks.map((track) => String(resolveTrack(track))).join(' '))
117
+ : minColumnWidth
118
+ ? styles.autoFit(resolveLength(minColumnWidth))
119
+ : typeof columns === 'number'
120
+ ? columnsMap[columns]
121
+ : columns
122
+ ? styles.template(gridTemplate(columnWeights(columns) ?? [1]))
123
+ : undefined
112
124
 
113
125
  const grid = <html.div style={[styles.base, gapMap[gap], columnStyle]}>{children}</html.div>
114
126
  // A named layout answers its container query from a wrapper: an element
@@ -2,9 +2,16 @@ import type {ComponentMeta} from '../component-meta'
2
2
 
3
3
  export const meta: ComponentMeta = {
4
4
  description:
5
- 'Text input with automatic Field/Form integration. Variant auto-switches to error when inside an invalid Field.',
6
- whenToUse: ['Single-line text entry (text, email, password, url, tel, number, search)'],
7
- whenNotToUse: ['Multi-line text — use Textarea', 'Picking from predefined options — use Select'],
5
+ 'Text input with automatic Field/Form integration. Variant auto-switches to error when inside an invalid Field. variant="ghost" reads as text until hovered (hairline border) or focused (accent border and ring): only for inline edit where a visible Field.Label names it; it shows the error state when the Field is invalid.',
6
+ whenToUse: [
7
+ 'Single-line text entry (text, email, password, url, tel, number, search)',
8
+ 'Inline edit of a labelled value in place (a ticket title) — variant="ghost"',
9
+ ],
10
+ whenNotToUse: [
11
+ 'Multi-line text — use Textarea',
12
+ 'Picking from predefined options — use Select',
13
+ 'A ghost field without a visible label — it reads as plain text, so the label is what says it is editable',
14
+ ],
8
15
  relatedTo: [
9
16
  {component: 'Field', kind: 'composition', relationship: 'Wrap in Field.Root for label + error'},
10
17
  {
@@ -1,7 +1,9 @@
1
1
  import type {Meta, StoryObj} from '@storybook/react'
2
- import {expect, fn} from 'storybook/test'
2
+ import {expect, fn, waitFor} from 'storybook/test'
3
3
  import {css, html} from 'react-strict-dom'
4
4
  import {Input} from './Input'
5
+ import {Field} from '../Field/Field'
6
+ import {Stack} from '../Stack/Stack'
5
7
  import {spacing} from '@duro-app/tokens/tokens/spacing.css'
6
8
  import {sizes} from '@duro-app/tokens/tokens/sizes.css'
7
9
 
@@ -14,7 +16,7 @@ const meta: Meta<typeof Input> = {
14
16
  argTypes: {
15
17
  variant: {
16
18
  control: 'select',
17
- options: ['default', 'error'],
19
+ options: ['default', 'error', 'ghost'],
18
20
  },
19
21
  type: {
20
22
  control: 'select',
@@ -105,3 +107,51 @@ export const AllVariants: Story = {
105
107
  await expect(disabled).toBeDisabled()
106
108
  },
107
109
  }
110
+
111
+ // --- Ghost (5.2, direction OutlineOnHover) ---
112
+
113
+ export const GhostInlineEdit: Story = {
114
+ render: () => (
115
+ <html.div style={layoutStyles.narrow}>
116
+ <Stack gap="md">
117
+ <Field.Root>
118
+ <Field.Label>Title</Field.Label>
119
+ <Input variant="ghost" defaultValue="Printer on floor 3 is jammed" />
120
+ </Field.Root>
121
+ <Field.Root invalid>
122
+ <Field.Label>Assignee</Field.Label>
123
+ <Input variant="ghost" defaultValue="" />
124
+ <Field.Error>Assignee is required</Field.Error>
125
+ </Field.Root>
126
+ <Field.Root disabled>
127
+ <Field.Label>Due</Field.Label>
128
+ <Input variant="ghost" defaultValue="Friday" />
129
+ </Field.Root>
130
+ </Stack>
131
+ </html.div>
132
+ ),
133
+ play: async ({canvas, userEvent}) => {
134
+ const title = canvas.getByRole('textbox', {name: 'Title'})
135
+ // Reads as text at rest: no border colour, no fill.
136
+ await expect(getComputedStyle(title).borderTopColor).toBe('rgba(0, 0, 0, 0)')
137
+ await userEvent.click(title)
138
+ await userEvent.keyboard('{Shift>}{Tab}{/Shift}{Tab}')
139
+ await expect(title).toHaveFocus()
140
+ await expect(getComputedStyle(title).outlineStyle).toBe('solid')
141
+ // The border colour transitions in (duration.fast).
142
+ await waitFor(() => expect(getComputedStyle(title).borderTopColor).not.toBe('rgba(0, 0, 0, 0)'))
143
+
144
+ const assignee = canvas.getByRole('textbox', {name: 'Assignee'})
145
+ await expect(assignee).toHaveAttribute('aria-invalid', 'true')
146
+ await expect(getComputedStyle(assignee).backgroundColor).not.toBe('rgba(0, 0, 0, 0)')
147
+
148
+ await expect(canvas.getByRole('textbox', {name: 'Due'})).toBeDisabled()
149
+ },
150
+ }
151
+
152
+ const layoutStyles = css.create({
153
+ narrow: {
154
+ maxWidth: sizes.panelSm,
155
+ padding: spacing.md,
156
+ },
157
+ })
@@ -6,9 +6,14 @@ import {styles} from './styles.css'
6
6
  type StrictInputProps = React.ComponentProps<typeof html.input>
7
7
  export type InputType = NonNullable<StrictInputProps['type']>
8
8
 
9
- export type InputVariant = 'default' | 'error'
9
+ export type InputVariant = 'default' | 'error' | 'ghost'
10
10
 
11
11
  interface InputProps {
12
+ /**
13
+ * `ghost` reads as text until hovered or focused — only for inline edit
14
+ * where a visible label names the field (Field.Label). It shows the error
15
+ * state when the Field is invalid.
16
+ */
12
17
  variant?: InputVariant
13
18
  /** Orthogonal to variant — `mono` keeps the error border but uses the
14
19
  * monospace family (slugs, identifiers, hashes). */
@@ -100,7 +105,9 @@ export function Input({
100
105
  const effectiveOnBlur = onBlur ?? fieldCtx?.onBlur
101
106
  const effectiveRef = ref ?? fieldCtx?.ref
102
107
  const effectiveDisabled = disabled ?? ctx?.disabled
103
- const effectiveVariant = ctx?.invalid ? 'error' : variant
108
+ const invalid = Boolean(ctx?.invalid) || variant === 'error'
109
+ const ghost = variant === 'ghost'
110
+ const effectiveVariant = ghost ? 'ghost' : ctx?.invalid ? 'error' : variant
104
111
  // Field context owns describedby (description + error); fall back to the
105
112
  // explicit prop only when standalone.
106
113
  const describedBy = ctx
@@ -134,7 +141,7 @@ export function Input({
134
141
  defaultValue={defaultValue}
135
142
  disabled={effectiveDisabled}
136
143
  aria-describedby={describedBy || undefined}
137
- aria-invalid={ctx?.invalid || variant === 'error' || undefined}
144
+ aria-invalid={invalid || undefined}
138
145
  onChange={effectiveOnChange as StrictInputProps['onChange']}
139
146
  onBlur={effectiveOnBlur as StrictInputProps['onBlur']}
140
147
  onFocus={onFocus as StrictInputProps['onFocus']}
@@ -144,6 +151,8 @@ export function Input({
144
151
  style={[
145
152
  styles.base,
146
153
  styles[effectiveVariant],
154
+ ghost && invalid && styles.ghostError,
155
+ ghost && effectiveDisabled && styles.ghostDisabled,
147
156
  font === 'mono' && styles.mono,
148
157
  groupCtx?.inGroup && styles.inGroup,
149
158
  ]}
@@ -53,6 +53,35 @@ export const styles = css.create({
53
53
  ':focus': colors.error,
54
54
  },
55
55
  },
56
+ // Direction OutlineOnHover (docs/mockups/input-ghost/OutlineOnHover.dc.html):
57
+ // reads as text at rest; hover draws the field's hairline border, focus
58
+ // turns it accent and adds the ring. For inline edit with a visible label.
59
+ ghost: {
60
+ backgroundColor: 'transparent',
61
+ paddingTop: spacing.xs,
62
+ paddingBottom: spacing.xs,
63
+ paddingLeft: spacing.sm,
64
+ paddingRight: spacing.sm,
65
+ // The text lines up with its label above.
66
+ marginLeft: `calc(-1 * ${spacing.sm})`,
67
+ borderColor: {
68
+ default: 'transparent',
69
+ ':hover': colors.border,
70
+ ':focus': colors.accent,
71
+ },
72
+ },
73
+ ghostError: {
74
+ backgroundColor: colors.errorBg,
75
+ borderColor: {
76
+ default: colors.errorBorder,
77
+ ':focus': colors.error,
78
+ },
79
+ },
80
+ ghostDisabled: {
81
+ color: colors.textMuted,
82
+ cursor: 'not-allowed',
83
+ borderColor: 'transparent',
84
+ },
56
85
  inGroup: {
57
86
  borderWidth: 0,
58
87
  borderRadius: 0,
@@ -140,3 +140,23 @@ export const AllVariants: Story = {
140
140
  </html.div>
141
141
  ),
142
142
  }
143
+
144
+ const onSearch = fn()
145
+
146
+ // An icon-only clickable addon is a button: aria-label gives it its name.
147
+ export const IconAddonNamed: Story = {
148
+ render: () => (
149
+ <html.div style={layoutStyles.container}>
150
+ <InputGroup.Root>
151
+ <Input placeholder="Search tickets" aria-label="Search tickets" />
152
+ <InputGroup.Addon onClick={onSearch} aria-label="Run search">
153
+ <Icon name="search" size="sm" />
154
+ </InputGroup.Addon>
155
+ </InputGroup.Root>
156
+ </html.div>
157
+ ),
158
+ play: async ({canvas, userEvent}) => {
159
+ await userEvent.click(canvas.getByRole('button', {name: 'Run search'}))
160
+ await expect(onSearch).toHaveBeenCalled()
161
+ },
162
+ }
@@ -33,10 +33,22 @@ interface AddonProps {
33
33
  /** Optional minimum width to prevent layout shift (e.g. Copy → Copied!): a
34
34
  * size token key or a relative length. */
35
35
  minWidth?: Length
36
+ /**
37
+ * Accessible name of a clickable addon (it renders a button). Required when
38
+ * its content is an icon (copy, reveal): without it the button has no name.
39
+ */
40
+ 'aria-label'?: string
36
41
  children: ReactNode
37
42
  }
38
43
 
39
- function Addon({position = 'end', onClick, disabled, minWidth, children}: AddonProps) {
44
+ function Addon({
45
+ position = 'end',
46
+ onClick,
47
+ disabled,
48
+ minWidth,
49
+ 'aria-label': ariaLabel,
50
+ children,
51
+ }: AddonProps) {
40
52
  const positionStyle = position === 'start' ? styles.addonStart : styles.addonEnd
41
53
  const style = [
42
54
  styles.addon,
@@ -49,7 +61,13 @@ function Addon({position = 'end', onClick, disabled, minWidth, children}: AddonP
49
61
 
50
62
  if (onClick) {
51
63
  return (
52
- <html.button type="button" onClick={onClick} disabled={disabled} style={style}>
64
+ <html.button
65
+ type="button"
66
+ onClick={onClick}
67
+ disabled={disabled}
68
+ aria-label={ariaLabel}
69
+ style={style}
70
+ >
53
71
  {children}
54
72
  </html.button>
55
73
  )
@@ -0,0 +1,52 @@
1
+ import type {ComponentMeta} from '../component-meta'
2
+
3
+ export const meta: ComponentMeta = {
4
+ description:
5
+ 'Popup list of options for an input that keeps focus — an editor typeahead (mentions, slash commands) or a custom combobox. The anchor owns focus and the keyboard: it sets the controlled highlightedId and spreads Listbox.getAnchorProps() for aria-controls / aria-expanded / aria-activedescendant. A press on an option never takes focus from the anchor. Portalled and placed against anchor() (an input rect or a caret rect), capped at a size-token maxHeight (default listMaxH).',
6
+ whenToUse: [
7
+ 'Typeahead inside a rich-text editor, where focus must stay in the editor',
8
+ 'A custom combobox whose input is not Combobox.Input',
9
+ ],
10
+ whenNotToUse: [
11
+ 'Picking a value from a filterable list in a form — use Combobox (built on Listbox)',
12
+ 'A short fixed list — use Select',
13
+ 'Actions — use Menu',
14
+ ],
15
+ anatomy: {
16
+ required: ['Root', 'Option'],
17
+ optional: ['Empty'],
18
+ },
19
+ relatedTo: [
20
+ {
21
+ component: 'Combobox',
22
+ kind: 'contrast',
23
+ relationship:
24
+ 'Combobox is a ready-made input + Listbox; Listbox alone serves an anchor you own (an editor)',
25
+ },
26
+ {
27
+ component: 'Menu',
28
+ kind: 'contrast',
29
+ relationship:
30
+ 'Menu takes focus and triggers actions; Listbox leaves focus on its anchor and offers values',
31
+ },
32
+ ],
33
+ example: `const id = useId()
34
+ const [highlightedId, setHighlightedId] = useState<string | null>(null)
35
+ const optionId = (value: string) => \`\${id}-\${value}\`
36
+ // On the editor root: Object.entries(Listbox.getAnchorProps({id, open, highlightedId}))
37
+ <Listbox.Root
38
+ id={id}
39
+ open={open}
40
+ anchor={() => caretRect()}
41
+ highlightedId={highlightedId}
42
+ onHighlight={setHighlightedId}
43
+ onSelect={(value) => insertMention(value)}
44
+ getOptionId={optionId}
45
+ aria-label="Mentions"
46
+ >
47
+ {people.map((p) => (
48
+ <Listbox.Option key={p.id} value={p.id}>{p.name}</Listbox.Option>
49
+ ))}
50
+ {people.length === 0 && <Listbox.Empty>No match</Listbox.Empty>}
51
+ </Listbox.Root>`,
52
+ }
@@ -0,0 +1,170 @@
1
+ import type {Meta, StoryObj} from '@storybook/react'
2
+ import {expect, fn, waitFor, within} from 'storybook/test'
3
+ import {useCallback, useEffect, useId, useRef, useState} from 'react'
4
+ import {css, html} from 'react-strict-dom'
5
+ import {colors} from '@duro-app/tokens/tokens/colors.css'
6
+ import {borders} from '@duro-app/tokens/tokens/borders.css'
7
+ import {sizes} from '@duro-app/tokens/tokens/sizes.css'
8
+ import {spacing, radii} from '@duro-app/tokens/tokens/spacing.css'
9
+ import {Listbox} from './Listbox'
10
+
11
+ const meta: Meta = {
12
+ title: 'Components/Listbox',
13
+ }
14
+
15
+ export default meta
16
+ type Story = StoryObj
17
+
18
+ const page = () => within(document.body)
19
+
20
+ const styles = css.create({
21
+ editor: {
22
+ minHeight: sizes.editorMinH,
23
+ padding: spacing.sm,
24
+ borderWidth: borders.hairline,
25
+ borderStyle: 'solid',
26
+ borderColor: colors.border,
27
+ borderRadius: radii.sm,
28
+ color: colors.text,
29
+ },
30
+ })
31
+
32
+ const PEOPLE = ['Ada', 'Grace', 'Linus', 'Margaret']
33
+ const onPick = fn()
34
+
35
+ // A contenteditable typeahead: '@' opens the list, arrows move the highlight,
36
+ // Enter picks. The editor keeps focus throughout.
37
+ function MentionEditor() {
38
+ const id = useId()
39
+ const editorRef = useRef<HTMLDivElement | null>(null)
40
+ const [open, setOpen] = useState(false)
41
+ const [highlighted, setHighlighted] = useState(0)
42
+ const optionId = useCallback((value: string) => `${id}-${value}`, [id])
43
+ const highlightedId = open ? optionId(PEOPLE[highlighted]!) : null
44
+
45
+ const pick = useCallback((value: string) => {
46
+ onPick(value)
47
+ editorRef.current?.append(`${value} `)
48
+ setOpen(false)
49
+ }, [])
50
+
51
+ // The anchor's ARIA, set on the contenteditable root like an editor would.
52
+ useEffect(() => {
53
+ const editor = editorRef.current
54
+ if (!editor) return
55
+ for (const [name, value] of Object.entries(Listbox.getAnchorProps({id, open, highlightedId}))) {
56
+ if (value === undefined) editor.removeAttribute(name)
57
+ else editor.setAttribute(name, String(value))
58
+ }
59
+ }, [id, open, highlightedId])
60
+
61
+ useEffect(() => {
62
+ const editor = editorRef.current
63
+ if (!editor) return
64
+ editor.setAttribute('contenteditable', 'true')
65
+ const onKeyDown = (e: KeyboardEvent) => {
66
+ if (e.key === '@') {
67
+ setOpen(true)
68
+ setHighlighted(0)
69
+ return
70
+ }
71
+ if (!openRef.current) return
72
+ if (e.key === 'ArrowDown') {
73
+ e.preventDefault()
74
+ setHighlighted((i) => (i + 1) % PEOPLE.length)
75
+ } else if (e.key === 'ArrowUp') {
76
+ e.preventDefault()
77
+ setHighlighted((i) => (i - 1 + PEOPLE.length) % PEOPLE.length)
78
+ } else if (e.key === 'Enter') {
79
+ e.preventDefault()
80
+ pick(PEOPLE[highlightedRef.current]!)
81
+ } else if (e.key === 'Escape') {
82
+ setOpen(false)
83
+ }
84
+ }
85
+ editor.addEventListener('keydown', onKeyDown)
86
+ return () => editor.removeEventListener('keydown', onKeyDown)
87
+ }, [pick])
88
+
89
+ const openRef = useRef(open)
90
+ openRef.current = open
91
+ const highlightedRef = useRef(highlighted)
92
+ highlightedRef.current = highlighted
93
+
94
+ return (
95
+ <>
96
+ <html.div
97
+ ref={editorRef}
98
+ role="textbox"
99
+ aria-label="Message"
100
+ aria-multiline={true}
101
+ style={styles.editor}
102
+ />
103
+ <Listbox.Root
104
+ id={id}
105
+ open={open}
106
+ anchor={() => editorRef.current?.getBoundingClientRect()}
107
+ highlightedId={highlightedId}
108
+ onHighlight={(next) => {
109
+ const index = PEOPLE.findIndex((p) => optionId(p) === next)
110
+ if (index >= 0) setHighlighted(index)
111
+ }}
112
+ onSelect={pick}
113
+ getOptionId={optionId}
114
+ aria-label="People"
115
+ >
116
+ {PEOPLE.map((person) => (
117
+ <Listbox.Option key={person} value={person}>
118
+ {person}
119
+ </Listbox.Option>
120
+ ))}
121
+ </Listbox.Root>
122
+ </>
123
+ )
124
+ }
125
+
126
+ export const EditorTypeahead: Story = {
127
+ beforeEach: () => {
128
+ onPick.mockClear()
129
+ },
130
+ render: () => <MentionEditor />,
131
+ play: async ({canvas, userEvent}) => {
132
+ const editor = canvas.getByRole('textbox', {name: 'Message'})
133
+ await userEvent.click(editor)
134
+ await userEvent.keyboard('@')
135
+ const list = await page().findByRole('listbox', {name: 'People'})
136
+ await expect(editor).toHaveFocus()
137
+ await expect(editor).toHaveAttribute('aria-expanded', 'true')
138
+ await expect(editor).toHaveAttribute('aria-controls', list.id)
139
+
140
+ await userEvent.keyboard('{ArrowDown}')
141
+ const grace = page().getByRole('option', {name: 'Grace'})
142
+ await expect(editor).toHaveAttribute('aria-activedescendant', grace.id)
143
+ await expect(editor).toHaveFocus()
144
+
145
+ // A press on an option picks it and leaves focus in the editor.
146
+ await userEvent.click(page().getByRole('option', {name: 'Linus'}))
147
+ await expect(onPick).toHaveBeenCalledWith('Linus')
148
+ await waitFor(() => expect(page().queryByRole('listbox')).not.toBeInTheDocument())
149
+ await expect(editor).toHaveFocus()
150
+ await expect(editor).toHaveAttribute('aria-expanded', 'false')
151
+ await expect(editor).not.toHaveAttribute('aria-activedescendant')
152
+ },
153
+ }
154
+
155
+ export const EmptyList: Story = {
156
+ render: () => (
157
+ <Listbox.Root
158
+ id="empty-list"
159
+ open
160
+ anchor={() => new DOMRect(16, 16, 200, 24)}
161
+ highlightedId={null}
162
+ aria-label="Results"
163
+ >
164
+ <Listbox.Empty>No match</Listbox.Empty>
165
+ </Listbox.Root>
166
+ ),
167
+ play: async () => {
168
+ await expect(await page().findByText('No match')).toBeVisible()
169
+ },
170
+ }