@aleph-alpha/ui-library 6.2.0 → 6.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 (59) hide show
  1. package/dist/system/components/UiButtonGroup/index.d.ts +1 -0
  2. package/dist/system/components/UiCodeBlock/types.d.ts +11 -0
  3. package/dist/system/components/UiInputGroup/UiInputGroup.vue.d.ts +20 -0
  4. package/dist/system/components/UiInputGroup/UiInputGroupAddon.vue.d.ts +20 -0
  5. package/dist/system/components/UiInputGroup/UiInputGroupButton.vue.d.ts +17 -0
  6. package/dist/system/components/UiInputGroup/UiInputGroupInput.vue.d.ts +11 -0
  7. package/dist/system/components/UiInputGroup/UiInputGroupTextarea.vue.d.ts +11 -0
  8. package/dist/system/components/UiInputGroup/index.d.ts +7 -0
  9. package/dist/system/components/UiInputGroup/types.d.ts +151 -0
  10. package/dist/system/components/UiLabel/UiLabel.vue.d.ts +3 -1
  11. package/dist/system/components/UiLabel/types.d.ts +7 -0
  12. package/dist/system/components/core/input-group/InputGroup.vue.d.ts +25 -0
  13. package/dist/system/components/core/input-group/InputGroupAddon.vue.d.ts +25 -0
  14. package/dist/system/components/core/input-group/InputGroupButton.vue.d.ts +28 -0
  15. package/dist/system/components/core/input-group/InputGroupInput.vue.d.ts +12 -0
  16. package/dist/system/components/core/input-group/InputGroupText.vue.d.ts +21 -0
  17. package/dist/system/components/core/input-group/InputGroupTextarea.vue.d.ts +12 -0
  18. package/dist/system/components/core/input-group/index.d.ts +18 -0
  19. package/dist/system/components/index.d.ts +1 -0
  20. package/dist/system/lib.js +14300 -13931
  21. package/package.json +1 -1
  22. package/src/components/UiButtonGroup/index.ts +4 -0
  23. package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +83 -0
  24. package/src/components/UiCodeBlock/UiCodeBlock.vue +30 -2
  25. package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +21 -0
  26. package/src/components/UiCodeBlock/types.ts +11 -0
  27. package/src/components/UiField/UiField.stories.ts +329 -52
  28. package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
  29. package/src/components/UiInput/UiInput.stories.ts +3 -1
  30. package/src/components/UiInput/UiInput.vue +26 -5
  31. package/src/components/UiInputGroup/UiInputGroup.stories.ts +2083 -0
  32. package/src/components/UiInputGroup/UiInputGroup.vue +18 -0
  33. package/src/components/UiInputGroup/UiInputGroupAddon.vue +18 -0
  34. package/src/components/UiInputGroup/UiInputGroupButton.vue +30 -0
  35. package/src/components/UiInputGroup/UiInputGroupInput.vue +16 -0
  36. package/src/components/UiInputGroup/UiInputGroupTextarea.vue +16 -0
  37. package/src/components/UiInputGroup/__tests__/UiInputGroup.test.ts +195 -0
  38. package/src/components/UiInputGroup/index.ts +10 -0
  39. package/src/components/UiInputGroup/types.ts +171 -0
  40. package/src/components/UiLabel/UiLabel.vue +7 -2
  41. package/src/components/UiLabel/types.ts +8 -0
  42. package/src/components/core/button/index.ts +23 -13
  43. package/src/components/core/button-group/ButtonGroupText.vue +4 -0
  44. package/src/components/core/button-group/index.ts +6 -2
  45. package/src/components/core/field/FieldError.vue +1 -1
  46. package/src/components/core/field/FieldLabel.vue +1 -1
  47. package/src/components/core/field/index.ts +7 -1
  48. package/src/components/core/input/Input.vue +4 -1
  49. package/src/components/core/input-group/InputGroup.vue +27 -0
  50. package/src/components/core/input-group/InputGroupAddon.vue +53 -0
  51. package/src/components/core/input-group/InputGroupButton.vue +35 -0
  52. package/src/components/core/input-group/InputGroupInput.vue +65 -0
  53. package/src/components/core/input-group/InputGroupText.vue +26 -0
  54. package/src/components/core/input-group/InputGroupTextarea.vue +62 -0
  55. package/src/components/core/input-group/index.ts +103 -0
  56. package/src/components/core/label/Label.vue +1 -1
  57. package/src/components/index.ts +1 -0
  58. package/src/theme/Typography.stories.ts +144 -6
  59. package/src/theme/__tests__/typography.test.ts +136 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aleph-alpha/ui-library",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/system/lib.js",
