@aleph-alpha/ui-library 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.
- package/README.md +2 -0
- package/dist/system/components/core/sidebar/SidebarInset.vue.d.ts +14 -1
- package/dist/system/lib.js +11 -5
- package/package.json +12 -3
- package/src/components/UiButton/UiButton.stories.ts +526 -38
- package/src/components/core/sidebar/SidebarInset.vue +19 -2
- package/src/patterns/UiSidebar/UiSidebarInset.stories.ts +259 -0
- package/src/patterns/UiSidebar/__tests__/UiSidebarInset.test.ts +20 -0
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { Component } from 'vue';
|
|
2
|
+
type Tag = keyof HTMLElementTagNameMap | (string & {}) | Component;
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/**
|
|
5
|
+
* The tag or component to render as the root element.
|
|
6
|
+
* Defaults to `main`. Use a different tag (e.g. `div` or `section`) when
|
|
7
|
+
* rendering multiple insets on a single page to avoid duplicate `main`
|
|
8
|
+
* landmarks.
|
|
9
|
+
*/
|
|
10
|
+
as?: Tag;
|
|
11
|
+
};
|
|
1
12
|
declare function __VLS_template(): {
|
|
2
13
|
attrs: Partial<{}>;
|
|
3
14
|
slots: {
|
|
@@ -7,7 +18,9 @@ declare function __VLS_template(): {
|
|
|
7
18
|
rootEl: any;
|
|
8
19
|
};
|
|
9
20
|
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
10
|
-
declare const __VLS_component: import('vue').DefineComponent<
|
|
21
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
22
|
+
as: Tag;
|
|
23
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
11
24
|
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
12
25
|
export default _default;
|
|
13
26
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
package/dist/system/lib.js
CHANGED
|
@@ -56212,19 +56212,25 @@ const PT = /* @__PURE__ */ _({
|
|
|
56212
56212
|
}, Symbol.toStringTag, { value: "Module" })), P1e = /* @__PURE__ */ _({
|
|
56213
56213
|
inheritAttrs: !1,
|
|
56214
56214
|
__name: "SidebarInset",
|
|
56215
|
+
props: {
|
|
56216
|
+
as: { default: "main" }
|
|
56217
|
+
},
|
|
56215
56218
|
setup(e) {
|
|
56216
|
-
return (t, a) => (h(),
|
|
56219
|
+
return (t, a) => (h(), b(Ee(e.as), q(t.$attrs, {
|
|
56217
56220
|
"data-slot": "sidebar-inset",
|
|
56218
56221
|
class: l(D)(
|
|
56219
56222
|
"bg-background relative flex w-full flex-1 flex-col transition-[border-radius,box-shadow,opacity,transform] duration-(--sidebar-mobile-transition-duration) ease-out will-change-[opacity,transform]",
|
|
56220
56223
|
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
|
56221
56224
|
t.$attrs.class ?? ""
|
|
56222
56225
|
)
|
|
56223
|
-
}),
|
|
56224
|
-
|
|
56225
|
-
|
|
56226
|
+
}), {
|
|
56227
|
+
default: v(() => [
|
|
56228
|
+
k(t.$slots, "default", {}, void 0, !0)
|
|
56229
|
+
]),
|
|
56230
|
+
_: 3
|
|
56231
|
+
}, 16, ["class"]));
|
|
56226
56232
|
}
|
|
56227
|
-
}), xB = /* @__PURE__ */ Os(P1e, [["__scopeId", "data-v-
|
|
56233
|
+
}), xB = /* @__PURE__ */ Os(P1e, [["__scopeId", "data-v-f9cff196"]]), D1e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
56228
56234
|
__proto__: null,
|
|
56229
56235
|
default: xB
|
|
56230
56236
|
}, Symbol.toStringTag, { value: "Module" })), CB = /* @__PURE__ */ _({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleph-alpha/ui-library",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/system/lib.js",
|
|
@@ -118,6 +118,15 @@
|
|
|
118
118
|
"vue-sonner": "^2.0.9",
|
|
119
119
|
"@aleph-alpha/config-unocss": "0.2.0"
|
|
120
120
|
},
|
|
121
|
+
"jest-junit": {
|
|
122
|
+
"outputDirectory": "reports/storybook",
|
|
123
|
+
"outputName": "junit.xml",
|
|
124
|
+
"ancestorSeparator": " › ",
|
|
125
|
+
"uniqueOutputName": "false",
|
|
126
|
+
"suiteNameTemplate": "{filepath}",
|
|
127
|
+
"classNameTemplate": "{classname}",
|
|
128
|
+
"titleTemplate": "{title}"
|
|
129
|
+
},
|
|
121
130
|
"scripts": {
|
|
122
131
|
"build": "node scripts/prepare-build.cjs && vite build",
|
|
123
132
|
"ci": "pnpm install --immutable --immutable-cache --check-cache",
|
|
@@ -128,8 +137,8 @@
|
|
|
128
137
|
"lint": "eslint 'src/**/*.{js,vue,ts}' --cache",
|
|
129
138
|
"test": "vitest --run --project=unit",
|
|
130
139
|
"test:watch": "vitest --project=unit",
|
|
131
|
-
"test:storybook": "pnpm concurrently -k --ks SIGKILL -s command-test -n \"storybook,test\" \"pnpm http-server ../../dist/storybook/ui-library --port 4400 --silent\" \"wait-on tcp:4400 && test-storybook --url http://127.0.0.1:4400\"",
|
|
132
|
-
"test:storybook:local": "pnpm build-storybook && pnpm concurrently -k --ks SIGKILL -s command-test -n \"storybook,test\" \"pnpm http-server storybook-static --port 4400 --silent\" \"wait-on tcp:4400 && test-storybook --url http://127.0.0.1:4400\"",
|
|
140
|
+
"test:storybook": "pnpm concurrently -k --ks SIGKILL -s command-test -n \"storybook,test\" \"pnpm http-server ../../dist/storybook/ui-library --port 4400 --silent\" \"wait-on tcp:4400 && test-storybook --url http://127.0.0.1:4400 --junit\"",
|
|
141
|
+
"test:storybook:local": "pnpm build-storybook && pnpm concurrently -k --ks SIGKILL -s command-test -n \"storybook,test\" \"pnpm http-server storybook-static --port 4400 --silent\" \"wait-on tcp:4400 && test-storybook --url http://127.0.0.1:4400 --junit\"",
|
|
133
142
|
"test:all": "vitest --run",
|
|
134
143
|
"storybook": "storybook dev -p 6006",
|
|
135
144
|
"build-storybook": "storybook build",
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { ref } from 'vue';
|
|
2
4
|
import UiButton from './UiButton.vue';
|
|
3
5
|
import { UiIcon } from '../UiIcon';
|
|
4
6
|
|
|
@@ -17,6 +19,11 @@ const MailIcon = {
|
|
|
17
19
|
template: '<UiIcon name="mail" :size="16" />',
|
|
18
20
|
};
|
|
19
21
|
|
|
22
|
+
// `UiButton` emits a native click (it declares no `onClick` prop), so play
|
|
23
|
+
// functions assert against this module-level spy bound via `@click` rather
|
|
24
|
+
// than through `args`. Each `play` clears it first, so the shared spy is safe.
|
|
25
|
+
const onClick = fn();
|
|
26
|
+
|
|
20
27
|
/**
|
|
21
28
|
* Buttons are used to initiate actions within an application. Their labels clearly describe the action they trigger.
|
|
22
29
|
*/
|
|
@@ -81,6 +88,12 @@ export default meta;
|
|
|
81
88
|
|
|
82
89
|
type Story = StoryObj<typeof UiButton>;
|
|
83
90
|
|
|
91
|
+
// Test-only stories drive the test-runner (interactive/a11y checks) but are
|
|
92
|
+
// hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
|
|
93
|
+
// tags. They keep the implicit `test` tag, so they still run in CI and appear
|
|
94
|
+
// in the automated report under their `test - …` name. `name`/`tags` must be
|
|
95
|
+
// literal properties so Storybook's static CSF indexer can read them.
|
|
96
|
+
|
|
84
97
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
85
98
|
import { UiButton } from '@aleph-alpha/ui-library'
|
|
86
99
|
</script>
|
|
@@ -291,6 +304,386 @@ export const Accessibility: Story = {
|
|
|
291
304
|
},
|
|
292
305
|
};
|
|
293
306
|
|
|
307
|
+
const keyboardNavigationTemplateSource = `<script setup lang="ts">
|
|
308
|
+
import { UiButton } from '@aleph-alpha/ui-library'
|
|
309
|
+
|
|
310
|
+
function handleSubmit() {
|
|
311
|
+
// …
|
|
312
|
+
}
|
|
313
|
+
</script>
|
|
314
|
+
|
|
315
|
+
<template>
|
|
316
|
+
<UiButton @click="handleSubmit">Submit</UiButton>
|
|
317
|
+
</template>`;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* `UiButton` is fully keyboard operable: it focuses with `Tab` and activates
|
|
321
|
+
* with `Enter`, `Space`, and pointer clicks.
|
|
322
|
+
*/
|
|
323
|
+
export const KeyboardNavigation: Story = {
|
|
324
|
+
name: 'test - Keyboard Navigation',
|
|
325
|
+
tags: ['!dev', '!autodocs'],
|
|
326
|
+
render: () => ({
|
|
327
|
+
components: { UiButton },
|
|
328
|
+
setup() {
|
|
329
|
+
return { onClick };
|
|
330
|
+
},
|
|
331
|
+
template: `<UiButton @click="onClick">Submit</UiButton>`,
|
|
332
|
+
}),
|
|
333
|
+
parameters: {
|
|
334
|
+
// Focus moves during the play function; skip the visual snapshot so the
|
|
335
|
+
// focus ring doesn't register as a Chromatic diff.
|
|
336
|
+
chromatic: { disableSnapshot: true },
|
|
337
|
+
docs: {
|
|
338
|
+
description: {
|
|
339
|
+
story:
|
|
340
|
+
'Press `Tab` to focus the button, then `Enter` or `Space` to activate it.',
|
|
341
|
+
},
|
|
342
|
+
source: {
|
|
343
|
+
code: keyboardNavigationTemplateSource,
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
play: async ({ canvasElement, step }) => {
|
|
348
|
+
// Scenario: a keyboard user tabs to the button and activates it with Enter,
|
|
349
|
+
// Space, and a pointer click.
|
|
350
|
+
const canvas = within(canvasElement);
|
|
351
|
+
const button = canvas.getByRole('button', { name: 'Submit' });
|
|
352
|
+
|
|
353
|
+
await step(
|
|
354
|
+
'interaction: exposes a button role with an accessible name',
|
|
355
|
+
async () => {
|
|
356
|
+
await expect(button).toHaveAccessibleName('Submit');
|
|
357
|
+
},
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
await step(
|
|
361
|
+
'keyboard: reachable via Tab (WCAG 2.1.1 Keyboard)',
|
|
362
|
+
async () => {
|
|
363
|
+
onClick.mockClear();
|
|
364
|
+
await userEvent.tab();
|
|
365
|
+
await expect(button).toHaveFocus();
|
|
366
|
+
},
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
await step('interaction: activates with Enter', async () => {
|
|
370
|
+
await userEvent.keyboard('{Enter}');
|
|
371
|
+
await expect(onClick).toHaveBeenCalledTimes(1);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
await step('interaction: activates with Space', async () => {
|
|
375
|
+
await userEvent.keyboard(' ');
|
|
376
|
+
await expect(onClick).toHaveBeenCalledTimes(2);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
await step('interaction: activates on pointer click', async () => {
|
|
380
|
+
onClick.mockClear();
|
|
381
|
+
await userEvent.click(button);
|
|
382
|
+
await expect(onClick).toHaveBeenCalledTimes(1);
|
|
383
|
+
});
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const keyboardGroupTemplateSource = `<script setup lang="ts">
|
|
388
|
+
import { UiButton } from '@aleph-alpha/ui-library'
|
|
389
|
+
</script>
|
|
390
|
+
|
|
391
|
+
<template>
|
|
392
|
+
<div role="group" aria-label="Playback controls" class="flex gap-2">
|
|
393
|
+
<UiButton variant="outline">Previous</UiButton>
|
|
394
|
+
<UiButton>Play</UiButton>
|
|
395
|
+
<UiButton variant="outline">Next</UiButton>
|
|
396
|
+
</div>
|
|
397
|
+
</template>`;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* A toolbar-style group of buttons: Tab moves focus between each control in DOM
|
|
401
|
+
* order and Space activates the focused one (WCAG 2.1.1, 2.4.3).
|
|
402
|
+
*/
|
|
403
|
+
export const KeyboardGroupNavigation: Story = {
|
|
404
|
+
name: 'test - Keyboard Group Navigation',
|
|
405
|
+
tags: ['!dev', '!autodocs'],
|
|
406
|
+
parameters: {
|
|
407
|
+
// Focus moves during the play function; skip the visual snapshot.
|
|
408
|
+
chromatic: { disableSnapshot: true },
|
|
409
|
+
docs: {
|
|
410
|
+
description: {
|
|
411
|
+
story:
|
|
412
|
+
'Tab between the buttons, then press Space to activate the focused one.',
|
|
413
|
+
},
|
|
414
|
+
source: {
|
|
415
|
+
code: keyboardGroupTemplateSource,
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
render: () => ({
|
|
420
|
+
components: { UiButton },
|
|
421
|
+
setup() {
|
|
422
|
+
return { onClick };
|
|
423
|
+
},
|
|
424
|
+
template: `
|
|
425
|
+
<div role="group" aria-label="Playback controls" class="flex gap-2">
|
|
426
|
+
<UiButton variant="outline" @click="onClick">Previous</UiButton>
|
|
427
|
+
<UiButton @click="onClick">Play</UiButton>
|
|
428
|
+
<UiButton variant="outline" @click="onClick">Next</UiButton>
|
|
429
|
+
</div>
|
|
430
|
+
`,
|
|
431
|
+
}),
|
|
432
|
+
play: async ({ canvasElement, step }) => {
|
|
433
|
+
// Scenario: a keyboard user tabs across the button group in DOM order and
|
|
434
|
+
// activates the focused control with Space.
|
|
435
|
+
onClick.mockClear();
|
|
436
|
+
const canvas = within(canvasElement);
|
|
437
|
+
const previous = canvas.getByRole('button', { name: 'Previous' });
|
|
438
|
+
const play = canvas.getByRole('button', { name: 'Play' });
|
|
439
|
+
const next = canvas.getByRole('button', { name: 'Next' });
|
|
440
|
+
|
|
441
|
+
await step(
|
|
442
|
+
'keyboard: Tab enters the group and focuses the first control',
|
|
443
|
+
async () => {
|
|
444
|
+
await userEvent.tab();
|
|
445
|
+
await expect(previous).toHaveFocus();
|
|
446
|
+
},
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
await step(
|
|
450
|
+
'keyboard: Tab moves focus through the group in order (WCAG 2.4.3)',
|
|
451
|
+
async () => {
|
|
452
|
+
await userEvent.tab();
|
|
453
|
+
await expect(play).toHaveFocus();
|
|
454
|
+
await userEvent.tab();
|
|
455
|
+
await expect(next).toHaveFocus();
|
|
456
|
+
},
|
|
457
|
+
);
|
|
458
|
+
|
|
459
|
+
await step(
|
|
460
|
+
'keyboard: Space activates the focused control (WCAG 2.1.1)',
|
|
461
|
+
async () => {
|
|
462
|
+
await userEvent.keyboard(' ');
|
|
463
|
+
await expect(onClick).toHaveBeenCalledTimes(1);
|
|
464
|
+
},
|
|
465
|
+
);
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const zoomMagnificationTemplateSource = `<script setup lang="ts">
|
|
470
|
+
import { UiButton } from '@aleph-alpha/ui-library'
|
|
471
|
+
</script>
|
|
472
|
+
|
|
473
|
+
<template>
|
|
474
|
+
<UiButton>Save changes</UiButton>
|
|
475
|
+
</template>`;
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
479
|
+
* try 400% reflow (WCAG 1.4.10); content must stay visible and operable.
|
|
480
|
+
*/
|
|
481
|
+
export const ZoomMagnification: Story = {
|
|
482
|
+
name: 'test - Zoom Magnification',
|
|
483
|
+
tags: ['!dev', '!autodocs'],
|
|
484
|
+
globals: { zoom: '200' },
|
|
485
|
+
parameters: {
|
|
486
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
487
|
+
// already covers magnified snapshots, so skip this one.
|
|
488
|
+
chromatic: { disableSnapshot: true },
|
|
489
|
+
docs: {
|
|
490
|
+
description: {
|
|
491
|
+
story:
|
|
492
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
493
|
+
},
|
|
494
|
+
source: {
|
|
495
|
+
code: zoomMagnificationTemplateSource,
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
render: () => ({
|
|
500
|
+
components: { UiButton },
|
|
501
|
+
setup() {
|
|
502
|
+
return { onClick };
|
|
503
|
+
},
|
|
504
|
+
template: `<UiButton @click="onClick">Save changes</UiButton>`,
|
|
505
|
+
}),
|
|
506
|
+
play: async ({ canvasElement, step }) => {
|
|
507
|
+
// Scenario: at 200% page zoom the button stays visible, keeps its
|
|
508
|
+
// accessible name, and remains clickable.
|
|
509
|
+
onClick.mockClear();
|
|
510
|
+
const canvas = within(canvasElement);
|
|
511
|
+
const button = canvas.getByRole('button', { name: 'Save changes' });
|
|
512
|
+
|
|
513
|
+
await step(
|
|
514
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
515
|
+
async () => {
|
|
516
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
517
|
+
},
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
await step(
|
|
521
|
+
'zoom: button stays visible with its accessible name',
|
|
522
|
+
async () => {
|
|
523
|
+
await expect(button).toBeVisible();
|
|
524
|
+
await expect(button).toHaveAccessibleName('Save changes');
|
|
525
|
+
},
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
await step('zoom: remains operable when magnified', async () => {
|
|
529
|
+
await userEvent.click(button);
|
|
530
|
+
await expect(onClick).toHaveBeenCalledTimes(1);
|
|
531
|
+
});
|
|
532
|
+
},
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const screenReaderTemplateSource = `<script setup lang="ts">
|
|
536
|
+
import { ref } from 'vue'
|
|
537
|
+
import { UiButton, UiIcon } from '@aleph-alpha/ui-library'
|
|
538
|
+
|
|
539
|
+
const muted = ref(false)
|
|
540
|
+
</script>
|
|
541
|
+
|
|
542
|
+
<template>
|
|
543
|
+
<div class="flex gap-2">
|
|
544
|
+
<UiButton aria-label="Search" size="icon-sm">
|
|
545
|
+
<UiIcon name="chevron-right" :size="16" />
|
|
546
|
+
</UiButton>
|
|
547
|
+
<UiButton :aria-pressed="muted ? 'true' : 'false'" @click="muted = !muted">
|
|
548
|
+
Mute
|
|
549
|
+
</UiButton>
|
|
550
|
+
</div>
|
|
551
|
+
</template>`;
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Screen-reader semantics: every control exposes a role and name, icon-only
|
|
555
|
+
* buttons carry a non-visual label, and toggle state is announced via
|
|
556
|
+
* aria-pressed (WCAG 4.1.2).
|
|
557
|
+
*/
|
|
558
|
+
export const ScreenReader: Story = {
|
|
559
|
+
name: 'test - Screen Reader',
|
|
560
|
+
tags: ['!dev', '!autodocs'],
|
|
561
|
+
parameters: {
|
|
562
|
+
// The toggle changes aria-pressed during the play function.
|
|
563
|
+
chromatic: { disableSnapshot: true },
|
|
564
|
+
docs: {
|
|
565
|
+
description: {
|
|
566
|
+
story:
|
|
567
|
+
'Verifies the roles, names, and state that assistive technology announces.',
|
|
568
|
+
},
|
|
569
|
+
source: {
|
|
570
|
+
code: screenReaderTemplateSource,
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
render: () => ({
|
|
575
|
+
components: { UiButton, UiIcon },
|
|
576
|
+
setup() {
|
|
577
|
+
const muted = ref(false);
|
|
578
|
+
const toggle = () => {
|
|
579
|
+
muted.value = !muted.value;
|
|
580
|
+
};
|
|
581
|
+
return { muted, toggle };
|
|
582
|
+
},
|
|
583
|
+
template: `
|
|
584
|
+
<div class="flex gap-2">
|
|
585
|
+
<UiButton aria-label="Search" size="icon-sm">
|
|
586
|
+
<UiIcon name="chevron-right" :size="16" />
|
|
587
|
+
</UiButton>
|
|
588
|
+
<UiButton :aria-pressed="muted ? 'true' : 'false'" @click="toggle">Mute</UiButton>
|
|
589
|
+
</div>
|
|
590
|
+
`,
|
|
591
|
+
}),
|
|
592
|
+
play: async ({ canvasElement, step }) => {
|
|
593
|
+
// Scenario: assistive tech reads each control's role and name, and hears the
|
|
594
|
+
// toggle's pressed state change via aria-pressed.
|
|
595
|
+
const canvas = within(canvasElement);
|
|
596
|
+
const toggle = canvas.getByRole('button', { name: 'Mute' });
|
|
597
|
+
|
|
598
|
+
await step(
|
|
599
|
+
'screen-reader: exposes a button role with an accessible name',
|
|
600
|
+
async () => {
|
|
601
|
+
await expect(toggle).toHaveAccessibleName('Mute');
|
|
602
|
+
},
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
await step(
|
|
606
|
+
'screen-reader: icon-only control is labelled via aria-label',
|
|
607
|
+
async () => {
|
|
608
|
+
const iconButton = canvas.getByRole('button', { name: 'Search' });
|
|
609
|
+
await expect(iconButton).toHaveAccessibleName('Search');
|
|
610
|
+
},
|
|
611
|
+
);
|
|
612
|
+
|
|
613
|
+
await step(
|
|
614
|
+
'screen-reader: toggle state is announced via aria-pressed (WCAG 4.1.2)',
|
|
615
|
+
async () => {
|
|
616
|
+
await expect(toggle).toHaveAttribute('aria-pressed', 'false');
|
|
617
|
+
await userEvent.click(toggle);
|
|
618
|
+
await expect(toggle).toHaveAttribute('aria-pressed', 'true');
|
|
619
|
+
},
|
|
620
|
+
);
|
|
621
|
+
},
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const mobileBreakpointTemplateSource = `<script setup lang="ts">
|
|
625
|
+
import { UiButton } from '@aleph-alpha/ui-library'
|
|
626
|
+
</script>
|
|
627
|
+
|
|
628
|
+
<template>
|
|
629
|
+
<UiButton>Continue</UiButton>
|
|
630
|
+
</template>`;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
634
|
+
* toolbar. Stays operable and meets the minimum touch-target size (WCAG 2.5.8).
|
|
635
|
+
*/
|
|
636
|
+
export const MobileBreakpoint: Story = {
|
|
637
|
+
name: 'test - Mobile Breakpoint',
|
|
638
|
+
tags: ['!dev', '!autodocs'],
|
|
639
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
640
|
+
parameters: {
|
|
641
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
642
|
+
chromatic: { disableSnapshot: true },
|
|
643
|
+
docs: {
|
|
644
|
+
description: {
|
|
645
|
+
story:
|
|
646
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
647
|
+
},
|
|
648
|
+
source: {
|
|
649
|
+
code: mobileBreakpointTemplateSource,
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
render: () => ({
|
|
654
|
+
components: { UiButton },
|
|
655
|
+
setup() {
|
|
656
|
+
return { onClick };
|
|
657
|
+
},
|
|
658
|
+
template: `<UiButton @click="onClick">Continue</UiButton>`,
|
|
659
|
+
}),
|
|
660
|
+
play: async ({ canvasElement, step }) => {
|
|
661
|
+
// Scenario: at the 320px mobile breakpoint the button stays operable and
|
|
662
|
+
// meets the minimum touch-target size.
|
|
663
|
+
onClick.mockClear();
|
|
664
|
+
const canvas = within(canvasElement);
|
|
665
|
+
const button = canvas.getByRole('button', { name: 'Continue' });
|
|
666
|
+
|
|
667
|
+
await step(
|
|
668
|
+
'mobile: renders and stays operable at the 320px breakpoint',
|
|
669
|
+
async () => {
|
|
670
|
+
await expect(button).toBeVisible();
|
|
671
|
+
await userEvent.click(button);
|
|
672
|
+
await expect(onClick).toHaveBeenCalledTimes(1);
|
|
673
|
+
},
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
await step(
|
|
677
|
+
'mobile: meets the minimum touch-target size (WCAG 2.5.8)',
|
|
678
|
+
async () => {
|
|
679
|
+
const { width, height } = button.getBoundingClientRect();
|
|
680
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
681
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
682
|
+
},
|
|
683
|
+
);
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
|
|
294
687
|
const outlineTemplateSource = `<script setup lang="ts">
|
|
295
688
|
import { UiButton } from '@aleph-alpha/ui-library'
|
|
296
689
|
</script>
|
|
@@ -508,7 +901,7 @@ export const IconUsage: Story = {
|
|
|
508
901
|
render: () => ({
|
|
509
902
|
components: { UiButton, UiIcon },
|
|
510
903
|
setup() {
|
|
511
|
-
return { ChevronLeftIcon, ChevronRightIcon };
|
|
904
|
+
return { ChevronLeftIcon, ChevronRightIcon, onClick };
|
|
512
905
|
},
|
|
513
906
|
template: `
|
|
514
907
|
<section class="flex flex-col gap-6 rounded-lg bg-background-surface-primary p-4">
|
|
@@ -541,7 +934,7 @@ export const IconUsage: Story = {
|
|
|
541
934
|
<div class="flex flex-col gap-3">
|
|
542
935
|
<h3 class="label-14-medium text-center text-content-on-surface-primary">Icon only</h3>
|
|
543
936
|
<div class="flex min-h-20 items-center justify-center rounded-sm bg-background-surface-muted-subtle p-6">
|
|
544
|
-
<UiButton size="icon-sm" aria-label="Go back">
|
|
937
|
+
<UiButton size="icon-sm" aria-label="Go back" @click="onClick">
|
|
545
938
|
<UiIcon name="chevron-left" :size="16" />
|
|
546
939
|
</UiButton>
|
|
547
940
|
</div>
|
|
@@ -557,6 +950,25 @@ export const IconUsage: Story = {
|
|
|
557
950
|
},
|
|
558
951
|
},
|
|
559
952
|
},
|
|
953
|
+
play: async ({ canvasElement, step }) => {
|
|
954
|
+
// Scenario: an icon-only button exposes an accessible name via aria-label
|
|
955
|
+
// and still responds to clicks.
|
|
956
|
+
onClick.mockClear();
|
|
957
|
+
const canvas = within(canvasElement);
|
|
958
|
+
const button = canvas.getByRole('button', { name: 'Go back' });
|
|
959
|
+
|
|
960
|
+
await step(
|
|
961
|
+
'interaction: icon-only button exposes an accessible name via aria-label (WCAG 1.1.1 / 4.1.2)',
|
|
962
|
+
async () => {
|
|
963
|
+
await expect(button).toHaveAccessibleName('Go back');
|
|
964
|
+
},
|
|
965
|
+
);
|
|
966
|
+
|
|
967
|
+
await step('interaction: remains an operable button on click', async () => {
|
|
968
|
+
await userEvent.click(button);
|
|
969
|
+
await expect(onClick).toHaveBeenCalledTimes(1);
|
|
970
|
+
});
|
|
971
|
+
},
|
|
560
972
|
};
|
|
561
973
|
|
|
562
974
|
const loadingTemplateSource = `<script setup lang="ts">
|
|
@@ -579,9 +991,9 @@ export const Loading: Story = {
|
|
|
579
991
|
render: () => ({
|
|
580
992
|
components: { UiButton },
|
|
581
993
|
setup() {
|
|
582
|
-
return { MailIcon };
|
|
994
|
+
return { MailIcon, onClick };
|
|
583
995
|
},
|
|
584
|
-
template: `<UiButton :loading="true" :start-icon="MailIcon">Please wait</UiButton>`,
|
|
996
|
+
template: `<UiButton :loading="true" :start-icon="MailIcon" @click="onClick">Please wait</UiButton>`,
|
|
585
997
|
}),
|
|
586
998
|
parameters: {
|
|
587
999
|
docs: {
|
|
@@ -590,6 +1002,39 @@ export const Loading: Story = {
|
|
|
590
1002
|
},
|
|
591
1003
|
},
|
|
592
1004
|
},
|
|
1005
|
+
play: async ({ canvasElement, step }) => {
|
|
1006
|
+
// Scenario: while loading, the button announces aria-busy, shows a labelled
|
|
1007
|
+
// spinner, drops out of the tab order, and ignores forced clicks.
|
|
1008
|
+
onClick.mockClear();
|
|
1009
|
+
const canvas = within(canvasElement);
|
|
1010
|
+
const button = canvas.getByRole('button');
|
|
1011
|
+
|
|
1012
|
+
await step(
|
|
1013
|
+
'interaction: announces the busy state via aria-busy',
|
|
1014
|
+
async () => {
|
|
1015
|
+
await expect(button).toHaveAttribute('aria-busy', 'true');
|
|
1016
|
+
},
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
await step('interaction: spinner exposes an accessible name', async () => {
|
|
1020
|
+
await expect(canvas.getByLabelText('Loading')).toBeInTheDocument();
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
await step(
|
|
1024
|
+
'interaction: stays disabled and out of the tab order (WCAG 4.1.2)',
|
|
1025
|
+
async () => {
|
|
1026
|
+
await expect(button).toBeDisabled();
|
|
1027
|
+
await expect(button).not.toHaveFocus();
|
|
1028
|
+
await userEvent.tab();
|
|
1029
|
+
await expect(button).not.toHaveFocus();
|
|
1030
|
+
},
|
|
1031
|
+
);
|
|
1032
|
+
|
|
1033
|
+
await step('interaction: ignores forced clicks while loading', async () => {
|
|
1034
|
+
await userEvent.click(button, { pointerEventsCheck: 0 });
|
|
1035
|
+
await expect(onClick).not.toHaveBeenCalled();
|
|
1036
|
+
});
|
|
1037
|
+
},
|
|
593
1038
|
};
|
|
594
1039
|
|
|
595
1040
|
const loadingWithBothIconsTemplateSource = `<script setup lang="ts">
|
|
@@ -662,6 +1107,33 @@ export const AsChild: Story = {
|
|
|
662
1107
|
},
|
|
663
1108
|
},
|
|
664
1109
|
},
|
|
1110
|
+
play: async ({ canvasElement, step }) => {
|
|
1111
|
+
// Scenario: rendered as a link via asChild, it exposes the link role and
|
|
1112
|
+
// href and does not expose a redundant button role.
|
|
1113
|
+
const canvas = within(canvasElement);
|
|
1114
|
+
const link = canvas.getByRole('link', { name: 'Login' });
|
|
1115
|
+
|
|
1116
|
+
await step(
|
|
1117
|
+
'interaction: exposes a link role with the child accessible name (WCAG 4.1.2)',
|
|
1118
|
+
async () => {
|
|
1119
|
+
await expect(link).toHaveAccessibleName('Login');
|
|
1120
|
+
},
|
|
1121
|
+
);
|
|
1122
|
+
|
|
1123
|
+
await step(
|
|
1124
|
+
'interaction: preserves the link destination (href)',
|
|
1125
|
+
async () => {
|
|
1126
|
+
await expect(link).toHaveAttribute('href', '/login');
|
|
1127
|
+
},
|
|
1128
|
+
);
|
|
1129
|
+
|
|
1130
|
+
await step(
|
|
1131
|
+
'interaction: does not expose a redundant button role',
|
|
1132
|
+
async () => {
|
|
1133
|
+
await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
|
|
1134
|
+
},
|
|
1135
|
+
);
|
|
1136
|
+
},
|
|
665
1137
|
};
|
|
666
1138
|
|
|
667
1139
|
const allVariantsTemplateSource = `<script setup lang="ts">
|
|
@@ -705,50 +1177,39 @@ export const AllVariants: Story = {
|
|
|
705
1177
|
},
|
|
706
1178
|
};
|
|
707
1179
|
|
|
708
|
-
const
|
|
1180
|
+
const disabledTemplateSource = `<script setup lang="ts">
|
|
709
1181
|
import { UiButton } from '@aleph-alpha/ui-library'
|
|
710
1182
|
</script>
|
|
711
1183
|
|
|
712
1184
|
<template>
|
|
713
|
-
<div class="flex flex-
|
|
714
|
-
<
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
</
|
|
718
|
-
<
|
|
719
|
-
|
|
720
|
-
</div>
|
|
721
|
-
<div class="w-96 border border-dashed border-border-surface-default p-6">
|
|
722
|
-
<UiButton variant="secondary" disabled>Disabled secondary</UiButton>
|
|
723
|
-
</div>
|
|
724
|
-
<div class="w-96 border border-dashed border-border-surface-default p-6">
|
|
725
|
-
<UiButton variant="destructive" disabled>Disabled destructive</UiButton>
|
|
726
|
-
</div>
|
|
1185
|
+
<div class="flex flex-wrap gap-2">
|
|
1186
|
+
<UiButton disabled>Default</UiButton>
|
|
1187
|
+
<UiButton variant="secondary" disabled>Secondary</UiButton>
|
|
1188
|
+
<UiButton variant="destructive" disabled>Destructive</UiButton>
|
|
1189
|
+
<UiButton variant="outline" disabled>Outline</UiButton>
|
|
1190
|
+
<UiButton variant="ghost" disabled>Ghost</UiButton>
|
|
1191
|
+
<UiButton variant="link" disabled>Link</UiButton>
|
|
727
1192
|
</div>
|
|
728
1193
|
</template>`;
|
|
729
1194
|
|
|
730
1195
|
/**
|
|
731
|
-
*
|
|
732
|
-
*
|
|
1196
|
+
* Disabled buttons across every variant. A disabled button is non-interactive:
|
|
1197
|
+
* it is removed from the tab order and never fires its click handler.
|
|
733
1198
|
*/
|
|
734
|
-
export const
|
|
1199
|
+
export const Disabled: Story = {
|
|
735
1200
|
render: () => ({
|
|
736
1201
|
components: { UiButton },
|
|
1202
|
+
setup() {
|
|
1203
|
+
return { onClick };
|
|
1204
|
+
},
|
|
737
1205
|
template: `
|
|
738
|
-
<div class="flex flex-
|
|
739
|
-
<
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
</
|
|
743
|
-
<
|
|
744
|
-
|
|
745
|
-
</div>
|
|
746
|
-
<div class="w-96 border border-dashed border-border-surface-default p-6">
|
|
747
|
-
<UiButton variant="secondary" disabled>Disabled secondary</UiButton>
|
|
748
|
-
</div>
|
|
749
|
-
<div class="w-96 border border-dashed border-border-surface-default p-6">
|
|
750
|
-
<UiButton variant="destructive" disabled>Disabled destructive</UiButton>
|
|
751
|
-
</div>
|
|
1206
|
+
<div class="flex flex-wrap gap-2">
|
|
1207
|
+
<UiButton disabled @click="onClick">Default</UiButton>
|
|
1208
|
+
<UiButton variant="secondary" disabled>Secondary</UiButton>
|
|
1209
|
+
<UiButton variant="destructive" disabled>Destructive</UiButton>
|
|
1210
|
+
<UiButton variant="outline" disabled>Outline</UiButton>
|
|
1211
|
+
<UiButton variant="ghost" disabled>Ghost</UiButton>
|
|
1212
|
+
<UiButton variant="link" disabled>Link</UiButton>
|
|
752
1213
|
</div>
|
|
753
1214
|
`,
|
|
754
1215
|
}),
|
|
@@ -756,13 +1217,40 @@ export const DisabledHoverBleed: Story = {
|
|
|
756
1217
|
docs: {
|
|
757
1218
|
description: {
|
|
758
1219
|
story:
|
|
759
|
-
'
|
|
1220
|
+
'Disabled state shown across all variants. Disabled buttons are skipped by keyboard navigation and do not respond to clicks.',
|
|
760
1221
|
},
|
|
761
1222
|
source: {
|
|
762
|
-
code:
|
|
1223
|
+
code: disabledTemplateSource,
|
|
763
1224
|
},
|
|
764
1225
|
},
|
|
765
1226
|
},
|
|
1227
|
+
play: async ({ canvasElement, step }) => {
|
|
1228
|
+
// Scenario: a disabled button reports its disabled state, is skipped by Tab,
|
|
1229
|
+
// and ignores forced clicks.
|
|
1230
|
+
onClick.mockClear();
|
|
1231
|
+
const canvas = within(canvasElement);
|
|
1232
|
+
const button = canvas.getByRole('button', { name: 'Default' });
|
|
1233
|
+
|
|
1234
|
+
await step(
|
|
1235
|
+
'interaction: exposes the disabled state (WCAG 4.1.2)',
|
|
1236
|
+
async () => {
|
|
1237
|
+
await expect(button).toBeDisabled();
|
|
1238
|
+
},
|
|
1239
|
+
);
|
|
1240
|
+
|
|
1241
|
+
await step(
|
|
1242
|
+
'keyboard: removed from the tab order — not reachable via Tab (WCAG 2.1.1)',
|
|
1243
|
+
async () => {
|
|
1244
|
+
await userEvent.tab();
|
|
1245
|
+
await expect(button).not.toHaveFocus();
|
|
1246
|
+
},
|
|
1247
|
+
);
|
|
1248
|
+
|
|
1249
|
+
await step('interaction: ignores forced clicks', async () => {
|
|
1250
|
+
await userEvent.click(button, { pointerEventsCheck: 0 });
|
|
1251
|
+
await expect(onClick).not.toHaveBeenCalled();
|
|
1252
|
+
});
|
|
1253
|
+
},
|
|
766
1254
|
};
|
|
767
1255
|
|
|
768
1256
|
type MatrixVariant =
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import type { Component } from 'vue';
|
|
2
3
|
import { cn } from '@/lib/utils';
|
|
3
4
|
|
|
5
|
+
type Tag = keyof HTMLElementTagNameMap | (string & {}) | Component;
|
|
6
|
+
|
|
4
7
|
defineOptions({ inheritAttrs: false });
|
|
8
|
+
|
|
9
|
+
withDefaults(
|
|
10
|
+
defineProps<{
|
|
11
|
+
/**
|
|
12
|
+
* The tag or component to render as the root element.
|
|
13
|
+
* Defaults to `main`. Use a different tag (e.g. `div` or `section`) when
|
|
14
|
+
* rendering multiple insets on a single page to avoid duplicate `main`
|
|
15
|
+
* landmarks.
|
|
16
|
+
*/
|
|
17
|
+
as?: Tag;
|
|
18
|
+
}>(),
|
|
19
|
+
{ as: 'main' },
|
|
20
|
+
);
|
|
5
21
|
</script>
|
|
6
22
|
|
|
7
23
|
<template>
|
|
8
|
-
<
|
|
24
|
+
<component
|
|
25
|
+
:is="as"
|
|
9
26
|
v-bind="$attrs"
|
|
10
27
|
data-slot="sidebar-inset"
|
|
11
28
|
:class="
|
|
@@ -17,7 +34,7 @@ defineOptions({ inheritAttrs: false });
|
|
|
17
34
|
"
|
|
18
35
|
>
|
|
19
36
|
<slot />
|
|
20
|
-
</
|
|
37
|
+
</component>
|
|
21
38
|
</template>
|
|
22
39
|
|
|
23
40
|
<style scoped>
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { UiButton } from '@/components/UiButton';
|
|
3
|
+
import { UiIcon } from '@/components/UiIcon';
|
|
4
|
+
import { useSidebar } from '@/components/core/sidebar';
|
|
5
|
+
import UiSidebar from './UiSidebar.vue';
|
|
6
|
+
import UiSidebarContent from './UiSidebarContent.vue';
|
|
7
|
+
import UiSidebarHeader from './UiSidebarHeader.vue';
|
|
8
|
+
import UiSidebarInset from './UiSidebarInset.vue';
|
|
9
|
+
import UiSidebarMenu from './UiSidebarMenu.vue';
|
|
10
|
+
import UiSidebarMenuButton from './UiSidebarMenuButton.vue';
|
|
11
|
+
import UiSidebarMenuItem from './UiSidebarMenuItem.vue';
|
|
12
|
+
import UiSidebarProvider from './UiSidebarProvider.vue';
|
|
13
|
+
|
|
14
|
+
const meta: Meta<typeof UiSidebarInset> = {
|
|
15
|
+
title: 'Patterns/UiSidebar/UiSidebarInset',
|
|
16
|
+
component: UiSidebarInset,
|
|
17
|
+
tags: ['autodocs'],
|
|
18
|
+
parameters: {
|
|
19
|
+
layout: 'fullscreen',
|
|
20
|
+
docs: {
|
|
21
|
+
description: {
|
|
22
|
+
component:
|
|
23
|
+
'The main content column that peers with `UiSidebar` inside a `UiSidebarProvider`. Renders as a `<main>` landmark by default. Use the `as` prop to render a different tag (e.g. `div`, `section`) or a Vue component — this is required when a page contains more than one inset so there is only a single `<main>` landmark for accessibility.',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
argTypes: {
|
|
28
|
+
as: {
|
|
29
|
+
control: 'text',
|
|
30
|
+
description:
|
|
31
|
+
'The tag or component to render as the root element. Defaults to `main`. Use a different tag when rendering multiple insets on a single page to avoid duplicate `main` landmarks.',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default meta;
|
|
37
|
+
|
|
38
|
+
type Story = StoryObj<typeof UiSidebarInset>;
|
|
39
|
+
|
|
40
|
+
const NAV_ITEMS = [
|
|
41
|
+
{ title: 'Home', icon: 'home' },
|
|
42
|
+
{ title: 'Collections', icon: 'folder' },
|
|
43
|
+
{ title: 'Chat', icon: 'message-square' },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A toggle button that opens/closes the nearest sidebar via `useSidebar()`.
|
|
48
|
+
* `toggleSidebar` collapses/expands on desktop and opens/closes the sheet on
|
|
49
|
+
* mobile; the label reflects the current desktop state.
|
|
50
|
+
*/
|
|
51
|
+
const SidebarToggle = {
|
|
52
|
+
name: 'SidebarToggle',
|
|
53
|
+
components: { UiButton, UiIcon },
|
|
54
|
+
props: {
|
|
55
|
+
name: { type: String, default: 'sidebar' },
|
|
56
|
+
},
|
|
57
|
+
setup() {
|
|
58
|
+
const { toggleSidebar, state } = useSidebar();
|
|
59
|
+
return { toggleSidebar, state };
|
|
60
|
+
},
|
|
61
|
+
template: `
|
|
62
|
+
<UiButton
|
|
63
|
+
variant="outline"
|
|
64
|
+
size="sm"
|
|
65
|
+
:aria-label="(state === 'expanded' ? 'Collapse ' : 'Expand ') + name"
|
|
66
|
+
@click="toggleSidebar"
|
|
67
|
+
>
|
|
68
|
+
<UiIcon name="panel-left" size="s" />
|
|
69
|
+
{{ state === 'expanded' ? 'Collapse' : 'Expand' }} {{ name }}
|
|
70
|
+
</UiButton>
|
|
71
|
+
`,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const sharedComponents = {
|
|
75
|
+
SidebarToggle,
|
|
76
|
+
UiButton,
|
|
77
|
+
UiIcon,
|
|
78
|
+
UiSidebar,
|
|
79
|
+
UiSidebarContent,
|
|
80
|
+
UiSidebarHeader,
|
|
81
|
+
UiSidebarInset,
|
|
82
|
+
UiSidebarMenu,
|
|
83
|
+
UiSidebarMenuButton,
|
|
84
|
+
UiSidebarMenuItem,
|
|
85
|
+
UiSidebarProvider,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const insetBody = (title: string) => `
|
|
89
|
+
<header class="flex h-14 items-center gap-3 border-b border-border-surface-default px-4">
|
|
90
|
+
<SidebarToggle name="sidebar" />
|
|
91
|
+
<span class="body-14-regular text-content-on-surface-primary">${title}</span>
|
|
92
|
+
</header>
|
|
93
|
+
<div class="flex min-h-[320px] flex-1 p-4">
|
|
94
|
+
<div class="w-full rounded-md border border-border-surface-default bg-background-surface-primary p-6">
|
|
95
|
+
<div class="heading-s mb-2 text-content-on-surface-primary">${title}</div>
|
|
96
|
+
<div class="body-14-regular text-content-on-surface-muted">
|
|
97
|
+
Content rendered inside the sidebar inset.
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
const navMarkup = (header: string) => `
|
|
104
|
+
<UiSidebarHeader tooltip="${header}" aria-label="${header}">${header}</UiSidebarHeader>
|
|
105
|
+
<UiSidebarContent>
|
|
106
|
+
<UiSidebarMenu class="px-2 pt-1">
|
|
107
|
+
<UiSidebarMenuItem v-for="item in navItems" :key="item.title">
|
|
108
|
+
<UiSidebarMenuButton :tooltip="item.title" :aria-label="item.title">
|
|
109
|
+
<template #start-icon>
|
|
110
|
+
<UiIcon :name="item.icon" size="s" />
|
|
111
|
+
</template>
|
|
112
|
+
{{ item.title }}
|
|
113
|
+
</UiSidebarMenuButton>
|
|
114
|
+
</UiSidebarMenuItem>
|
|
115
|
+
</UiSidebarMenu>
|
|
116
|
+
</UiSidebarContent>
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A single `UiSidebarProvider` with a `UiSidebar` and a `UiSidebarInset`
|
|
121
|
+
* rendered with its default `as` value, so the content column is a `<main>`
|
|
122
|
+
* landmark.
|
|
123
|
+
*/
|
|
124
|
+
export const Default: Story = {
|
|
125
|
+
render: () => ({
|
|
126
|
+
components: sharedComponents,
|
|
127
|
+
setup() {
|
|
128
|
+
return { navItems: NAV_ITEMS };
|
|
129
|
+
},
|
|
130
|
+
template: `
|
|
131
|
+
<UiSidebarProvider :default-open="true">
|
|
132
|
+
<UiSidebar collapsible="icon">
|
|
133
|
+
${navMarkup('Assistant')}
|
|
134
|
+
</UiSidebar>
|
|
135
|
+
|
|
136
|
+
<UiSidebarInset>
|
|
137
|
+
${insetBody('Main content (<main>)')}
|
|
138
|
+
</UiSidebarInset>
|
|
139
|
+
</UiSidebarProvider>
|
|
140
|
+
`,
|
|
141
|
+
}),
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Passing `as="div"` renders the inset root as a `<div>` instead of `<main>`.
|
|
146
|
+
* Useful when the `<main>` landmark is owned by an ancestor.
|
|
147
|
+
*/
|
|
148
|
+
export const CustomTag: Story = {
|
|
149
|
+
render: () => ({
|
|
150
|
+
components: sharedComponents,
|
|
151
|
+
setup() {
|
|
152
|
+
return { navItems: NAV_ITEMS };
|
|
153
|
+
},
|
|
154
|
+
template: `
|
|
155
|
+
<UiSidebarProvider :default-open="true">
|
|
156
|
+
<UiSidebar collapsible="icon">
|
|
157
|
+
${navMarkup('Assistant')}
|
|
158
|
+
</UiSidebar>
|
|
159
|
+
|
|
160
|
+
<UiSidebarInset as="div">
|
|
161
|
+
${insetBody('Custom tag (<div>)')}
|
|
162
|
+
</UiSidebarInset>
|
|
163
|
+
</UiSidebarProvider>
|
|
164
|
+
`,
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const PanelSection = {
|
|
169
|
+
name: 'PanelSection',
|
|
170
|
+
template: `
|
|
171
|
+
<section aria-label="Panel section">
|
|
172
|
+
<slot />
|
|
173
|
+
</section>
|
|
174
|
+
`,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The `as` prop also accepts a Vue component. Here the inset renders as a custom
|
|
179
|
+
* `PanelSection` component, which receives the inset's `data-slot`, classes, and
|
|
180
|
+
* slot content on its root element.
|
|
181
|
+
*/
|
|
182
|
+
export const CustomComponent: Story = {
|
|
183
|
+
render: () => ({
|
|
184
|
+
components: { ...sharedComponents, PanelSection },
|
|
185
|
+
setup() {
|
|
186
|
+
return { navItems: NAV_ITEMS, PanelSection };
|
|
187
|
+
},
|
|
188
|
+
template: `
|
|
189
|
+
<UiSidebarProvider :default-open="true">
|
|
190
|
+
<UiSidebar collapsible="icon">
|
|
191
|
+
${navMarkup('Assistant')}
|
|
192
|
+
</UiSidebar>
|
|
193
|
+
|
|
194
|
+
<UiSidebarInset :as="PanelSection">
|
|
195
|
+
${insetBody('Custom component (<PanelSection>)')}
|
|
196
|
+
</UiSidebarInset>
|
|
197
|
+
</UiSidebarProvider>
|
|
198
|
+
`,
|
|
199
|
+
}),
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Two sidebars on one page: an inner right sidebar nested inside the left
|
|
204
|
+
* sidebar's inset. The outer inset keeps the single `<main>` landmark, while the
|
|
205
|
+
* inner inset renders as a `<div>` (`as="div"`) so the page does not end up with
|
|
206
|
+
* duplicate `<main>` landmarks — keeping the layout accessible.
|
|
207
|
+
*/
|
|
208
|
+
export const NestedSidebars: Story = {
|
|
209
|
+
parameters: {
|
|
210
|
+
docs: {
|
|
211
|
+
description: {
|
|
212
|
+
story:
|
|
213
|
+
'A right sidebar nested inside the left sidebar’s inset. The outer inset is the sole `<main>` landmark; the inner inset uses `as="div"` to avoid a second `<main>`, so accessibility (landmark uniqueness) is preserved.',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
render: () => ({
|
|
218
|
+
components: sharedComponents,
|
|
219
|
+
setup() {
|
|
220
|
+
return { navItems: NAV_ITEMS };
|
|
221
|
+
},
|
|
222
|
+
template: `
|
|
223
|
+
<UiSidebarProvider :default-open="true">
|
|
224
|
+
<UiSidebar side="left" collapsible="icon">
|
|
225
|
+
${navMarkup('Primary')}
|
|
226
|
+
</UiSidebar>
|
|
227
|
+
|
|
228
|
+
<UiSidebarInset>
|
|
229
|
+
<header class="flex h-14 items-center gap-3 border-b border-border-surface-default px-4">
|
|
230
|
+
<SidebarToggle name="left sidebar" />
|
|
231
|
+
<span class="body-14-regular text-content-on-surface-primary">Outer inset (<main>)</span>
|
|
232
|
+
</header>
|
|
233
|
+
|
|
234
|
+
<UiSidebarProvider :default-open="true">
|
|
235
|
+
<UiSidebar side="right" collapsible="icon">
|
|
236
|
+
${navMarkup('Secondary')}
|
|
237
|
+
</UiSidebar>
|
|
238
|
+
|
|
239
|
+
<UiSidebarInset as="div">
|
|
240
|
+
<header class="flex h-14 items-center gap-3 border-b border-border-surface-default px-4">
|
|
241
|
+
<SidebarToggle name="right sidebar" />
|
|
242
|
+
<span class="body-14-regular text-content-on-surface-primary">Inner inset (<div>)</span>
|
|
243
|
+
</header>
|
|
244
|
+
<div class="flex min-h-[320px] flex-1 p-4">
|
|
245
|
+
<div class="w-full rounded-md border border-border-surface-default bg-background-surface-primary p-6">
|
|
246
|
+
<div class="heading-s mb-2 text-content-on-surface-primary">Nested content</div>
|
|
247
|
+
<div class="body-14-regular text-content-on-surface-muted">
|
|
248
|
+
The inner inset is rendered as a <div> so the page keeps a single <main> landmark.
|
|
249
|
+
Use the toggles above to open and close each sidebar.
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
</UiSidebarInset>
|
|
254
|
+
</UiSidebarProvider>
|
|
255
|
+
</UiSidebarInset>
|
|
256
|
+
</UiSidebarProvider>
|
|
257
|
+
`,
|
|
258
|
+
}),
|
|
259
|
+
};
|
|
@@ -33,4 +33,24 @@ describe('UiSidebarInset', () => {
|
|
|
33
33
|
expect(container.querySelector('[data-slot="sidebar-inset"]')).toBeTruthy();
|
|
34
34
|
expect(container).toHaveTextContent('Main');
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
test('renders a main tag by default', () => {
|
|
38
|
+
const { container } = render(UiSidebarInset, {
|
|
39
|
+
slots: { default: 'Main' },
|
|
40
|
+
});
|
|
41
|
+
expect(
|
|
42
|
+
container.querySelector('main[data-slot="sidebar-inset"]'),
|
|
43
|
+
).toBeTruthy();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('renders a custom tag when the "as" prop is provided', () => {
|
|
47
|
+
const { container } = render(UiSidebarInset, {
|
|
48
|
+
props: { as: 'div' },
|
|
49
|
+
slots: { default: 'Main' },
|
|
50
|
+
});
|
|
51
|
+
expect(container.querySelector('main')).toBeFalsy();
|
|
52
|
+
expect(
|
|
53
|
+
container.querySelector('div[data-slot="sidebar-inset"]'),
|
|
54
|
+
).toBeTruthy();
|
|
55
|
+
});
|
|
36
56
|
});
|