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

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 (71) hide show
  1. package/README.md +11 -1
  2. package/dist/icons.svg +73 -0
  3. package/dist/index.js +1 -1
  4. package/dist/nurvus.css +13 -10
  5. package/dist/respawn.js +1 -1
  6. package/dist/types/breakpoints.d.ts +14 -0
  7. package/dist/types/components/FullPageModal/FullPageModal.d.ts +11 -2
  8. package/dist/types/components/Grid/Grid.d.ts +26 -0
  9. package/dist/types/components/Loader/Loader.d.ts +21 -0
  10. package/dist/types/components/Menu/Menu.d.ts +54 -19
  11. package/dist/types/components/Progress/Progress.d.ts +19 -5
  12. package/dist/types/components/Stack/Stack.d.ts +26 -0
  13. package/dist/types/dialog.d.ts +12 -0
  14. package/dist/types/icons.d.ts +28 -0
  15. package/dist/types/index.d.ts +9 -1
  16. package/dist/types/loader.d.ts +28 -0
  17. package/dist/types/logo.d.ts +5 -0
  18. package/dist/types/menu.d.ts +43 -14
  19. package/dist/types/progress.d.ts +11 -0
  20. package/dist/types/respawn/FullPageModal.d.ts +7 -1
  21. package/dist/types/respawn/Grid.d.ts +21 -0
  22. package/dist/types/respawn/Loader.d.ts +18 -0
  23. package/dist/types/respawn/Menu.d.ts +45 -15
  24. package/dist/types/respawn/Progress.d.ts +18 -6
  25. package/dist/types/respawn/Stack.d.ts +21 -0
  26. package/dist/types/respawn/index.d.ts +9 -1
  27. package/package.json +1 -3
  28. package/src/breakpoints.ts +28 -0
  29. package/src/components/Button/Button.scss +20 -20
  30. package/src/components/FullPageModal/FullPageModal.md +20 -17
  31. package/src/components/FullPageModal/FullPageModal.scss +5 -0
  32. package/src/components/FullPageModal/FullPageModal.tsx +37 -3
  33. package/src/components/Grid/Grid.md +37 -0
  34. package/src/components/Grid/Grid.scss +37 -0
  35. package/src/components/Grid/Grid.tsx +54 -0
  36. package/src/components/HistoryList/HistoryList.scss +2 -2
  37. package/src/components/Loader/Loader.md +30 -0
  38. package/src/components/Loader/Loader.scss +42 -0
  39. package/src/components/Loader/Loader.tsx +68 -0
  40. package/src/components/Menu/Menu.md +67 -3
  41. package/src/components/Menu/Menu.scss +48 -18
  42. package/src/components/Menu/Menu.tsx +146 -39
  43. package/src/components/Progress/Progress.md +27 -26
  44. package/src/components/Progress/Progress.scss +41 -36
  45. package/src/components/Progress/Progress.tsx +50 -6
  46. package/src/components/Select/Select.scss +20 -19
  47. package/src/components/Stack/Stack.md +43 -0
  48. package/src/components/Stack/Stack.scss +36 -0
  49. package/src/components/Stack/Stack.tsx +52 -0
  50. package/src/components/Table/Table.scss +1 -1
  51. package/src/components/Tag/Tag.scss +2 -2
  52. package/src/components/Title/Title.scss +6 -6
  53. package/src/components/Tree/Tree.md +1 -1
  54. package/src/css.ts +3 -0
  55. package/src/dialog.ts +47 -0
  56. package/src/icons.ts +29 -0
  57. package/src/index.ts +9 -1
  58. package/src/loader.ts +43 -0
  59. package/src/logo.ts +12 -0
  60. package/src/menu.ts +91 -21
  61. package/src/progress.ts +21 -0
  62. package/src/respawn/FullPageModal.ts +30 -3
  63. package/src/respawn/Grid.ts +41 -0
  64. package/src/respawn/Loader.ts +77 -0
  65. package/src/respawn/Menu.ts +138 -34
  66. package/src/respawn/Progress.ts +56 -13
  67. package/src/respawn/Stack.ts +37 -0
  68. package/src/respawn/index.ts +9 -1
  69. package/src/styles/breakpoints.scss +3 -0
  70. package/src/styles/theme.scss +55 -55
  71. package/src/styles/type.json +9 -9