@@ -1,2 +1,6 @@
1
1
  export { default as UiButtonGroup } from './UiButtonGroup.vue';
2
+
3
+ // Pure presentational wrapper with no extra logic — re-exported from core.
4
+ export { ButtonGroupText as UiButtonGroupText } from '@/components/core/button-group';
5
+
2
6
  export type { UiButtonGroupProps, UiButtonGroupOrientation } from './types';
@@ -287,6 +287,89 @@ export const WithoutCopyButton: Story = {
287
287
  },
288
288
  };
289
289
 
290
+ const headerColorsTemplateSource = `<script setup lang="ts">
291
+ import { UiCodeBlock } from '@aleph-alpha/ui-library'
292
+ </script>
293
+
294
+ <template>
295
+ <!-- Set the properties on the block, or on any ancestor to recolor several at once. -->
296
+ <UiCodeBlock
297
+ :code="code"
298
+ language="typescript"
299
+ filename="theme.ts"
300
+ :style="{
301
+ '--ui-code-block-header-surface': '#0d1117',
302
+ '--ui-code-block-header-content': '#c9d1d9',
303
+ '--ui-code-block-header-border': '#30363d',
304
+ }"
305
+ />
306
+ </template>`;
307
+
308
+ /** Story-only args: these are CSS custom properties, not component props. */
309
+ interface HeaderColorArgs {
310
+ headerSurface: string;
311
+ headerContent: string;
312
+ headerBorder: string;
313
+ }
314
+
315
+ /**
316
+ * Recolor the header from the outside with the `--ui-code-block-header-surface`,
317
+ * `--ui-code-block-header-content` and `--ui-code-block-header-border` custom
318
+ * properties — set them on the block or on any ancestor. Use this when the block
319
+ * sits on a surface the default muted header clashes with; each property falls
320
+ * back to its design token when unset. Edit the three colors in the Controls
321
+ * panel to see the header follow.
322
+ */
323
+ export const HeaderColors: StoryObj<HeaderColorArgs> = {
324
+ argTypes: {
325
+ headerSurface: {
326
+ control: 'color',
327
+ description:
328
+ 'Value for `--ui-code-block-header-surface` — the header background.',
329
+ },
330
+ headerContent: {
331
+ control: 'color',
332
+ description:
333
+ 'Value for `--ui-code-block-header-content` — the filename/language label and the copy icon.',
334
+ },
335
+ headerBorder: {
336
+ control: 'color',
337
+ description:
338
+ 'Value for `--ui-code-block-header-border` — the divider under the header.',
339
+ },
340
+ },
341
+ args: {
342
+ headerSurface: '#0d1117',
343
+ headerContent: '#c9d1d9',
344
+ headerBorder: '#30363d',
345
+ },
346
+ render: (args) => ({
347
+ components: { UiCodeBlock },
348
+ setup() {
349
+ return { args, code: typescriptExample };
350
+ },
351
+ template: `
352
+ <UiCodeBlock
353
+ :code="code"
354
+ language="typescript"
355
+ filename="theme.ts"
356
+ :style="{
357
+ '--ui-code-block-header-surface': args.headerSurface,
358
+ '--ui-code-block-header-content': args.headerContent,
359
+ '--ui-code-block-header-border': args.headerBorder,
360
+ }"
361
+ />
362
+ `,
363
+ }),
364
+ parameters: {
365
+ docs: {
366
+ source: {
367
+ code: headerColorsTemplateSource,
368
+ },
369
+ },
370
+ },
371
+ };
372
+
290
373
  const plainTextExample = `This is plain text output from a command.
291
374
  No syntax highlighting is applied.
292
375
  Useful for terminal output or log files.`;
