@nurvus/ui 0.1.0-alpha.13 → 0.1.0-alpha.15

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 (61) hide show
  1. package/README.md +8 -0
  2. package/dist/index.js +1 -1
  3. package/dist/nurvus.css +7 -5
  4. package/dist/respawn.js +1 -1
  5. package/dist/types/components/Icon/Icon.d.ts +20 -0
  6. package/dist/types/components/Menu/Menu.d.ts +35 -27
  7. package/dist/types/components/Select/Select.d.ts +55 -0
  8. package/dist/types/components/Tree/Tree.d.ts +39 -0
  9. package/dist/types/icons.d.ts +55 -0
  10. package/dist/types/index.d.ts +9 -3
  11. package/dist/types/menu.d.ts +24 -0
  12. package/dist/types/respawn/Icon.d.ts +22 -0
  13. package/dist/types/respawn/Menu.d.ts +36 -26
  14. package/dist/types/respawn/Select.d.ts +54 -0
  15. package/dist/types/respawn/Tree.d.ts +36 -0
  16. package/dist/types/respawn/index.d.ts +9 -3
  17. package/dist/types/respawn/spawn.d.ts +2 -0
  18. package/dist/types/select.d.ts +70 -0
  19. package/dist/types/tree.d.ts +9 -0
  20. package/package.json +2 -2
  21. package/src/components/Button/Button.scss +8 -2
  22. package/src/components/ButtonGroup/ButtonGroup.md +8 -12
  23. package/src/components/Icon/Icon.md +22 -0
  24. package/src/components/Icon/Icon.scss +10 -0
  25. package/src/components/Icon/Icon.tsx +45 -0
  26. package/src/components/Layout/Layout.md +10 -18
  27. package/src/components/Link/Link.md +11 -2
  28. package/src/components/Menu/Menu.md +34 -126
  29. package/src/components/Menu/Menu.scss +133 -51
  30. package/src/components/Menu/Menu.tsx +118 -67
  31. package/src/components/Select/Select.md +72 -0
  32. package/src/components/Select/Select.scss +170 -0
  33. package/src/components/Select/Select.tsx +196 -0
  34. package/src/components/Table/Table.md +3 -2
  35. package/src/components/Tag/Tag.scss +3 -1
  36. package/src/components/Text/Text.md +3 -5
  37. package/src/components/Tree/Tree.md +62 -0
  38. package/src/components/Tree/Tree.scss +73 -0
  39. package/src/components/Tree/Tree.tsx +125 -0
  40. package/src/css.ts +3 -1
  41. package/src/icons.ts +88 -0
  42. package/src/index.ts +9 -3
  43. package/src/menu.ts +66 -0
  44. package/src/respawn/Icon.ts +47 -0
  45. package/src/respawn/Menu.ts +113 -62
  46. package/src/respawn/Select.ts +212 -0
  47. package/src/respawn/Tree.ts +116 -0
  48. package/src/respawn/index.ts +9 -3
  49. package/src/respawn/spawn.ts +5 -3
  50. package/src/select.ts +140 -0
  51. package/src/styles/theme.scss +1 -1
  52. package/src/styles/type.json +1 -1
  53. package/src/tree.ts +46 -0
  54. package/dist/types/components/NavList/NavList.d.ts +0 -43
  55. package/dist/types/navList.d.ts +0 -7
  56. package/dist/types/respawn/NavList.d.ts +0 -43
  57. package/src/components/NavList/NavList.md +0 -39
  58. package/src/components/NavList/NavList.scss +0 -149
  59. package/src/components/NavList/NavList.tsx +0 -129
  60. package/src/navList.ts +0 -9
  61. package/src/respawn/NavList.ts +0 -126
@@ -1,35 +1,43 @@
1
1
  import React from 'react';
