@vieo-io/ui 0.0.0-stage → 0.1.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/LICENSE +373 -0
- package/README.md +28 -2
- package/dist/AppShell.d.ts +15 -0
- package/dist/AppShell.jsx +16 -0
- package/dist/AppSwitcher.d.ts +23 -0
- package/dist/AppSwitcher.jsx +24 -0
- package/dist/Badge.d.ts +7 -0
- package/dist/Badge.jsx +4 -0
- package/dist/Button.d.ts +9 -0
- package/dist/Button.jsx +17 -0
- package/dist/Checkbox.d.ts +8 -0
- package/dist/Checkbox.jsx +9 -0
- package/dist/CommandPalette.d.ts +42 -0
- package/dist/CommandPalette.jsx +107 -0
- package/dist/Dialog.d.ts +13 -0
- package/dist/Dialog.jsx +37 -0
- package/dist/EmptyState.d.ts +11 -0
- package/dist/EmptyState.jsx +17 -0
- package/dist/Icon.d.ts +11 -0
- package/dist/Icon.jsx +12 -0
- package/dist/IconButton.d.ts +16 -0
- package/dist/IconButton.jsx +25 -0
- package/dist/Kbd.d.ts +8 -0
- package/dist/Kbd.jsx +23 -0
- package/dist/Listbox.d.ts +18 -0
- package/dist/Listbox.jsx +48 -0
- package/dist/Menu.d.ts +31 -0
- package/dist/Menu.jsx +114 -0
- package/dist/ObjectCard.d.ts +23 -0
- package/dist/ObjectCard.jsx +41 -0
- package/dist/Popover.d.ts +15 -0
- package/dist/Popover.jsx +50 -0
- package/dist/Resizer.d.ts +17 -0
- package/dist/Resizer.jsx +43 -0
- package/dist/SegmentedControl.d.ts +19 -0
- package/dist/SegmentedControl.jsx +39 -0
- package/dist/Select.d.ts +13 -0
- package/dist/Select.jsx +17 -0
- package/dist/SettingRow.d.ts +15 -0
- package/dist/SettingRow.jsx +26 -0
- package/dist/Sidebar.d.ts +29 -0
- package/dist/Sidebar.jsx +106 -0
- package/dist/Switch.d.ts +10 -0
- package/dist/Switch.jsx +11 -0
- package/dist/Tabs.d.ts +17 -0
- package/dist/Tabs.jsx +31 -0
- package/dist/TextField.d.ts +20 -0
- package/dist/TextField.jsx +36 -0
- package/dist/Toast.d.ts +23 -0
- package/dist/Toast.jsx +124 -0
- package/dist/Toolbar.d.ts +17 -0
- package/dist/Toolbar.jsx +67 -0
- package/dist/Tooltip.d.ts +12 -0
- package/dist/Tooltip.jsx +54 -0
- package/dist/Tree.d.ts +29 -0
- package/dist/Tree.jsx +130 -0
- package/dist/app-switcher.css +72 -0
- package/dist/aria.d.ts +2 -0
- package/dist/aria.js +6 -0
- package/dist/button.css +117 -0
- package/dist/controls.css +182 -0
- package/dist/dialog.css +60 -0
- package/dist/field.css +61 -0
- package/dist/icon.css +5 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +28 -0
- package/dist/layers.d.ts +7 -0
- package/dist/layers.js +38 -0
- package/dist/listbox.css +49 -0
- package/dist/menu.css +56 -0
- package/dist/object-card.css +81 -0
- package/dist/palette.css +86 -0
- package/dist/paths.d.ts +68 -0
- package/dist/paths.js +68 -0
- package/dist/popover.css +21 -0
- package/dist/roving.d.ts +21 -0
- package/dist/roving.js +48 -0
- package/dist/setting.css +42 -0
- package/dist/shell.css +155 -0
- package/dist/small.css +77 -0
- package/dist/styles.css +20 -0
- package/dist/tabs.css +44 -0
- package/dist/toast.css +72 -0
- package/dist/toolbar.css +46 -0
- package/dist/tooltip.css +14 -0
- package/dist/tree.css +92 -0
- package/dist/trigger.d.ts +15 -0
- package/dist/trigger.js +1 -0
- package/package.json +52 -3
package/dist/Resizer.jsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const STEP = 16;
|
|
2
|
+
/**
|
|
3
|
+
* A drag handle between two panes, as a focusable separator. Arrow keys step it, Home and End reach its limits,
|
|
4
|
+
* and a double-click resets it.
|
|
5
|
+
*/
|
|
6
|
+
export function Resizer(props) {
|
|
7
|
+
const clamp = (value) => Math.min(props.max, Math.max(props.min, Math.round(value)));
|
|
8
|
+
const onKeyDown = (event) => {
|
|
9
|
+
const step = props.step ?? STEP;
|
|
10
|
+
const next = {
|
|
11
|
+
ArrowLeft: props.value - step,
|
|
12
|
+
ArrowDown: props.value - step,
|
|
13
|
+
ArrowRight: props.value + step,
|
|
14
|
+
ArrowUp: props.value + step,
|
|
15
|
+
Home: props.min,
|
|
16
|
+
End: props.max,
|
|
17
|
+
}[event.key];
|
|
18
|
+
if (next === undefined)
|
|
19
|
+
return;
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
props.onChange(clamp(next));
|
|
22
|
+
};
|
|
23
|
+
const onPointerDown = (event) => {
|
|
24
|
+
if (event.button !== 0)
|
|
25
|
+
return;
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
const handle = event.currentTarget;
|
|
28
|
+
const [startX, startValue] = [event.clientX, props.value];
|
|
29
|
+
handle.setPointerCapture(event.pointerId);
|
|
30
|
+
const onMove = (move) => props.onChange(clamp(startValue + move.clientX - startX));
|
|
31
|
+
const onUp = () => {
|
|
32
|
+
handle.removeEventListener('pointermove', onMove);
|
|
33
|
+
handle.removeEventListener('pointerup', onUp);
|
|
34
|
+
handle.removeEventListener('pointercancel', onUp);
|
|
35
|
+
};
|
|
36
|
+
handle.addEventListener('pointermove', onMove);
|
|
37
|
+
handle.addEventListener('pointerup', onUp);
|
|
38
|
+
handle.addEventListener('pointercancel', onUp);
|
|
39
|
+
};
|
|
40
|
+
return (
|
|
41
|
+
// biome-ignore lint/a11y/useSemanticElements: a window splitter is a separator with a value and a tab stop, which an <hr> doesn't announce.
|
|
42
|
+
<div class='vds-resizer' role='separator' aria-label={props.label} aria-orientation='vertical' aria-valuenow={props.value} aria-valuemin={props.min} aria-valuemax={props.max} tabindex='0' onKeyDown={onKeyDown} onPointerDown={onPointerDown} onDblClick={() => props.onChange(clamp(props.reset))}/>);
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type IconName } from './Icon';
|
|
2
|
+
export type SegmentedControlProps = {
|
|
3
|
+
/** Names the group for assistive technology. */
|
|
4
|
+
label: string;
|
|
5
|
+
onChange: (value: string) => void;
|
|
6
|
+
options: SegmentedOption[];
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
export type SegmentedOption = {
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
icon?: IconName;
|
|
12
|
+
label: string;
|
|
13
|
+
value: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A row of mutually exclusive options, as a radio group. The chosen option is the one tab stop, and
|
|
17
|
+
* arrow keys, Home, and End choose the next enabled option as they move.
|
|
18
|
+
*/
|
|
19
|
+
export declare function SegmentedControl(props: SegmentedControlProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { For, Show } from '@solidjs/web';
|
|
2
|
+
import { aria } from './aria';
|
|
3
|
+
import { Icon } from './Icon';
|
|
4
|
+
import { first, moveFor, rows } from './roving';
|
|
5
|
+
/**
|
|
6
|
+
* A row of mutually exclusive options, as a radio group. The chosen option is the one tab stop, and
|
|
7
|
+
* arrow keys, Home, and End choose the next enabled option as they move.
|
|
8
|
+
*/
|
|
9
|
+
export function SegmentedControl(props) {
|
|
10
|
+
let group;
|
|
11
|
+
const tabStop = () => {
|
|
12
|
+
const chosen = props.options.findIndex((option) => option.value === props.value && !option.disabled);
|
|
13
|
+
return chosen >= 0 ? chosen : first(props.options);
|
|
14
|
+
};
|
|
15
|
+
const onKeyDown = (event) => {
|
|
16
|
+
const from = props.options.findIndex((option) => option.value === props.value);
|
|
17
|
+
const move = moveFor(event.key, props.options, from, 'horizontal') ??
|
|
18
|
+
moveFor(event.key, props.options, from, 'vertical');
|
|
19
|
+
const option = move === undefined ? undefined : props.options[move];
|
|
20
|
+
if (move === undefined || !option)
|
|
21
|
+
return;
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
rows(group, 'radio')[move]?.focus();
|
|
24
|
+
if (option.value !== props.value)
|
|
25
|
+
props.onChange(option.value);
|
|
26
|
+
};
|
|
27
|
+
return (<div ref={group} class='vds-segmented' role='radiogroup' aria-label={props.label} onKeyDown={onKeyDown}>
|
|
28
|
+
<For each={props.options}>
|
|
29
|
+
{(option, index) => (
|
|
30
|
+
// biome-ignore lint/a11y/useSemanticElements: a segment is a button styled as one of a row, and the group handles the arrow keys.
|
|
31
|
+
<button type='button' class='vds-segmented__option' role='radio' aria-checked={aria(option.value === props.value)} tabindex={index() === tabStop() ? '0' : '-1'} disabled={option.disabled} onClick={() => props.onChange(option.value)}>
|
|
32
|
+
<Show when={option.icon}>
|
|
33
|
+
{(name) => <Icon name={name()} size='var(--icon-size-sm)'/>}
|
|
34
|
+
</Show>
|
|
35
|
+
{option.label}
|
|
36
|
+
</button>)}
|
|
37
|
+
</For>
|
|
38
|
+
</div>);
|
|
39
|
+
}
|
package/dist/Select.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ComponentProps } from '@solidjs/web';
|
|
2
|
+
export type SelectOption = {
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
7
|
+
export type SelectProps = Omit<ComponentProps<'select'>, 'onChange' | 'value'> & {
|
|
8
|
+
onChange: (value: string) => void;
|
|
9
|
+
options: SelectOption[];
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
/** A native select with a chevron, so the platform's own picker opens on every device. */
|
|
13
|
+
export declare function Select(props: SelectProps): import("@solidjs/web").JSX.Element;
|
package/dist/Select.jsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { For } from '@solidjs/web';
|
|
2
|
+
import { omit } from 'solid-js';
|
|
3
|
+
import { Icon } from './Icon';
|
|
4
|
+
/** A native select with a chevron, so the platform's own picker opens on every device. */
|
|
5
|
+
export function Select(props) {
|
|
6
|
+
const rest = omit(props, 'class', 'onChange', 'options', 'value');
|
|
7
|
+
return (<span class={['vds-select', props.class]}>
|
|
8
|
+
<select class='vds-select__input' value={props.value} onChange={(event) => props.onChange(event.currentTarget.value)} {...rest}>
|
|
9
|
+
<For each={props.options}>
|
|
10
|
+
{(option) => (<option value={option.value} disabled={option.disabled}>
|
|
11
|
+
{option.label}
|
|
12
|
+
</option>)}
|
|
13
|
+
</For>
|
|
14
|
+
</select>
|
|
15
|
+
<Icon name='chevron-down' class='vds-select__chevron' size='var(--icon-size-sm)'/>
|
|
16
|
+
</span>);
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type JSX } from '@solidjs/web';
|
|
2
|
+
/** What the row's control must carry so the row's label and hint name and describe it. */
|
|
3
|
+
export type SettingControlProps = {
|
|
4
|
+
'aria-describedby'?: string;
|
|
5
|
+
'aria-labelledby': string;
|
|
6
|
+
};
|
|
7
|
+
export type SettingRowProps = {
|
|
8
|
+
children: (props: SettingControlProps) => JSX.Element;
|
|
9
|
+
hint?: string;
|
|
10
|
+
label: string;
|
|
11
|
+
/** Puts the control under the label rather than beside it, for a wide control such as a text field. */
|
|
12
|
+
stacked?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** A setting: its label and hint on the left, its control on the right, wrapping when the row is narrow. */
|
|
15
|
+
export declare function SettingRow(props: SettingRowProps): JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Show } from '@solidjs/web';
|
|
2
|
+
import { createUniqueId } from 'solid-js';
|
|
3
|
+
/** A setting: its label and hint on the left, its control on the right, wrapping when the row is narrow. */
|
|
4
|
+
export function SettingRow(props) {
|
|
5
|
+
const id = createUniqueId();
|
|
6
|
+
return (<div class={['vds-setting', { 'vds-setting--stacked': props.stacked }]}>
|
|
7
|
+
<div class='vds-setting__text'>
|
|
8
|
+
<span id={`${id}-label`} class='vds-setting__label'>
|
|
9
|
+
{props.label}
|
|
10
|
+
</span>
|
|
11
|
+
<Show when={props.hint}>
|
|
12
|
+
<span id={`${id}-hint`} class='vds-setting__hint'>
|
|
13
|
+
{props.hint}
|
|
14
|
+
</span>
|
|
15
|
+
</Show>
|
|
16
|
+
</div>
|
|
17
|
+
<div class='vds-setting__control'>
|
|
18
|
+
{props.children({
|
|
19
|
+
'aria-labelledby': `${id}-label`,
|
|
20
|
+
get 'aria-describedby'() {
|
|
21
|
+
return props.hint ? `${id}-hint` : undefined;
|
|
22
|
+
},
|
|
23
|
+
})}
|
|
24
|
+
</div>
|
|
25
|
+
</div>);
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type JSX } from '@solidjs/web';
|
|
2
|
+
export type SidebarProps = {
|
|
3
|
+
/** The width in pixels below which the sidebar becomes a drawer over the page. */
|
|
4
|
+
breakpoint?: number;
|
|
5
|
+
children: JSX.Element;
|
|
6
|
+
collapsed: boolean;
|
|
7
|
+
/** Where focus goes as the drawer closes, such as the page after a navigation. Unset, it goes back to whatever opened the drawer. */
|
|
8
|
+
drawerFocusAfter?: () => HTMLElement | undefined;
|
|
9
|
+
/** Whether the drawer is open, below the breakpoint. Close it after the person navigates. */
|
|
10
|
+
drawerOpen: boolean;
|
|
11
|
+
/** Below the rows, such as an app switcher or an account button. */
|
|
12
|
+
footer?: JSX.Element;
|
|
13
|
+
/** Names the navigation for assistive technology. */
|
|
14
|
+
label: string;
|
|
15
|
+
maxWidth?: number;
|
|
16
|
+
minWidth?: number;
|
|
17
|
+
onCollapsedChange: (collapsed: boolean) => void;
|
|
18
|
+
onDrawerOpenChange: (open: boolean) => void;
|
|
19
|
+
onWidthChange: (width: number) => void;
|
|
20
|
+
/** The width a double-click on the handle goes back to. */
|
|
21
|
+
resetWidth?: number;
|
|
22
|
+
width: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The app's navigation. On a wide window it sits beside the page with a handle to resize it, and Mod-B hides it.
|
|
26
|
+
* Below the breakpoint it is a modal drawer that slides over the page. The app keeps the width, the collapsed state,
|
|
27
|
+
* and whether the drawer is open, and stores them however it likes.
|
|
28
|
+
*/
|
|
29
|
+
export declare function Sidebar(props: SidebarProps): JSX.Element;
|
package/dist/Sidebar.jsx
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createFocusTrap } from '@solid-primitives/focus';
|
|
2
|
+
import { createPresence } from '@solid-primitives/presence';
|
|
3
|
+
import { Show } from '@solidjs/web';
|
|
4
|
+
import { createEffect, createSignal, onSettled } from 'solid-js';
|
|
5
|
+
import { isTopDialog, pushDialog } from './layers';
|
|
6
|
+
import { Resizer } from './Resizer';
|
|
7
|
+
const BREAKPOINT = 640;
|
|
8
|
+
/** How long the drawer takes to slide in or out, matching `--vds-drawer-duration`. */
|
|
9
|
+
const DRAWER_MS = 160;
|
|
10
|
+
const WIDTH = { min: 220, max: 480, reset: 256 };
|
|
11
|
+
/**
|
|
12
|
+
* The app's navigation. On a wide window it sits beside the page with a handle to resize it, and Mod-B hides it.
|
|
13
|
+
* Below the breakpoint it is a modal drawer that slides over the page. The app keeps the width, the collapsed state,
|
|
14
|
+
* and whether the drawer is open, and stores them however it likes.
|
|
15
|
+
*/
|
|
16
|
+
export function Sidebar(props) {
|
|
17
|
+
const narrow = createNarrow(() => props.breakpoint ?? BREAKPOINT);
|
|
18
|
+
const drawer = createPresence(() => (narrow() && props.drawerOpen) || undefined, {
|
|
19
|
+
transitionDuration: DRAWER_MS,
|
|
20
|
+
});
|
|
21
|
+
const [panel, setPanel] = createSignal();
|
|
22
|
+
const self = {};
|
|
23
|
+
createFocusTrap({
|
|
24
|
+
element: panel,
|
|
25
|
+
enabled: () => narrow() && props.drawerOpen,
|
|
26
|
+
finalFocusElement: () => props.drawerFocusAfter?.(),
|
|
27
|
+
});
|
|
28
|
+
// Escape is heard on the document, since focus reaches the drawer two frames after it opens.
|
|
29
|
+
createEffect(() => narrow() && props.drawerOpen, (open) => {
|
|
30
|
+
if (!open)
|
|
31
|
+
return;
|
|
32
|
+
const pop = pushDialog(self);
|
|
33
|
+
const onKeyDown = (event) => {
|
|
34
|
+
if (event.key !== 'Escape' || event.defaultPrevented || !isTopDialog(self))
|
|
35
|
+
return;
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
props.onDrawerOpenChange(false);
|
|
38
|
+
};
|
|
39
|
+
document.addEventListener('keydown', onKeyDown);
|
|
40
|
+
return () => {
|
|
41
|
+
pop();
|
|
42
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
onSettled(() => {
|
|
46
|
+
const onKeyDown = (event) => {
|
|
47
|
+
if (event.key.toLowerCase() !== 'b' ||
|
|
48
|
+
!(event.metaKey || event.ctrlKey) ||
|
|
49
|
+
event.altKey ||
|
|
50
|
+
event.shiftKey ||
|
|
51
|
+
editable(event.target))
|
|
52
|
+
return;
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
if (narrow())
|
|
55
|
+
props.onDrawerOpenChange(!props.drawerOpen);
|
|
56
|
+
else
|
|
57
|
+
props.onCollapsedChange(!props.collapsed);
|
|
58
|
+
};
|
|
59
|
+
document.addEventListener('keydown', onKeyDown);
|
|
60
|
+
return () => document.removeEventListener('keydown', onKeyDown);
|
|
61
|
+
});
|
|
62
|
+
const body = () => (<>
|
|
63
|
+
<div class='vds-sidebar__scroll'>{props.children}</div>
|
|
64
|
+
<Show when={props.footer}>
|
|
65
|
+
<div class='vds-sidebar__footer'>{props.footer}</div>
|
|
66
|
+
</Show>
|
|
67
|
+
</>);
|
|
68
|
+
return (<Show when={narrow()} fallback={<Show when={!props.collapsed}>
|
|
69
|
+
<div class='vds-sidebar-frame' style={{ width: `${props.width}px` }}>
|
|
70
|
+
<nav class='vds-sidebar' aria-label={props.label}>
|
|
71
|
+
{body()}
|
|
72
|
+
</nav>
|
|
73
|
+
<Resizer label={`Resize ${props.label}`} value={props.width} min={props.minWidth ?? WIDTH.min} max={props.maxWidth ?? WIDTH.max} reset={props.resetWidth ?? WIDTH.reset} onChange={props.onWidthChange}/>
|
|
74
|
+
</div>
|
|
75
|
+
</Show>}>
|
|
76
|
+
<Show when={drawer.isMounted()}>
|
|
77
|
+
<div class={['vds-drawer-scrim', { 'vds-drawer--visible': drawer.isVisible() }]} onPointerDown={() => props.onDrawerOpenChange(false)}/>
|
|
78
|
+
<div ref={setPanel} class={[
|
|
79
|
+
'vds-sidebar',
|
|
80
|
+
'vds-drawer',
|
|
81
|
+
{ 'vds-drawer--visible': drawer.isVisible() },
|
|
82
|
+
]} role='dialog' aria-modal='true' aria-label={props.label} tabindex='-1'>
|
|
83
|
+
<nav class='vds-drawer__nav' aria-label={props.label}>
|
|
84
|
+
{body()}
|
|
85
|
+
</nav>
|
|
86
|
+
</div>
|
|
87
|
+
</Show>
|
|
88
|
+
</Show>);
|
|
89
|
+
}
|
|
90
|
+
/** Whether the window is narrower than `breakpoint()`, following it as the window resizes. */
|
|
91
|
+
function createNarrow(breakpoint) {
|
|
92
|
+
const [narrow, setNarrow] = createSignal(false);
|
|
93
|
+
createEffect(breakpoint, (width) => {
|
|
94
|
+
const query = window.matchMedia(`(max-width: ${width - 0.02}px)`);
|
|
95
|
+
const update = () => setNarrow(query.matches);
|
|
96
|
+
update();
|
|
97
|
+
query.addEventListener('change', update);
|
|
98
|
+
return () => query.removeEventListener('change', update);
|
|
99
|
+
});
|
|
100
|
+
return narrow;
|
|
101
|
+
}
|
|
102
|
+
/** A text field or rich-text editor, where Mod-B belongs to the text. */
|
|
103
|
+
function editable(target) {
|
|
104
|
+
return (target instanceof HTMLElement &&
|
|
105
|
+
(target.isContentEditable || target.matches('input, textarea, select')));
|
|
106
|
+
}
|
package/dist/Switch.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentProps } from '@solidjs/web';
|
|
2
|
+
export type SwitchProps = Omit<ComponentProps<'input'>, 'onChange' | 'role' | 'type'> & {
|
|
3
|
+
checked: boolean;
|
|
4
|
+
onChange: (checked: boolean) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* An on-off switch: a native checkbox with the switch role, so it works in a form and with a label.
|
|
8
|
+
* Name it with `aria-label`, a wrapping `<label>`, or a SettingRow's props.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Switch(props: SwitchProps): import("@solidjs/web").JSX.Element;
|
package/dist/Switch.jsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { omit } from 'solid-js';
|
|
2
|
+
/**
|
|
3
|
+
* An on-off switch: a native checkbox with the switch role, so it works in a form and with a label.
|
|
4
|
+
* Name it with `aria-label`, a wrapping `<label>`, or a SettingRow's props.
|
|
5
|
+
*/
|
|
6
|
+
export function Switch(props) {
|
|
7
|
+
const rest = omit(props, 'checked', 'class', 'onChange');
|
|
8
|
+
return (<input type='checkbox'
|
|
9
|
+
// biome-ignore lint/a11y/useAriaPropsForRole: a native checkbox exposes its own checked state, which aria-checked would duplicate.
|
|
10
|
+
role='switch' class={['vds-switch', props.class]} checked={props.checked} onChange={(event) => props.onChange(event.currentTarget.checked)} {...rest}/>);
|
|
11
|
+
}
|
package/dist/Tabs.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type JSX } from '@solidjs/web';
|
|
2
|
+
export type Tab = {
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
7
|
+
export type TabsProps = {
|
|
8
|
+
/** The selected tab's panel. */
|
|
9
|
+
children: JSX.Element;
|
|
10
|
+
/** Names the tab list for assistive technology. */
|
|
11
|
+
label: string;
|
|
12
|
+
onChange: (value: string) => void;
|
|
13
|
+
tabs: Tab[];
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
/** A row of tabs over one panel. Arrow keys, Home, and End move between tabs and select as they go. */
|
|
17
|
+
export declare function Tabs(props: TabsProps): JSX.Element;
|
package/dist/Tabs.jsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { For } from '@solidjs/web';
|
|
2
|
+
import { createUniqueId } from 'solid-js';
|
|
3
|
+
import { aria } from './aria';
|
|
4
|
+
import { moveFor, rows } from './roving';
|
|
5
|
+
/** A row of tabs over one panel. Arrow keys, Home, and End move between tabs and select as they go. */
|
|
6
|
+
export function Tabs(props) {
|
|
7
|
+
const id = createUniqueId();
|
|
8
|
+
let list;
|
|
9
|
+
const onKeyDown = (event) => {
|
|
10
|
+
const from = props.tabs.findIndex((tab) => tab.value === props.value);
|
|
11
|
+
const move = moveFor(event.key, props.tabs, from, 'horizontal');
|
|
12
|
+
const tab = move === undefined ? undefined : props.tabs[move];
|
|
13
|
+
if (move === undefined || !tab)
|
|
14
|
+
return;
|
|
15
|
+
event.preventDefault();
|
|
16
|
+
rows(list, 'tab')[move]?.focus();
|
|
17
|
+
props.onChange(tab.value);
|
|
18
|
+
};
|
|
19
|
+
return (<div class='vds-tabs'>
|
|
20
|
+
<div ref={list} class='vds-tabs__list' role='tablist' aria-label={props.label} onKeyDown={onKeyDown}>
|
|
21
|
+
<For each={props.tabs}>
|
|
22
|
+
{(tab) => (<button type='button' id={`${id}-tab-${tab.value}`} class='vds-tabs__tab' role='tab' aria-selected={aria(tab.value === props.value)} aria-controls={`${id}-panel`} tabindex={tab.value === props.value ? '0' : '-1'} disabled={tab.disabled} onClick={() => props.onChange(tab.value)}>
|
|
23
|
+
{tab.label}
|
|
24
|
+
</button>)}
|
|
25
|
+
</For>
|
|
26
|
+
</div>
|
|
27
|
+
<div id={`${id}-panel`} class='vds-tabs__panel' role='tabpanel' aria-labelledby={`${id}-tab-${props.value}`} tabindex='0'>
|
|
28
|
+
{props.children}
|
|
29
|
+
</div>
|
|
30
|
+
</div>);
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type TextFieldProps = {
|
|
2
|
+
disabled?: boolean;
|
|
3
|
+
error?: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** A textarea rather than a single line. */
|
|
7
|
+
multiline?: boolean;
|
|
8
|
+
/** Called with the text once it's committed: on blur, or Enter in a single line. */
|
|
9
|
+
onChange: (value: string) => void;
|
|
10
|
+
/** Called on every keystroke, for a caller that validates as the person types. */
|
|
11
|
+
onInput?: (value: string) => void;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
type?: 'text' | 'email' | 'password' | 'search' | 'url';
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A labelled text input with a hint and an error read along with it. Typing goes to a draft that
|
|
18
|
+
* follows `value` whenever the caller changes it, so typed text survives any other prop changing.
|
|
19
|
+
*/
|
|
20
|
+
export declare function TextField(props: TextFieldProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Show } from '@solidjs/web';
|
|
2
|
+
import { createSignal, createUniqueId } from 'solid-js';
|
|
3
|
+
import { aria } from './aria';
|
|
4
|
+
/**
|
|
5
|
+
* A labelled text input with a hint and an error read along with it. Typing goes to a draft that
|
|
6
|
+
* follows `value` whenever the caller changes it, so typed text survives any other prop changing.
|
|
7
|
+
*/
|
|
8
|
+
export function TextField(props) {
|
|
9
|
+
const id = createUniqueId();
|
|
10
|
+
const [draft, setDraft] = createSignal(() => props.value);
|
|
11
|
+
const describedBy = () => [props.hint && `${id}-hint`, props.error && `${id}-error`].filter(Boolean).join(' ') ||
|
|
12
|
+
undefined;
|
|
13
|
+
const onInput = (event) => {
|
|
14
|
+
setDraft(event.currentTarget.value);
|
|
15
|
+
props.onInput?.(event.currentTarget.value);
|
|
16
|
+
};
|
|
17
|
+
const onChange = (event) => props.onChange(event.currentTarget.value);
|
|
18
|
+
return (<div class={['vds-field', { 'vds-field--invalid': !!props.error }]}>
|
|
19
|
+
<label class='vds-field__label' for={`${id}-input`}>
|
|
20
|
+
{props.label}
|
|
21
|
+
</label>
|
|
22
|
+
<Show when={props.multiline} fallback={<input id={`${id}-input`} class='vds-field__input' type={props.type ?? 'text'} value={draft()} placeholder={props.placeholder} disabled={props.disabled} aria-invalid={aria(!!props.error)} aria-describedby={describedBy()} onInput={onInput} onChange={onChange}/>}>
|
|
23
|
+
<textarea id={`${id}-input`} class='vds-field__input vds-field__input--multiline' value={draft()} placeholder={props.placeholder} disabled={props.disabled} aria-invalid={aria(!!props.error)} aria-describedby={describedBy()} onInput={onInput} onChange={onChange}/>
|
|
24
|
+
</Show>
|
|
25
|
+
<Show when={props.hint}>
|
|
26
|
+
<span id={`${id}-hint`} class='vds-field__hint'>
|
|
27
|
+
{props.hint}
|
|
28
|
+
</span>
|
|
29
|
+
</Show>
|
|
30
|
+
<Show when={props.error}>
|
|
31
|
+
<span id={`${id}-error`} class='vds-field__error'>
|
|
32
|
+
{props.error}
|
|
33
|
+
</span>
|
|
34
|
+
</Show>
|
|
35
|
+
</div>);
|
|
36
|
+
}
|
package/dist/Toast.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ToastKind = 'info' | 'success' | 'error';
|
|
2
|
+
export type ToastOptions = {
|
|
3
|
+
action?: {
|
|
4
|
+
label: string;
|
|
5
|
+
onAction: () => void;
|
|
6
|
+
};
|
|
7
|
+
/** Milliseconds before it goes. Defaults to 4 seconds, or 8 with an action. */
|
|
8
|
+
duration?: number;
|
|
9
|
+
/** A toast with the same key replaces the one already showing. */
|
|
10
|
+
key?: string;
|
|
11
|
+
kind?: ToastKind;
|
|
12
|
+
/** Stays until it's dismissed or its action runs. */
|
|
13
|
+
pinned?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/** Removes a toast, fading it out first. */
|
|
16
|
+
export declare function dismissToast(id: number): void;
|
|
17
|
+
/** Shows a message in the Toaster and returns its id. It never takes focus. */
|
|
18
|
+
export declare function toast(message: string, options?: ToastOptions): number;
|
|
19
|
+
/**
|
|
20
|
+
* Where toasts appear: a polite live region in the corner, newest last. Mount one near the root.
|
|
21
|
+
* Hovering or focusing a toast pauses its timer.
|
|
22
|
+
*/
|
|
23
|
+
export declare function Toaster(): import("@solidjs/web").JSX.Element;
|
package/dist/Toast.jsx
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { createPresence } from '@solid-primitives/presence';
|
|
2
|
+
import { For, Show } from '@solidjs/web';
|
|
3
|
+
import { createEffect, createStore, onSettled } from 'solid-js';
|
|
4
|
+
import { Button } from './Button';
|
|
5
|
+
import { Icon } from './Icon';
|
|
6
|
+
const ACTION_DURATION_MS = 8000;
|
|
7
|
+
const DEFAULT_DURATION_MS = 4000;
|
|
8
|
+
/** How long a toast takes to fade out, and so how long it stays in the list after it's dismissed. */
|
|
9
|
+
const EXIT_MS = 160;
|
|
10
|
+
const ICONS = { info: 'info', success: 'check', error: 'alert' };
|
|
11
|
+
const [toasts, setToasts] = createStore({ list: [] });
|
|
12
|
+
let nextId = 1;
|
|
13
|
+
/** Removes a toast, fading it out first. */
|
|
14
|
+
export function dismissToast(id) {
|
|
15
|
+
setToasts((state) => {
|
|
16
|
+
const entry = state.list.find((item) => item.id === id);
|
|
17
|
+
if (entry)
|
|
18
|
+
entry.leaving = true;
|
|
19
|
+
});
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
setToasts((state) => {
|
|
22
|
+
state.list = state.list.filter((item) => item.id !== id);
|
|
23
|
+
});
|
|
24
|
+
}, EXIT_MS);
|
|
25
|
+
}
|
|
26
|
+
/** Shows a message in the Toaster and returns its id. It never takes focus. */
|
|
27
|
+
export function toast(message, options = {}) {
|
|
28
|
+
const id = nextId++;
|
|
29
|
+
setToasts((state) => {
|
|
30
|
+
const kept = options.key
|
|
31
|
+
? state.list.filter((item) => item.key !== options.key)
|
|
32
|
+
: state.list;
|
|
33
|
+
state.list = [...kept, { ...options, id, leaving: false, message }];
|
|
34
|
+
});
|
|
35
|
+
return id;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Where toasts appear: a polite live region in the corner, newest last. Mount one near the root.
|
|
39
|
+
* Hovering or focusing a toast pauses its timer.
|
|
40
|
+
*/
|
|
41
|
+
export function Toaster() {
|
|
42
|
+
onSettled(() => () => setToasts((state) => {
|
|
43
|
+
state.list = [];
|
|
44
|
+
}));
|
|
45
|
+
return (<section class='vds-toaster' aria-label='Notifications' aria-live='polite'>
|
|
46
|
+
<For each={toasts.list}>{(entry) => <ToastItem entry={entry}/>}</For>
|
|
47
|
+
</section>);
|
|
48
|
+
}
|
|
49
|
+
function ToastItem(props) {
|
|
50
|
+
const presence = createPresence(() => (props.entry.leaving ? undefined : props.entry), {
|
|
51
|
+
transitionDuration: EXIT_MS,
|
|
52
|
+
initialEnter: true,
|
|
53
|
+
});
|
|
54
|
+
let remaining = 0;
|
|
55
|
+
let startedAt = 0;
|
|
56
|
+
let timer;
|
|
57
|
+
let hovered = false;
|
|
58
|
+
let focused = false;
|
|
59
|
+
const start = (id) => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
startedAt = Date.now();
|
|
62
|
+
timer = setTimeout(() => dismissToast(id), remaining);
|
|
63
|
+
};
|
|
64
|
+
const resume = () => {
|
|
65
|
+
if (hovered || focused || props.entry.pinned || props.entry.leaving)
|
|
66
|
+
return;
|
|
67
|
+
start(props.entry.id);
|
|
68
|
+
};
|
|
69
|
+
const pause = () => {
|
|
70
|
+
if (timer === undefined)
|
|
71
|
+
return;
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
timer = undefined;
|
|
74
|
+
remaining -= Date.now() - startedAt;
|
|
75
|
+
};
|
|
76
|
+
createEffect(() => ({
|
|
77
|
+
id: props.entry.id,
|
|
78
|
+
duration: props.entry.duration ??
|
|
79
|
+
(props.entry.action ? ACTION_DURATION_MS : DEFAULT_DURATION_MS),
|
|
80
|
+
timed: !props.entry.pinned && !props.entry.leaving,
|
|
81
|
+
}), ({ id, duration, timed }) => {
|
|
82
|
+
remaining = duration;
|
|
83
|
+
if (timed)
|
|
84
|
+
start(id);
|
|
85
|
+
return () => clearTimeout(timer);
|
|
86
|
+
});
|
|
87
|
+
return (<Show when={presence.isMounted()}>
|
|
88
|
+
<div class={[
|
|
89
|
+
'vds-toast',
|
|
90
|
+
`vds-toast--${props.entry.kind ?? 'info'}`,
|
|
91
|
+
{ 'vds-toast--visible': presence.isVisible() },
|
|
92
|
+
]} onPointerEnter={() => {
|
|
93
|
+
hovered = true;
|
|
94
|
+
pause();
|
|
95
|
+
}} onPointerLeave={() => {
|
|
96
|
+
hovered = false;
|
|
97
|
+
resume();
|
|
98
|
+
}} onFocusIn={() => {
|
|
99
|
+
focused = true;
|
|
100
|
+
pause();
|
|
101
|
+
}} onFocusOut={(event) => {
|
|
102
|
+
if (event.currentTarget.contains(event.relatedTarget))
|
|
103
|
+
return;
|
|
104
|
+
focused = false;
|
|
105
|
+
resume();
|
|
106
|
+
}}>
|
|
107
|
+
<Show when={props.entry.kind && props.entry.kind !== 'info'}>
|
|
108
|
+
<Icon name={ICONS[props.entry.kind ?? 'info']} class='vds-toast__icon'/>
|
|
109
|
+
</Show>
|
|
110
|
+
<span class='vds-toast__message'>{props.entry.message}</span>
|
|
111
|
+
<Show when={props.entry.action}>
|
|
112
|
+
{(action) => (<Button variant='ghost' size='sm' onClick={() => {
|
|
113
|
+
action().onAction();
|
|
114
|
+
dismissToast(props.entry.id);
|
|
115
|
+
}}>
|
|
116
|
+
{action().label}
|
|
117
|
+
</Button>)}
|
|
118
|
+
</Show>
|
|
119
|
+
<Button variant='ghost' size='sm' class='vds-toast__dismiss' aria-label='Dismiss' onClick={() => dismissToast(props.entry.id)}>
|
|
120
|
+
<Icon name='close' size='var(--icon-size-sm)'/>
|
|
121
|
+
</Button>
|
|
122
|
+
</div>
|
|
123
|
+
</Show>);
|
|
124
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type JSX } from '@solidjs/web';
|
|
2
|
+
export type ToolbarProps = {
|
|
3
|
+
/** The trailing actions, an overflow menu's trigger last. */
|
|
4
|
+
children?: JSX.Element;
|
|
5
|
+
/** Names the toolbar for assistive technology. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Before the title, such as a back or a sidebar button. */
|
|
8
|
+
leading?: JSX.Element;
|
|
9
|
+
/** Beside the title in muted text, such as what kind of page it is. */
|
|
10
|
+
subtitle?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A page's header bar: leading controls, a title, and trailing actions. It is one tab stop, and arrow keys, Home,
|
|
15
|
+
* and End move between its controls, as in the WAI-ARIA toolbar pattern.
|
|
16
|
+
*/
|
|
17
|
+
export declare function Toolbar(props: ToolbarProps): JSX.Element;
|