@@ -171,13 +171,14 @@ onUnmounted(() => {
171
171
  >
172
172
  <div
173
173
  v-if="showHeader"
174
- class="flex items-center justify-between border-b border-border bg-background-surface-muted px-4 py-2"
174
+ class="ui-code-block__header flex items-center justify-between border-b px-4 py-2"
175
175
  >
176
- <span class="font-mono text-sm text-content-on-surface-secondary">
176
+ <span class="ui-code-block__header-label font-mono text-sm">
177
177
  {{ headerLabel !== 'text' ? headerLabel : '' }}
178
178
  </span>
179
179
  <UiButton
180
180
  v-if="showCopyButton"
181
+ class="ui-code-block__header-action"
181
182
  variant="ghost"
182
183
  size="icon-sm"
183
184
  :aria-label="isCopied ? copiedLabel : copyLabel"
@@ -219,6 +220,33 @@ onUnmounted(() => {
219
220
  </template>
220
221
 
221
222
  <style scoped>
223
+ /*
224
+ * The header is the one surface a caller may need to match to something else —
225
+ * a code canvas that is not the muted surface, a branded panel. It is recolored
226
+ * from the outside with these custom properties, set on the code block or any
227
+ * ancestor; unset, each falls back to the token it used before.
228
+ */
229
+ .ui-code-block__header {
230
+ background-color: var(
231
+ --ui-code-block-header-surface,
232
+ oklch(var(--background-surface-muted))
233
+ );
234
+ border-color: var(--ui-code-block-header-border, oklch(var(--border)));
235
+ }
236
+
237
+ .ui-code-block__header-label {
238
+ color: var(
239
+ --ui-code-block-header-content,
240
+ oklch(var(--content-on-surface-secondary))
241
+ );
242
+ }
243
+
244
+ /* Beats the ghost button's own `text-foreground`, so the copy icon stays
245
+ legible on a recolored header. */
246
+ .ui-code-block__header-action {
247
+ color: var(--ui-code-block-header-content, oklch(var(--foreground)));
248
+ }
249
+
222
250
  /* Dark mode: :global() needed because html.dark is outside component scope */
223
251
  :global(html.dark .ui-code-block .shiki),
224
252
  :global(html.dark .ui-code-block .shiki span) {
@@ -112,6 +112,27 @@ describe('UiCodeBlock', () => {
112
112
  });
113
113
  });
114
114
 
115
+ test('exposes the header styling hooks used to recolor it from the outside', async () => {
116
+ const { container, getByRole } = render(UiCodeBlock, {
117
+ props: { code: 'code', language: 'typescript' },
118
+ });
119
+
120
+ await waitFor(() => {
121
+ expect(getByRole('button')).toBeInTheDocument();
122
+ });
123
+
124
+ // The `--ui-code-block-header-*` custom properties are applied through
125
+ // these classes, so a caller's override has nothing to hook onto without
126
+ // them.
127
+ expect(container.querySelector('.ui-code-block__header')).not.toBeNull();
128
+ expect(
129
+ container.querySelector('.ui-code-block__header-label'),
130
+ ).not.toBeNull();
131
+ expect(
132
+ container.querySelector('.ui-code-block__header-action'),
133
+ ).not.toBeNull();
134
+ });
135
+
115
136
  test('shows copy button by default', async () => {
116
137
  const { getByRole } = render(UiCodeBlock, {
117
138
  props: { code: 'code', language: 'typescript' },
@@ -1,6 +1,17 @@
1
1
  /**
2
2
  * A code block component for displaying source code with syntax highlighting,
3
3
  * line numbers, and copy-to-clipboard functionality. Powered by Shiki.
4
+ *
5
+ * The header (language label + copy button) can be recolored from the outside
6
+ * with CSS custom properties, set on the code block or on any ancestor. Use
7
+ * them when the block sits on a surface the default muted header clashes with:
8
+ *
9
+ * - `--ui-code-block-header-surface` — header background
10
+ * - `--ui-code-block-header-content` — label and copy-icon color
11
+ * - `--ui-code-block-header-border` — divider under the header
12
+ *
13
+ * Each takes a full CSS color (`#0d1117`, `oklch(var(--background-surface-primary))`)
14
+ * and falls back to the design token it used before when unset.
4
15
  * @category Content
5
16
  * @useCases code display, code snippet, syntax highlighting, API response, terminal output
6
17
  * @keywords code, codeblock, syntax, highlight, copy, pre, snippet
@@ -16,6 +16,12 @@ import { UiCheckbox } from '../UiCheckbox';
16
16
  import { UiChip } from '../UiChip';
17
17
  import { UiIcon } from '../UiIcon';
18
18
  import { UiInput } from '../UiInput';
19
+ import {
20
+ UiInputGroup,
21
+ UiInputGroupAddon,
22
+ UiInputGroupButton,
23
+ UiInputGroupInput,
24
+ } from '../UiInputGroup';
19
25
  import { UiKbd } from '../UiKbd';
20
26
  import { UiRadioGroup, UiRadioGroupItem } from '../UiRadioGroup';
21
27
  import {
@@ -1588,45 +1594,156 @@ const validationAndErrorsTemplateSource = `<script setup lang="ts">
1588
1594
  import { ref } from 'vue'
1589
1595
  import {
1590
1596
  UiField,
1591
- UiFieldLabel,
1592
1597
  UiFieldError,
1598
+ UiFieldLabel,
1599
+ UiIcon,
1593
1600
  UiInput,
1601
+ UiInputGroup,
1602
+ UiInputGroupAddon,
1603
+ UiInputGroupButton,
1604
+ UiInputGroupInput,
1594
1605
  } from '@aleph-alpha/ui-library'
1595
1606
 
1596
1607
  const email = ref('not-an-email')
1608
+ const username = ref('john doe')
1597
1609
  </script>
1598
1610
 
1599
1611
  <template>
1600
- <UiField data-invalid>
1601
- <UiFieldLabel for="email-invalid">Email</UiFieldLabel>
1602
- <UiInput id="email-invalid" v-model="email" name="email" type="email" aria-invalid />
1603
- <UiFieldError>Enter a valid email address.</UiFieldError>
1604
- </UiField>
1612
+ <div class="flex w-full max-w-sm flex-col gap-6">
1613
+ <!-- data-invalid="true" on the field cascades the error color top-down:
1614
+ label, control border, and text turn error-colored via CSS;
1615
+ the placeholder keeps its muted color. The value must be the string
1616
+ "true" (a bare attribute renders "" and matches nothing). aria-invalid
1617
+ on the control conveys the state to assistive technology. -->
1618
+ <UiField data-invalid="true">
1619
+ <UiFieldLabel for="email-invalid">Email</UiFieldLabel>
1620
+ <UiInput id="email-invalid" v-model="email" name="email" type="email" aria-invalid="true" />
1621
+ <UiFieldError>Enter a valid email address.</UiFieldError>
1622
+ </UiField>
1623
+
1624
+ <!-- Inside an input group the cascade also covers addons and buttons. -->
1625
+ <UiField data-invalid="true">
1626
+ <UiFieldLabel for="username-invalid">Username</UiFieldLabel>
1627
+ <UiInputGroup>
1628
+ <UiInputGroupInput id="username-invalid" v-model="username" placeholder="Username" aria-invalid="true" />
1629
+ <UiInputGroupAddon align="inline-end">
1630
+ <UiInputGroupButton size="icon-xs" aria-label="Clear username" @click="username = ''">
1631
+ <UiIcon name="circle-x" :size="16" />
1632
+ </UiInputGroupButton>
1633
+ </UiInputGroupAddon>
1634
+ </UiInputGroup>
1635
+ <UiFieldError>Username must not contain spaces.</UiFieldError>
1636
+ </UiField>
1637
+ </div>
1605
1638
  </template>`;
1606
1639
 
1607
1640
  /**
1608
- * Validation styling + a11y: apply `data-invalid` to the field and `aria-invalid` to the control.
1641
+ * Validation styling + a11y: apply `data-invalid="true"` to the field and `aria-invalid` to the control.
1642
+ * `data-invalid` cascades the error color top-down through CSS — the label, the control border,
1643
+ * the text inside the control, and any input-group addons/buttons all turn error-colored;
1644
+ * only the placeholder keeps its muted color.
1609
1645
  * Mirrors the “Validation and Errors” section from shadcn-vue field docs.
1610
1646
  */
1611
1647
  export const ValidationAndErrors: Story = {
1612
1648
  render: () => ({
1613
- components: { UiField, UiFieldError, UiFieldLabel, UiInput },
1649
+ components: {
1650
+ UiField,
1651
+ UiFieldError,
1652
+ UiFieldLabel,
1653
+ UiIcon,
1654
+ UiInput,
1655
+ UiInputGroup,
1656
+ UiInputGroupAddon,
1657
+ UiInputGroupButton,
1658
+ UiInputGroupInput,
1659
+ },
1614
1660
  setup() {
1615
1661
  const email = ref('not-an-email');
1616
- return { email };
1662
+ const username = ref('john doe');
1663
+ return { email, username };
1617
1664
  },
1618
1665
  template: `
1619
- <UiField data-invalid>
1620
- <UiFieldLabel for="email-invalid">Email</UiFieldLabel>
1621
- <UiInput id="email-invalid" v-model="email" name="email" type="email" aria-invalid />
1622
- <UiFieldError>Enter a valid email address.</UiFieldError>
1623
- </UiField>
1666
+ <div class="flex w-full max-w-sm flex-col gap-6">
1667
+ <UiField data-invalid="true">
1668
+ <UiFieldLabel for="email-invalid">Email</UiFieldLabel>
1669
+ <UiInput id="email-invalid" v-model="email" name="email" type="email" aria-invalid="true" />
1670
+ <UiFieldError>Enter a valid email address.</UiFieldError>
1671
+ </UiField>
1672
+
1673
+ <UiField data-invalid="true">
1674
+ <UiFieldLabel for="username-invalid">Username</UiFieldLabel>
1675
+ <UiInputGroup>
1676
+ <UiInputGroupInput id="username-invalid" v-model="username" placeholder="Username" aria-invalid="true" />
1677
+ <UiInputGroupAddon align="inline-end">
1678
+ <UiInputGroupButton size="icon-xs" aria-label="Clear username" @click="username = ''">
1679
+ <UiIcon name="circle-x" :size="16" />
1680
+ </UiInputGroupButton>
1681
+ </UiInputGroupAddon>
1682
+ </UiInputGroup>
1683
+ <UiFieldError>Username must not contain spaces.</UiFieldError>
1684
+ </UiField>
1685
+ </div>
1624
1686
  `,
1625
1687
  }),
1626
1688
  parameters: {
1627
1689
  controls: { disable: true },
1628
1690
  docs: { source: { code: validationAndErrorsTemplateSource } },
1629
1691
  },
1692
+ play: async ({ canvasElement, step }) => {
1693
+ // Scenario: the field-level data-invalid switch drives every error visual
1694
+ // through CSS, and the same color resolves on the label, the input group
1695
+ // boundary, and the addon button.
1696
+ const canvas = within(canvasElement);
1697
+
1698
+ await step(
1699
+ 'screen-reader: both invalid controls expose aria-invalid (WCAG 4.1.2)',
1700
+ async () => {
1701
+ const email = canvas.getByRole('textbox', { name: 'Email' });
1702
+ await expect(email).toHaveAttribute('aria-invalid', 'true');
1703
+ const username = canvas.getByRole('textbox', { name: 'Username' });
1704
+ await expect(username).toHaveAttribute('aria-invalid', 'true');
1705
+ },
1706
+ );
1707
+
1708
+ await step(
1709
+ 'interaction: label, input text, and clear button share the cascaded error color',
1710
+ async () => {
1711
+ const username = canvas.getByRole('textbox', {
1712
+ name: 'Username',
1713
+ });
1714
+ const label = canvasElement.querySelector<HTMLElement>(
1715
+ 'label[for="username-invalid"]',
1716
+ );
1717
+ const clear = canvas.getByRole('button', { name: 'Clear username' });
1718
+ await expect(label).not.toBeNull();
1719
+ if (!label) return; // unreachable — the assertion above already threw
1720
+ // Resolve the border/input/error token through a probe. It is authored
1721
+ // in the same `color-mix(...)` form the generated `text-*` utilities
1722
+ // use, so the computed values serialize identically and the comparison
1723
+ // cannot pass with the cascade inactive (all elements sharing an
1724
+ // unrelated fallback color).
1725
+ const probe = document.createElement('span');
1726
+ probe.style.color =
1727
+ 'color-mix(in srgb, oklch(var(--border-input-error)) 100%, transparent)';
1728
+ canvasElement.appendChild(probe);
1729
+ const errorColor = getComputedStyle(probe).color;
1730
+ probe.remove();
1731
+ await expect(getComputedStyle(label).color).toBe(errorColor);
1732
+ await expect(getComputedStyle(username).color).toBe(errorColor);
1733
+ await expect(getComputedStyle(clear).color).toBe(errorColor);
1734
+ },
1735
+ );
1736
+
1737
+ await step('interaction: the clear icon renders at 16x16', async () => {
1738
+ const clear = canvas.getByRole('button', { name: 'Clear username' });
1739
+ const icon = clear.querySelector('svg');
1740
+ await expect(icon).not.toBeNull();
1741
+ if (!icon) return; // unreachable — the assertion above already threw
1742
+ const { width, height } = icon.getBoundingClientRect();
1743
+ await expect(width).toBe(16);
1744
+ await expect(height).toBe(16);
1745
+ });
1746
+ },
1630
1747
  };
1631
1748
 
1632
1749
  const checkboxGroupTemplateSource = `<script setup lang="ts">
@@ -2151,9 +2268,94 @@ export const ProfileSettingsForm: Story = {
2151
2268
  },
2152
2269
  };
2153
2270
 
2271
+ const personalInformationFormTemplateSource = `<script setup lang="ts">
2272
+ import { ref } from 'vue'
2273
+ import {
2274
+ UiButton,
2275
+ UiCheckbox,
2276
+ UiField,
2277
+ UiFieldContent,
2278
+ UiFieldDescription,
2279
+ UiFieldGroup,
2280
+ UiFieldLabel,
2281
+ UiFieldLegend,
2282
+ UiFieldSet,
2283
+ UiIcon,
2284
+ UiInput,
2285
+ UiInputGroup,
2286
+ UiInputGroupAddon,
2287
+ UiInputGroupButton,
2288
+ UiInputGroupInput,
2289
+ } from '@aleph-alpha/ui-library'
2290
+
2291
+ const firstName = ref('')
2292
+ const lastName = ref('')
2293
+ const agreeTerms = ref(false)
2294
+ </script>
2295
+
2296
+ <template>
2297
+ <div class="w-full max-w-sm rounded-xl border border-border-surface-default bg-background-surface-secondary p-6">
2298
+ <UiFieldGroup>
2299
+ <UiFieldSet>
2300
+ <UiFieldLegend>Personal Information</UiFieldLegend>
2301
+ <UiFieldDescription>Your basic contact information.</UiFieldDescription>
2302
+
2303
+ <UiFieldGroup>
2304
+ <UiField data-invalid="true">
2305
+ <UiFieldLabel for="pi-first" tooltip="As it appears on official documents.">First Name</UiFieldLabel>
2306
+ <UiFieldContent>
2307
+ <UiInputGroup>
2308
+ <UiInputGroupInput id="pi-first" v-model="firstName" placeholder="John" aria-invalid="true" />
2309
+ <UiInputGroupAddon align="inline-end">
2310
+ <UiInputGroupButton size="icon-xs" aria-label="Clear first name" @click="firstName = ''">
2311
+ <UiIcon name="circle-x" :size="16" />
2312
+ </UiInputGroupButton>
2313
+ </UiInputGroupAddon>
2314
+ </UiInputGroup>
2315
+ </UiFieldContent>
2316
+ </UiField>
2317
+
2318
+ <UiField data-invalid="true">
2319
+ <UiFieldLabel for="pi-last" tooltip="As it appears on official documents.">Last Name</UiFieldLabel>
2320
+ <UiFieldContent>
2321
+ <UiInputGroup>
2322
+ <UiInputGroupInput id="pi-last" v-model="lastName" placeholder="Doe" aria-invalid="true" />
2323
+ <UiInputGroupAddon align="inline-end">
2324
+ <UiInputGroupButton size="icon-xs" aria-label="Clear last name" @click="lastName = ''">
2325
+ <UiIcon name="circle-x" :size="16" />
2326
+ </UiInputGroupButton>
2327
+ </UiInputGroupAddon>
2328
+ </UiInputGroup>
2329
+ </UiFieldContent>
2330
+ </UiField>
2331
+
2332
+ <UiField data-invalid="true">
2333
+ <UiFieldLabel for="pi-resume" tooltip="PDF or DOCX, max 5 MB.">Upload Resume</UiFieldLabel>
2334
+ <UiInput id="pi-resume" name="resume" type="file" accept=".pdf,.docx" upload-button-label="Choose file" aria-invalid="true" />
2335
+ </UiField>
2336
+ </UiFieldGroup>
2337
+ </UiFieldSet>
2338
+
2339
+ <UiField orientation="responsive" data-invalid="true">
2340
+ <UiCheckbox id="pi-terms" v-model="agreeTerms" name="terms" aria-invalid="true" />
2341
+ <UiFieldContent>
2342
+ <UiFieldLabel for="pi-terms" class="font-normal">I agree to the terms and conditions</UiFieldLabel>
2343
+ </UiFieldContent>
2344
+ </UiField>
2345
+
2346
+ <UiField orientation="horizontal" class="justify-end">
2347
+ <UiButton variant="outline">Cancel</UiButton>
2348
+ <UiButton disabled>Submit</UiButton>
2349
+ </UiField>
2350
+ </UiFieldGroup>
2351
+ </div>
2352
+ </template>`;
2353
+
2154
2354
  /**
2155
- * Personal information form with file upload and terms checkbox.
2156
- * Demonstrates `tooltip` labels, file input, and validation-style checkbox.
2355
+ * Personal information form in an invalid state, composing `UiField` with
2356
+ * `UiInputGroup` (error border via `border/input/error`, inline-end clear
2357
+ * buttons) and `UiInput type="file"`. `data-invalid` on the field colors the
2358
+ * label; `aria-invalid` on the control colors the input boundary.
2157
2359
  */
2158
2360
  export const PersonalInformationForm: Story = {
2159
2361
  render: () => ({
@@ -2167,58 +2369,133 @@ export const PersonalInformationForm: Story = {
2167
2369
  UiFieldLabel,
2168
2370
  UiFieldLegend,
2169
2371
  UiFieldSet,
2372
+ UiIcon,
2170
2373
  UiInput,
2374
+ UiInputGroup,
2375
+ UiInputGroupAddon,
2376
+ UiInputGroupButton,
2377
+ UiInputGroupInput,
2171
2378
  },
2172
2379
  setup() {
2173
- const pFirstName = ref('John');
2174
- const pLastName = ref('Doe');
2380
+ const firstName = ref('');
2381
+ const lastName = ref('');
2175
2382
  const agreeTerms = ref(false);
2176
- return { pFirstName, pLastName, agreeTerms };
2383
+ return { firstName, lastName, agreeTerms };
2177
2384
  },
2178
2385
  template: `
2179
- <div class="w-full max-w-sm">
2180
- <form>
2181
- <UiFieldGroup>
2182
- <UiFieldSet>
2183
- <UiFieldLegend>Personal Information</UiFieldLegend>
2184
- <UiFieldDescription>Your basic contact information.</UiFieldDescription>
2386
+ <div class="w-full max-w-sm rounded-xl border border-border-surface-default bg-background-surface-secondary p-6">
2387
+ <UiFieldGroup>
2388
+ <UiFieldSet>
2389
+ <UiFieldLegend>Personal Information</UiFieldLegend>
2390
+ <UiFieldDescription>Your basic contact information.</UiFieldDescription>
2185
2391
 
2186
- <UiFieldGroup>
2187
- <UiField>
2188
- <UiFieldLabel for="p-first" tooltip="As it appears on official documents.">First Name</UiFieldLabel>
2189
- <UiInput id="p-first" v-model="pFirstName" name="pFirstName" placeholder="John" />
2190
- </UiField>
2392
+ <UiFieldGroup>
2393
+ <UiField data-invalid="true">
2394
+ <UiFieldLabel for="pi-first" tooltip="As it appears on official documents.">First Name</UiFieldLabel>
2395
+ <UiFieldContent>
2396
+ <UiInputGroup>
2397
+ <UiInputGroupInput id="pi-first" v-model="firstName" placeholder="John" aria-invalid="true" />
2398
+ <UiInputGroupAddon align="inline-end">
2399
+ <UiInputGroupButton size="icon-xs" aria-label="Clear first name" @click="firstName = ''">
2400
+ <UiIcon name="circle-x" :size="16" />
2401
+ </UiInputGroupButton>
2402
+ </UiInputGroupAddon>
2403
+ </UiInputGroup>
2404
+ </UiFieldContent>
2405
+ </UiField>
2191
2406
 
2192
- <UiField>
2193
- <UiFieldLabel for="p-last" tooltip="As it appears on official documents.">Last Name</UiFieldLabel>
2194
- <UiInput id="p-last" v-model="pLastName" name="pLastName" placeholder="Doe" />
2195
- </UiField>
2407
+ <UiField data-invalid="true">
2408
+ <UiFieldLabel for="pi-last" tooltip="As it appears on official documents.">Last Name</UiFieldLabel>
2409
+ <UiFieldContent>
2410
+ <UiInputGroup>
2411
+ <UiInputGroupInput id="pi-last" v-model="lastName" placeholder="Doe" aria-invalid="true" />
2412
+ <UiInputGroupAddon align="inline-end">
2413
+ <UiInputGroupButton size="icon-xs" aria-label="Clear last name" @click="lastName = ''">
2414
+ <UiIcon name="circle-x" :size="16" />
2415
+ </UiInputGroupButton>
2416
+ </UiInputGroupAddon>
2417
+ </UiInputGroup>
2418
+ </UiFieldContent>
2419
+ </UiField>
2196
2420
 
2197
- <UiField>
2198
- <UiFieldLabel for="p-resume" tooltip="PDF or DOCX, max 5 MB.">Upload Resume</UiFieldLabel>
2199
- <UiInput id="p-resume" name="resume" type="file" />
2200
- </UiField>
2201
- </UiFieldGroup>
2202
- </UiFieldSet>
2421
+ <UiField data-invalid="true">
2422
+ <UiFieldLabel for="pi-resume" tooltip="PDF or DOCX, max 5 MB.">Upload Resume</UiFieldLabel>
2423
+ <UiInput id="pi-resume" name="resume" type="file" accept=".pdf,.docx" upload-button-label="Choose file" aria-invalid="true" />
2424
+ </UiField>
2425
+ </UiFieldGroup>
2426
+ </UiFieldSet>
2203
2427
 
2204
- <UiField orientation="responsive" data-invalid="true">
2205
- <UiCheckbox id="agree-terms" v-model="agreeTerms" />
2206
- <UiFieldContent>
2207
- <UiFieldLabel for="agree-terms" class="font-normal">I agree to the terms and conditions</UiFieldLabel>
2208
- </UiFieldContent>
2209
- </UiField>
2428
+ <UiField orientation="responsive" data-invalid="true">
2429
+ <UiCheckbox id="pi-terms" v-model="agreeTerms" name="terms" aria-invalid="true" />
2430
+ <UiFieldContent>
2431
+ <UiFieldLabel for="pi-terms" class="font-normal">I agree to the terms and conditions</UiFieldLabel>
2432
+ </UiFieldContent>
2433
+ </UiField>
2210
2434
 
2211
- <UiField orientation="responsive">
2212
- <UiButton type="submit">Submit</UiButton>
2213
- <UiButton variant="outline" type="button">Cancel</UiButton>
2214
- </UiField>
2215
- </UiFieldGroup>
2216
- </form>
2435
+ <UiField orientation="horizontal" class="justify-end">
2436
+ <UiButton variant="outline">Cancel</UiButton>
2437
+ <UiButton disabled>Submit</UiButton>
2438
+ </UiField>
2439
+ </UiFieldGroup>
2217
2440
  </div>
2218
2441
  `,
2219
2442
  }),
2220
2443
  parameters: {
2221
2444
  controls: { disable: true },
2445
+ docs: { source: { code: personalInformationFormTemplateSource } },
2446
+ },
2447
+ play: async ({ canvasElement, step }) => {
2448
+ // Scenario: the invalid state is conveyed both visually (error border on
2449
+ // the group, error-colored labels) and programmatically (aria-invalid),
2450
+ // and the inline clear buttons stay operable.
2451
+ const canvas = within(canvasElement);
2452
+
2453
+ await step(
2454
+ 'screen-reader: invalid controls expose aria-invalid (WCAG 4.1.2)',
2455
+ async () => {
2456
+ const firstName = canvas.getByRole('textbox', { name: /First Name/ });
2457
+ await expect(firstName).toHaveAttribute('aria-invalid', 'true');
2458
+ const checkbox = canvas.getByRole('checkbox', {
2459
+ name: 'I agree to the terms and conditions',
2460
+ });
2461
+ await expect(checkbox).toHaveAttribute('aria-invalid', 'true');
2462
+ },
2463
+ );
2464
+
2465
+ await step(
2466
+ 'interaction: the inline clear button empties the field',
2467
+ async () => {
2468
+ const firstName = canvas.getByRole('textbox', {
2469
+ name: /First Name/,
2470
+ }) as HTMLInputElement;
2471
+ await userEvent.type(firstName, 'Johanna');
2472
+ await expect(firstName.value).toBe('Johanna');
2473
+ const clear = canvas.getByRole('button', {
2474
+ name: 'Clear first name',
2475
+ });
2476
+ await userEvent.click(clear);
2477
+ await waitFor(() => expect(firstName.value).toBe(''));
2478
+ },
2479
+ );
2480
+
2481
+ await step(
2482
+ 'interaction: the label info icon shares the cascaded error color',
2483
+ async () => {
2484
+ const label = canvasElement.querySelector<HTMLElement>(
2485
+ 'label[for="pi-first"]',
2486
+ );
2487
+ const info = canvas.getAllByRole('button', {
2488
+ name: 'As it appears on official documents.',
2489
+ })[0];
2490
+ const icon = info?.querySelector('svg');
2491
+ await expect(label).not.toBeNull();
2492
+ await expect(icon).not.toBeNull();
2493
+ if (!label || !icon) return; // unreachable — the assertions above already threw
2494
+ await expect(getComputedStyle(icon).color).toBe(
2495
+ getComputedStyle(label).color,
2496
+ );
2497
+ },
2498
+ );
2222
2499
  },
2223
2500
  };
2224
2501
 
@@ -19,7 +19,7 @@ const props = withDefaults(defineProps<UiFieldLabelInfoProps>(), {
19
19
  <UiIcon
20
20
  :name="props.icon"
21
21
  :size="14"
22
- class="text-content-on-surface-muted"
22
+ class="text-content-on-surface-muted group-data-[invalid=true]/field:text-border-input-error"
23
23
  />
24
24
  </UiButton>
25
25
  </UiTooltip>