2
2
  export interface MenuItem {
3
- /** What the row shows (unless itemRenderer draws it). */
4
- label?: React.ReactNode;
5
- /** Child rows, shown indented under this one. */
6
- items?: MenuItem[];
7
- /** Custom class name for this row. */
8
- className?: string;
9
- /** Inline style for this row. */
10
- style?: React.CSSProperties;
11
- /** Anything else your itemRenderer needs. */
12
- [key: string]: any;
3
+ /** What the link says. */
4
+ label: React.ReactNode;
5
+ /** Where it goes. The item whose href equals `current` is marked as the current page. */
6
+ href: string;
7
+ /** Draws a hairline above this item, to split a section into groups. */
8
+ divider?: boolean;
9
+ }
10
+ export interface MenuSection {
11
+ /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
12
+ id?: string;
13
+ /** The section heading. */
14
+ title: React.ReactNode;
15
+ /** Makes the heading a link too (e.g. to the section's overview page). */
16
+ href?: string;
17
+ /** The section's links. */
18
+ items: MenuItem[];
13
19
  }
14
- export interface MenuProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick'> {
15
- /** The rows to render; each can have child `items`. */
16
- items?: MenuItem[];
17
- /** The active row as a path of indexes, e.g. [2, 0] = the first child of the third row. */
18
- activePath?: number[];
19
- /** Draws a row's content instead of its label. */
20
- itemRenderer?: (item: MenuItem) => React.ReactNode;
21
- /** Called on a row click with the event and that row's path. */
22
- onClick?: (event: React.MouseEvent<HTMLDivElement>, path: number[]) => void;
23
- /**
24
- * Deepest level that still indents. Deeper rows stay at that indent, so the
25
- * label keeps its room in a narrow panel.
26
- */
27
- maxIndentDepth?: number;
20
+ export interface MenuProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onToggle'> {
21
+ /** The sections, in order. */
22
+ sections: MenuSection[];
23
+ /** The href of the page being shown: its link is marked, and its section opens. */
24
+ current?: string;
25
+ /** Which sections start open: true (all), false (none) or a map of section id → open. Defaults to all. */
26
+ defaultOpen?: boolean | Record<string, boolean>;
27
+ /** Called when a section opens or closes (e.g. to remember it). */
28
+ onToggle?: (id: string, open: boolean) => void;
29
+ /** Called when any link is clicked, with its href (e.g. to close a drawer). */
30
+ onNavigate?: (href: string, event: React.MouseEvent<HTMLAnchorElement>) => void;
31
+ /** Accessible name of the navigation landmark. */
32
+ label?: string;
33
+ /** Prefix for the ids that link each toggle to its list. Defaults to "menu". */
34
+ id?: string;
28
35
  /** Custom class name. */
29
36
  className?: string;
30
37
  }
31
38
  /**
32
- * A nested list of rows, like a layers panel. Rows indent by depth, the
33
- * active one is highlighted, and a click reports the row's path.
39
+ * Site navigation: sections of links that open and close (an accordion, with
40
+ * a smooth animation), and the current page marked by a bar beside it.
41
+ * A section opens by itself when the current page is in it.
34
42
  */