@@ -0,0 +1,14 @@
1
+ export type Breakpoint = 'sm' | 'md' | 'lg' | 'xl';
2
+ /** Each breakpoint's min-width: from this width up, the `sm`/`md`/`lg`/`xl` value applies. */
3
+ export declare const BREAKPOINTS: Record<Breakpoint, string>;
4
+ /** A value for every width (`base`), changing from a breakpoint up: { base: 1, md: 2, lg: 3 }. */
5
+ export type Responsive<T> = T | ({
6
+ base?: T;
7
+ } & Partial<Record<Breakpoint, T>>);
8
+ /** `true` once the window is at least as wide as `breakpoint` (for your own code). */
9
+ export declare const isAtLeast: (breakpoint: Breakpoint) => boolean;
10
+ /**
11
+ * The data attributes for a responsive value: data-<name>="base value" and
12
+ * data-<name>-md="…" for each breakpoint given. The CSS reads them.
13
+ */
14
+ export declare function responsiveData<T>(name: string, value: Responsive<T> | undefined): Record<string, T | undefined>;
@@ -8,8 +8,17 @@ export interface FullPageModalProps extends Omit<React.HTMLAttributes<HTMLDivEle
8
8
  headerActions?: React.ReactNode;
9
9
  /** The modal's content. */
10
10
  children?: React.ReactNode;
11
+ /** Called when someone presses Esc. Set visible to false in it to close the modal. */
12
+ onClose?: () => void;
13
+ /** Names the modal and its title: the title gets the id "<id>-title", and the modal is labelled by it. */
14
+ id?: string;
11
15
  /** Custom class name. */
12
16
  className?: string;
13
17
  }
14
- /** Shows additional content over the whole screen, rendered into `<body>`. */
15
- export default function FullPageModal({ children, className, headerActions, title, visible, ...restProps }: FullPageModalProps): React.ReactElement;
18
+ /**
19
+ * Shows content over the whole screen, rendered into `<body>`: a modal dialog
20
+ * (the WAI-ARIA dialog pattern). Opening it moves focus into it, and screen
21
+ * readers say its title and "dialog"; Tab stays inside; Esc calls onClose;
22
+ * closing it gives focus back to where it was.
23
+ */
24
+ export default function FullPageModal({ children, className, headerActions, title, visible, onClose, id, onKeyDown, ...restProps }: FullPageModalProps): React.ReactElement;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { Spacing } from '../../spacing';
3
+ import { Responsive } from '../../breakpoints';
4
+ export type GridColumns = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
5
+ export interface GridProps extends React.HTMLAttributes<HTMLDivElement> {
6
+ /** How many equal columns: 1 to 12. Can change with the width: { base: 1, md: 2, lg: 3 }. */
7
+ columns?: Responsive<GridColumns>;
8
+ /** Instead of a count: as many columns as fit, each at least this wide (e.g. "15rem" or 240). They fill the row. */
9
+ minItemWidth?: string | number;
10
+ /** Space between cells, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
11
+ gap?: Spacing;
12
+ /** Space between rows when it differs from gap. */
13
+ rowGap?: Spacing;
14
+ /** How cells line up in their row. Defaults to stretch (equal heights). */
15
+ align?: 'start' | 'center' | 'end' | 'stretch';
16
+ /** What to lay out. A child spans more columns with style={{ gridColumn: 'span 2' }}. */
17
+ children?: React.ReactNode;
18
+ /** Custom class name. */
19
+ className?: string;
20
+ }
21
+ /**
22
+ * Lays its children out in columns: a fixed count that changes at the
23
+ * breakpoints (1 on phones, 3 on desktops), or as many as fit at a minimum
24
+ * width. Columns share the width equally and never overflow it.
25
+ */
26
+ export default function Grid({ columns, minItemWidth, gap, rowGap, align, className, style, ...restProps }: GridProps): React.ReactElement;
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ export interface LoaderProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ /** Width and height of the mark. Defaults to 2em (twice the text size). A number is pixels. */
4
+ size?: number | string;
5
+ /** What is loading, for screen readers ("Loading photos"). Defaults to "Loading". */
6
+ label?: string;
7
+ /** Shows the label beside the mark, not only to screen readers. */
8
+ showLabel?: boolean;
9
+ /** Fills the segments with the logo's gradients (for big loaders); their ids start with this. Without it, one color each. */
10
+ id?: string;
11
+ /** Custom class name. */
12
+ className?: string;
13
+ }
14
+ /**
15
+ * Shows that something is loading: the NURVUS mark with a light running round
16
+ * it (the logo's Pulse). Screen readers hear the label once, politely
17
+ * (role="status"). The light keeps running with reduced motion: it only
18
+ * changes brightness, nothing moves, and a loader that stopped would look
19
+ * stuck (WCAG 2.2.2 counts a loading animation as essential).
20
+ */
21
+ export default function Loader({ size, label, showLabel, id, className, ...restProps }: LoaderProps): React.ReactElement;
@@ -1,43 +1,78 @@
1
1
  import React from 'react';
