@aleph-alpha/ui-library 5.0.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.
@@ -205,6 +205,7 @@ const renderStory = (args: Story['args']) => ({
205
205
  <UiSidebarMenuItem v-for="item in primaryItems" :key="item.title">
206
206
  <UiSidebarMenuButton
207
207
  :tooltip="item.title"
208
+ :aria-label="item.title"
208
209
  :is-active="isMenuActive(item.title)"
209
210
  @click="selectMenu(item)"
210
211
  >
@@ -230,6 +231,7 @@ const renderStory = (args: Story['args']) => ({
230
231
  <UiSidebarMenuItem v-for="item in agentItems" :key="item.title">
231
232
  <UiSidebarMenuButton
232
233
  :tooltip="item.title"
234
+ :aria-label="item.title"
233
235
  :is-active="isMenuActive(item.title)"
234
236
  @click="selectMenu(item)"
235
237
  >
@@ -257,6 +259,7 @@ const renderStory = (args: Story['args']) => ({
257
259
  <UiSidebarMenuItem v-for="item in appItems" :key="item.title">
258
260
  <UiSidebarMenuButton
259
261
  :tooltip="item.title"
262
+ :aria-label="item.title"
260
263
  :is-active="isMenuActive(item.title)"
261
264
  @click="selectMenu(item)"
262
265
  >
@@ -274,7 +277,7 @@ const renderStory = (args: Story['args']) => ({
274
277
  <UiSidebarFooter>
275
278
  <Popover>
276
279
  <PopoverTrigger as-child>
277
- <UiSidebarMenuButton tooltip="Profile menu">
280
+ <UiSidebarMenuButton tooltip="Profile menu" aria-label="Profile menu">
278
281
  <template #start-icon>
279
282
  <div
280
283
  class="flex size-8 items-center justify-center overflow-hidden rounded-md bg-background-surface-muted body-14-regular text-content-on-surface-primary"
@@ -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 (&lt;main&gt;)')}
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 (&lt;div&gt;)')}
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 (&lt;PanelSection&gt;)')}
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 (&lt;main&gt;)</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 (&lt;div&gt;)</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 &lt;div&gt; so the page keeps a single &lt;main&gt; 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
  });
@@ -9,7 +9,7 @@ const ThemePlaceholder = defineComponent({
9
9
  });
10
10
 
11
11
  const meta: Meta<typeof ThemePlaceholder> = {
12
- title: 'CSS utility/Shadow',
12
+ title: 'CSS utility/Box shadow',
13
13
  component: ThemePlaceholder,
14
14
  tags: ['autodocs'],
15
15
  parameters: {
@@ -31,11 +31,23 @@ const copyScript = `
31
31
  }
32
32
  `;
33
33
 
34
+ const SHADOW_LEVELS = ['sm', 'md', 'lg', 'xl'] as const;
35
+
36
+ const shadowSwatch = (level: string) => `
37
+ <div class="flex flex-col items-center gap-2">
38
+ <div class="w-28 h-28 rounded-lg bg-background-surface-secondary border border-border-surface-default shadow-${level}"></div>
39
+ <div class="text-center max-w-[8rem]">
40
+ <span class="label-12-medium text-content-on-surface-primary block">${level}</span>
41
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded break-all" onclick="copyToClipboard('shadow-${level}', this)">shadow-${level}</code>
42
+ </div>
43
+ </div>
44
+ `;
45
+
34
46
  /**
35
- * Drop shadows aligned with design tokens under `global.shadow` in the token file.
36
- * Use UnoCSS utilities `shadow-sm` … `shadow-xl` (not token paths like `global.shadow.xl`).
47
+ * Box-shadow variants (`shadow-sm` … `shadow-xl`). Each variant is emitted as a
48
+ * `--shadow-*` CSS variable and powers the matching UnoCSS utility.
37
49
  */
38
- export const DropShadow: Story = {
50
+ export const BoxShadow: Story = {
39
51
  render: () => ({
40
52
  template: `
41
53
  <div class="p-8 bg-background-surface-secondary">
@@ -48,48 +60,15 @@ export const DropShadow: Story = {
48
60
  <script>${copyScript}</script>
49
61
 
50
62
  <div class="mb-6">
51
- <h2 class="heading-s text-content-on-surface-primary mb-1">Drop shadows</h2>
63
+ <h2 class="heading-s text-content-on-surface-primary mb-1">Box shadow</h2>
52
64
  <p class="body-14-regular text-content-on-surface-muted">
53
- Token group <code class="label-12-medium">global.shadow</code>. Click a utility class to copy.
65
+ Shadow variants <code class="label-12-medium">sm</code>–<code class="label-12-medium">xl</code>, emitted as
66
+ <code class="label-12-medium">--shadow-*</code> CSS variables. Click a utility class to copy.
54
67
  </p>
55
68
  </div>
56
69
 
57
70
  <div class="flex flex-wrap gap-8 items-end">
58
- <div class="flex flex-col items-center gap-2">
59
- <div class="w-28 h-28 rounded-lg bg-background-surface-primary border border-border-surface-default shadow-sm"></div>
60
- <div class="text-center max-w-[8rem]">
61
- <span class="label-12-medium text-content-on-surface-primary block">sm</span>
62
- <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded break-all" onclick="copyToClipboard('shadow-sm', this)">shadow-sm</code>
63
- <span class="label-12-regular text-content-on-surface-muted block mt-1">shadow-sm</span>
64
- </div>
65
- </div>
66
-
67
- <div class="flex flex-col items-center gap-2">
68
- <div class="w-28 h-28 rounded-lg bg-background-surface-primary border border-border-surface-default shadow-md"></div>
69
- <div class="text-center max-w-[8rem]">
70
- <span class="label-12-medium text-content-on-surface-primary block">md</span>
71
- <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded break-all" onclick="copyToClipboard('shadow-md', this)">shadow-md</code>
72
- <span class="label-12-regular text-content-on-surface-muted block mt-1">shadow-md</span>
73
- </div>
74
- </div>
75
-
76
- <div class="flex flex-col items-center gap-2">
77
- <div class="w-28 h-28 rounded-lg bg-background-surface-primary border border-border-surface-default shadow-lg"></div>
78
- <div class="text-center max-w-[8rem]">
79
- <span class="label-12-medium text-content-on-surface-primary block">lg</span>
80
- <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded break-all" onclick="copyToClipboard('shadow-lg', this)">shadow-lg</code>
81
- <span class="label-12-regular text-content-on-surface-muted block mt-1">shadow-lg</span>
82
- </div>
83
- </div>
84
-
85
- <div class="flex flex-col items-center gap-2">
86
- <div class="w-28 h-28 rounded-lg bg-background-surface-primary border border-border-surface-default shadow-xl"></div>
87
- <div class="text-center max-w-[8rem]">
88
- <span class="label-12-medium text-content-on-surface-primary block">xl</span>
89
- <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded break-all" onclick="copyToClipboard('shadow-xl', this)">shadow-xl</code>
90
- <span class="label-12-regular text-content-on-surface-muted block mt-1">shadow-xl</span>
91
- </div>
92
- </div>
71
+ ${SHADOW_LEVELS.map(shadowSwatch).join('')}
93
72
  </div>
94
73
  </div>
95
74
  `,