@aleph-alpha/ui-library 6.1.0 → 6.2.1
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/config.js +42 -0
- package/dist/system/components/UiCodeBlock/types.d.ts +11 -0
- package/dist/system/components/core/sidebar/utils.d.ts +9 -0
- package/dist/system/icons/story-sidebar-icons.json +1 -0
- package/dist/system/lib.js +4949 -4883
- package/dist/system/patterns/UiLayout/UiLayoutContent.vue.d.ts +39 -0
- package/dist/system/patterns/UiLayout/index.d.ts +2 -0
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +944 -0
- package/dist/system/patterns/UiLayout/types.d.ts +43 -0
- package/dist/system/patterns/index.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +1 -0
- package/package.json +5 -5
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +83 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +30 -2
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +21 -0
- package/src/components/UiCodeBlock/types.ts +11 -0
- package/src/components/core/sidebar/Sidebar.vue +21 -5
- package/src/components/core/sidebar/utils.ts +10 -0
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +1234 -0
- package/src/patterns/UiLayout/UiLayoutContent.vue +98 -0
- package/src/patterns/UiLayout/__tests__/UiLayoutContent.test.ts +97 -0
- package/src/patterns/UiLayout/index.ts +2 -0
- package/src/patterns/UiLayout/layout-shell.ts +64 -15
- package/src/patterns/UiLayout/types.ts +44 -0
- package/src/patterns/index.ts +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the content box is divided between the primary content and the sidebar
|
|
3
|
+
* when the `sidebar` slot is filled, in columns of the 12-column layout grid.
|
|
4
|
+
*/
|
|
5
|
+
export type UiLayoutContentSidebarMode = 'default' | 'wide' | 'max';
|
|
6
|
+
/**
|
|
7
|
+
* Container for the primary content area — the main part of an application
|
|
8
|
+
* layout. It renders the sheet surface (`background/surface/secondary`) and
|
|
9
|
+
* carries the design system's 48px margin on its left and right edges — 32px
|
|
10
|
+
* below the `desktop` breakpoint (1200px), toward the minimum desktop size of
|
|
11
|
+
* 1024px — so pages start from the same inset instead of each carrying its
|
|
12
|
+
* own spacing. Divide the space inside it with a 12-column grid and 24px
|
|
13
|
+
* gutters.
|
|
14
|
+
*
|
|
15
|
+
* Slots: `default` for the page content; `split` for a split view — a border
|
|
16
|
+
* divides the content box into two equal parts, each keeping a 28px margin
|
|
17
|
+
* from the divider and a 6-column grid of its own; and `sidebar` for
|
|
18
|
+
* secondary content — locked to the right edge and sized by `sidebarMode`.
|
|
19
|
+
* In the sidebar view the primary area is the rounded sheet (12px radius)
|
|
20
|
+
* while the sidebar has no surface of its own; both keep 48px margins.
|
|
21
|
+
* @category Layout
|
|
22
|
+
* @useCases main content area, page body, layout grid container, split view, secondary sidebar
|
|
23
|
+
* @keywords layout, content, main, margin, grid, page, split, sidebar
|
|
24
|
+
* @related UiSidebar, UiTopBar
|
|
25
|
+
*/
|
|
26
|
+
export interface UiLayoutContentProps {
|
|
27
|
+
/**
|
|
28
|
+
* The element the content area renders as. Defaults to `main`, so the
|
|
29
|
+
* content area is exposed as the page's main landmark; pass another tag
|
|
30
|
+
* when the page already has a `main` landmark.
|
|
31
|
+
* @type {string}
|
|
32
|
+
* @default 'main'
|
|
33
|
+
*/
|
|
34
|
+
as?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Column split between the primary content and the sidebar, applied when
|
|
37
|
+
* the `sidebar` slot is filled: `default` is 8 to 4, `wide` is 7 to 5, and
|
|
38
|
+
* `max` is 6 to 6.
|
|
39
|
+
* @type {'default' | 'wide' | 'max'}
|
|
40
|
+
* @default 'default'
|
|
41
|
+
*/
|
|
42
|
+
sidebarMode?: UiLayoutContentSidebarMode;
|
|
43
|
+
}
|
|
@@ -6,6 +6,7 @@ export * from './UiDataTable';
|
|
|
6
6
|
export * from './UiDatePicker';
|
|
7
7
|
export * from './UiFileUpload';
|
|
8
8
|
export * from './UiFloatActions';
|
|
9
|
+
export * from './UiLayout';
|
|
9
10
|
export * from './UiPlaceholder';
|
|
10
11
|
export * from './UiProfileCard';
|
|
11
12
|
export * from './UiSidebar';
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"components-uiautocomplete--accessibility": "accessibility",
|
|
33
33
|
"components-uibreadcrumb--accessibility": "accessibility",
|
|
34
34
|
"patterns-uifloatactions--accessibility": "accessibility",
|
|
35
|
+
"patterns-uilayout-content--accessibility": "accessibility",
|
|
35
36
|
"patterns-uidatatable--accessibility": "accessibility",
|
|
36
37
|
"patterns-uitopbar--accessibility": "accessibility",
|
|
37
38
|
"patterns-uifileupload-uifileitem--accessibility": "accessibility",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleph-alpha/ui-library",
|
|
3
|
-
"version": "6.1
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/system/lib.js",
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
"http-server": "14.1.1",
|
|
72
72
|
"playwright": "^1.57.0",
|
|
73
73
|
"postcss": "8.5.10",
|
|
74
|
-
"react": "
|
|
75
|
-
"react-dom": "
|
|
74
|
+
"react": "19.2.7",
|
|
75
|
+
"react-dom": "19.2.7",
|
|
76
76
|
"sb-addon-versions": "^1.0.12",
|
|
77
77
|
"storybook": "10.2.17",
|
|
78
78
|
"storybook-addon-tag-badges": "^3.1.0",
|
|
@@ -89,9 +89,9 @@
|
|
|
89
89
|
"wait-on": "9.0.3",
|
|
90
90
|
"@aleph-alpha/eslint-config-frontend": "0.7.1",
|
|
91
91
|
"@aleph-alpha/prettier-config-frontend": "2.1.1",
|
|
92
|
+
"@aleph-alpha/storybook-addon-filters": "0.0.1",
|
|
92
93
|
"@aleph-alpha/storybook-addon-sidebar": "0.0.1",
|
|
93
94
|
"@aleph-alpha/storybook-addon-theming": "0.0.1",
|
|
94
|
-
"@aleph-alpha/storybook-addon-filters": "0.0.1",
|
|
95
95
|
"@aleph-alpha/tsconfig-frontend": "0.7.3"
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
"lint": "eslint 'src/**/*.{js,vue,ts}' --cache",
|
|
148
148
|
"test": "vitest --run --project=unit",
|
|
149
149
|
"test:watch": "vitest --project=unit",
|
|
150
|
-
"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\"",
|
|
150
|
+
"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 $STORYBOOK_TEST_PATTERN\"",
|
|
151
151
|
"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\"",
|
|
152
152
|
"test:all": "vitest --run",
|
|
153
153
|
"storybook": "storybook dev -p 6006",
|
|
@@ -287,6 +287,89 @@ export const WithoutCopyButton: Story = {
|
|
|
287
287
|
},
|
|
288
288
|
};
|
|
289
289
|
|
|
290
|
+
const headerColorsTemplateSource = `<script setup lang="ts">
|
|
291
|
+
import { UiCodeBlock } from '@aleph-alpha/ui-library'
|
|
292
|
+
</script>
|
|
293
|
+
|
|
294
|
+
<template>
|
|
295
|
+
<!-- Set the properties on the block, or on any ancestor to recolor several at once. -->
|
|
296
|
+
<UiCodeBlock
|
|
297
|
+
:code="code"
|
|
298
|
+
language="typescript"
|
|
299
|
+
filename="theme.ts"
|
|
300
|
+
:style="{
|
|
301
|
+
'--ui-code-block-header-surface': '#0d1117',
|
|
302
|
+
'--ui-code-block-header-content': '#c9d1d9',
|
|
303
|
+
'--ui-code-block-header-border': '#30363d',
|
|
304
|
+
}"
|
|
305
|
+
/>
|
|
306
|
+
</template>`;
|
|
307
|
+
|
|
308
|
+
/** Story-only args: these are CSS custom properties, not component props. */
|
|
309
|
+
interface HeaderColorArgs {
|
|
310
|
+
headerSurface: string;
|
|
311
|
+
headerContent: string;
|
|
312
|
+
headerBorder: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Recolor the header from the outside with the `--ui-code-block-header-surface`,
|
|
317
|
+
* `--ui-code-block-header-content` and `--ui-code-block-header-border` custom
|
|
318
|
+
* properties — set them on the block or on any ancestor. Use this when the block
|
|
319
|
+
* sits on a surface the default muted header clashes with; each property falls
|
|
320
|
+
* back to its design token when unset. Edit the three colors in the Controls
|
|
321
|
+
* panel to see the header follow.
|
|
322
|
+
*/
|
|
323
|
+
export const HeaderColors: StoryObj<HeaderColorArgs> = {
|
|
324
|
+
argTypes: {
|
|
325
|
+
headerSurface: {
|
|
326
|
+
control: 'color',
|
|
327
|
+
description:
|
|
328
|
+
'Value for `--ui-code-block-header-surface` — the header background.',
|
|
329
|
+
},
|
|
330
|
+
headerContent: {
|
|
331
|
+
control: 'color',
|
|
332
|
+
description:
|
|
333
|
+
'Value for `--ui-code-block-header-content` — the filename/language label and the copy icon.',
|
|
334
|
+
},
|
|
335
|
+
headerBorder: {
|
|
336
|
+
control: 'color',
|
|
337
|
+
description:
|
|
338
|
+
'Value for `--ui-code-block-header-border` — the divider under the header.',
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
args: {
|
|
342
|
+
headerSurface: '#0d1117',
|
|
343
|
+
headerContent: '#c9d1d9',
|
|
344
|
+
headerBorder: '#30363d',
|
|
345
|
+
},
|
|
346
|
+
render: (args) => ({
|
|
347
|
+
components: { UiCodeBlock },
|
|
348
|
+
setup() {
|
|
349
|
+
return { args, code: typescriptExample };
|
|
350
|
+
},
|
|
351
|
+
template: `
|
|
352
|
+
<UiCodeBlock
|
|
353
|
+
:code="code"
|
|
354
|
+
language="typescript"
|
|
355
|
+
filename="theme.ts"
|
|
356
|
+
:style="{
|
|
357
|
+
'--ui-code-block-header-surface': args.headerSurface,
|
|
358
|
+
'--ui-code-block-header-content': args.headerContent,
|
|
359
|
+
'--ui-code-block-header-border': args.headerBorder,
|
|
360
|
+
}"
|
|
361
|
+
/>
|
|
362
|
+
`,
|
|
363
|
+
}),
|
|
364
|
+
parameters: {
|
|
365
|
+
docs: {
|
|
366
|
+
source: {
|
|
367
|
+
code: headerColorsTemplateSource,
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
|
|
290
373
|
const plainTextExample = `This is plain text output from a command.
|
|
291
374
|
No syntax highlighting is applied.
|
|
292
375
|
Useful for terminal output or log files.`;
|
|
@@ -171,13 +171,14 @@ onUnmounted(() => {
|
|
|
171
171
|
>
|
|
172
172
|
<div
|
|
173
173
|
v-if="showHeader"
|
|
174
|
-
class="flex items-center justify-between border-b
|
|
174
|
+
class="ui-code-block__header flex items-center justify-between border-b px-4 py-2"
|
|
175
175
|
>
|
|
176
|
-
<span class="font-mono text-sm
|
|
176
|
+
<span class="ui-code-block__header-label font-mono text-sm">
|
|
177
177
|
{{ headerLabel !== 'text' ? headerLabel : '' }}
|
|
178
178
|
</span>
|
|
179
179
|
<UiButton
|
|
180
180
|
v-if="showCopyButton"
|
|
181
|
+
class="ui-code-block__header-action"
|
|
181
182
|
variant="ghost"
|
|
182
183
|
size="icon-sm"
|
|
183
184
|
:aria-label="isCopied ? copiedLabel : copyLabel"
|
|
@@ -219,6 +220,33 @@ onUnmounted(() => {
|
|
|
219
220
|
</template>
|
|
220
221
|
|
|
221
222
|
<style scoped>
|
|
223
|
+
/*
|
|
224
|
+
* The header is the one surface a caller may need to match to something else —
|
|
225
|
+
* a code canvas that is not the muted surface, a branded panel. It is recolored
|
|
226
|
+
* from the outside with these custom properties, set on the code block or any
|
|
227
|
+
* ancestor; unset, each falls back to the token it used before.
|
|
228
|
+
*/
|
|
229
|
+
.ui-code-block__header {
|
|
230
|
+
background-color: var(
|
|
231
|
+
--ui-code-block-header-surface,
|
|
232
|
+
oklch(var(--background-surface-muted))
|
|
233
|
+
);
|
|
234
|
+
border-color: var(--ui-code-block-header-border, oklch(var(--border)));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.ui-code-block__header-label {
|
|
238
|
+
color: var(
|
|
239
|
+
--ui-code-block-header-content,
|
|
240
|
+
oklch(var(--content-on-surface-secondary))
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* Beats the ghost button's own `text-foreground`, so the copy icon stays
|
|
245
|
+
legible on a recolored header. */
|
|
246
|
+
.ui-code-block__header-action {
|
|
247
|
+
color: var(--ui-code-block-header-content, oklch(var(--foreground)));
|
|
248
|
+
}
|
|
249
|
+
|
|
222
250
|
/* Dark mode: :global() needed because html.dark is outside component scope */
|
|
223
251
|
:global(html.dark .ui-code-block .shiki),
|
|
224
252
|
:global(html.dark .ui-code-block .shiki span) {
|
|
@@ -112,6 +112,27 @@ describe('UiCodeBlock', () => {
|
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
+
test('exposes the header styling hooks used to recolor it from the outside', async () => {
|
|
116
|
+
const { container, getByRole } = render(UiCodeBlock, {
|
|
117
|
+
props: { code: 'code', language: 'typescript' },
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
await waitFor(() => {
|
|
121
|
+
expect(getByRole('button')).toBeInTheDocument();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// The `--ui-code-block-header-*` custom properties are applied through
|
|
125
|
+
// these classes, so a caller's override has nothing to hook onto without
|
|
126
|
+
// them.
|
|
127
|
+
expect(container.querySelector('.ui-code-block__header')).not.toBeNull();
|
|
128
|
+
expect(
|
|
129
|
+
container.querySelector('.ui-code-block__header-label'),
|
|
130
|
+
).not.toBeNull();
|
|
131
|
+
expect(
|
|
132
|
+
container.querySelector('.ui-code-block__header-action'),
|
|
133
|
+
).not.toBeNull();
|
|
134
|
+
});
|
|
135
|
+
|
|
115
136
|
test('shows copy button by default', async () => {
|
|
116
137
|
const { getByRole } = render(UiCodeBlock, {
|
|
117
138
|
props: { code: 'code', language: 'typescript' },
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A code block component for displaying source code with syntax highlighting,
|
|
3
3
|
* line numbers, and copy-to-clipboard functionality. Powered by Shiki.
|
|
4
|
+
*
|
|
5
|
+
* The header (language label + copy button) can be recolored from the outside
|
|
6
|
+
* with CSS custom properties, set on the code block or on any ancestor. Use
|
|
7
|
+
* them when the block sits on a surface the default muted header clashes with:
|
|
8
|
+
*
|
|
9
|
+
* - `--ui-code-block-header-surface` — header background
|
|
10
|
+
* - `--ui-code-block-header-content` — label and copy-icon color
|
|
11
|
+
* - `--ui-code-block-header-border` — divider under the header
|
|
12
|
+
*
|
|
13
|
+
* Each takes a full CSS color (`#0d1117`, `oklch(var(--background-surface-primary))`)
|
|
14
|
+
* and falls back to the design token it used before when unset.
|
|
4
15
|
* @category Content
|
|
5
16
|
* @useCases code display, code snippet, syntax highlighting, API response, terminal output
|
|
6
17
|
* @keywords code, codeblock, syntax, highlight, copy, pre, snippet
|
|
@@ -17,12 +17,14 @@ import {
|
|
|
17
17
|
SIDEBAR_COOKIE_MAX_AGE,
|
|
18
18
|
SIDEBAR_COOKIE_NAME,
|
|
19
19
|
SIDEBAR_KEYBOARD_SHORTCUT,
|
|
20
|
+
SIDEBAR_MIN_DESKTOP_MEDIA_QUERY,
|
|
20
21
|
SIDEBAR_OFFSET_TOP_CLASS,
|
|
21
22
|
SIDEBAR_WIDTH,
|
|
22
23
|
SIDEBAR_WIDTH_DEFAULT,
|
|
23
24
|
SIDEBAR_WIDTH_ICON,
|
|
24
25
|
SIDEBAR_WIDTH_MAX,
|
|
25
26
|
SIDEBAR_WIDTH_MIN,
|
|
27
|
+
SIDEBAR_WIDTH_MIN_DESKTOP,
|
|
26
28
|
SIDEBAR_WIDTH_MOBILE,
|
|
27
29
|
SIDEBAR_WIDTH_STORAGE_KEY,
|
|
28
30
|
} from './utils';
|
|
@@ -153,10 +155,18 @@ const isResizing = ref(false);
|
|
|
153
155
|
let resizeStartX = 0;
|
|
154
156
|
let resizeStartWidth = 0;
|
|
155
157
|
|
|
158
|
+
// Toward the minimum desktop size (1024px) the sidebar narrows to a fixed
|
|
159
|
+
// 162px and its content truncates. The clamp lives on the width variable, so
|
|
160
|
+
// everything reading `--sidebar-width` — the column, the offcanvas collapse
|
|
161
|
+
// margin, a top bar aligning its gutter — follows along.
|
|
162
|
+
const isMinDesktop = useMediaQuery(SIDEBAR_MIN_DESKTOP_MEDIA_QUERY);
|
|
163
|
+
|
|
156
164
|
const canResize = computed(
|
|
157
165
|
() =>
|
|
158
166
|
resolvedResizable.value &&
|
|
159
167
|
!isMobile.value &&
|
|
168
|
+
// The compact-desktop clamp fixes the width, so a drag would not move it.
|
|
169
|
+
!isMinDesktop.value &&
|
|
160
170
|
(props.collapsible === 'none' || state.value === 'expanded'),
|
|
161
171
|
);
|
|
162
172
|
// The provider used to own these. The sidebar sets them on itself so it can be
|
|
@@ -169,12 +179,18 @@ const widthVars = computed(() => ({
|
|
|
169
179
|
'--sidebar-mobile-transition-duration': props.mobileTransitionDuration,
|
|
170
180
|
}));
|
|
171
181
|
|
|
172
|
-
const sidebarStyle = computed(() =>
|
|
173
|
-
|
|
174
|
-
'--sidebar-width': resolvedResizable.value
|
|
182
|
+
const sidebarStyle = computed(() => {
|
|
183
|
+
let width = resolvedResizable.value
|
|
175
184
|
? `${sidebarWidth.value}px`
|
|
176
|
-
: SIDEBAR_WIDTH
|
|
177
|
-
|
|
185
|
+
: SIDEBAR_WIDTH;
|
|
186
|
+
// The compact-desktop clamp overrides both the constant and a stored drag.
|
|
187
|
+
if (isMinDesktop.value) width = SIDEBAR_WIDTH_MIN_DESKTOP;
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
...widthVars.value,
|
|
191
|
+
'--sidebar-width': width,
|
|
192
|
+
};
|
|
193
|
+
});
|
|
178
194
|
|
|
179
195
|
const mobileStyle = computed(() => ({
|
|
180
196
|
...widthVars.value,
|
|
@@ -7,6 +7,16 @@ export const SIDEBAR_WIDTH = '16rem';
|
|
|
7
7
|
export const SIDEBAR_WIDTH_DEFAULT = 256;
|
|
8
8
|
export const SIDEBAR_WIDTH_MIN = 240;
|
|
9
9
|
export const SIDEBAR_WIDTH_MAX = 480;
|
|
10
|
+
/**
|
|
11
|
+
* Width on compact desktop viewports (from `md` up to below the `desktop`
|
|
12
|
+
* breakpoint, 1200px): toward the minimum desktop size of 1024px the sidebar
|
|
13
|
+
* narrows to 162px and its content truncates, leaving the room to the content
|
|
14
|
+
* area's grid.
|
|
15
|
+
*/
|
|
16
|
+
export const SIDEBAR_WIDTH_MIN_DESKTOP = '162px';
|
|
17
|
+
/** Matches compact desktop viewports — at or above `md`, below `desktop`. */
|
|
18
|
+
export const SIDEBAR_MIN_DESKTOP_MEDIA_QUERY =
|
|
19
|
+
'(min-width: 768px) and (max-width: 1199.9px)';
|
|
10
20
|
export const SIDEBAR_WIDTH_MOBILE = '16rem';
|
|
11
21
|
export const SIDEBAR_WIDTH_ICON = '3rem';
|
|
12
22
|
export const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|