35
- export default function Menu({ activePath, className, itemRenderer, items, maxIndentDepth, onClick, children: _children, ...props }: MenuProps): React.ReactElement;
43
+ export default function Menu({ defaultOpen, label, ...props }: MenuProps): React.ReactElement;
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ export interface SelectOption {
3
+ /** The value onChange reports. */
4
+ value: string;
5
+ /** What the option says. */
6
+ label: React.ReactNode;
7
+ /** A second, quieter line under the label. */
8
+ description?: React.ReactNode;
9
+ /** Options with the same group are listed together, under the group as a heading. */
10
+ group?: string;
11
+ /** Shown, but can't be picked. */
12
+ disabled?: boolean;
13
+ /** The text typing matches, when the label isn't plain text. Defaults to the label. */
14
+ textValue?: string;
15
+ }
16
+ /** Where an option stands while the list is open. */
17
+ export interface SelectOptionState {
18
+ /** It is the picked value. */
19
+ selected: boolean;
20
+ /** The keys or the pointer are on it. */
21
+ active: boolean;
22
+ }
23
+ export interface SelectProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'placeholder'> {
24
+ /** The options, in order (grouped ones are listed together under their group). */
25
+ options: SelectOption[];
26
+ /** The picked value. Pass it with onChange to control the select yourself. */
27
+ value?: string;
28
+ /** The value it starts with, when you don't pass value. */
29
+ defaultValue?: string;
30
+ /** Called when an option is picked (not when the same one is picked again). */
31
+ onChange?: (value: string, option: SelectOption) => void;
32
+ /** Accessible name (screen readers say it), e.g. "Theme". */
33
+ label: string;
34
+ /** Shown while nothing is picked. */
35
+ placeholder?: React.ReactNode;
36
+ /** Draws an option's content instead of its label and description. */
37
+ renderOption?: (option: SelectOption, state: SelectOptionState) => React.ReactNode;
38
+ /** Draws the picked option inside the button instead of its label. */
39
+ renderValue?: (option: SelectOption | undefined) => React.ReactNode;
40
+ /** Which edge of the button the list lines up with. */
41
+ align?: 'start' | 'end';
42
+ /** Can't be opened. */
43
+ disabled?: boolean;
44
+ /** Prefix for the ids that tie the button to its list and options. */
45
+ id?: string;
46
+ /** Custom class name. */
47
+ className?: string;
48
+ }
49
+ /**
50
+ * Pick one value from a list: a button that opens a list of options (the
51
+ * WAI-ARIA select-only combobox). Focus stays on the button: ↓ ↑ move, Home
52
+ * and End jump, typing finds an option by its first letters, Enter or Space
53
+ * picks, Esc closes. Options can be grouped, and drawn your own way.
54
+ */
55
+ export default function Select({ options, value, defaultValue, onChange, label, placeholder, renderOption, renderValue, align, disabled, id, className, ...restProps }: SelectProps): React.ReactElement;
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ export interface TreeItem {
3
+ /** What the row shows (unless itemRenderer draws it). */
4
+ label?: React.ReactNode;
5
+ /** Child rows, shown indented under this one. */
6
+ items?: TreeItem[];
7
+ /** Custom class name for this row. */
8
+ className?: string;
9
+ /** Inline style for this row. */
10
+ style?: React.CSSProperties;
11
+ /** Anything else your itemRenderer needs. */
12
+ [key: string]: any;
13
+ }
14
+ export interface TreeProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick'> {
15
+ /** The rows to render; each can have child `items`. */
16
+ items?: TreeItem[];
17
+ /** The active row as a path of indexes, e.g. [2, 0] = the first child of the third row. */
18
+ activePath?: number[];
19
+ /** Draws a row's content instead of its label. */
20
+ itemRenderer?: (item: TreeItem) => React.ReactNode;
21
+ /** Called when a row is clicked (or picked with Enter or Space), with the event and that row's path. */
22
+ onClick?: (event: React.MouseEvent<HTMLDivElement>, path: number[]) => void;
23
+ /**
24
+ * Deepest level that still indents. Deeper rows stay at that indent, so the
25
+ * label keeps its room in a narrow panel.
26
+ */
27
+ maxIndentDepth?: number;
28
+ /** Accessible name of the tree (screen readers say it), e.g. "Layers". */
29
+ label?: string;
30
+ /** Custom class name. */
31
+ className?: string;
32
+ }
33
+ /**
34
+ * A nested list of rows to pick from, like a layers panel. Rows indent by
35
+ * depth, the active one is highlighted, and a click reports the row's path.
36
+ * By keyboard (the WAI-ARIA tree pattern): Tab reaches the active row, the
37
+ * arrow keys move between rows, Enter or Space picks one.
38
+ */
39
+ export default function Tree({ activePath, className, itemRenderer, items, maxIndentDepth, onClick, label, onKeyDown, children: _children, ...props }: TreeProps): React.ReactElement;
@@ -0,0 +1,55 @@
1
+ /** One SVG element of an icon: its tag and attributes. */
2
+ export type IconNode = [tag: 'path' | 'circle' | 'rect', attrs: Record<string, string | number>];
3
+ declare const DEFS: {
4
+ menu: IconNode[];
5
+ close: IconNode[];
6
+ 'chevron-down': IconNode[];
7
+ 'chevron-up': IconNode[];
8
+ 'chevron-left': IconNode[];
9
+ 'chevron-right': IconNode[];
10
+ 'arrow-left': IconNode[];
11
+ 'arrow-right': IconNode[];
12
+ 'arrow-up': IconNode[];
13
+ 'arrow-down': IconNode[];
14
+ 'external-link': IconNode[];
15
+ add: IconNode[];
16
+ remove: IconNode[];
17
+ edit: IconNode[];
18
+ copy: IconNode[];
19
+ delete: IconNode[];
20
+ download: IconNode[];
21
+ upload: IconNode[];
22
+ search: IconNode[];
23
+ filter: IconNode[];
24
+ sliders: IconNode[];
25
+ refresh: IconNode[];
26
+ undo: IconNode[];
27
+ redo: IconNode[];
28
+ check: IconNode[];
29
+ info: IconNode[];
30
+ warning: IconNode[];
31
+ error: IconNode[];
32
+ help: IconNode[];
33
+ file: IconNode[];
34
+ folder: IconNode[];
35
+ image: IconNode[];
36
+ layers: IconNode[];
37
+ eye: IconNode[];
38
+ 'eye-off': IconNode[];
39
+ lock: IconNode[];
40
+ unlock: IconNode[];
41
+ link: IconNode[];
42
+ sun: IconNode[];
43
+ moon: IconNode[];
44
+ code: IconNode[];
45
+ terminal: IconNode[];
46
+ };
47
+ /** Every icon's name. */
48
+ export type IconName = keyof typeof DEFS;
49
+ /** Every icon: its name and the shapes it is drawn with. */
50
+ export declare const ICONS: Record<IconName, IconNode[]>;
51
+ /** The names, in the order above (groups: navigation, actions, status, things, theme, code). */
52
+ export declare const ICON_NAMES: IconName[];
53
+ /** An unknown name draws an empty icon and says so once. */
54
+ export declare function iconNodes(name: string): IconNode[];
55
+ export {};
@@ -12,10 +12,16 @@ export { default as Progress } from './components/Progress/Progress';
12
12
  export type { ProgressProps, ProgressSize, ProgressStatus } from './components/Progress/Progress';
