@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.
Files changed (89) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +28 -2
  3. package/dist/AppShell.d.ts +15 -0
  4. package/dist/AppShell.jsx +16 -0
  5. package/dist/AppSwitcher.d.ts +23 -0
  6. package/dist/AppSwitcher.jsx +24 -0
  7. package/dist/Badge.d.ts +7 -0
  8. package/dist/Badge.jsx +4 -0
  9. package/dist/Button.d.ts +9 -0
  10. package/dist/Button.jsx +17 -0
  11. package/dist/Checkbox.d.ts +8 -0
  12. package/dist/Checkbox.jsx +9 -0
  13. package/dist/CommandPalette.d.ts +42 -0
  14. package/dist/CommandPalette.jsx +107 -0
  15. package/dist/Dialog.d.ts +13 -0
  16. package/dist/Dialog.jsx +37 -0
  17. package/dist/EmptyState.d.ts +11 -0
  18. package/dist/EmptyState.jsx +17 -0
  19. package/dist/Icon.d.ts +11 -0
  20. package/dist/Icon.jsx +12 -0
  21. package/dist/IconButton.d.ts +16 -0
  22. package/dist/IconButton.jsx +25 -0
  23. package/dist/Kbd.d.ts +8 -0
  24. package/dist/Kbd.jsx +23 -0
  25. package/dist/Listbox.d.ts +18 -0
  26. package/dist/Listbox.jsx +48 -0
  27. package/dist/Menu.d.ts +31 -0
  28. package/dist/Menu.jsx +114 -0
  29. package/dist/ObjectCard.d.ts +23 -0
  30. package/dist/ObjectCard.jsx +41 -0
  31. package/dist/Popover.d.ts +15 -0
  32. package/dist/Popover.jsx +50 -0
  33. package/dist/Resizer.d.ts +17 -0
  34. package/dist/Resizer.jsx +43 -0
  35. package/dist/SegmentedControl.d.ts +19 -0
  36. package/dist/SegmentedControl.jsx +39 -0
  37. package/dist/Select.d.ts +13 -0
  38. package/dist/Select.jsx +17 -0
  39. package/dist/SettingRow.d.ts +15 -0
  40. package/dist/SettingRow.jsx +26 -0
  41. package/dist/Sidebar.d.ts +29 -0
  42. package/dist/Sidebar.jsx +106 -0
  43. package/dist/Switch.d.ts +10 -0
  44. package/dist/Switch.jsx +11 -0
  45. package/dist/Tabs.d.ts +17 -0
  46. package/dist/Tabs.jsx +31 -0
  47. package/dist/TextField.d.ts +20 -0
  48. package/dist/TextField.jsx +36 -0
  49. package/dist/Toast.d.ts +23 -0
  50. package/dist/Toast.jsx +124 -0
  51. package/dist/Toolbar.d.ts +17 -0
  52. package/dist/Toolbar.jsx +67 -0
  53. package/dist/Tooltip.d.ts +12 -0
  54. package/dist/Tooltip.jsx +54 -0
  55. package/dist/Tree.d.ts +29 -0
  56. package/dist/Tree.jsx +130 -0
  57. package/dist/app-switcher.css +72 -0
  58. package/dist/aria.d.ts +2 -0
  59. package/dist/aria.js +6 -0
  60. package/dist/button.css +117 -0
  61. package/dist/controls.css +182 -0
  62. package/dist/dialog.css +60 -0
  63. package/dist/field.css +61 -0
  64. package/dist/icon.css +5 -0
  65. package/dist/index.d.ts +29 -0
  66. package/dist/index.js +28 -0
  67. package/dist/layers.d.ts +7 -0
  68. package/dist/layers.js +38 -0
  69. package/dist/listbox.css +49 -0
  70. package/dist/menu.css +56 -0
  71. package/dist/object-card.css +81 -0
  72. package/dist/palette.css +86 -0
  73. package/dist/paths.d.ts +68 -0
  74. package/dist/paths.js +68 -0
  75. package/dist/popover.css +21 -0
  76. package/dist/roving.d.ts +21 -0
  77. package/dist/roving.js +48 -0
  78. package/dist/setting.css +42 -0
  79. package/dist/shell.css +155 -0
  80. package/dist/small.css +77 -0
  81. package/dist/styles.css +20 -0
  82. package/dist/tabs.css +44 -0
  83. package/dist/toast.css +72 -0
  84. package/dist/toolbar.css +46 -0
  85. package/dist/tooltip.css +14 -0
  86. package/dist/tree.css +92 -0
  87. package/dist/trigger.d.ts +15 -0
  88. package/dist/trigger.js +1 -0
  89. package/package.json +52 -3
