@aleph-alpha/ui-library 6.0.0 → 6.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 (55) hide show
  1. package/config.d.ts +28 -4
  2. package/config.js +141 -23
  3. package/dist/system/components/UiTagsInput/UiTagsInput.vue.d.ts +2 -0
  4. package/dist/system/components/UiTagsInput/UiTagsInputItemDelete.vue.d.ts +2 -1
  5. package/dist/system/components/UiTagsInput/types.d.ts +21 -2
  6. package/dist/system/components/core/sidebar/utils.d.ts +9 -0
  7. package/dist/system/components/core/tags-input/TagsInputItemDelete.vue.d.ts +5 -0
  8. package/dist/system/icons/story-sidebar-icons.json +8 -0
  9. package/dist/system/lib.js +6106 -5997
  10. package/dist/system/patterns/UiLayout/UiLayoutContent.vue.d.ts +39 -0
  11. package/dist/system/patterns/UiLayout/index.d.ts +2 -0
  12. package/dist/system/patterns/UiLayout/layout-shell.d.ts +944 -0
  13. package/dist/system/patterns/UiLayout/types.d.ts +43 -0
  14. package/dist/system/patterns/index.d.ts +1 -0
  15. package/dist/system/story-sidebar-icons.json +8 -0
  16. package/docs/public-docs/migration-guide.md +402 -0
  17. package/docs/public-docs/quick-start.md +19 -10
  18. package/package.json +7 -4
  19. package/src/components/UiAlert/UiAlert.stories.ts +732 -0
  20. package/src/components/UiAlert/__tests__/UiAlert.test.ts +57 -11
  21. package/src/components/UiChip/UiChip.stories.ts +756 -2
  22. package/src/components/UiChip/UiChip.vue +7 -6
  23. package/src/components/UiChip/__tests__/UiChip.test.ts +38 -61
  24. package/src/components/UiDrawer/UiDrawer.stories.ts +665 -0
  25. package/src/components/UiDrawer/__tests__/UiDrawer.test.ts +6 -190
  26. package/src/components/UiLabel/UiLabel.stories.ts +691 -16
  27. package/src/components/UiLabel/__tests__/UiLabel.test.ts +18 -26
  28. package/src/components/UiSheet/UiSheet.stories.ts +751 -0
  29. package/src/components/UiSheet/__tests__/UiSheet.test.ts +6 -190
  30. package/src/components/UiSlider/UiSlider.stories.ts +716 -0
  31. package/src/components/UiSlider/__tests__/UiSlider.test.ts +8 -45
  32. package/src/components/UiSwitch/UiSwitch.stories.ts +11 -5
  33. package/src/components/UiTagsInput/UiTagsInput.stories.ts +850 -4
  34. package/src/components/UiTagsInput/UiTagsInput.vue +34 -0
  35. package/src/components/UiTagsInput/UiTagsInputItemDelete.vue +4 -1
  36. package/src/components/UiTagsInput/__tests__/UiTagsInput.test.ts +113 -29
  37. package/src/components/UiTagsInput/types.ts +24 -2
  38. package/src/components/core/sheet/SheetContent.vue +6 -1
  39. package/src/components/core/sidebar/Sidebar.vue +21 -5
  40. package/src/components/core/sidebar/utils.ts +10 -0
  41. package/src/components/core/switch/index.ts +8 -7
  42. package/src/components/core/tags-input/TagsInput.vue +4 -1
  43. package/src/components/core/tags-input/TagsInputItem.vue +13 -1
  44. package/src/components/core/tags-input/TagsInputItemDelete.vue +40 -7
  45. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +1234 -0
  46. package/src/patterns/UiLayout/UiLayoutContent.vue +98 -0
  47. package/src/patterns/UiLayout/__tests__/UiLayoutContent.test.ts +97 -0
  48. package/src/patterns/UiLayout/index.ts +2 -0
  49. package/src/patterns/UiLayout/layout-shell.ts +64 -15
  50. package/src/patterns/UiLayout/types.ts +44 -0
  51. package/src/patterns/index.ts +1 -0
  52. package/src/theme/Typography.stories.ts +125 -133
  53. package/tokens.json +8132 -2475
  54. package/dist/system/icons/mobile-device-frame.png +0 -0
  55. package/dist/system/mobile-device-frame.png +0 -0