13
13
  export { default as Layout } from './components/Layout/Layout';
14
14
  export type { LayoutProps, Spacing, LegacySpacing } from './components/Layout/Layout';
15
+ export { default as Icon } from './components/Icon/Icon';
16
+ export type { IconProps } from './components/Icon/Icon';
17
+ export { ICONS, ICON_NAMES } from './icons';
18
+ export type { IconName, IconNode } from './icons';
19
+ export { default as Tree } from './components/Tree/Tree';
20
+ export type { TreeProps, TreeItem } from './components/Tree/Tree';
15
21
  export { default as Menu } from './components/Menu/Menu';
16
- export type { MenuProps, MenuItem } from './components/Menu/Menu';
17
- export { default as NavList } from './components/NavList/NavList';
18
- export type { NavListProps, NavListItem, NavListSection } from './components/NavList/NavList';
22
+ export type { MenuProps, MenuItem, MenuSection } from './components/Menu/Menu';
23
+ export { default as Select } from './components/Select/Select';
24
+ export type { SelectProps, SelectOption, SelectOptionState } from './components/Select/Select';
19
25
  export { default as FullPageModal } from './components/FullPageModal/FullPageModal';
20
26
  export type { FullPageModalProps } from './components/FullPageModal/FullPageModal';
21
27
  export { default as HistoryList } from './components/HistoryList/HistoryList';