2
+ import { MenuKind } from '../../menu';
3
+ import { TreeProps, TreeItem } from '../Tree/Tree';
4
+ export type { MenuKind };
2
5
  export interface MenuItem {
3
- /** What the link says. */
6
+ /** What the item says. */
4
7
  label: React.ReactNode;
5
- /** Where it goes. The item whose href equals `current` is marked as the current page. */
6
- href: string;
8
+ /** Makes the item a link to this address. The item whose href equals `current` is marked as the current page. */
9
+ href?: string;
10
+ /** Makes the item a button that calls this (an action: "Duplicate", "Sign out"). */
11
+ onSelect?: (event: React.MouseEvent<HTMLElement>) => void;
12
+ /** Shows the item but stops it working (actions only). */
13
+ disabled?: boolean;
7
14
  /** Draws a hairline above this item, to split a section into groups. */
8
15
  divider?: boolean;
9
16
  }
10
17
  export interface MenuSection {
11
18
  /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
12
19
  id?: string;
13
- /** The section heading. */
14
- title: React.ReactNode;
20
+ /** The section heading. Optional for actions. */
21
+ title?: React.ReactNode;
15
22
  /** Makes the heading a link too (e.g. to the section's overview page). */
16
23
  href?: string;
17
- /** The section's links. */
24
+ /** The section's items. */
18
25
  items: MenuItem[];
19
26
  }
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. */
27
+ export interface MenuProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onToggle' | 'onClick'> {
28
+ /**
29
+ * What the menu is, which decides what screen readers hear and which keys
30
+ * work: 'nav' (links: a navigation landmark), 'actions' (commands: a menu
31
+ * of buttons) or 'tree' (rows to pick from, with Tree's props). Left out,
32
+ * it follows the props: navigation if any item has an href, actions if none
33
+ * has, a tree for `items`.
34
+ */
35
+ kind?: MenuKind;
36
+ /** Navigation and actions: the sections, in order. */
37
+ sections?: MenuSection[];
38
+ /** Navigation: the href of the page being shown. Its link is marked, and its section opens. */
24
39
  current?: string;
25
- /** Which sections start open: true (all), false (none) or a map of section id → open. Defaults to all. */
40
+ /** Navigation: which sections start open: true (all), false (none) or a map of section id → open. Defaults to all. */
26
41
  defaultOpen?: boolean | Record<string, boolean>;
27
- /** Called when a section opens or closes (e.g. to remember it). */
42
+ /** Navigation: called when a section opens or closes (e.g. to remember it). */
28
43
  onToggle?: (id: string, open: boolean) => void;
29
- /** Called when any link is clicked, with its href (e.g. to close a drawer). */
44
+ /** Navigation: called when any link is clicked, with its href (e.g. to close a drawer). */
30
45
  onNavigate?: (href: string, event: React.MouseEvent<HTMLAnchorElement>) => void;
31
- /** Accessible name of the navigation landmark. */
46
+ /** Tree: the rows, each with optional child `items`. */
47
+ items?: TreeItem[];
48
+ /** Tree: the picked row as a path of indexes, e.g. [2, 0] = the first child of the third row. */
49
+ activePath?: number[];
50
+ /** Tree: called when a row is picked (a click, Enter or Space), with the event and the row's path. */
51
+ onClick?: (event: React.MouseEvent<HTMLDivElement>, path: number[]) => void;
52
+ /** Tree: draws a row's content instead of its label. */
53
+ itemRenderer?: (item: TreeItem) => React.ReactNode;
54
+ /** Tree: the deepest level that still indents. */
55
+ maxIndentDepth?: number;
56
+ /** What screen readers call the menu ("Pages", "Actions", "Layers"). */
32
57
  label?: string;