@@ -0,0 +1,107 @@
1
+ import { For, Show } from '@solidjs/web';
2
+ import { createEffect, createMemo, createSignal, createUniqueId } from 'solid-js';
3
+ import { aria } from './aria';
4
+ import { Icon } from './Icon';
5
+ import { first, moveFor, rows } from './roving';
6
+ /**
7
+ * A search field over a list of commands, in the combobox pattern: focus stays in the field, arrow
8
+ * keys move the highlighted command, and Enter runs it. Every word typed must appear in a command's
9
+ * label or keywords.
10
+ */
11
+ export function CommandPalette(props) {
12
+ const id = createUniqueId();
13
+ const [query, setQuery] = createSignal('');
14
+ const results = createMemo(() => matching(props.commands, query()));
15
+ const groups = createMemo(() => grouped(results()));
16
+ /** The results in the order they're shown, which the highlight's index counts in. */
17
+ const shown = createMemo(() => groups().flatMap((group) => group.rows.map((row) => row.command)));
18
+ const [active, setActive] = createSignal(() => first(shown()));
19
+ let list;
20
+ createEffect(() => active(), (at) => rows(list, 'option')[at]?.scrollIntoView?.({ block: 'nearest' }));
21
+ const run = (at) => {
22
+ const command = shown()[at];
23
+ if (command && !command.disabled)
24
+ command.onSelect();
25
+ };
26
+ const onKeyDown = (event) => {
27
+ if (event.key === 'Escape') {
28
+ event.preventDefault();
29
+ props.onClose?.();
30
+ return;
31
+ }
32
+ if (event.key === 'Enter') {
33
+ event.preventDefault();
34
+ run(active());
35
+ return;
36
+ }
37
+ if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp')
38
+ return;
39
+ const move = moveFor(event.key, shown(), active());
40
+ if (move === undefined || move < 0)
41
+ return;
42
+ event.preventDefault();
43
+ setActive(move);
44
+ };
45
+ const optionId = (at) => `${id}-option-${at}`;
46
+ return (<div class='vds-palette'>
47
+ <input class={['vds-palette__input', { 'vds-palette__input--empty': !results().length }]} type='text' role='combobox' aria-label={props.label} aria-expanded='true' aria-controls={`${id}-list`} aria-autocomplete='list' aria-activedescendant={active() >= 0 ? optionId(active()) : undefined} placeholder={props.placeholder} autocomplete='off' spellcheck={false} onInput={(event) => setQuery(event.currentTarget.value)} onKeyDown={onKeyDown}/>
48
+ <div ref={list} id={`${id}-list`} class='vds-palette__list' role='listbox' aria-label={props.label}>
49
+ <For each={groups()}>
50
+ {(group) => (
51
+ // biome-ignore lint/a11y/useSemanticElements: a listbox's groups take role group; a fieldset isn't allowed in one.
52
+ <div class='vds-palette__group' role='group' aria-label={group.name}>
53
+ <Show when={group.name}>
54
+ <div class='vds-palette__heading' aria-hidden='true'>
55
+ {group.name}
56
+ </div>
57
+ </Show>
58
+ <For each={group.rows}>
59
+ {(row) => (
60
+ // biome-ignore lint/a11y/useFocusableInteractive lint/a11y/useKeyWithClickEvents: in the combobox pattern focus stays in the field, which handles the keys.
61
+ <div id={optionId(row.index)} class='vds-palette__option' role='option' aria-selected={aria(row.index === active())} aria-disabled={aria(row.command.disabled)} onPointerMove={() => {
62
+ if (!row.command.disabled)
63
+ setActive(row.index);
64
+ }} onClick={() => run(row.index)}>
65
+ <Show when={row.command.icon}>
66
+ {(name) => <Icon name={name()}/>}
67
+ </Show>
68
+ <span class='vds-palette__label'>{row.command.label}</span>
69
+ <Show when={row.command.hint}>
70
+ <kbd class='vds-palette__hint'>{row.command.hint}</kbd>
71
+ </Show>
72
+ </div>)}
73
+ </For>
74
+ </div>)}
75
+ </For>
76
+ </div>
77
+ <Show when={!results().length}>
78
+ <p class='vds-palette__empty' role='status'>
79
+ {props.emptyText ?? 'No matching commands'}
80
+ </p>
81
+ </Show>
82
+ </div>);
83
+ }
84
+ /** The commands in group order, each group in the order its commands were given. */
85
+ export function grouped(commands) {
86
+ const groups = new Map();
87
+ for (const command of commands) {
88
+ const group = groups.get(command.group) ?? { name: command.group, rows: [] };
89
+ groups.set(command.group, group);
90
+ group.rows.push({ command, index: -1 });
91
+ }
92
+ let index = 0;
93
+ for (const group of groups.values())
94
+ for (const row of group.rows)
95
+ row.index = index++;
96
+ return [...groups.values()];
97
+ }
98
+ /** The commands whose label or keywords contain every word of the query, ignoring case. */
99
+ export function matching(commands, query) {
100
+ const words = query.toLowerCase().split(/\s+/).filter(Boolean);
101
+ if (!words.length)
102
+ return commands;
103
+ return commands.filter((command) => {
104
+ const text = [command.label, ...(command.keywords ?? [])].join(' ').toLowerCase();
105
+ return words.every((word) => text.includes(word));
106
+ });
107
+ }
@@ -0,0 +1,13 @@
1
+ import { type JSX } from '@solidjs/web';
2
+ export type DialogProps = {
3
+ children: JSX.Element;
4
+ description?: string;
5
+ onOpenChange: (open: boolean) => void;
6
+ open: boolean;
7
+ title: string;
8
+ };
9
+ /**
10
+ * A modal dialog. Escape or a click on the backdrop closes the top dialog only, focus stays inside
11
+ * while it's open, and focus goes back to whatever had it before the dialog opened.
12
+ */
13
+ export declare function Dialog(props: DialogProps): JSX.Element;
@@ -0,0 +1,37 @@
1
+ import { createFocusTrap } from '@solid-primitives/focus';
2
+ import { Portal, Show } from '@solidjs/web';
3
+ import { createEffect, createSignal, createUniqueId } from 'solid-js';
4
+ import { isTopDialog, pushDialog } from './layers';
5
+ /**
6
+ * A modal dialog. Escape or a click on the backdrop closes the top dialog only, focus stays inside
7
+ * while it's open, and focus goes back to whatever had it before the dialog opened.
8
+ */
9
+ export function Dialog(props) {
10
+ const id = createUniqueId();
11
+ const [panel, setPanel] = createSignal();
12
+ const self = {};
13
+ createFocusTrap({ element: panel, enabled: () => props.open });
14
+ createEffect(() => props.open, (open) => (open ? pushDialog(self) : undefined));
15
+ const onKeyDown = (event) => {
16
+ if (event.key !== 'Escape' || !isTopDialog(self))
17
+ return;
18
+ event.preventDefault();
19
+ props.onOpenChange(false);
20
+ };
21
+ return (<Show when={props.open}>
22
+ <Portal>
23
+ <div class='vds-dialog-backdrop' onPointerDown={() => props.onOpenChange(false)}/>
24
+ <div ref={setPanel} class='vds-dialog' role='dialog' aria-modal='true' aria-labelledby={`${id}-title`} aria-describedby={props.description ? `${id}-description` : undefined} tabindex='-1' onKeyDown={onKeyDown}>
25
+ <h2 id={`${id}-title`} class='vds-dialog__title'>
26
+ {props.title}
27
+ </h2>
28
+ <Show when={props.description}>
29
+ <p id={`${id}-description`} class='vds-dialog__description'>
30
+ {props.description}
31
+ </p>
32
+ </Show>
33
+ {props.children}
34
+ </div>
35
+ </Portal>
36
+ </Show>);
37
+ }
@@ -0,0 +1,11 @@
1
+ import { type JSX } from '@solidjs/web';
2
+ import { type IconName } from './Icon';
3
+ export type EmptyStateProps = {
4
+ /** An action, such as a button that makes the first item. */
5
+ children?: JSX.Element;
6
+ description?: string;
7
+ icon?: IconName;
8
+ title: string;
9
+ };
10
+ /** What a list or page shows when it has nothing in it yet. */
11
+ export declare function EmptyState(props: EmptyStateProps): JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { Show } from '@solidjs/web';
2
+ import { Icon } from './Icon';
3
+ /** What a list or page shows when it has nothing in it yet. */
4
+ export function EmptyState(props) {
5
+ return (<div class='vds-empty'>
6
+ <Show when={props.icon}>
7
+ {(name) => <Icon name={name()} class='vds-empty__icon' size='24px'/>}
8
+ </Show>
9
+ <p class='vds-empty__title'>{props.title}</p>
10
+ <Show when={props.description}>
11
+ <p class='vds-empty__description'>{props.description}</p>
12
+ </Show>
13
+ <Show when={props.children}>
14
+ <div class='vds-empty__actions'>{props.children}</div>
15
+ </Show>
16
+ </div>);
17
+ }
package/dist/Icon.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { ComponentProps } from '@solidjs/web';
2
+ import { PATHS } from './paths';
3
+ export type IconName = keyof typeof PATHS;
4
+ export type IconProps = Omit<ComponentProps<'svg'>, 'name'> & {
5
+ name: IconName;
6
+ /** A CSS length. Defaults to `--icon-size`. */
7
+ size?: string;
8
+ };
9
+ /** An inline SVG icon in `currentColor`, hidden from assistive technology. */
10
+ export declare function Icon(props: IconProps): import("@solidjs/web").JSX.Element;
11
+ export declare function iconNames(): IconName[];
package/dist/Icon.jsx ADDED
@@ -0,0 +1,12 @@
1
+ import { omit } from 'solid-js';
2
+ import { PATHS } from './paths';
3
+ /** An inline SVG icon in `currentColor`, hidden from assistive technology. */
4
+ export function Icon(props) {
5
+ const rest = omit(props, 'class', 'name', 'size', 'style');
6
+ return (<svg class={['vds-icon', props.class]} style={{ '--vds-icon-size': props.size }} viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round' aria-hidden='true' {...rest}>
7
+ <path d={PATHS[props.name]}/>
8
+ </svg>);
9
+ }
10
+ export function iconNames() {
11
+ return Object.keys(PATHS);
12
+ }
@@ -0,0 +1,16 @@
1
+ import type { Placement } from '@floating-ui/dom';
2
+ import { type ButtonProps } from './Button';
3
+ import type { IconName } from './Icon';
4
+ export type IconButtonProps = Omit<ButtonProps, 'children' | 'icon'> & {
5
+ icon: IconName;
6
+ /** The button's name, read by assistive technology and shown in its tooltip. */
7
+ label: string;
8
+ /** Shows the label beside the icon while the toolbar it sits in has room, for an icon that isn't clear alone. */
9
+ showLabel?: boolean;
10
+ tooltipPlacement?: Placement;
11
+ };
12
+ /**
13
+ * A button drawn as an icon, with its label in a tooltip. With `showLabel` the label shows beside the icon until
14
+ * the toolbar narrows, and the tooltip opens only once it has gone.
15
+ */
16
+ export declare function IconButton(props: IconButtonProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { Show } from '@solidjs/web';
2
+ import { merge, omit } from 'solid-js';
3
+ import { Button } from './Button';
4
+ import { Tooltip } from './Tooltip';
5
+ /**
6
+ * A button drawn as an icon, with its label in a tooltip. With `showLabel` the label shows beside the icon until
7
+ * the toolbar narrows, and the tooltip opens only once it has gone.
8
+ */
9
+ export function IconButton(props) {
10
+ const rest = omit(props, 'class', 'label', 'showLabel', 'tooltipPlacement');
11
+ let label;
12
+ const collapsed = () => !label || getComputedStyle(label).getPropertyValue('--vds-collapsed').trim() === '1';
13
+ return (<Tooltip content={props.label} placement={props.tooltipPlacement ?? 'bottom'} when={() => !props.showLabel || collapsed()}>
14
+ {(trigger) => (<Button {...merge(rest, trigger)} class={[
15
+ props.showLabel ? 'vds-button--collapse' : 'vds-button--icon',
16
+ props.class,
17
+ ]} aria-label={props.showLabel ? undefined : props.label}>
18
+ <Show when={props.showLabel}>
19
+ <span ref={label} class='vds-button__label'>
20
+ {props.label}
21
+ </span>
22
+ </Show>
23
+ </Button>)}
24
+ </Tooltip>);
25
+ }
package/dist/Kbd.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type KbdProps = {
2
+ /** Keys joined with `+`, such as `Mod+K`. */
3
+ keys: string;
4
+ };
5
+ /** A keyboard shortcut as the person's platform writes it. */
6
+ export declare function Kbd(props: KbdProps): import("@solidjs/web").JSX.Element;
7
+ /** `Mod+Shift+K` as `⌘⇧K` on Apple platforms and `Ctrl+Shift+K` elsewhere. */
8
+ export declare function shortcutLabel(keys: string, apple: boolean): string;
package/dist/Kbd.jsx ADDED
@@ -0,0 +1,23 @@
1
+ /** A keyboard shortcut as the person's platform writes it. */
2
+ export function Kbd(props) {
3
+ return <kbd class='vds-kbd'>{shortcutLabel(props.keys, isApple())}</kbd>;
4
+ }
5
+ /** `Mod+Shift+K` as `⌘⇧K` on Apple platforms and `Ctrl+Shift+K` elsewhere. */
6
+ export function shortcutLabel(keys, apple) {
7
+ const names = {
8
+ mod: ['⌘', 'Ctrl'],
9
+ shift: ['⇧', 'Shift'],
10
+ alt: ['⌥', 'Alt'],
11
+ ctrl: ['⌃', 'Ctrl'],
12
+ };
13
+ const parts = keys
14
+ .split('+')
15
+ .map((key) => names[key.toLowerCase()]?.[apple ? 0 : 1] ?? keyName(key));
16
+ return parts.join(apple ? '' : '+');
17
+ }
18
+ function isApple() {
19
+ return typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform);
20
+ }
21
+ function keyName(key) {
22
+ return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
23
+ }
@@ -0,0 +1,18 @@
1
+ export type ListboxOption = {
2
+ description?: string;
3
+ disabled?: boolean;
4
+ label: string;
5
+ value: string;
6
+ };
7
+ export type ListboxProps = {
8
+ /** Names the list for assistive technology. */
9
+ label: string;
10
+ onChange: (value: string) => void;
11
+ options: ListboxOption[];
12
+ value?: string;
13
+ };
14
+ /**
15
+ * A single-choice list with roving focus: one option is in the tab order, arrow keys, Home, and End
16
+ * move between the enabled ones, and Enter, Space, or a click chooses.
17
+ */
18
+ export declare function Listbox(props: ListboxProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { For, Show } from '@solidjs/web';
2
+ import { createSignal } from 'solid-js';
3
+ import { aria } from './aria';
4
+ import { first, moveFor, rows } from './roving';
5
+ /**
6
+ * A single-choice list with roving focus: one option is in the tab order, arrow keys, Home, and End
7
+ * move between the enabled ones, and Enter, Space, or a click chooses.
8
+ */
9
+ export function Listbox(props) {
10
+ let list;
11
+ const elements = () => rows(list, 'option');
12
+ const [active, setActive] = createSignal(() => {
13
+ const chosen = props.options.findIndex((option) => option.value === props.value);
14
+ return chosen >= 0 ? chosen : first(props.options);
15
+ });
16
+ const onKeyDown = (event) => {
17
+ const from = elements().indexOf(document.activeElement);
18
+ const move = moveFor(event.key, props.options, from);
19
+ if (move !== undefined && move >= 0) {
20
+ event.preventDefault();
21
+ setActive(move);
22
+ elements()[move]?.focus();
23
+ return;
24
+ }
25
+ const option = props.options[from];
26
+ if ((event.key === 'Enter' || event.key === ' ') && option && !option.disabled) {
27
+ event.preventDefault();
28
+ props.onChange(option.value);
29
+ }
30
+ };
31
+ return (<div ref={list} class='vds-listbox' role='listbox' aria-label={props.label} onKeyDown={onKeyDown}>
32
+ <For each={props.options}>
33
+ {(option, index) => (
34
+ // biome-ignore lint/a11y/useFocusableInteractive lint/a11y/useKeyWithClickEvents: the tabindex is set below, and the list handles the keys.
35
+ <div class='vds-listbox__option' role='option' aria-selected={aria(option.value === props.value)} aria-disabled={aria(option.disabled)} tabindex={index() === active() ? '0' : '-1'} onClick={() => {
36
+ if (option.disabled)
37
+ return;
38
+ setActive(index());
39
+ props.onChange(option.value);
40
+ }}>
41
+ <span class='vds-listbox__label'>{option.label}</span>
42
+ <Show when={option.description}>
43
+ <span class='vds-listbox__description'>{option.description}</span>
44
+ </Show>
45
+ </div>)}
46
+ </For>
47
+ </div>);
48
+ }
package/dist/Menu.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { Placement } from '@floating-ui/dom';
2
+ import { type JSX } from '@solidjs/web';
3
+ import { type IconName } from './Icon';
4
+ import type { TriggerProps } from './trigger';
5
+ export type MenuItem = {
6
+ /** Marks the item for where the person already is, such as the open app. */
7
+ current?: boolean;
8
+ danger?: boolean;
9
+ /** A second, quieter line under the label. */
10
+ description?: string;
11
+ disabled?: boolean;
12
+ icon?: IconName;
13
+ label: string;
14
+ /** Drawn before the label in place of an icon. */
15
+ leading?: () => JSX.Element;
16
+ onSelect: () => void;
17
+ };
18
+ export type MenuProps = {
19
+ class?: string;
20
+ items: MenuItem[];
21
+ /** Names the menu for assistive technology. */
22
+ label: string;
23
+ placement?: Placement;
24
+ trigger: (props: TriggerProps) => JSX.Element;
25
+ };
26
+ /**
27
+ * A menu of actions. Arrow keys, Home, End, and a typed letter move between items; Enter or a click
28
+ * runs one. Escape, Tab, and a click elsewhere close it, and Escape and a choice return focus to the
29
+ * trigger.
30
+ */
31
+ export declare function Menu(props: MenuProps): JSX.Element;
package/dist/Menu.jsx ADDED
@@ -0,0 +1,114 @@
1
+ import { For, Portal, Show } from '@solidjs/web';
2
+ import { createEffect, createSignal, createUniqueId, onFlush } from 'solid-js';
3
+ import { aria } from './aria';
4
+ import { Icon } from './Icon';
5
+ import { closeOnOutside, place } from './layers';
6
+ import { first, moveFor, rows, typeahead } from './roving';
7
+ /**
8
+ * A menu of actions. Arrow keys, Home, End, and a typed letter move between items; Enter or a click
9
+ * runs one. Escape, Tab, and a click elsewhere close it, and Escape and a choice return focus to the
10
+ * trigger.
11
+ */
12
+ export function Menu(props) {
13
+ const id = createUniqueId();
14
+ const [open, setOpen] = createSignal(false);
15
+ const [anchor, setAnchor] = createSignal();
16
+ const [content, setContent] = createSignal();
17
+ const elements = (menu = content()) => rows(menu, 'menuitem');
18
+ const focused = () => elements().indexOf(document.activeElement);
19
+ const close = (refocus) => {
20
+ setOpen(false);
21
+ if (refocus)
22
+ anchor()?.focus();
23
+ };
24
+ createEffect(() => ({ open: open(), anchor: anchor(), content: content() }), (now) => {
25
+ if (!now.open || !now.anchor || !now.content)
26
+ return;
27
+ const stopPlacing = place(now.anchor, now.content, props.placement ?? 'bottom-start');
28
+ const stopListening = closeOnOutside(() => [now.anchor, now.content], () => close(false));
29
+ elements(now.content)[first(props.items)]?.focus();
30
+ return () => {
31
+ stopPlacing();
32
+ stopListening();
33
+ };
34
+ });
35
+ const choose = (item) => {
36
+ if (item.disabled)
37
+ return;
38
+ onFlush(() => close(true));
39
+ item.onSelect();
40
+ };
41
+ const onKeyDown = (event) => {
42
+ if (event.key === 'Escape') {
43
+ event.preventDefault();
44
+ close(true);
45
+ return;
46
+ }
47
+ if (event.key === 'Tab') {
48
+ close(false);
49
+ return;
50
+ }
51
+ const item = props.items[focused()];
52
+ if ((event.key === 'Enter' || event.key === ' ') && item) {
53
+ event.preventDefault();
54
+ choose(item);
55
+ return;
56
+ }
57
+ const move = moveFor(event.key, props.items, focused());
58
+ if (move !== undefined) {
59
+ event.preventDefault();
60
+ elements()[move]?.focus();
61
+ return;
62
+ }
63
+ if (event.key.length === 1 && /\S/.test(event.key)) {
64
+ const at = typeahead(props.items, focused(), event.key);
65
+ if (at >= 0)
66
+ elements()[at]?.focus();
67
+ }
68
+ };
69
+ const onTriggerKeyDown = (event) => {
70
+ if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp')
71
+ return;
72
+ event.preventDefault();
73
+ setOpen(true);
74
+ };
75
+ return (<>
76
+ {props.trigger({
77
+ ref: setAnchor,
78
+ 'aria-haspopup': 'menu',
79
+ get 'aria-expanded'() {
80
+ return aria(open());
81
+ },
82
+ 'aria-controls': id,
83
+ onClick: () => setOpen((was) => !was),
84
+ onKeyDown: onTriggerKeyDown,
85
+ })}
86
+ <Show when={open()}>
87
+ <Portal>
88
+ <div ref={setContent} id={id} class={['vds-menu', props.class]} role='menu' aria-label={props.label} onKeyDown={onKeyDown}>
89
+ <For each={props.items}>
90
+ {(item) => (<button type='button' class={[
91
+ 'vds-menu__item',
92
+ {
93
+ 'vds-menu__item--danger': item.danger,
94
+ 'vds-menu__item--current': item.current,
95
+ },
96
+ ]} role='menuitem' tabindex='-1' aria-current={item.current ? 'true' : undefined} aria-disabled={aria(item.disabled)} onClick={() => choose(item)}>
97
+ {item.leading?.() ?? (<Show when={item.icon}>
98
+ {(name) => <Icon name={name()}/>}
99
+ </Show>)}
100
+ <Show when={item.description} fallback={item.label}>
101
+ <span class='vds-menu__lines'>
102
+ <span>{item.label}</span>
103
+ <span class='vds-menu__description'>
104
+ {item.description}
105
+ </span>
106
+ </span>
107
+ </Show>
108
+ </button>)}
109
+ </For>
110
+ </div>
111
+ </Portal>
112
+ </Show>
113
+ </>);
114
+ }
@@ -0,0 +1,23 @@
1
+ import type { IconName } from './Icon';
2
+ export type ObjectCardData = {
3
+ /** The owning app's colour, behind the icon. */
4
+ colour: string;
5
+ href: string;
6
+ icon: IconName;
7
+ status?: string;
8
+ summary?: string;
9
+ title: string;
10
+ /** The kind of object in the owning app's words, such as "Tracker issue". */
11
+ type: string;
12
+ version: number;
13
+ };
14
+ export type ObjectCardProps = {
15
+ card: ObjectCardData;
16
+ /** Opens the object in its app. Without it, Open follows the card's link. */
17
+ onOpen?: (card: ObjectCardData) => void;
18
+ };
19
+ /**
20
+ * Another app's object drawn in this one: its icon, type, status, title, a summary line, and an Open
21
+ * action. A card from a schema version it doesn't know is shown as a plain link to the object.
22
+ */
23
+ export declare function ObjectCard(props: ObjectCardProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,41 @@
1
+ import { Show } from '@solidjs/web';
2
+ import { createUniqueId } from 'solid-js';
3
+ import { AppMark } from './AppSwitcher';
4
+ const KNOWN_VERSIONS = [1];
5
+ /**
6
+ * Another app's object drawn in this one: its icon, type, status, title, a summary line, and an Open
7
+ * action. A card from a schema version it doesn't know is shown as a plain link to the object.
8
+ */
9
+ export function ObjectCard(props) {
10
+ const id = createUniqueId();
11
+ const open = (event) => {
12
+ if (!props.onOpen || event.ctrlKey || event.metaKey || event.shiftKey)
13
+ return;
14
+ event.preventDefault();
15
+ props.onOpen(props.card);
16
+ };
17
+ return (<Show when={KNOWN_VERSIONS.includes(props.card.version)} fallback={<a class='vds-object-link' href={props.card.href}>
18
+ {props.card.title}
19
+ </a>}>
20
+ <article class='vds-object-card' aria-labelledby={`${id}-title`}>
21
+ <AppMark app={props.card} size='lg'/>
22
+ <div class='vds-object-card__lines'>
23
+ <span class='vds-object-card__what'>
24
+ {props.card.type}
25
+ <Show when={props.card.status}>
26
+ <span class='vds-object-card__status'>{props.card.status}</span>
27
+ </Show>
28
+ </span>
29
+ <span id={`${id}-title`} class='vds-object-card__title'>
30
+ {props.card.title}
31
+ </span>
32
+ <Show when={props.card.summary}>
33
+ <span class='vds-object-card__summary'>{props.card.summary}</span>
34
+ </Show>
35
+ </div>
36
+ <a class='vds-button vds-button--ghost vds-button--sm' href={props.card.href} aria-label={`Open ${props.card.title}`} onClick={open}>
37
+ Open
38
+ </a>
39
+ </article>
40
+ </Show>);
41
+ }
@@ -0,0 +1,15 @@
1
+ import type { Placement } from '@floating-ui/dom';
2
+ import { type JSX } from '@solidjs/web';
3
+ import type { TriggerProps } from './trigger';
4
+ export type PopoverProps = {
5
+ children: JSX.Element;
6
+ /** Names the popover for assistive technology. */
7
+ label: string;
8
+ placement?: Placement;
9
+ trigger: (props: TriggerProps) => JSX.Element;
10
+ };
11
+ /**
12
+ * Content that floats beside its trigger. A click on the trigger toggles it; Escape closes it and
13
+ * returns focus to the trigger, and a click elsewhere closes it and leaves focus where the click put it.
14
+ */
15
+ export declare function Popover(props: PopoverProps): JSX.Element;
@@ -0,0 +1,50 @@
1
+ import { Portal, Show } from '@solidjs/web';
2
+ import { createEffect, createSignal, createUniqueId } from 'solid-js';
3
+ import { aria } from './aria';
4
+ import { closeOnOutside, place } from './layers';
5
+ /**
6
+ * Content that floats beside its trigger. A click on the trigger toggles it; Escape closes it and
7
+ * returns focus to the trigger, and a click elsewhere closes it and leaves focus where the click put it.
8
+ */
9
+ export function Popover(props) {
10
+ const id = createUniqueId();
11
+ const [open, setOpen] = createSignal(false);
12
+ const [anchor, setAnchor] = createSignal();
13
+ const [content, setContent] = createSignal();
14
+ createEffect(() => ({ open: open(), anchor: anchor(), content: content() }), (now) => {
15
+ if (!now.open || !now.anchor || !now.content)
16
+ return;
17
+ const stopPlacing = place(now.anchor, now.content, props.placement ?? 'bottom-start');
18
+ const stopListening = closeOnOutside(() => [now.anchor, now.content], () => setOpen(false));
19
+ now.content.focus();
20
+ return () => {
21
+ stopPlacing();
22
+ stopListening();
23
+ };
24
+ });
25
+ const onKeyDown = (event) => {
26
+ if (event.key !== 'Escape')
27
+ return;
28
+ event.preventDefault();
29
+ setOpen(false);
30
+ anchor()?.focus();
31
+ };
32
+ return (<>
33
+ {props.trigger({
34
+ ref: setAnchor,
35
+ 'aria-haspopup': 'dialog',
36
+ get 'aria-expanded'() {
37
+ return aria(open());
38
+ },
39
+ 'aria-controls': id,
40
+ onClick: () => setOpen((was) => !was),
41
+ })}
42
+ <Show when={open()}>
43
+ <Portal>
44
+ <div ref={setContent} id={id} class='vds-popover' role='dialog' aria-label={props.label} tabindex='-1' onKeyDown={onKeyDown}>
45
+ {props.children}
46
+ </div>
47
+ </Portal>
48
+ </Show>
49
+ </>);
50
+ }
@@ -0,0 +1,17 @@
1
+ export type ResizerProps = {
2
+ /** Names what it resizes, for assistive technology. */
3
+ label: string;
4
+ max: number;
5
+ min: number;
6
+ onChange: (value: number) => void;
7
+ /** The width a double-click goes back to. */
8
+ reset: number;
9
+ /** Pixels per arrow key. */
10
+ step?: number;
11
+ value: number;
12
+ };
13
+ /**
14
+ * A drag handle between two panes, as a focusable separator. Arrow keys step it, Home and End reach its limits,
15
+ * and a double-click resets it.
16
+ */
17
+ export declare function Resizer(props: ResizerProps): import("@solidjs/web").JSX.Element;