@@ -0,0 +1,24 @@
1
+ /** A section's id: its own, or its title as a slug ("Get started" -> "get-started"). */
2
+ export declare const sectionId: (section: {
3
+ id?: string;
4
+ title: unknown;
5
+ }) => string;
6
+ /** Whether a section starts open: true / false for all, or a map of id -> open (missing = open). */
7
+ export declare const startsOpen: (defaultOpen: boolean | Record<string, boolean> | undefined, id: string) => boolean;
8
+ /** Menu used to be the nested, selectable list that is Tree now: say so once. */
9
+ export declare function warnOldMenuProps(props: {
10
+ sections?: unknown;
11
+ items?: unknown;
12
+ activePath?: unknown;
13
+ }): boolean;
14
+ /**
15
+ * The arrow keys on a Menu (the WAI-ARIA disclosure navigation pattern's
16
+ * optional keys). Tab still goes link by link; on top of that:
17
+ * - Up / Down: the previous / next row (section titles and the links in open
18
+ * sections), going round at the ends;
19
+ * - Home / End: the first / last row;
20
+ * - Right on a section: opens it, or (when open) goes to its first link;
21
+ * - Left on a section: closes it; Left on a link: goes up to its section.
22
+ * Returns true when it used the key.
23
+ */
24
+ export declare function menuKeydown(event: KeyboardEvent, nav: HTMLElement): boolean;
@@ -0,0 +1,22 @@
1
+ import { IconName } from '../icons';
2
+ import { ElementProps } from './spawn';
3
+ export interface IconProps extends ElementProps {
4
+ /** Which icon (Foundations > Icons lists them all). */
5
+ name: IconName;
6
+ /** Width and height. Defaults to 1em: the icon is as big as the text around it. A number is pixels. */
7
+ size?: number | string;
8
+ /** Says what the icon means, for an icon that stands alone (screen readers read it). Leave it out when text beside it already says it. */
9
+ label?: string;
10
+ /** Line thickness in grid units (the grid is 24). */
11
+ strokeWidth?: number;
12
+ }
13
+ /** The <svg> Icon returns, with update() like every other component. */
14
+ export type IconElement = SVGSVGElement & {
15
+ update(changes: Partial<IconProps>): IconElement;
16
+ };
17
+ /**
18
+ * An icon from the NURVUS set, as an <svg> element: the same markup as the
19
+ * React Icon. 1em by default, in the text's color; decorative unless it has a
20
+ * label. icon.update({ name: 'check' }) swaps it for another.
21
+ */
22
+ export default function Icon(props: IconProps): IconElement;
@@ -1,33 +1,43 @@
1
- import { Child, ElementProps, Style } from './spawn';
1
+ import { Child, ElementProps } from './spawn';
2
2
  import { NurvusElement } from './update';
3
3
  export interface MenuItem {
4
- /** What the row shows (unless itemRenderer draws it). */
5
- label?: Child;
6
- /** Child rows, shown indented under this one. */
7
- items?: MenuItem[];
8
- /** Custom class name for this row. */
9
- className?: string;
10
- /** Inline style for this row. */
11
- style?: Style;
12
- /** Anything else your itemRenderer needs. */
13
- [key: string]: any;
4
+ /** What the link says. */
5
+ label: Child;
6
+ /** Where it goes. The item whose href equals `current` is marked as the current page. */
7
+ href: string;
8
+ /** Draws a hairline above this item, to split a section into groups. */
9
+ divider?: boolean;
10
+ }
11
+ export interface MenuSection {
12
+ /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
13
+ id?: string;
14
+ /** The section heading. */
15
+ title: string;
16
+ /** Makes the heading a link too (e.g. to the section's overview page). */
17
+ href?: string;
18
+ /** The section's links. */
19
+ items: MenuItem[];
14
20
  }
15
21
  export interface MenuProps extends ElementProps {
16
- /** The rows to render; each can have child `items`. */
17
- items?: MenuItem[];
18
- /** The active row as a path of indexes, e.g. [2, 0] = the first child of the third row. */
19
- activePath?: number[];
20
- /** Draws a row's content instead of its label. */
21
- itemRenderer?: (item: MenuItem) => Child;
22
- /** Called on a row click with the event and that row's path, after the row is marked active. */
23
- onClick?: (event: MouseEvent, path: number[]) => void;
24
- /** Deepest level that still indents. Deeper rows stay at that indent. */
25
- maxIndentDepth?: number;
22
+ /** The sections, in order. */
23
+ sections: MenuSection[];
24
+ /** The href of the page being shown: its link is marked, and its section opens. */
25
+ current?: string;
26
+ /** Which sections start open: true (all), false (none) or a map of section id -> open. Defaults to all. */
27
+ defaultOpen?: boolean | Record<string, boolean>;
28
+ /** Called when a section opens or closes (e.g. to remember it). */
29
+ onToggle?: (id: string, open: boolean) => void;
30
+ /** Called when any link is clicked, with its href (e.g. to close a drawer). */
31
+ onNavigate?: (href: string, event: MouseEvent) => void;
32
+ /** Accessible name of the navigation landmark. */
33
+ label?: string;
34
+ /** Prefix for the ids that link each toggle to its list. Defaults to "menu". */
35
+ id?: string;
26
36
  }
