@bridgebrew/design-system 0.0.0-stage → 0.1.9
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 +21 -2
- package/browser.tsx +227 -0
- package/design-system.css +110 -0
- package/e2e.test.ts +253 -0
- package/highlight.ts +29 -0
- package/model.test.ts +69 -0
- package/package.json +72 -3
- package/stories/action.tsx +101 -0
- package/stories/data-display.tsx +371 -0
- package/stories/feedback.tsx +109 -0
- package/stories/foundations.tsx +157 -0
- package/stories/input.tsx +851 -0
- package/stories/interaction.tsx +76 -0
- package/stories/layout.tsx +510 -0
- package/stories/navigation.tsx +220 -0
- package/stories/overlay.tsx +293 -0
- package/stories/parts.tsx +201 -0
- package/stories.ts +149 -0
- package/tsconfig.json +20 -0
package/model.test.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { test } from 'node:test';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { layers, screenOf, screens, search, stories, storiesOf, storyOf } from './stories.ts';
|
|
7
|
+
|
|
8
|
+
/** The kit's components folder, beside its entry (the linked @bridge/ui). */
|
|
9
|
+
const components = fileURLToPath(new URL('./components/', import.meta.resolve('@bridge/ui')));
|
|
10
|
+
const dirs = (path: string) => readdirSync(path, { withFileTypes: true }).filter((each) => each.isDirectory()).map((each) => each.name);
|
|
11
|
+
/** Each component's folder, under its layer (`core/button`, `composite/list`); a folder with no `index.ts` is a layer. */
|
|
12
|
+
const paths = dirs(components).flatMap((name) =>
|
|
13
|
+
existsSync(join(components, name, 'index.ts')) ? [name] : dirs(join(components, name)).map((each) => join(name, each)));
|
|
14
|
+
const folders = paths.map((path) => basename(path));
|
|
15
|
+
/** Every `*.meta.yaml`: its name (`textarea` lives in `input/`) and layer, its folder's (`core/button`: core). */
|
|
16
|
+
const metas = paths.flatMap((folder) => readdirSync(join(components, folder))
|
|
17
|
+
.filter((file) => file.endsWith('.meta.yaml'))
|
|
18
|
+
.map((file) => ({ id: file.slice(0, -'.meta.yaml'.length), layer: folder.includes('/') ? dirname(folder) : undefined })));
|
|
19
|
+
|
|
20
|
+
test('story ids are unique, kebab-case, and in a known layer', () => {
|
|
21
|
+
const ids = stories.map((each) => each.id);
|
|
22
|
+
assert.equal(new Set(ids).size, ids.length);
|
|
23
|
+
for (const id of ids) assert.match(id, /^[a-z]+(-[a-z]+)*$/);
|
|
24
|
+
for (const story of stories) assert.ok(layers.some((each) => each.id === story.layer), story.id);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('every kit component has a story, in its layer', () => {
|
|
28
|
+
assert.ok(folders.length >= 30, `found ${folders.length} component folders in ${components}`);
|
|
29
|
+
const byId = new Map<string, (typeof stories)[number]>(stories.map((each) => [each.id, each]));
|
|
30
|
+
const missing = [...new Set([...folders, ...metas.map((each) => each.id)])].filter((id) => !byId.has(id));
|
|
31
|
+
assert.deepEqual(missing, [], `kit components without a story: ${missing.join(', ')}`);
|
|
32
|
+
for (const { id, layer } of metas) assert.equal(byId.get(id)?.layer, layer, `${id}'s layer`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('every component story is a kit component; Foundations come first', () => {
|
|
36
|
+
const known = new Set([...folders, ...metas.map((each) => each.id)]);
|
|
37
|
+
for (const story of stories) assert.equal(known.has(story.id), !('foundation' in story), story.id);
|
|
38
|
+
const order = layers.map((each) => each.id);
|
|
39
|
+
const positions = stories.map((each) => order.indexOf(each.layer));
|
|
40
|
+
assert.deepEqual(positions, [...positions].sort((a, b) => a - b), 'stories grouped in layer order');
|
|
41
|
+
assert.deepEqual(stories.slice(0, 4).map((each) => each.id), ['colors', 'typography', 'sizes', 'icons']);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('each story is on one screen, its layer\'s; Design system, the home, has none', () => {
|
|
45
|
+
assert.deepEqual(storiesOf('design-system'), []);
|
|
46
|
+
const shown = Object.keys(screens).flatMap((screen) => storiesOf(screen).map((each) => each.id));
|
|
47
|
+
assert.deepEqual([...shown].sort(), stories.map((each) => each.id).sort());
|
|
48
|
+
for (const story of stories) assert.ok(storiesOf(screenOf(story)).includes(story), story.id);
|
|
49
|
+
assert.deepEqual(storiesOf('layout').map((each) => each.id), ['single-pane', 'multi-pane']);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('search matches titles, ids and layers on its screen, any case or accent', () => {
|
|
53
|
+
const ids = (query: string, screen = 'core') => search(query, screen).map((each) => each.id);
|
|
54
|
+
assert.deepEqual(ids('tog'), ['toggle', 'toggle-group']);
|
|
55
|
+
assert.deepEqual(ids(' '), storiesOf('core').map((each) => each.id));
|
|
56
|
+
assert.deepEqual(ids('SÉLECT'), ['select']);
|
|
57
|
+
assert.ok(ids('composite', 'composite').includes('wizard'));
|
|
58
|
+
assert.deepEqual(ids('menu drop'), ['dropdown-menu']);
|
|
59
|
+
assert.deepEqual(ids('dialog', 'layout'), []);
|
|
60
|
+
assert.deepEqual(ids('nothing like it'), []);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('an item names its story on its screen; an unknown one, another screen\'s, or none, the screen\'s first', () => {
|
|
64
|
+
assert.equal(storyOf('picker', 'composite').id, 'picker');
|
|
65
|
+
assert.equal(storyOf(undefined, 'foundations').id, 'colors');
|
|
66
|
+
assert.equal(storyOf('nope/x', 'foundations').id, 'colors');
|
|
67
|
+
assert.equal(storyOf('sidebar', 'shell').id, 'sidebar');
|
|
68
|
+
assert.equal(storyOf('button', 'layout').id, 'single-pane');
|
|
69
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgebrew/design-system",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A storyboard of the @bridge/ui kit: every component's variants, sizes and states, live, in the page's theme.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"bridge-plugin"
|
|
8
|
+
],
|
|
9
|
+
"bridge": {
|
|
10
|
+
"kind": "application",
|
|
11
|
+
"title": "Design system",
|
|
12
|
+
"icon": "layout-dashboard",
|
|
13
|
+
"domain": "development",
|
|
14
|
+
"browser": "./browser.tsx",
|
|
15
|
+
"screen": {
|
|
16
|
+
"id": "design-system",
|
|
17
|
+
"title": "Design system",
|
|
18
|
+
"icon": "layout-dashboard",
|
|
19
|
+
"children": [
|
|
20
|
+
{
|
|
21
|
+
"id": "foundations",
|
|
22
|
+
"title": "Foundations",
|
|
23
|
+
"icon": "palette",
|
|
24
|
+
"mobile": true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "core",
|
|
28
|
+
"title": "Core",
|
|
29
|
+
"icon": "box",
|
|
30
|
+
"mobile": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "layout",
|
|
34
|
+
"title": "Layout",
|
|
35
|
+
"icon": "dashboard",
|
|
36
|
+
"mobile": true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "composite",
|
|
40
|
+
"title": "Composite",
|
|
41
|
+
"icon": "puzzle",
|
|
42
|
+
"mobile": true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "template",
|
|
46
|
+
"title": "Template",
|
|
47
|
+
"icon": "files",
|
|
48
|
+
"mobile": true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "shell",
|
|
52
|
+
"title": "Shell",
|
|
53
|
+
"icon": "app-window",
|
|
54
|
+
"mobile": true
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"mobile": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"@bridge/ui": ">=0.1.9",
|
|
62
|
+
"react": "19.3.0"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"shiki": "4.4.3"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@bridge/ui": "npm:@bridgebrew/ui@0.1.9"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"test": "node --test model.test.ts",
|
|
72
|
+
"e2e": "node --test --test-concurrency=1 e2e.test.ts",
|
|
73
|
+
"typecheck": "node ../../scripts/bridge.mjs plugin check ."
|
|
74
|
+
}
|
|
6
75
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Action: Button, every variant and size, its states, and a save button with real state.
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Button, Icon, StatusIcon, Tooltip, TooltipContent, TooltipTrigger } from '@bridge/ui';
|
|
4
|
+
import { Group, Sample } from './parts.tsx';
|
|
5
|
+
|
|
6
|
+
/** An icon-only control with its tooltip (the kit's rule for lossy glyphs). */
|
|
7
|
+
export const Tip = ({ label, children }: { label: string; children: React.ReactElement }) => (
|
|
8
|
+
<Tooltip>
|
|
9
|
+
<TooltipTrigger render={children} />
|
|
10
|
+
<TooltipContent>{label}</TooltipContent>
|
|
11
|
+
</Tooltip>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const variants = [
|
|
15
|
+
['primary', 'The one main action of a view', <><Icon name="plus" />New issue</>],
|
|
16
|
+
['outline', 'Secondary actions beside a primary one', <><Icon name="copy" />Duplicate</>],
|
|
17
|
+
['ghost', 'Toolbars, quiet actions; the default', <><Icon name="filter" />Filter</>],
|
|
18
|
+
['destructive', 'Deletes or discards', <><Icon name="trash" />Delete</>],
|
|
19
|
+
['property', 'A property pill on a detail card', <><StatusIcon status="in-progress" />In progress</>],
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
function SaveButton() {
|
|
23
|
+
const [state, setState] = React.useState<'idle' | 'saving' | 'saved'>('idle');
|
|
24
|
+
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
25
|
+
React.useEffect(() => () => clearTimeout(timer.current), []);
|
|
26
|
+
const save = () => {
|
|
27
|
+
setState('saving');
|
|
28
|
+
timer.current = setTimeout(() => {
|
|
29
|
+
setState('saved');
|
|
30
|
+
timer.current = setTimeout(() => setState('idle'), 1500);
|
|
31
|
+
}, 900);
|
|
32
|
+
};
|
|
33
|
+
return (
|
|
34
|
+
<Button variant="primary" disabled={state === 'saving'} onClick={save}>
|
|
35
|
+
{state === 'saving' ? <><Icon name="loader-circle" className="animate-spin motion-reduce:animate-none" />Saving…</>
|
|
36
|
+
: state === 'saved' ? <><Icon name="check" />Saved</> : 'Save changes'}
|
|
37
|
+
</Button>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function ButtonStory() {
|
|
42
|
+
const [count, setCount] = React.useState(0);
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<Group title="Variants" layout="grid" code={`{variants.map(([variant, use, label]) => (\n <Button variant={variant}>{label}</Button>\n))}`}>
|
|
46
|
+
{variants.map(([variant, use, label]) => (
|
|
47
|
+
<Sample key={variant} title={variant} description={use}>
|
|
48
|
+
<Button variant={variant}>{label}</Button>
|
|
49
|
+
</Sample>
|
|
50
|
+
))}
|
|
51
|
+
</Group>
|
|
52
|
+
<Group title="Sizes" description="Text sizes sit on the sm, md and lg heights; icon-only sizes are square." layout="stack" code={`{(['sm', 'default', 'lg'] as const).map((size) => (\n {variants.map(([variant, , label]) => <Button key={variant} variant={variant} size={size}>{label}</Button>)}\n))}\n{(['icon-sm', 'icon', 'icon-lg'] as const).map((size) => (\n {variants.map(([variant]) => (\n <Tip key={variant} label={\`\${variant} \${size}\`}>\n <Button variant={variant} size={size} aria-label={\`\${variant} \${size}\`}><Icon name={variant === 'destructive' ? 'trash' : 'settings'} /></Button>\n </Tip>\n ))}\n))}`}>
|
|
53
|
+
{(['sm', 'default', 'lg'] as const).map((size) => (
|
|
54
|
+
<Sample key={size} title={size} wide>
|
|
55
|
+
{variants.map(([variant, , label]) => <Button key={variant} variant={variant} size={size}>{label}</Button>)}
|
|
56
|
+
</Sample>
|
|
57
|
+
))}
|
|
58
|
+
{(['icon-sm', 'icon', 'icon-lg'] as const).map((size) => (
|
|
59
|
+
<Sample key={size} title={size} wide>
|
|
60
|
+
{variants.map(([variant]) => (
|
|
61
|
+
<Tip key={variant} label={`${variant} ${size}`}>
|
|
62
|
+
<Button variant={variant} size={size} aria-label={`${variant} ${size}`}><Icon name={variant === 'destructive' ? 'trash' : 'settings'} /></Button>
|
|
63
|
+
</Tip>
|
|
64
|
+
))}
|
|
65
|
+
</Sample>
|
|
66
|
+
))}
|
|
67
|
+
</Group>
|
|
68
|
+
<Group title="States" layout="columns" code={`{variants.map(([variant, , label]) => <Button key={variant} variant={variant} disabled>{label}</Button>)}\n<Button variant="primary" disabled><Icon name="loader-circle" className="animate-spin motion-reduce:animate-none" />Saving…</Button>\n<Button variant="outline" disabled><Icon name="loader-circle" className="animate-spin motion-reduce:animate-none" />Exporting…</Button>\n<Sample title="as a link" description={'render={<a href="…" />}'}>\n <Button variant="outline" render={<a href="#design-system" onClick={(event) => event.preventDefault()} />}><Icon name="link" />Open in a new tab</Button>`}>
|
|
69
|
+
<Sample title="disabled" description="Faded, not clickable">
|
|
70
|
+
{variants.map(([variant, , label]) => <Button key={variant} variant={variant} disabled>{label}</Button>)}
|
|
71
|
+
</Sample>
|
|
72
|
+
<Sample title="loading" description="Disabled, with a spinning loader-circle">
|
|
73
|
+
<Button variant="primary" disabled><Icon name="loader-circle" className="animate-spin motion-reduce:animate-none" />Saving…</Button>
|
|
74
|
+
<Button variant="outline" disabled><Icon name="loader-circle" className="animate-spin motion-reduce:animate-none" />Exporting…</Button>
|
|
75
|
+
</Sample>
|
|
76
|
+
<Sample title="as a link" description={'render={<a href="…" />}'}>
|
|
77
|
+
<Button variant="outline" render={<a href="#design-system" onClick={(event) => event.preventDefault()} />}><Icon name="link" />Open in a new tab</Button>
|
|
78
|
+
</Sample>
|
|
79
|
+
</Group>
|
|
80
|
+
<Group title="Examples" layout="stack" code={`<SaveButton />\n<Button variant="ghost">Discard</Button>\n<Button variant="outline" onClick={() => setCount((n) => n + 1)}><Icon name="plus" />Add one</Button>\n<Button variant="ghost" disabled={count === 0} onClick={() => setCount(0)}><Icon name="rotate-cw" />Reset</Button>\n<Button variant="property">{\`\${count} \${count === 1 ? 'click' : 'clicks'}\`}</Button>\n<Tip label="Search"><Button variant="ghost" size="icon" aria-label="Search"><Icon name="search" /></Button></Tip>\n<Tip label="Filter"><Button variant="ghost" size="icon" aria-label="Filter"><Icon name="filter" /></Button></Tip>\n<Button variant="ghost"><Icon name="list" />Display</Button>\n<Button variant="primary"><Icon name="plus" />New issue</Button>`}>
|
|
81
|
+
<Sample title="save, with real state" description="Saving… for a moment, then Saved" wide>
|
|
82
|
+
<SaveButton />
|
|
83
|
+
<Button variant="ghost">Discard</Button>
|
|
84
|
+
</Sample>
|
|
85
|
+
<Sample title="a counter" description="Each click counts" wide>
|
|
86
|
+
<Button variant="outline" onClick={() => setCount((n) => n + 1)}><Icon name="plus" />Add one</Button>
|
|
87
|
+
<Button variant="ghost" disabled={count === 0} onClick={() => setCount(0)}><Icon name="rotate-cw" />Reset</Button>
|
|
88
|
+
<Button variant="property">{`${count} ${count === 1 ? 'click' : 'clicks'}`}</Button>
|
|
89
|
+
</Sample>
|
|
90
|
+
<Sample title="a toolbar" description="Ghost tools, one primary action" wide>
|
|
91
|
+
<Tip label="Search"><Button variant="ghost" size="icon" aria-label="Search"><Icon name="search" /></Button></Tip>
|
|
92
|
+
<Tip label="Filter"><Button variant="ghost" size="icon" aria-label="Filter"><Icon name="filter" /></Button></Tip>
|
|
93
|
+
<Button variant="ghost"><Icon name="list" />Display</Button>
|
|
94
|
+
<Button variant="primary"><Icon name="plus" />New issue</Button>
|
|
95
|
+
</Sample>
|
|
96
|
+
</Group>
|
|
97
|
+
</>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const action = { button: ButtonStory };
|