33
- /** Prefix for the ids that link each toggle to its list. Defaults to "menu". */
58
+ /** Prefix for the ids inside (each toggle names its list). Defaults to "menu". */
34
59
  id?: string;
35
60
  /** Custom class name. */
36
61
  className?: string;
37
62
  }
63
+ /** Menu's props for navigation and actions. */
64
+ export type MenuListProps = Omit<MenuProps, 'items' | 'activePath' | 'onClick' | 'itemRenderer' | 'maxIndentDepth'>;
65
+ /** Menu kind="tree": Tree's props (Tree is the same thing under its own name). */
66
+ export type MenuTreeProps = TreeProps & {
67
+ kind: 'tree';
68
+ };
38
69
  /**
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.
70
+ * One component for lists of things to go to, do or pick. The items decide
71
+ * what it is, and screen readers hear it that way:
72
+ * - links: site navigation (sections that open and close, the current page
73
+ * marked), and Tab goes link by link;
74
+ * - actions: a menu of commands, one Tab stop, the arrow keys move;
75
+ * - kind="tree": a tree to pick a row from, like layers (see Tree).
76
+ * Up and Down move between items in all three.
42
77
  */
43
- export default function Menu({ defaultOpen, label, ...props }: MenuProps): React.ReactElement;
78
+ export default function Menu(props: MenuProps): React.ReactElement;
@@ -1,15 +1,29 @@
1
1
  import React from 'react';
2
+ import { ProgressStatus } from '../../progress';
2
3
  export type ProgressSize = 'small' | 'medium' | 'large';