27
37
  /**
28
- * A nested list of rows, like a layers panel. Rows indent by depth and the
29
- * active one is highlighted. A click marks that row active (in place: the
30
- * element stays the same) and calls onClick(event, path). To set the active
31
- * row from code: menu.update({ activePath: [1] }).
38
+ * Site navigation: sections of links that open and close (an accordion, with
39
+ * a smooth animation), and the current page marked by a bar beside it. A
40
+ * click on a toggle opens or closes its section in place (the element stays
41
+ * the same); update({ current }) marks another page and opens its section.
32
42
  */
33
- export default function Menu(props?: MenuProps): NurvusElement<HTMLDivElement, MenuProps>;
43
+ export default function Menu(props?: MenuProps): NurvusElement<HTMLElement, MenuProps>;
@@ -0,0 +1,54 @@
1
+ import { Child, ElementProps } from './spawn';
2
+ import { NurvusElement } from './update';
3
+ export interface SelectOption {
4
+ /** The value onChange reports. */
5
+ value: string;
6
+ /** What the option says. */
7
+ label: Child;
8
+ /** A second, quieter line under the label. */
9
+ description?: Child;
10
+ /** Options with the same group are listed together, under the group as a heading. */
11
+ group?: string;
12
+ /** Shown, but can't be picked. */
13
+ disabled?: boolean;
14
+ /** The text typing matches, when the label isn't plain text. Defaults to the label. */
15
+ textValue?: string;
16
+ }
17
+ /** Where an option stands when it is drawn. */
18
+ export interface SelectOptionState {
19
+ /** It is the picked value. */
20
+ selected: boolean;
21
+ /** The keys or the pointer are on it. */
22
+ active: boolean;
23
+ }
24
+ export interface SelectProps extends ElementProps {
25
+ /** The options, in order (grouped ones are listed together under their group). */
26
+ options: SelectOption[];
27
+ /** The picked value. */
28
+ value?: string;
29
+ /** The value it starts with (the same as value here: the element keeps its own value). */
30
+ defaultValue?: string;
31
+ /** Called when an option is picked (not when the same one is picked again), after it is shown as picked. */
32
+ onChange?: (value: string, option: SelectOption) => void;
33
+ /** Accessible name (screen readers say it), e.g. "Theme". */
34
+ label: string;
35
+ /** Shown while nothing is picked. */
36
+ placeholder?: Child;
37
+ /** Draws an option's content instead of its label and description (once, when the element is built). */
38
+ renderOption?: (option: SelectOption, state: SelectOptionState) => Child;
39
+ /** Draws the picked option inside the button instead of its label. */
40
+ renderValue?: (option: SelectOption | undefined) => Child;
41
+ /** Which edge of the button the list lines up with. */
42
+ align?: 'start' | 'end';
43
+ /** Can't be opened. */
44
+ disabled?: boolean;
45
+ /** Prefix for the ids that tie the button to its list and options. */
46
+ id?: string;
47
+ }
48
+ /**
49
+ * Pick one value from a list: a button that opens a list of options (the
50
+ * WAI-ARIA select-only combobox), with the same keys as the React Select.
51
+ * Opening, moving and picking change the element in place; picking calls
52
+ * onChange(value, option). To set the value from code: select.update({ value }).
53
+ */
54
+ export default function Select(props: SelectProps): NurvusElement<HTMLDivElement, SelectProps>;
@@ -0,0 +1,36 @@
1
+ import { Child, ElementProps, Style } from './spawn';
2
+ import { NurvusElement } from './update';
3
+ export interface TreeItem {
4
+ /** What the row shows (unless itemRenderer draws it). */
5
+ label?: Child;
6
+ /** Child rows, shown indented under this one. */
7
+ items?: TreeItem[];
8
+ /** Custom class name for this row. */
9
+ className?: string;
10
+ /** Inline style for this row. */
11
+ style?: Style;
12
+ /** Anything else your itemRenderer needs. */
13
+ [key: string]: any;
14
+ }
15
+ export interface TreeProps extends ElementProps {
16
+ /** The rows to render; each can have child `items`. */
17
+ items?: TreeItem[];
18
+ /** The active row as a path of indexes, e.g. [2, 0] = the first child of the third row. */
19
+ activePath?: number[];
20
+ /** Draws a row's content instead of its label. */
21
+ itemRenderer?: (item: TreeItem) => Child;
22
+ /** Called when a row is clicked (or picked with Enter or Space), after it is marked active, with the event and its path. */
23
+ onClick?: (event: MouseEvent, path: number[]) => void;
24
+ /** Deepest level that still indents. Deeper rows stay at that indent. */
25
+ maxIndentDepth?: number;
26
+ /** Accessible name of the tree (screen readers say it), e.g. "Layers". */
27
+ label?: string;
28
+ }
29
+ /**
30
+ * A nested list of rows to pick from, like a layers panel. Rows indent by
31
+ * depth and the active one is highlighted. A click (or Enter / Space) marks
32
+ * that row active (in place: the element stays the same) and calls
33
+ * onClick(event, path); the arrow keys move between rows. To set the active
34
+ * row from code: tree.update({ activePath: [1] }).
35
+ */
36
+ export default function Tree(props?: TreeProps): NurvusElement<HTMLDivElement, TreeProps>;
@@ -15,10 +15,16 @@ export { default as Progress } from './Progress';
15
15
  export type { ProgressProps, ProgressSize, ProgressStatus } from './Progress';