@@ -0,0 +1,1234 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, userEvent, waitFor, within } from 'storybook/test';
3
+ import { renderShellWith } from './layout-shell';
4
+ import UiLayoutContent from './UiLayoutContent.vue';
5
+
6
+ const meta: Meta<typeof UiLayoutContent> = {
7
+ title: 'Patterns/UiLayout/Content',
8
+ component: UiLayoutContent,
9
+ tags: ['autodocs', 'experimental'],
10
+ argTypes: {
11
+ as: {
12
+ control: { type: 'text' },
13
+ description:
14
+ 'The HTML tag or Vue component to render as the root element.',
15
+ defaultValue: 'main',
16
+ },
17
+ },
18
+ parameters: {
19
+ layout: 'fullscreen',
20
+ // A whole app screen — preview padding would shift the bar and the sidebar
21
+ // out of alignment with each other.
22
+ surface: 'bleed',
23
+ docs: {
24
+ codePanel: true,
25
+ description: {
26
+ component:
27
+ 'Our layout grid consists of:\n\n- **12 columns**\n- **48px margins**\n- **24px gutter**\n\nInstead of applying the grid to the main artboard, we apply the grid to the primary content area. This allows for more flexible layout arrangements while maintaining correct spacing.\n\n`UiLayoutContent` is that primary content area — the column the **Desktop** shell leaves beside the sidebar. It renders a `main` landmark by default and carries the 48px margin on its left and right edges (as padding, so the column still fills the space the shell gives it). Inside the margins, content sits on `grid grid-cols-12 gap-6` and spans columns (`col-span-4`, `col-span-6`, …) rather than taking arbitrary widths.\n\nFor a **split view**, fill the `split` slot: a border divides the content box into two equal parts, each keeping a 28px margin from the divider, and each part carries a 6-column grid of its own.\n\nFor a **sidebar view**, fill the `sidebar` slot: secondary content is always locked to the right edge, with no surface or radius of its own, while the primary content becomes the rounded sheet (12px radius, `rounded-xl`). Both areas keep 48px horizontal margins. The `sidebarMode` prop sets the column split — `default` is 8 to 4, `wide` is 7 to 5, and `max` is 6 to 6.\n\n**Modals** open centered over the full layout, on the modal overlay, with a 12px corner radius — sized by a 12-column grid that covers the whole screen with 48px margins and stays drawn over everything. **Small** spans 4 of the 12 columns at 585px height, **medium** spans 6 at 746px, and **large** spans 10 at 889px.\n\nOur **minimum desktop size** is 1024px. At this size the grid is adjusted to use 32px margin instead of 48px, and the sidebar resizes to 162px width, truncating anything that does not fit — see the **Minimum desktop size** story, which previews the shell at that width inside a laptop frame.\n\nThe layout grid is a desktop arrangement, so these stories are locked to the desktop breakpoint; the phone shell is covered by the **Mobile** section.',
28
+ },
29
+ },
30
+ },
31
+ };
32
+
33
+ export default meta;
34
+
35
+ type Story = StoryObj<typeof UiLayoutContent>;
36
+
37
+ /**
38
+ * The content column of the grid demo. Two layers inside `UiLayoutContent`:
39
+ * first a skeleton of page content placed on the grid, then the twelve columns
40
+ * drawn in translucent red over it — the way a design tool paints its layout
41
+ * grid. Both layers share the component's 48px margins, which is what the
42
+ * overlay makes visible on either edge.
43
+ */
44
+ const layoutContentTemplate = `
45
+ <!-- the inline --spacing pins the theme's spacing base for the Vitest
46
+ browser project, which serves utilities without the theme preflight;
47
+ in Storybook proper it matches what the theme already provides -->
48
+ <UiLayoutContent
49
+ class="relative min-h-0 min-w-0 flex-1 overflow-hidden rounded-md shadow-lg"
50
+ style="--spacing: 0.25rem"
51
+ >
52
+ <!-- first layer: a skeleton of page content, placed on the grid -->
53
+ <div
54
+ class="grid h-full min-h-0 grid-cols-12 content-center gap-6"
55
+ data-layout-grid-content
56
+ aria-hidden="true"
57
+ >
58
+ <div class="col-span-3 col-start-4 h-4 rounded-md bg-background-surface-muted" />
59
+ <div class="col-span-4 col-start-4 h-8 rounded-md bg-background-surface-muted" />
60
+ <div class="col-span-6 col-start-4 mt-4 h-32 rounded-md bg-background-surface-muted" />
61
+ </div>
62
+
63
+ <!-- second layer: the twelve columns, drawn over the content. The margins
64
+ are what the overlay keeps clear on either side — 48px, compacting to
65
+ 32px below the desktop breakpoint (1200px), mirroring the component. -->
66
+ <div
67
+ class="pointer-events-none absolute inset-y-0 left-8 right-8 grid grid-cols-12 gap-6 lg-min:left-12 lg-min:right-12"
68
+ data-layout-grid-columns
69
+ aria-hidden="true"
70
+ >
71
+ <div v-for="n in 12" :key="n" class="bg-red-500/10" />
72
+ </div>
73
+ </UiLayoutContent>
74
+ `;
75
+
76
+ const layoutContentTemplateSource = `<script setup lang="ts">
77
+ import { UiLayoutContent } from '@aleph-alpha/ui-library'
78
+ </script>
79
+
80
+ <template>
81
+ <!-- the content column of the application shell, beside the sidebar -->
82
+ <UiLayoutContent class="relative min-h-0 min-w-0 flex-1 overflow-hidden">
83
+ <!-- content sits on the layout grid: 12 columns, 24px gutters -->
84
+ <div class="grid h-full grid-cols-12 content-center gap-6">
85
+ <div class="col-span-3 col-start-4 h-4 rounded-md bg-background-surface-muted" />
86
+ <div class="col-span-4 col-start-4 h-8 rounded-md bg-background-surface-muted" />
87
+ <div class="col-span-6 col-start-4 mt-4 h-32 rounded-md bg-background-surface-muted" />
88
+ </div>
89
+
90
+ <!-- the grid itself, drawn over the content to check alignment; the
91
+ insets mirror the component's margins (32px below the desktop
92
+ breakpoint, 48px from it up) -->
93
+ <div
94
+ class="pointer-events-none absolute inset-y-0 left-8 right-8 grid grid-cols-12 gap-6 lg-min:left-12 lg-min:right-12"
95
+ aria-hidden="true"
96
+ >
97
+ <div v-for="n in 12" :key="n" class="bg-red-500/10" />
98
+ </div>
99
+ </UiLayoutContent>
100
+ </template>`;
101
+
102
+ /**
103
+ * One area of a divided view: a skeleton of primary content on its own grid,
104
+ * with the columns drawn over it in red. The wrapper is `relative h-full` so
105
+ * the overlay covers exactly the area's content box — the margins around it
106
+ * stay clear, the way the 48px margins do on the edges.
107
+ * @param cols How many columns the area carries.
108
+ * @returns Template string for the area.
109
+ */
110
+ function contentPane(cols: number): string {
111
+ return `
112
+ <div class="relative h-full min-h-0">
113
+ <div class="grid h-full grid-cols-${cols} content-center gap-6" aria-hidden="true">
114
+ <div class="col-span-2 col-start-2 h-4 rounded-md bg-background-surface-muted" />
115
+ <div class="col-span-3 col-start-2 h-8 rounded-md bg-background-surface-muted" />
116
+ <div class="col-span-4 col-start-2 mt-4 h-32 rounded-md bg-background-surface-muted" />
117
+ </div>
118
+
119
+ <div
120
+ class="pointer-events-none absolute inset-0 grid grid-cols-${cols} gap-6"
121
+ data-layout-grid-columns
122
+ aria-hidden="true"
123
+ >
124
+ <div v-for="n in ${cols}" :key="n" class="bg-red-500/10" />
125
+ </div>
126
+ </div>
127
+ `;
128
+ }
129
+
130
+ const splitPaneTemplate = contentPane(6);
131
+
132
+ /**
133
+ * The sidebar area of the sidebar view: a skeleton of secondary content —
134
+ * heading, two cards, a list — with its columns drawn over it in
135
+ * `#00E1FF1A`, so the two grids can be told apart at a glance.
136
+ * @param cols How many columns the sidebar carries.
137
+ * @returns Template string for the sidebar area.
138
+ */
139
+ function sidebarPane(cols: number): string {
140
+ return `
141
+ <div class="relative h-full min-h-0">
142
+ <div class="grid h-full grid-cols-${cols} content-center gap-6" aria-hidden="true">
143
+ <div class="col-span-2 h-4 rounded-md bg-background-surface-muted" />
144
+ <div class="col-span-2 h-24 rounded-md bg-background-surface-muted" />
145
+ <div class="col-span-2 h-24 rounded-md bg-background-surface-muted" />
146
+ <div class="col-span-full h-40 rounded-md bg-background-surface-muted" />
147
+ </div>
148
+
149
+ <div
150
+ class="pointer-events-none absolute inset-0 grid grid-cols-${cols} gap-6"
151
+ data-layout-grid-columns
152
+ aria-hidden="true"
153
+ >
154
+ <div v-for="n in ${cols}" :key="n" class="bg-[#00E1FF1A]" />
155
+ </div>
156
+ </div>
157
+ `;
158
+ }
159
+
160
+ const splitViewTemplate = `
161
+ <!-- the inline --spacing pins the theme's spacing base for the Vitest
162
+ browser project, which serves utilities without the theme preflight;
163
+ in Storybook proper it matches what the theme already provides -->
164
+ <UiLayoutContent
165
+ class="relative min-h-0 min-w-0 flex-1 overflow-hidden rounded-md shadow-lg"
166
+ style="--spacing: 0.25rem"
167
+ >
168
+ ${splitPaneTemplate}
169
+
170
+ <template #split>${splitPaneTemplate}</template>
171
+ </UiLayoutContent>
172
+ `;
173
+
174
+ const splitViewTemplateSource = `<script setup lang="ts">
175
+ import { UiLayoutContent } from '@aleph-alpha/ui-library'
176
+ </script>
177
+
178
+ <template>
179
+ <!-- filling the split slot draws a border through the content box; each
180
+ part keeps a 28px margin from it and carries its own 6-column grid -->
181
+ <UiLayoutContent class="relative min-h-0 min-w-0 flex-1 overflow-hidden">
182
+ <div class="grid h-full grid-cols-6 content-center gap-6">
183
+ <!-- leading part, on its own 6-column grid -->
184
+ </div>
185
+
186
+ <template #split>
187
+ <div class="grid h-full grid-cols-6 content-center gap-6">
188
+ <!-- trailing part, on its own 6-column grid -->
189
+ </div>
190
+ </template>
191
+ </UiLayoutContent>
192
+ </template>`;
193
+
194
+ /**
195
+ * The layout grid inside the application shell: the bar and the sidebar stay
196
+ * around the content area, which carries the 48px margins on its left and
197
+ * right. A skeleton of page content sits on the grid, and the twelve columns
198
+ * with their 24px gutters are drawn over it in red, the way a design tool
199
+ * paints its layout grid.
200
+ */
201
+ export const Default: Story = {
202
+ globals: { mediaBreakpoint: 'default' },
203
+ render: renderShellWith(layoutContentTemplate, { UiLayoutContent }),
204
+ parameters: {
205
+ docs: {
206
+ source: {
207
+ code: layoutContentTemplateSource,
208
+ },
209
+ },
210
+ },
211
+ play: async ({ canvasElement, step }) => {
212
+ // Scenario (layout grid): the content area is the main landmark between
213
+ // the shell's other landmarks, its 48px margins inset the grid on either
214
+ // side, and the grid divides the rest into 12 columns with 24px gutters.
215
+ // Non-mutating assertions only, so this story's Chromatic snapshot stays
216
+ // valid.
217
+ const canvas = within(canvasElement);
218
+ const main = canvas.getByRole('main');
219
+ const overlay = canvasElement.querySelector<HTMLElement>(
220
+ '[data-layout-grid-columns]',
221
+ );
222
+ const content = canvasElement.querySelector<HTMLElement>(
223
+ '[data-layout-grid-content]',
224
+ );
225
+
226
+ await step(
227
+ 'interaction: the shell keeps its landmarks around the content area (WCAG 1.3.1)',
228
+ async () => {
229
+ await expect(
230
+ canvas.getByRole('banner', { name: 'Top bar' }),
231
+ ).toBeVisible();
232
+ await expect(
233
+ canvas.getByRole('navigation', { name: 'Main' }),
234
+ ).toBeVisible();
235
+ await expect(main).toBeVisible();
236
+ },
237
+ );
238
+
239
+ await step(
240
+ 'interaction: the 48px margins inset the grid from the left and right edges',
241
+ async () => {
242
+ await expect(overlay).not.toBeNull();
243
+
244
+ await waitFor(() => {
245
+ const mainRect = main.getBoundingClientRect();
246
+ const overlayRect = overlay!.getBoundingClientRect();
247
+
248
+ expect(overlayRect.left - mainRect.left).toBe(48);
249
+ expect(mainRect.right - overlayRect.right).toBe(48);
250
+ });
251
+ },
252
+ );
253
+
254
+ await step(
255
+ 'interaction: twelve columns 24px apart, with the content on the same grid',
256
+ async () => {
257
+ const columns = Array.from(overlay!.children) as HTMLElement[];
258
+
259
+ await expect(columns).toHaveLength(12);
260
+
261
+ await waitFor(() => {
262
+ const [first, second] = columns;
263
+ const gutter =
264
+ second.getBoundingClientRect().left -
265
+ first.getBoundingClientRect().right;
266
+
267
+ expect(gutter).toBeCloseTo(24, 0);
268
+
269
+ // The content layer shares the component's margins, so its blocks
270
+ // land exactly on the overlay's columns.
271
+ expect(content!.getBoundingClientRect().left).toBeCloseTo(
272
+ first.getBoundingClientRect().left,
273
+ 0,
274
+ );
275
+ });
276
+ },
277
+ );
278
+ },
279
+ };
280
+
281
+ /**
282
+ * A page skeleton on the layout grid, used by the Accessibility guidance
283
+ * examples below. Decorative blocks only, so it stays `aria-hidden`.
284
+ */
285
+ const accessibilityExampleContent = `
286
+ <div class="grid grid-cols-12 gap-6 py-8" aria-hidden="true">
287
+ <div class="col-span-3 h-4 rounded-md bg-background-surface-muted" />
288
+ <div class="col-span-6 h-8 rounded-md bg-background-surface-muted" />
289
+ <div class="col-span-9 mt-4 h-16 rounded-md bg-background-surface-muted" />
290
+ </div>
291
+ `;
292
+
293
+ /**
294
+ * Accessibility guidance for the content area: what the default `main` tag
295
+ * means as a landmark, when to change the `as` tag and what that costs, and
296
+ * the accessibility theme for contrast.
297
+ */
298
+ export const Accessibility: Story = {
299
+ render: () => ({
300
+ components: { UiLayoutContent },
301
+ template: `
302
+ <section class="flex flex-col gap-6 p-4">
303
+ <div>
304
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
305
+ Accessibility
306
+ </h2>
307
+ </div>
308
+
309
+ <div class="flex flex-col gap-6">
310
+ <div class="flex flex-col gap-2">
311
+ <h3 class="body-16-medium text-content-on-surface-primary">
312
+ Requirements
313
+ </h3>
314
+ <ul class="body-16-regular list-disc pl-5 text-content-on-surface-primary">
315
+ <li>The component renders a <code class="label-14-regular">main</code> element by default, so the content column is the page's <code class="label-14-regular">main</code> landmark (WCAG 1.3.1 Info and Relationships) and screen-reader users can jump straight to it (WCAG 2.4.1 Bypass Blocks). Keep the default when the column holds the page's primary content.</li>
316
+ <li>A page may expose only one visible <code class="label-14-regular">main</code> landmark. If the shell already provides one, pass a different tag via <code class="label-14-regular">as</code> instead of nesting a second <code class="label-14-regular">main</code>.</li>
317
+ <li>Choose the <code class="label-14-regular">as</code> tag for its semantics, not its styling — every tag renders identically here. A generic tag like <code class="label-14-regular">div</code> carries no landmark; if the column should stay a landmark, use a sectioning tag and name it (e.g. <code class="label-14-regular">as="section"</code> with <code class="label-14-regular">aria-label</code>), since an unnamed <code class="label-14-regular">section</code> is not exposed as a region.</li>
318
+ <li>The component brings no accessible name, heading, or focusable target of its own — the page's heading structure and controls come from your content.</li>
319
+ <li>The margins and the 12-column grid are visual only. Keep DOM order matching reading order inside the column, so the sequence stays meaningful without the grid (WCAG 1.3.2 Meaningful Sequence).</li>
320
+ <li>Span columns with <code class="label-14-regular">col-span-*</code> rather than fixed widths, so content reflows at 200% resize text and 400% reflow instead of clipping (WCAG 1.4.4, 1.4.10).</li>
321
+ </ul>
322
+ </div>
323
+
324
+ <div class="flex flex-col gap-2">
325
+ <h3 class="body-16-medium text-content-on-surface-primary">
326
+ Enable accessibility theme
327
+ </h3>
328
+ <p class="body-16-regular text-content-on-surface-primary">
329
+ When accessibility is required, enable our accessibility theme. This
330
+ increases contrast and ensures there are no color contrast issues.
331
+ </p>
332
+ </div>
333
+ </div>
334
+
335
+ <div class="flex flex-col gap-4">
336
+ <div class="flex flex-col gap-3">
337
+ <h3 class="label-16-medium text-content-on-surface-primary">
338
+ Default
339
+ </h3>
340
+ <UiLayoutContent class="rounded-md bg-background-surface-secondary shadow-lg">
341
+ ${accessibilityExampleContent}
342
+ </UiLayoutContent>
343
+ </div>
344
+
345
+ <div class="accessible-theme flex flex-col gap-3">
346
+ <h3 class="label-16-medium text-content-on-surface-primary">
347
+ Accessible
348
+ </h3>
349
+ <!-- as="section" + aria-label: the page already has a main landmark
350
+ above, and a second one would violate the one-main rule the
351
+ requirements describe. -->
352
+ <UiLayoutContent
353
+ as="section"
354
+ aria-label="Accessible theme example"
355
+ class="rounded-md bg-background-surface-secondary shadow-lg"
356
+ >
357
+ ${accessibilityExampleContent}
358
+ </UiLayoutContent>
359
+ </div>
360
+ </div>
361
+ </section>
362
+ `,
363
+ }),
364
+ tags: ['!autodocs'],
365
+ parameters: {
366
+ a11y: { test: 'off' },
367
+ chromatic: { disableSnapshot: true },
368
+ docs: { canvas: { sourceState: 'none' } },
369
+ // Long-form guidance, not a shell demo: keep the preview padding instead
370
+ // of the fullscreen bleed the grid stories use, and stay on the primary
371
+ // surface so the secondary-sheet examples keep their contrast.
372
+ layout: 'padded',
373
+ surface: 'primary',
374
+ },
375
+ };
376
+
377
+ /**
378
+ * The split view: filling the `split` slot draws a border through the middle
379
+ * of the content box, and each part keeps a 28px margin from it. The 48px
380
+ * margins stay on the outer edges, and each part carries a 6-column grid with
381
+ * the same 24px gutters — the two halves of the 12-column grid.
382
+ */
383
+ export const SplitView: Story = {
384
+ globals: { mediaBreakpoint: 'default' },
385
+ render: renderShellWith(splitViewTemplate, { UiLayoutContent }),
386
+ parameters: {
387
+ docs: {
388
+ description: {
389
+ story:
390
+ 'In split view the primary content area is split into equal left and right area, each utilizing a 6 column grid.\n\nUse for things like translation or whenever a side by side view is required.',
391
+ },
392
+ source: {
393
+ code: splitViewTemplateSource,
394
+ },
395
+ },
396
+ },
397
+ play: async ({ canvasElement, step }) => {
398
+ // Scenario (split view): the divider splits the content box into two equal
399
+ // parts, each inset 28px from it, with the 48px margins still on the outer
400
+ // edges and six columns with 24px gutters in each part. Non-mutating
401
+ // assertions only, so this story's Chromatic snapshot stays valid.
402
+ const canvas = within(canvasElement);
403
+ const main = canvas.getByRole('main');
404
+ const overlays = canvasElement.querySelectorAll<HTMLElement>(
405
+ '[data-layout-grid-columns]',
406
+ );
407
+
408
+ await step(
409
+ 'interaction: the border splits the content box into two equal parts',
410
+ async () => {
411
+ await expect(overlays).toHaveLength(2);
412
+
413
+ const [leading, trailing] = Array.from(overlays);
414
+
415
+ await waitFor(() => {
416
+ const leadingRect = leading.getBoundingClientRect();
417
+ const trailingRect = trailing.getBoundingClientRect();
418
+
419
+ // Both parts keep their 28px margin from the 1px divider…
420
+ expect(trailingRect.left - leadingRect.right).toBeCloseTo(57, 0);
421
+ // …and split the space evenly.
422
+ expect(
423
+ Math.abs(leadingRect.width - trailingRect.width),
424
+ ).toBeLessThanOrEqual(1);
425
+ });
426
+ },
427
+ );
428
+
429
+ await step(
430
+ 'interaction: the 48px margins stay on the outer edges of the split',
431
+ async () => {
432
+ const [leading, trailing] = Array.from(overlays);
433
+
434
+ await waitFor(() => {
435
+ const mainRect = main.getBoundingClientRect();
436
+
437
+ expect(leading.getBoundingClientRect().left - mainRect.left).toBe(48);
438
+ expect(mainRect.right - trailing.getBoundingClientRect().right).toBe(
439
+ 48,
440
+ );
441
+ });
442
+ },
443
+ );
444
+
445
+ await step(
446
+ 'interaction: each part carries six columns, 24px apart',
447
+ async () => {
448
+ for (const overlay of Array.from(overlays)) {
449
+ await expect(overlay.children).toHaveLength(6);
450
+ }
451
+
452
+ await waitFor(() => {
453
+ const [first, second] = Array.from(
454
+ overlays[0].children,
455
+ ) as HTMLElement[];
456
+ const gutter =
457
+ second.getBoundingClientRect().left -
458
+ first.getBoundingClientRect().right;
459
+
460
+ expect(gutter).toBeCloseTo(24, 0);
461
+ });
462
+ },
463
+ );
464
+
465
+ await step(
466
+ 'screen-reader: the demo layers stay decorative in both parts (WCAG 1.3.1)',
467
+ async () => {
468
+ for (const overlay of Array.from(overlays)) {
469
+ await expect(overlay).toHaveAttribute('aria-hidden', 'true');
470
+ }
471
+ },
472
+ );
473
+ },
474
+ };
475
+
476
+ /**
477
+ * The sidebar view inside the shell, for one of the three modes.
478
+ * @param mode `sidebarMode` under demonstration.
479
+ * @param contentCols Columns of the primary content area.
480
+ * @param sidebarCols Columns of the sidebar area.
481
+ * @returns Template string for the content column.
482
+ */
483
+ function sidebarViewTemplate(
484
+ mode: string,
485
+ contentCols: number,
486
+ sidebarCols: number,
487
+ ): string {
488
+ return `
489
+ <!-- the inline --spacing pins the theme's spacing base for the Vitest
490
+ browser project, which serves utilities without the theme preflight;
491
+ in Storybook proper it matches what the theme already provides.
492
+ No sheet styling on the box itself: in the sidebar view the primary
493
+ area is the rounded sheet, and the sidebar stays on the base layer. -->
494
+ <UiLayoutContent
495
+ sidebar-mode="${mode}"
496
+ class="relative min-h-0 min-w-0 flex-1"
497
+ style="--spacing: 0.25rem"
498
+ >
499
+ ${contentPane(contentCols)}
500
+
501
+ <template #sidebar>${sidebarPane(sidebarCols)}</template>
502
+ </UiLayoutContent>
503
+ `;
504
+ }
505
+
506
+ /**
507
+ * The copy-paste snippet for a sidebar-view story.
508
+ * @param mode `sidebarMode` under demonstration.
509
+ * @param contentCols Columns of the primary content area.
510
+ * @param sidebarCols Columns of the sidebar area.
511
+ * @returns Full SFC source for the docs panel.
512
+ */
513
+ function sidebarViewTemplateSource(
514
+ mode: string,
515
+ contentCols: number,
516
+ sidebarCols: number,
517
+ ): string {
518
+ return `<script setup lang="ts">
519
+ import { UiLayoutContent } from '@aleph-alpha/ui-library'
520
+ </script>
521
+
522
+ <template>
523
+ <!-- filling the sidebar slot locks secondary content to the right;
524
+ the primary area becomes the rounded sheet, the sidebar stays flat;
525
+ sidebar-mode sets the ${contentCols} to ${sidebarCols} column split -->
526
+ <UiLayoutContent
527
+ sidebar-mode="${mode}"
528
+ class="relative min-h-0 min-w-0 flex-1"
529
+ >
530
+ <div class="grid h-full grid-cols-${contentCols} content-center gap-6">
531
+ <!-- primary content, on its own ${contentCols}-column grid -->
532
+ </div>
533
+
534
+ <template #sidebar>
535
+ <div class="grid h-full grid-cols-${sidebarCols} content-center gap-6">
536
+ <!-- secondary content, on its own ${sidebarCols}-column grid -->
537
+ </div>
538
+ </template>
539
+ </UiLayoutContent>
540
+ </template>`;
541
+ }
542
+
543
+ /**
544
+ * A play checking the sidebar view's arrangement: the sidebar is locked to the
545
+ * right edge of the content box, both areas keep their 48px margins, and each
546
+ * carries the mode's column count with 24px gutters.
547
+ * @param contentCols Columns expected in the primary content area.
548
+ * @param sidebarCols Columns expected in the sidebar area.
549
+ * @returns Play function for the story.
550
+ */
551
+ function sidebarViewPlay(contentCols: number, sidebarCols: number) {
552
+ return async ({
553
+ canvasElement,
554
+ step,
555
+ }: {
556
+ canvasElement: HTMLElement;
557
+ step: (label: string, fn: () => Promise<void>) => void | Promise<void>;
558
+ }) => {
559
+ // Scenario (sidebar view): secondary content sits on the muted surface on
560
+ // the right, and both areas keep the 48px margins and 24px gutters.
561
+ // Non-mutating assertions only, so the Chromatic snapshots stay valid.
562
+ const canvas = within(canvasElement);
563
+ const main = canvas.getByRole('main');
564
+ const overlays = canvasElement.querySelectorAll<HTMLElement>(
565
+ '[data-layout-grid-columns]',
566
+ );
567
+
568
+ await step(
569
+ `interaction: ${contentCols} columns for primary content, ${sidebarCols} for the sidebar`,
570
+ async () => {
571
+ await expect(overlays).toHaveLength(2);
572
+ await expect(overlays[0].children).toHaveLength(contentCols);
573
+ await expect(overlays[1].children).toHaveLength(sidebarCols);
574
+ },
575
+ );
576
+
577
+ await step(
578
+ 'interaction: the sidebar is locked to the right, and both areas keep the 48px margins',
579
+ async () => {
580
+ const [content, sidebar] = Array.from(overlays);
581
+
582
+ await waitFor(() => {
583
+ const mainRect = main.getBoundingClientRect();
584
+ const contentRect = content.getBoundingClientRect();
585
+ const sidebarRect = sidebar.getBoundingClientRect();
586
+
587
+ expect(sidebarRect.left).toBeGreaterThan(contentRect.right);
588
+ expect(contentRect.left - mainRect.left).toBe(48);
589
+ expect(mainRect.right - sidebarRect.right).toBe(48);
590
+ });
591
+ },
592
+ );
593
+
594
+ await step('interaction: 24px gutters inside both areas', async () => {
595
+ await waitFor(() => {
596
+ for (const overlay of Array.from(overlays)) {
597
+ const [first, second] = Array.from(overlay.children) as HTMLElement[];
598
+ const gutter =
599
+ second.getBoundingClientRect().left -
600
+ first.getBoundingClientRect().right;
601
+
602
+ expect(gutter).toBeCloseTo(24, 0);
603
+ }
604
+ });
605
+ });
606
+
607
+ await step(
608
+ 'screen-reader: the demo layers stay decorative in both areas (WCAG 1.3.1)',
609
+ async () => {
610
+ for (const overlay of Array.from(overlays)) {
611
+ await expect(overlay).toHaveAttribute('aria-hidden', 'true');
612
+ }
613
+ },
614
+ );
615
+ };
616
+ }
617
+
618
+ /**
619
+ * The sidebar view in its default mode: 8 columns for primary content, 4 for
620
+ * the sidebar — secondary content on a muted surface, locked to the right.
621
+ */
622
+ export const SidebarDefault: Story = {
623
+ globals: { mediaBreakpoint: 'default' },
624
+ render: renderShellWith(sidebarViewTemplate('default', 8, 4), {
625
+ UiLayoutContent,
626
+ }),
627
+ parameters: {
628
+ docs: {
629
+ description: {
630
+ story:
631
+ 'The sidebar view uses 8 column for primary content and 4 column secondary content.\n\nThis layout can be used whenever there is secondary content to show, i.e. chain of thought or notifications list.',
632
+ },
633
+ source: {
634
+ code: sidebarViewTemplateSource('default', 8, 4),
635
+ },
636
+ },
637
+ },
638
+ play: sidebarViewPlay(8, 4),
639
+ };
640
+
641
+ /**
642
+ * The wide sidebar mode: the split moves to 7 columns for primary content and
643
+ * 5 for the sidebar, when the secondary content needs more room.
644
+ */
645
+ export const SidebarWide: Story = {
646
+ globals: { mediaBreakpoint: 'default' },
647
+ render: renderShellWith(sidebarViewTemplate('wide', 7, 5), {
648
+ UiLayoutContent,
649
+ }),
650
+ parameters: {
651
+ docs: {
652
+ description: {
653
+ story:
654
+ 'The wide sidebar mode splits the content area 7 to 5: 7 columns for primary content, 5 for the sidebar.',
655
+ },
656
+ source: {
657
+ code: sidebarViewTemplateSource('wide', 7, 5),
658
+ },
659
+ },
660
+ },
661
+ play: sidebarViewPlay(7, 5),
662
+ };
663
+
664
+ /**
665
+ * The max sidebar mode: an even 6 to 6 split, when the secondary content
666
+ * carries as much weight as the page itself.
667
+ */
668
+ export const SidebarMax: Story = {
669
+ globals: { mediaBreakpoint: 'default' },
670
+ render: renderShellWith(sidebarViewTemplate('max', 6, 6), {
671
+ UiLayoutContent,
672
+ }),
673
+ parameters: {
674
+ docs: {
675
+ description: {
676
+ story: 'The max sidebar mode splits the content area evenly, 6 to 6.',
677
+ },
678
+ source: {
679
+ code: sidebarViewTemplateSource('max', 6, 6),
680
+ },
681
+ },
682
+ },
683
+ play: sidebarViewPlay(6, 6),
684
+ };
685
+
686
+ /**
687
+ * The page of default content a modal demo opens over: the same skeleton the
688
+ * grid demo uses, sitting inside the content area behind the backdrop.
689
+ */
690
+ const MODAL_PAGE_SKELETON = `
691
+ <!-- the page of default content behind the modal -->
692
+ <div
693
+ class="grid h-full min-h-0 grid-cols-12 content-center gap-6"
694
+ data-layout-grid-content
695
+ aria-hidden="true"
696
+ >
697
+ <div class="col-span-3 col-start-4 h-4 rounded-md bg-background-surface-muted" />
698
+ <div class="col-span-4 col-start-4 h-8 rounded-md bg-background-surface-muted" />
699
+ <div class="col-span-6 col-start-4 mt-4 h-32 rounded-md bg-background-surface-muted" />
700
+ </div>
701
+ `;
702
+
703
+ /**
704
+ * The page's twelve columns, drawn over the whole screen — full width and
705
+ * full height, sidebar and bar included, with the 48px margins measured from
706
+ * the screen edges — above the backdrop and the modal (inline position and
707
+ * z-index, story scaffolding only), the way a design tool keeps its layout
708
+ * grid on top of everything.
709
+ */
710
+ const MODAL_PAGE_COLUMNS = `
711
+ <!-- the layout grid covers the whole screen, over the backdrop and modal -->
712
+ <div
713
+ class="pointer-events-none left-8 right-8 grid grid-cols-12 gap-6 lg-min:left-12 lg-min:right-12"
714
+ data-layout-grid-columns
715
+ aria-hidden="true"
716
+ style="position: fixed; top: 0; bottom: 0; z-index: 60"
717
+ >
718
+ <div v-for="n in 12" :key="n" class="bg-red-500/10" />
719
+ </div>
720
+ `;
721
+
722
+ /**
723
+ * A modal grid demo inside the full layout: default page content behind, the
724
+ * modal overlay as backdrop over the whole shell, and the screen-wide layout
725
+ * grid drawn over everything. The dialog is sized by that grid rather than a
726
+ * fixed width — it spans a run of its columns, centered vertically at its
727
+ * design height — so the columns run straight through it. The positioning
728
+ * and z-order are inline (story scaffolding): the utility classes for them
729
+ * belong to the app shell too, and safelisting them would restyle it under
730
+ * test. The inline --spacing pins the theme's spacing base for the Vitest
731
+ * browser project, which serves utilities without the theme preflight.
732
+ * @param size Size name, for the dialog's accessible name.
733
+ * @param height Design height of the modal, in pixels.
734
+ * @param span How many of the 12 screen columns the modal spans.
735
+ * @param start The column the modal starts on, keeping it centered.
736
+ * @returns Template string for the content column.
737
+ */
738
+ function modalShellTemplate(
739
+ size: string,
740
+ height: number,
741
+ span: number,
742
+ start: number,
743
+ ): string {
744
+ return `
745
+ <UiLayoutContent
746
+ class="relative min-h-0 min-w-0 flex-1 rounded-md shadow-lg"
747
+ style="--spacing: 0.25rem"
748
+ >
749
+ ${MODAL_PAGE_SKELETON}
750
+
751
+ <!-- the backdrop covers the full layout -->
752
+ <div
753
+ class="bg-overlay-surface-modal-overlay"
754
+ data-modal-backdrop
755
+ aria-hidden="true"
756
+ style="position: fixed; inset: 0; z-index: 40"
757
+ ></div>
758
+
759
+ <!-- the dialog sits on the screen-wide 12-column grid, spanning
760
+ ${span} columns. The single full-height row keeps it centered
761
+ vertically and makes its max-height resolvable -->
762
+ <div
763
+ class="left-8 right-8 grid grid-cols-12 gap-6 lg-min:left-12 lg-min:right-12"
764
+ style="position: fixed; top: 0; bottom: 0; z-index: 50; grid-template-rows: 100%"
765
+ >
766
+ <div
767
+ role="dialog"
768
+ aria-modal="true"
769
+ aria-label="${size} modal"
770
+ class="col-span-${span} col-start-${start} overflow-hidden rounded-xl border border-border-surface-default bg-background-surface-modal shadow-lg"
771
+ style="height: ${height}px; max-height: 100%; align-self: center"
772
+ ></div>
773
+ </div>
774
+
775
+ ${MODAL_PAGE_COLUMNS}
776
+ </UiLayoutContent>
777
+ `;
778
+ }
779
+
780
+ /**
781
+ * The copy-paste snippet for a modal-grid story.
782
+ * @param height Design height of the modal, in pixels.
783
+ * @param span How many of the 12 screen columns the modal spans.
784
+ * @param start The column the modal starts on.
785
+ * @returns Full SFC source for the docs panel.
786
+ */
787
+ function modalTemplateSource(
788
+ height: number,
789
+ span: number,
790
+ start: number,
791
+ ): string {
792
+ return `<template>
793
+ <!-- the app layout stays underneath; the backdrop covers all of it -->
794
+ <div class="fixed inset-0 z-40 bg-overlay-surface-modal-overlay" aria-hidden="true"></div>
795
+
796
+ <!-- the screen-wide 12-column grid with 48px margins; the dialog spans
797
+ ${span} of its columns, centered, at its ${height}px design height -->
798
+ <div class="fixed inset-y-0 left-12 right-12 z-50 grid grid-cols-12 grid-rows-[100%] gap-6">
799
+ <div
800
+ role="dialog"
801
+ aria-modal="true"
802
+ class="col-span-${span} col-start-${start} self-center rounded-xl border border-border-surface-default bg-background-surface-modal shadow-lg"
803
+ style="height: ${height}px; max-height: 100%"
804
+ >
805
+ <!-- modal content shares the ${span} screen columns it spans -->
806
+ <div class="grid h-full grid-cols-${span} gap-6">
807
+ <!-- content spans columns of the grid -->
808
+ </div>
809
+ </div>
810
+ </div>
811
+ </template>`;
812
+ }
813
+
814
+ /**
815
+ * A play checking a modal grid story: the backdrop covers the full layout
816
+ * with the default page behind it, the screen-wide grid keeps its 12 columns
817
+ * and margins over everything, and the dialog spans its run of columns,
818
+ * centered vertically at its design height with the 12px curve.
819
+ * @param height Design height of the modal, in pixels.
820
+ * @param span How many of the 12 screen columns the modal spans.
821
+ * @param start The column the modal starts on.
822
+ * @returns Play function for the story.
823
+ */
824
+ function modalPlay(height: number, span: number, start: number) {
825
+ return async ({
826
+ canvasElement,
827
+ step,
828
+ }: {
829
+ canvasElement: HTMLElement;
830
+ step: (label: string, fn: () => Promise<void>) => void | Promise<void>;
831
+ }) => {
832
+ // Scenario (modal grid): the modal opens over the full layout — backdrop
833
+ // across the shell, the layout grid covering the whole screen — and the
834
+ // dialog is sized by that grid, so the columns run straight through it.
835
+ // Non-mutating assertions only, so the Chromatic snapshots stay valid.
836
+ const canvas = within(canvasElement);
837
+ const dialog = canvas.getByRole('dialog');
838
+ const backdrop = canvasElement.querySelector<HTMLElement>(
839
+ '[data-modal-backdrop]',
840
+ )!;
841
+ const pageGrid = canvasElement.querySelector<HTMLElement>(
842
+ '[data-layout-grid-columns]',
843
+ )!;
844
+
845
+ await step(
846
+ 'interaction: the backdrop covers the full layout, with the page behind it',
847
+ async () => {
848
+ await expect(canvas.getByRole('main')).toBeVisible();
849
+ await expect(
850
+ canvas.getByRole('banner', { name: 'Top bar' }),
851
+ ).toBeVisible();
852
+
853
+ await waitFor(() => {
854
+ const rect = backdrop.getBoundingClientRect();
855
+
856
+ expect(rect.left).toBeLessThanOrEqual(0);
857
+ expect(rect.top).toBeLessThanOrEqual(0);
858
+ expect(rect.right).toBeGreaterThanOrEqual(
859
+ document.documentElement.clientWidth,
860
+ );
861
+ expect(rect.bottom).toBeGreaterThanOrEqual(
862
+ document.documentElement.clientHeight,
863
+ );
864
+ });
865
+ },
866
+ );
867
+
868
+ await step(
869
+ 'interaction: the grid covers the whole screen with its margins, over the modal',
870
+ async () => {
871
+ await expect(pageGrid.children).toHaveLength(12);
872
+ await expect(Number(getComputedStyle(pageGrid).zIndex)).toBeGreaterThan(
873
+ Number(getComputedStyle(backdrop).zIndex),
874
+ );
875
+
876
+ await waitFor(() => {
877
+ const rect = pageGrid.getBoundingClientRect();
878
+ const { clientWidth, clientHeight } = document.documentElement;
879
+ // 48px margins from the screen edges; 32px below the desktop
880
+ // breakpoint, per the minimum-desktop adjustment.
881
+ const margin = clientWidth >= 1200 ? 48 : 32;
882
+
883
+ expect(rect.top).toBeCloseTo(0, 0);
884
+ expect(rect.bottom).toBeCloseTo(clientHeight, 0);
885
+ expect(rect.left).toBeCloseTo(margin, 0);
886
+ expect(rect.right).toBeCloseTo(clientWidth - margin, 0);
887
+ });
888
+ },
889
+ );
890
+
891
+ await step(
892
+ `interaction: the modal spans ${span} of the 12 columns, centered at its ${height}px design height, curved by 12px`,
893
+ async () => {
894
+ const columns = Array.from(pageGrid.children) as HTMLElement[];
895
+
896
+ await waitFor(() => {
897
+ const dialogRect = dialog.getBoundingClientRect();
898
+ const clientHeight = document.documentElement.clientHeight;
899
+
900
+ // The dialog's edges land on its first and last column.
901
+ expect(dialogRect.left).toBeCloseTo(
902
+ columns[start - 1].getBoundingClientRect().left,
903
+ 0,
904
+ );
905
+ expect(dialogRect.right).toBeCloseTo(
906
+ columns[start + span - 2].getBoundingClientRect().right,
907
+ 0,
908
+ );
909
+ // max-height lets a short canvas clamp the design height.
910
+ expect(dialogRect.height).toBeCloseTo(
911
+ Math.min(height, clientHeight),
912
+ 0,
913
+ );
914
+ // Centered on the screen: equal room above and below.
915
+ expect(dialogRect.top).toBeCloseTo(
916
+ clientHeight - dialogRect.bottom,
917
+ 0,
918
+ );
919
+ expect(getComputedStyle(dialog).borderTopLeftRadius).toBe('12px');
920
+ });
921
+ },
922
+ );
923
+
924
+ await step(
925
+ 'screen-reader: the dialog is named and modal, the demo layers stay decorative (WCAG 1.3.1, 4.1.2)',
926
+ async () => {
927
+ await expect(dialog).toHaveAttribute('aria-modal', 'true');
928
+ await expect(dialog).toHaveAccessibleName();
929
+ await expect(pageGrid).toHaveAttribute('aria-hidden', 'true');
930
+ },
931
+ );
932
+ };
933
+ }
934
+
935
+ /**
936
+ * The small modal: 4 of the screen's 12 columns at 585px height, centered
937
+ * over the full layout on the modal overlay with a 12px corner radius, under
938
+ * the screen-wide layout grid.
939
+ */
940
+ export const ModalSmall: Story = {
941
+ globals: { mediaBreakpoint: 'default' },
942
+ render: renderShellWith(modalShellTemplate('Small', 585, 4, 5), {
943
+ UiLayoutContent,
944
+ }),
945
+ parameters: {
946
+ docs: {
947
+ description: {
948
+ story:
949
+ 'The small modal opens over the full layout and is sized by the screen-wide grid: it spans 4 of the 12 columns at 585px height, centered, with a 12px corner radius. The layout grid covers the whole screen with 48px margins and runs through the modal.',
950
+ },
951
+ source: {
952
+ code: modalTemplateSource(585, 4, 5),
953
+ },
954
+ },
955
+ },
956
+ play: modalPlay(585, 4, 5),
957
+ };
958
+
959
+ /**
960
+ * The medium modal: 6 of the screen's 12 columns at 746px height, centered
961
+ * over the full layout on the modal overlay with a 12px corner radius, under
962
+ * the screen-wide layout grid.
963
+ */
964
+ export const ModalMedium: Story = {
965
+ globals: { mediaBreakpoint: 'default' },
966
+ render: renderShellWith(modalShellTemplate('Medium', 746, 6, 4), {
967
+ UiLayoutContent,
968
+ }),
969
+ parameters: {
970
+ docs: {
971
+ description: {
972
+ story:
973
+ 'The medium modal opens over the full layout and is sized by the screen-wide grid: it spans 6 of the 12 columns at 746px height, centered, with a 12px corner radius. The layout grid covers the whole screen with 48px margins and runs through the modal.',
974
+ },
975
+ source: {
976
+ code: modalTemplateSource(746, 6, 4),
977
+ },
978
+ },
979
+ },
980
+ play: modalPlay(746, 6, 4),
981
+ };
982
+
983
+ /**
984
+ * The large modal: 10 of the screen's 12 columns at 889px height, centered
985
+ * over the full layout on the modal overlay with a 12px corner radius, under
986
+ * the screen-wide layout grid.
987
+ */
988
+ export const ModalLarge: Story = {
989
+ globals: { mediaBreakpoint: 'default' },
990
+ render: renderShellWith(modalShellTemplate('Large', 889, 10, 2), {
991
+ UiLayoutContent,
992
+ }),
993
+ parameters: {
994
+ docs: {
995
+ description: {
996
+ story:
997
+ 'The large modal opens over the full layout and is sized by the screen-wide grid: it spans 10 of the 12 columns at 889px height, centered, with a 12px corner radius. The layout grid covers the whole screen with 48px margins and runs through the modal.',
998
+ },
999
+ source: {
1000
+ code: modalTemplateSource(889, 10, 2),
1001
+ },
1002
+ },
1003
+ },
1004
+ play: modalPlay(889, 10, 2),
1005
+ };
1006
+
1007
+ /**
1008
+ * The shell at the design system's minimum desktop size: the preview is pinned
1009
+ * to 1024px (and framed as a laptop on the canvas), the grid compacts to 32px
1010
+ * margins, and the sidebar narrows to its fixed 162px width.
1011
+ */
1012
+ export const MinimumDesktopSize: Story = {
1013
+ name: 'Minimum desktop size',
1014
+ globals: { mediaBreakpoint: 'min-desktop' },
1015
+ render: renderShellWith(layoutContentTemplate, { UiLayoutContent }),
1016
+ parameters: {
1017
+ docs: {
1018
+ description: {
1019
+ story:
1020
+ 'Our minimum desktop size is 1024px. At this size the grid is adjusted to use 32px margin instead of 48px. Additionally the sidebar resizes to 162px width and we truncate anything that doesn’t fit.',
1021
+ },
1022
+ source: {
1023
+ code: layoutContentTemplateSource,
1024
+ },
1025
+ },
1026
+ },
1027
+ play: async ({ canvasElement, step }) => {
1028
+ // Scenario (minimum desktop): at the 1024px floor the layout keeps the
1029
+ // 12-column grid but compacts its margins to 32px, and the sidebar drops
1030
+ // to its fixed 162px width. Non-mutating assertions only, so the
1031
+ // Chromatic snapshot stays valid.
1032
+ const canvas = within(canvasElement);
1033
+ const main = canvas.getByRole('main');
1034
+ const overlay = canvasElement.querySelector<HTMLElement>(
1035
+ '[data-layout-grid-columns]',
1036
+ );
1037
+ const sidebar = canvasElement.querySelector<HTMLElement>(
1038
+ '[data-slot="sidebar"]',
1039
+ );
1040
+
1041
+ await step(
1042
+ 'mobile: the min-desktop breakpoint narrows the preview to 1024px',
1043
+ async () => {
1044
+ await waitFor(() =>
1045
+ expect(document.documentElement.clientWidth).toBe(1024),
1046
+ );
1047
+ },
1048
+ );
1049
+
1050
+ await step(
1051
+ 'mobile: the grid compacts to 32px margins at the minimum desktop size',
1052
+ async () => {
1053
+ await expect(overlay).not.toBeNull();
1054
+
1055
+ await waitFor(() => {
1056
+ const mainRect = main.getBoundingClientRect();
1057
+ const overlayRect = overlay!.getBoundingClientRect();
1058
+
1059
+ expect(overlayRect.left - mainRect.left).toBe(32);
1060
+ expect(mainRect.right - overlayRect.right).toBe(32);
1061
+ });
1062
+ },
1063
+ );
1064
+
1065
+ await step(
1066
+ 'mobile: the sidebar narrows to its fixed 162px width',
1067
+ async () => {
1068
+ await expect(sidebar).not.toBeNull();
1069
+
1070
+ // The clamp lives on the width variable the sidebar column and its
1071
+ // dependents read; asserting it directly keeps the check independent
1072
+ // of the utility CSS the Vitest browser project serves.
1073
+ await waitFor(() =>
1074
+ expect(sidebar!.style.getPropertyValue('--sidebar-width')).toBe(
1075
+ '162px',
1076
+ ),
1077
+ );
1078
+ },
1079
+ );
1080
+
1081
+ await step(
1082
+ 'interaction: the twelve columns keep their 24px gutters',
1083
+ async () => {
1084
+ const columns = Array.from(overlay!.children) as HTMLElement[];
1085
+
1086
+ await expect(columns).toHaveLength(12);
1087
+
1088
+ await waitFor(() => {
1089
+ const [first, second] = columns;
1090
+ const gutter =
1091
+ second.getBoundingClientRect().left -
1092
+ first.getBoundingClientRect().right;
1093
+
1094
+ expect(gutter).toBeCloseTo(24, 0);
1095
+ });
1096
+ },
1097
+ );
1098
+
1099
+ await step(
1100
+ 'screen-reader: the demo layers stay decorative at this width too (WCAG 1.3.1)',
1101
+ async () => {
1102
+ await expect(overlay).toHaveAttribute('aria-hidden', 'true');
1103
+ },
1104
+ );
1105
+ },
1106
+ };
1107
+
1108
+ /**
1109
+ * The content area is purely presentational, so the keyboard category asserts
1110
+ * the absence: it introduces no focusable target of its own, and tabbing lands
1111
+ * on the shell's controls instead.
1112
+ */
1113
+ export const KeyboardNavigation: Story = {
1114
+ name: 'test - Keyboard Navigation',
1115
+ tags: ['!dev', '!autodocs'],
1116
+ globals: { mediaBreakpoint: 'default' },
1117
+ parameters: {
1118
+ // The play moves focus, and a focus ring reads as a visual diff.
1119
+ chromatic: { disableSnapshot: true },
1120
+ },
1121
+ render: renderShellWith(layoutContentTemplate, { UiLayoutContent }),
1122
+ play: async ({ canvasElement, step }) => {
1123
+ // Scenario (layout grid): a purely presentational container must not trap
1124
+ // or attract keyboard focus (WCAG 2.1.1 has nothing to operate here).
1125
+ const canvas = within(canvasElement);
1126
+ const main = canvas.getByRole('main');
1127
+
1128
+ await step(
1129
+ 'keyboard: the content area adds no tab stops of its own',
1130
+ async () => {
1131
+ await expect(
1132
+ main.querySelectorAll(
1133
+ 'a[href], button, input, select, textarea, [tabindex]',
1134
+ ),
1135
+ ).toHaveLength(0);
1136
+
1137
+ await userEvent.tab();
1138
+
1139
+ // The first tab stop is in the shell (the bar's sidebar toggle), never
1140
+ // inside the content area.
1141
+ await expect(main.contains(document.activeElement)).toBe(false);
1142
+ },
1143
+ );
1144
+ },
1145
+ };
1146
+
1147
+ /**
1148
+ * Screen-reader semantics: the content area is a bare `main` landmark with no
1149
+ * accessible name or content of its own, and both layers of the grid demo stay
1150
+ * decorative, so the landmark is all assistive technology announces
1151
+ * (WCAG 1.3.1). Hidden test-only story.
1152
+ */
1153
+ export const ScreenReader: Story = {
1154
+ name: 'test - Screen Reader',
1155
+ tags: ['!dev', '!autodocs'],
1156
+ globals: { mediaBreakpoint: 'default' },
1157
+ parameters: {
1158
+ // Same arrangement as Default, which already carries the snapshot.
1159
+ chromatic: { disableSnapshot: true },
1160
+ docs: {
1161
+ description: {
1162
+ story:
1163
+ 'Verifies that the content area exposes only its main landmark: both demo layers are aria-hidden, so nothing else is announced.',
1164
+ },
1165
+ },
1166
+ },
1167
+ render: renderShellWith(layoutContentTemplate, { UiLayoutContent }),
1168
+ play: async ({ canvasElement, step }) => {
1169
+ // Scenario (layout grid): the component adds nothing to the accessibility
1170
+ // tree beyond the landmark itself, and the demo's skeleton and column
1171
+ // overlay are visual aids only — so a screen reader hears the main
1172
+ // landmark and nothing else.
1173
+ const overlay = canvasElement.querySelector<HTMLElement>(
1174
+ '[data-layout-grid-columns]',
1175
+ );
1176
+ const content = canvasElement.querySelector<HTMLElement>(
1177
+ '[data-layout-grid-content]',
1178
+ );
1179
+
1180
+ await step(
1181
+ 'screen-reader: both demo layers stay decorative, so the landmark is all that is announced (WCAG 1.3.1)',
1182
+ async () => {
1183
+ await expect(content).toHaveAttribute('aria-hidden', 'true');
1184
+ await expect(overlay).toHaveAttribute('aria-hidden', 'true');
1185
+ },
1186
+ );
1187
+ },
1188
+ };
1189
+
1190
+ /**
1191
+ * Magnified to 200%. The margins and the columns scale with the zoom, so the
1192
+ * landmark stays visible and the grid keeps its twelve columns (WCAG 1.4.4).
1193
+ */
1194
+ export const ZoomMagnification: Story = {
1195
+ name: 'test - Zoom Magnification',
1196
+ tags: ['!dev', '!autodocs'],
1197
+ globals: { zoom: '200', mediaBreakpoint: 'default' },
1198
+ parameters: {
1199
+ // The accessible-reflow Chromatic mode already covers magnified snapshots.
1200
+ chromatic: { disableSnapshot: true },
1201
+ docs: {
1202
+ description: {
1203
+ story:
1204
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the content area.',
1205
+ },
1206
+ },
1207
+ },
1208
+ render: renderShellWith(layoutContentTemplate, { UiLayoutContent }),
1209
+ play: async ({ canvasElement, step }) => {
1210
+ // Scenario (layout grid): at 200% zoom the content area keeps its landmark
1211
+ // and the grid keeps its columns.
1212
+ const canvas = within(canvasElement);
1213
+
1214
+ await step(
1215
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1216
+ async () => {
1217
+ await expect(document.documentElement.style.zoom).toBe('200%');
1218
+ },
1219
+ );
1220
+
1221
+ await step(
1222
+ 'zoom: the content area and its twelve columns stay in place',
1223
+ async () => {
1224
+ await expect(canvas.getByRole('main')).toBeVisible();
1225
+
1226
+ const overlay = canvasElement.querySelector<HTMLElement>(
1227
+ '[data-layout-grid-columns]',
1228
+ );
1229
+ await expect(overlay).not.toBeNull();
1230
+ await expect(overlay!.children).toHaveLength(12);
1231
+ },
1232
+ );
1233
+ },
1234
+ };