3
- export type ProgressStatus = 'active' | 'success' | 'warning' | 'critical';
4
- export interface ProgressProps {
4
+ export type { ProgressStatus };
5
+ export interface ProgressProps extends React.HTMLAttributes<HTMLDivElement> {
5
6
  /** How far along, 0 to 100. */
6
7
  percent?: number;
7
8
  /** Bar height. */
8
9
  size?: ProgressSize;
9
- /** The bar color: active (accent), success, warning or critical (danger). */
10
+ /** The bar color: active (accent), success, warning or critical (danger). With a label or showValue, a status also shows as an icon and a word. */
10
11
  status?: ProgressStatus;
12
+ /** What is in progress ("Uploading"): shown above the bar, and its name for screen readers. */
13
+ label?: string;
14
+ /** Keeps the label for screen readers only. */
15
+ hideLabel?: boolean;
16
+ /** Shows the percent (and the status, as an icon and a word) at the right, above the bar. */
17
+ showValue?: boolean;
18
+ /** What screen readers say for the value, instead of "40%" (e.g. "3 of 8 files"). */
19
+ valueText?: string;
11
20
  /** Custom class name. */
12
21
  className?: string;
13
22
  }
14
- /** A progress bar. Use it to track progress! */
15
- export default function Progress({ className, percent, size, status }: ProgressProps): React.ReactElement;
23
+ /**
24
+ * A progress bar: how far along something is. Screen readers hear it as a
25
+ * progress bar with its label and value ("Uploading, progress bar, 40%").
26
+ * Its status is never color alone: with a label or showValue it shows as an
27
+ * icon and a word too, and screen readers hear the word.
28
+ */
29
+ export default function Progress({ className, percent, size, status, label, hideLabel, showValue, valueText, ...restProps }: ProgressProps): React.ReactElement;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { Spacing } from '../../spacing';
3
+ import { Responsive } from '../../breakpoints';
4
+ export type StackDirection = 'column' | 'row';
5
+ export interface StackProps extends React.HTMLAttributes<HTMLDivElement> {
6
+ /** column (top to bottom, the default) or row. Can change with the width: { base: 'column', md: 'row' }. */
7
+ direction?: Responsive<StackDirection>;
8
+ /** Space between the children, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
9
+ gap?: Spacing;
10
+ /** How the children line up across the stack. */
11
+ align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
12
+ /** How the children spread along the stack. */
13
+ justify?: 'start' | 'center' | 'end' | 'between';
14
+ /** Lets a row wrap onto more lines when it runs out of room. */
15
+ wrap?: boolean;
16
+ /** What to lay out. */
17
+ children?: React.ReactNode;
18
+ /** Custom class name. */
19
+ className?: string;
20
+ }
21
+ /**
22
+ * Puts its children in a column or a row with even space between them, from
23
+ * the 4px grid (CSS gap, so wrapped rows keep their spacing too). The
24
+ * direction can change at a breakpoint: a column on phones, a row from md up.
25
+ */
26
+ export default function Stack({ direction, gap, align, justify, wrap, className, ...restProps }: StackProps): React.ReactElement;
@@ -0,0 +1,12 @@
1
+ /** The elements Tab can reach inside `root`, in order (shown ones, not tabindex="-1"). */
2
+ export declare function focusables(root: HTMLElement): HTMLElement[];
3
+ /**
4
+ * The keys of a modal dialog (the WAI-ARIA dialog pattern): Tab and
5
+ * Shift+Tab go round the dialog's own controls and never leave it; Esc calls
6
+ * onClose. Returns true when it used the key.
7
+ */
8
+ export declare function dialogKeydown(event: KeyboardEvent, dialog: HTMLElement, onClose?: () => void): boolean;
9
+ /** Moves focus to the dialog itself once it shows (screen readers then say its name and "dialog"). */
10
+ export declare function focusDialog(dialog: HTMLElement): void;
11
+ /** Gives focus back to what had it before the dialog opened, if it is still on the page. */
12
+ export declare function restoreFocus(opener: Element | null): void;
@@ -12,6 +12,12 @@ declare const DEFS: {
12
12
  'arrow-up': IconNode[];
13
13
  'arrow-down': IconNode[];
14
14
  'external-link': IconNode[];
15
+ home: IconNode[];
16
+ 'panel-left': IconNode[];
17
+ 'more-horizontal': IconNode[];
18
+ 'more-vertical': IconNode[];
19
+ maximize: IconNode[];
20
+ minimize: IconNode[];
15
21
  add: IconNode[];
16
22
  remove: IconNode[];
17
23
  edit: IconNode[];
@@ -25,6 +31,11 @@ declare const DEFS: {
25
31
  refresh: IconNode[];
26
32
  undo: IconNode[];
27
33
  redo: IconNode[];
34
+ settings: IconNode[];
35
+ share: IconNode[];
36
+ play: IconNode[];
37
+ pause: IconNode[];
38
+ 'sign-out': IconNode[];
28
39
  check: IconNode[];
29
40
  info: IconNode[];
30
41
  warning: IconNode[];
@@ -38,9 +49,26 @@ declare const DEFS: {
38
49
  'eye-off': IconNode[];
39
50
  lock: IconNode[];
40
51
  unlock: IconNode[];
52
+ user: IconNode[];
53
+ users: IconNode[];
54
+ mail: IconNode[];
55
+ bell: IconNode[];
56
+ calendar: IconNode[];
57
+ clock: IconNode[];
58
+ globe: IconNode[];
59
+ 'map-pin': IconNode[];
60
+ tag: IconNode[];
61
+ bookmark: IconNode[];
62
+ star: IconNode[];
63
+ heart: IconNode[];
64
+ grid: IconNode[];
65
+ list: IconNode[];
41
66
  link: IconNode[];
42
67
  sun: IconNode[];
43
68
  moon: IconNode[];
69
+ palette: IconNode[];
70
+ sparkles: IconNode[];
71
+ zap: IconNode[];
44
72
  code: IconNode[];
45
73
  terminal: IconNode[];
46
74
  };
@@ -12,14 +12,22 @@ 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 Stack } from './components/Stack/Stack';
16
+ export type { StackProps, StackDirection } from './components/Stack/Stack';
17
+ export { default as Grid } from './components/Grid/Grid';
18
+ export type { GridProps, GridColumns } from './components/Grid/Grid';
19
+ export { BREAKPOINTS, isAtLeast } from './breakpoints';
20
+ export type { Breakpoint, Responsive } from './breakpoints';
15
21
  export { default as Icon } from './components/Icon/Icon';
16
22
  export type { IconProps } from './components/Icon/Icon';
17
23
  export { ICONS, ICON_NAMES } from './icons';
18
24
  export type { IconName, IconNode } from './icons';
25
+ export { default as Loader } from './components/Loader/Loader';
26
+ export type { LoaderProps } from './components/Loader/Loader';
19
27
  export { default as Tree } from './components/Tree/Tree';
20
28
  export type { TreeProps, TreeItem } from './components/Tree/Tree';
21
29
  export { default as Menu } from './components/Menu/Menu';
22
- export type { MenuProps, MenuItem, MenuSection } from './components/Menu/Menu';
30
+ export type { MenuProps, MenuListProps, MenuTreeProps, MenuItem, MenuSection, MenuKind } from './components/Menu/Menu';
23
31
  export { default as Select } from './components/Select/Select';
24
32
  export type { SelectProps, SelectOption, SelectOptionState } from './components/Select/Select';
25
33
  export { default as FullPageModal } from './components/FullPageModal/FullPageModal';
@@ -0,0 +1,28 @@
1
+ export { LOGO_VIEWBOX } from './logo';
2
+ export interface LoaderSegment {
3
+ d: string;
4
+ /** "url(#<id>-<n>)" with gradients, else one color. */
5
+ fill: string;
6
+ /** Where it sits round the ring, 0 to 1 from the top, clockwise: the pulse reaches it then. */
7
+ angle: number;
8
+ }
9
+ export interface LoaderGradient {
10
+ id: string;
11
+ x1: number;
12
+ y1: number;
13
+ x2: number;
14
+ y2: number;
15
+ from: string;
16
+ to: string;
17
+ }
18
+ /**
19
+ * The two rings' segments. With an `id`, each segment is filled with its own
20
+ * gradient (ids "<id>-0", "<id>-1"…), as in the logo; without one, with its
21
+ * gradient's middle color, so a page can show any number of loaders with no
22
+ * ids at all. They look the same up to about 64 pixels.
23
+ */
24
+ export declare function loaderRings(id?: string): {
25
+ inner: LoaderSegment[];
26
+ outer: LoaderSegment[];
27
+ gradients: LoaderGradient[];
28
+ };
@@ -0,0 +1,5 @@
1
+ export type LogoSegment = [d: string, from: string, to: string, line: [number, number, number, number], angle: number];
2
+ /** The artwork's viewBox around the mark alone. */
3
+ export declare const LOGO_VIEWBOX = "492 149 540 540";
4
+ export declare const LOGO_INNER: LogoSegment[];
5
+ export declare const LOGO_OUTER: LogoSegment[];
@@ -1,24 +1,53 @@
1
+ /**
2
+ * What a Menu is, and so what screen readers hear:
3
+ * - 'nav': navigation. A <nav> landmark of links ("link", "current page");
4
+ * an item without an href is a button in it ("button").
5
+ * - 'actions': a menu of commands (the WAI-ARIA menu pattern): role="menu",
6
+ * each item a "menu item"; one Tab stop, the arrow keys move.
7
+ * - 'tree': a tree to pick from (the WAI-ARIA tree pattern), like layers:
8
+ * "tree", each row "level 2, 3 of 5, selected". Drawn by Tree.
9
+ */
10
+ export type MenuKind = 'nav' | 'actions' | 'tree';
11
+ interface KindProps {
12
+ kind?: MenuKind;
13
+ sections?: {
14
+ href?: string;
15
+ items?: {
16
+ href?: string;
17
+ }[];
18
+ }[];
19
+ items?: unknown;
20
+ activePath?: unknown;
21
+ }
22
+ /**
23
+ * The kind to draw: `kind` when given; else a tree for Tree's props (items,
24
+ * activePath), navigation when any item is a link, a menu of actions when
25
+ * none is.
26
+ */
27
+ export declare function menuKind(props: KindProps): MenuKind;
1
28
  /** A section's id: its own, or its title as a slug ("Get started" -> "get-started"). */
2
29
  export declare const sectionId: (section: {
3
30
  id?: string;
4
- title: unknown;
31
+ title?: unknown;
5
32
  }) => string;
6
33
  /** Whether a section starts open: true / false for all, or a map of id -> open (missing = open). */
7
34
  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;
35
+ /** Makes `row` the one item of an actions menu that Tab reaches (roving tabindex). */
36
+ export declare function roveTo(menu: HTMLElement, row: HTMLElement): void;
37
+ /** Focus moved onto an item of an actions menu (a click, say): it becomes the Tab stop. */
38
+ export declare function menuFocus(event: FocusEvent, menu: HTMLElement): void;
14
39
  /**
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.
40
+ * The keys on a Menu. Up / Down move to the previous / next item (going round
41
+ * at the ends) and Home / End to the first / last, in every kind.
42
+ * - Navigation (the WAI-ARIA disclosure navigation pattern, with its
43
+ * optional keys): Tab still goes link by link. The rows are the section
44
+ * titles and the links in open sections; Right on a section opens it, or
45
+ * goes to its first link; Left closes it, or goes from a link up to its
46
+ * section. Enter follows a link; Enter or Space opens a section.
47
+ * - Actions (the WAI-ARIA menu pattern): one Tab stop that follows the
48
+ * focus; typing a letter goes to the next item starting with it; Enter or
49
+ * Space runs the item.
22
50
  * Returns true when it used the key.
23
51
  */
24
52
  export declare function menuKeydown(event: KeyboardEvent, nav: HTMLElement): boolean;
53
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { IconName } from './icons';
2
+ export type ProgressStatus = 'active' | 'success' | 'warning' | 'critical';
3
+ /** What each status means, in words and as an icon, so it never rests on color alone (WCAG 1.4.1). */
4
+ export declare const PROGRESS_STATUS: Record<ProgressStatus, {
5
+ word: string;
6
+ icon?: IconName;
7
+ }>;
8
+ /** 0 to 100, whole numbers; anything else (NaN, -5, 140) is pulled into range. */
9
+ export declare const clampPercent: (percent: number) => number;
10
+ /** What screen readers say for the value: "40%", or "100%, Done". */
11
+ export declare const progressValueText: (percent: number, status: ProgressStatus) => string;
@@ -11,9 +11,15 @@ export interface FullPageModalProps extends ElementProps {
11
11
  children?: Child;
12
12
  /** Appends the modal to this element when it is made, e.g. document.body. */
13
13
  mountEl?: Element;
14
+ /** Called when someone presses Esc. Close the modal in it: modal.update({ visible: false }). */
15
+ onClose?: () => void;
16
+ /** Names the modal and its title: the title gets the id "<id>-title", and the modal is labelled by it. */
17
+ id?: string;
14
18
  }
15
19
  /**
16
- * Shows content over the whole screen. Returns the modal's outer element
20
+ * Shows content over the whole screen: a modal dialog, like the React one
21
+ * (focus moves in when it opens and back when it closes, Tab stays inside,
22
+ * Esc calls onClose). Returns the modal's outer element
17
23
  * (`<div class="portal nurvus">`, the one React puts into `<body>` itself):
18
24
  * mount it on document.body, or pass `mountEl: document.body`.
19
25
  *
@@ -0,0 +1,21 @@
1
+ import { Spacing } from '../spacing';
2
+ import { Responsive } from '../breakpoints';
3
+ import { Child, ElementProps } from './spawn';
4
+ import { NurvusElement } from './update';
5
+ export type GridColumns = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
6
+ export interface GridProps extends ElementProps {
7
+ /** How many equal columns: 1 to 12. Can change with the width: { base: 1, md: 2, lg: 3 }. */
8
+ columns?: Responsive<GridColumns>;
9
+ /** Instead of a count: as many columns as fit, each at least this wide (e.g. "15rem" or 240). They fill the row. */
10
+ minItemWidth?: string | number;
11
+ /** Space between cells, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
12
+ gap?: Spacing;
13
+ /** Space between rows when it differs from gap. */
14
+ rowGap?: Spacing;
15
+ /** How cells line up in their row. Defaults to stretch (equal heights). */
16
+ align?: 'start' | 'center' | 'end' | 'stretch';
17
+ /** What to lay out. */
18
+ children?: Child;
19
+ }
20
+ /** Columns: a count that changes at the breakpoints, or as many as fit. The same markup as the React Grid. */
21
+ export default function Grid(props?: GridProps): NurvusElement<HTMLDivElement, GridProps>;
@@ -0,0 +1,18 @@
1
+ import { ElementProps } from './spawn';
2
+ import { NurvusElement } from './update';
3
+ export interface LoaderProps extends ElementProps {
4
+ /** Width and height of the mark. Defaults to 2em (twice the text size). A number is pixels. */
5
+ size?: number | string;
6
+ /** What is loading, for screen readers ("Loading photos"). Defaults to "Loading". */
7
+ label?: string;
8
+ /** Shows the label beside the mark, not only to screen readers. */
9
+ showLabel?: boolean;
10
+ /** Fills the segments with the logo's gradients (for big loaders); their ids start with this. Without it, one color each. */
11
+ id?: string;
12
+ }
13
+ /**
14
+ * Shows that something is loading: the NURVUS mark with a light running round
15
+ * it, the same markup as the React Loader. Screen readers hear the label once
16
+ * (role="status"). Remove it when the thing has loaded.
17
+ */
18
+ export default function Loader(props?: LoaderProps): NurvusElement<HTMLDivElement, LoaderProps>;
@@ -1,26 +1,34 @@
1
+ import { MenuKind } from '../menu';
2
+ import { TreeProps } from './Tree';
1
3
  import { Child, ElementProps } from './spawn';
2
4
  import { NurvusElement } from './update';
5
+ export type { MenuKind };
3
6
  export interface MenuItem {
4
- /** What the link says. */
7
+ /** What the item says. */
5
8
  label: Child;
6
- /** Where it goes. The item whose href equals `current` is marked as the current page. */
7
- href: string;
9
+ /** Makes the item a link to this address. The item whose href equals `current` is marked as the current page. */
10
+ href?: string;
11
+ /** Makes the item a button that calls this (an action: "Duplicate", "Sign out"). */
12
+ onSelect?: (event: MouseEvent) => void;
13
+ /** Shows the item but stops it working (actions only). */
14
+ disabled?: boolean;
8
15
  /** Draws a hairline above this item, to split a section into groups. */
9
16
  divider?: boolean;
10
17
  }
11
18
  export interface MenuSection {
12
19
  /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
13
20
  id?: string;
14
- /** The section heading. */
15
- title: string;
21
+ /** The section heading. Optional for actions. */
22
+ title?: string;
16
23
  /** Makes the heading a link too (e.g. to the section's overview page). */
17
24
  href?: string;
18
- /** The section's links. */
25
+ /** The section's items. */
19
26
  items: MenuItem[];
20
27
  }
21
- export interface MenuProps extends ElementProps {
22
- /** The sections, in order. */
23
- sections: MenuSection[];
28
+ /** What navigation and actions take. */
29
+ interface MenuBaseProps extends ElementProps {
30
+ /** Navigation and actions: the sections, in order. */
31
+ sections?: MenuSection[];
24
32
  /** The href of the page being shown: its link is marked, and its section opens. */
25
33
  current?: string;
26
34
  /** Which sections start open: true (all), false (none) or a map of section id -> open. Defaults to all. */
@@ -29,15 +37,37 @@ export interface MenuProps extends ElementProps {
29
37
  onToggle?: (id: string, open: boolean) => void;
30
38
  /** Called when any link is clicked, with its href (e.g. to close a drawer). */
31
39
  onNavigate?: (href: string, event: MouseEvent) => void;
32
- /** Accessible name of the navigation landmark. */
40
+ /** What screen readers call the menu ("Pages", "Actions"). */
33
41
  label?: string;
34
- /** Prefix for the ids that link each toggle to its list. Defaults to "menu". */
42
+ /** Prefix for the ids inside (each toggle names its list). Defaults to "menu". */
35
43
  id?: string;
36
44
  }
45
+ export interface MenuProps extends MenuBaseProps {
46
+ /** What the menu is: 'nav' (links), 'actions' (commands) or 'tree' (rows to pick from, with Tree's props). Left out, it follows the props. */
47
+ kind?: MenuKind;
48
+ /** Tree: the rows, each with optional child `items`. */
49
+ items?: TreeProps['items'];
50
+ /** Tree: the picked row as a path of indexes. */
51
+ activePath?: number[];
52
+ /** Tree: draws a row's content instead of its label. */
53
+ itemRenderer?: TreeProps['itemRenderer'];
54
+ /** Tree: the deepest level that still indents. */
55
+ maxIndentDepth?: number;
56
+ }
57
+ /** Menu's props for navigation and actions. */
58
+ export interface MenuListProps extends MenuBaseProps {
59
+ /** 'nav' or 'actions'; left out, it follows the items. */
60
+ kind?: 'nav' | 'actions';
61
+ }
62
+ /** Menu kind: 'tree': Tree's props. */
63
+ export type MenuTreeProps = TreeProps & {
64
+ kind: 'tree';
65
+ };
37
66
  /**
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.
67
+ * One component for lists of things to go to, do or pick, the same markup as
68
+ * the React Menu. The items decide what it is, and screen readers hear it so:
69
+ * links make navigation (sections open and close in place; update({ current })
70
+ * marks another page), actions make a menu of commands (one Tab stop, the
71
+ * arrow keys move), kind: 'tree' makes a Tree.
42
72
  */
43
73
  export default function Menu(props?: MenuProps): NurvusElement<HTMLElement, MenuProps>;