16
16
  export { default as Layout } from './Layout';
17
17
  export type { LayoutProps, Spacing, LegacySpacing } from './Layout';
18
+ export { default as Icon } from './Icon';
19
+ export type { IconProps, IconElement } from './Icon';
20
+ export { ICONS, ICON_NAMES } from '../icons';
21
+ export type { IconName, IconNode } from '../icons';
22
+ export { default as Tree } from './Tree';
23
+ export type { TreeProps, TreeItem } from './Tree';
18
24
  export { default as Menu } from './Menu';
19
- export type { MenuProps, MenuItem } from './Menu';
20
- export { default as NavList } from './NavList';
21
- export type { NavListProps, NavListItem, NavListSection } from './NavList';
25
+ export type { MenuProps, MenuItem, MenuSection } from './Menu';
26
+ export { default as Select } from './Select';
27
+ export type { SelectProps, SelectOption, SelectOptionState } from './Select';
22
28
  export { default as FullPageModal } from './FullPageModal';
23
29
  export type { FullPageModalProps } from './FullPageModal';
24
30
  export { default as HistoryList } from './HistoryList';
@@ -33,6 +33,8 @@ export interface SpawnProps extends ElementProps {
33
33
  children?: Child | ((el: HTMLElement) => void);
34
34
  /** Appends the new element to this one. */
35
35
  mountEl?: Element;
36
+ /** Makes the element in this namespace, e.g. 'http://www.w3.org/2000/svg' for SVG (Icon uses it). */
37
+ namespace?: string;
36
38
  }
37
39
  /** Appends `child` (any Child) to `parent`. */
38
40
  export declare function append(parent: Node, child: Child): void;
@@ -0,0 +1,70 @@
1
+ export interface OptionLike {
2
+ value: string;
3
+ label?: unknown;
4
+ textValue?: string;
5
+ group?: string;
6
+ disabled?: boolean;
7
+ }
8
+ /** A run of options under one heading ('' = no heading). */
9
+ export interface OptionGroup<O> {
10
+ name: string;
11
+ options: {
12
+ option: O;
13
+ index: number;
14
+ }[];
15
+ }
16
+ /**
17
+ * The options as the list shows them: grouped, groups in the order they first
18
+ * appear. `index` is the place in that order, which the keys move through.
19
+ */
20
+ export declare function groupOptions<O extends OptionLike>(options: O[]): {
21
+ groups: OptionGroup<O>[];
22
+ ordered: O[];
23
+ };
24
+ /** The text typing matches: textValue, else a plain-text label, else the value. */
25
+ export declare const optionText: (option: OptionLike) => string;
26
+ /** The next option that can be picked, `delta` steps away (stops at the ends). */
27
+ export declare function stepOption(options: OptionLike[], from: number, delta: number): number;
28
+ /** The first (or last) option that can be picked, or -1. */
29
+ export declare function edgeOption(options: OptionLike[], last?: boolean): number;
30
+ /**
31
+ * Typing: the next option (after `from`, going round) whose text starts with
32
+ * what was typed. Typing one letter again and again steps through the options
33
+ * that start with it, as a native select does.
34
+ */
35
+ export declare function matchOption(options: OptionLike[], typed: string, from: number): number;
36
+ export type SelectAction = {
37
+ type: 'open';
38
+ active: number;
39
+ } | {
40
+ type: 'move';
41
+ active: number;
42
+ } | {
43
+ type: 'pick';
44
+ active: number;
45
+ } | {
46
+ type: 'close';
47
+ };
48
+ /**
49
+ * What a key does. Closed: ↓ ↑ Enter Space (and Alt+↓) open the list at the
50
+ * picked option; Home / End open it at the first / last. Open: ↓ ↑ Home End
51
+ * Page Up / Page Down move; Enter, Space, Alt+↑ and Tab pick and close; Esc
52
+ * closes without picking. null: not a key the select uses.
53
+ */
54
+ export declare function selectKey(key: string, altKey: boolean, state: {
55
+ open: boolean;
56
+ active: number;
57
+ selected: number;
58
+ }, options: OptionLike[]): SelectAction | null;
59
+ /** Remembers what was typed for half a second (typeahead). While text is pending, Space is part of the search, not a pick. */
60
+ export declare function typeahead(): {
61
+ add: (key: string) => string;
62
+ pending: () => boolean;
63
+ };
64
+ /** A key that types a character (no Ctrl, Cmd or Alt). */
65
+ export declare const isPrintable: (event: {
66
+ key: string;
67
+ ctrlKey: boolean;
68
+ metaKey: boolean;
69
+ altKey: boolean;
70
+ }) => boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Moves focus like the WAI-ARIA tree pattern, with one row in the tab order
3
+ * at a time (roving tabindex):
4
+ * - Up / Down: the previous / next row; Home / End: the first / last;
5
+ * - Right: the first child row; Left: the parent row;
6
+ * - Enter / Space: selects the row (the same as a click).
7
+ * Returns true when it used the key.
8
+ */
9
+ export declare function treeKeydown(event: KeyboardEvent, tree: HTMLElement): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nurvus/ui",
3
- "version": "0.1.0-alpha.13",
3
+ "version": "0.1.0-alpha.15",
4
4
  "description": "NURVUS Design System",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -65,7 +65,7 @@
65
65
  "@codemirror/language": "^6.13.1",
66
66
  "@codemirror/state": "^6.7.6",
67
67
  "@codemirror/view": "^6.44.0",
68
- "@fontsource/inter": "^5.3.0",
68
+ "@fontsource-variable/inter": "^5.3.0",
69
69
  "@fontsource/jetbrains-mono": "^5.3.0",
70
70
  "@lezer/highlight": "^1.2.5",
71
71
  "@material-ui/core": "^4.12.3",
@@ -5,7 +5,13 @@
5
5
  .#{$cls-prefix}.button {
6
6
  border: none;
7
7
  cursor: pointer;
8
- transition: all 0.3s ease;
8
+ // Colors fade (theme switches, hover); the focus ring appears at once.
9
+ transition: background-color 0.3s ease, color 0.3s ease, opacity 0.3s ease;
10
+
11
+ &:focus-visible {
12
+ outline: 2px solid var(--nv-accent);
13
+ outline-offset: 2px;
14
+ }
9
15
 
10
16
  // Type
11
17
  &[data-type="primary"] {
@@ -99,6 +105,6 @@
99
105
  padding: 0 10px 0 10px;
100
106
  font-size: $--12--medium;
101
107
  font-weight: 500;
102
- line-height: 16.8x;
108
+ line-height: 16.8px;
103
109
  }
104
110
  }