@nurvus/ui 0.1.0-alpha.14 → 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 (82) hide show
  1. package/README.md +13 -0
  2. package/dist/icons.svg +73 -0
  3. package/dist/index.js +1 -1
  4. package/dist/nurvus.css +14 -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/Icon/Icon.d.ts +20 -0
  10. package/dist/types/components/Loader/Loader.d.ts +21 -0
  11. package/dist/types/components/Menu/Menu.d.ts +54 -19
  12. package/dist/types/components/Progress/Progress.d.ts +19 -5
  13. package/dist/types/components/Stack/Stack.d.ts +26 -0
  14. package/dist/types/dialog.d.ts +12 -0
  15. package/dist/types/icons.d.ts +83 -0
  16. package/dist/types/index.d.ts +13 -1
  17. package/dist/types/loader.d.ts +28 -0
  18. package/dist/types/logo.d.ts +5 -0
  19. package/dist/types/menu.d.ts +43 -14
  20. package/dist/types/progress.d.ts +11 -0
  21. package/dist/types/respawn/FullPageModal.d.ts +7 -1
  22. package/dist/types/respawn/Grid.d.ts +21 -0
  23. package/dist/types/respawn/Icon.d.ts +22 -0
  24. package/dist/types/respawn/Loader.d.ts +18 -0
  25. package/dist/types/respawn/Menu.d.ts +45 -15
  26. package/dist/types/respawn/Progress.d.ts +18 -6
  27. package/dist/types/respawn/Stack.d.ts +21 -0
  28. package/dist/types/respawn/index.d.ts +13 -1
  29. package/dist/types/respawn/spawn.d.ts +2 -0
  30. package/package.json +1 -3
  31. package/src/breakpoints.ts +28 -0
  32. package/src/components/Button/Button.scss +20 -20
  33. package/src/components/ButtonGroup/ButtonGroup.md +8 -12
  34. package/src/components/FullPageModal/FullPageModal.md +20 -17
  35. package/src/components/FullPageModal/FullPageModal.scss +5 -0
  36. package/src/components/FullPageModal/FullPageModal.tsx +37 -3
  37. package/src/components/Grid/Grid.md +37 -0
  38. package/src/components/Grid/Grid.scss +37 -0
  39. package/src/components/Grid/Grid.tsx +54 -0
  40. package/src/components/HistoryList/HistoryList.scss +2 -2
  41. package/src/components/Icon/Icon.md +22 -0
  42. package/src/components/Icon/Icon.scss +10 -0
  43. package/src/components/Icon/Icon.tsx +45 -0
  44. package/src/components/Layout/Layout.md +10 -18
  45. package/src/components/Loader/Loader.md +30 -0
  46. package/src/components/Loader/Loader.scss +42 -0
  47. package/src/components/Loader/Loader.tsx +68 -0
  48. package/src/components/Menu/Menu.md +68 -2
  49. package/src/components/Menu/Menu.scss +48 -18
  50. package/src/components/Menu/Menu.tsx +146 -39
  51. package/src/components/Progress/Progress.md +27 -26
  52. package/src/components/Progress/Progress.scss +41 -36
  53. package/src/components/Progress/Progress.tsx +50 -6
  54. package/src/components/Select/Select.scss +20 -19
  55. package/src/components/Stack/Stack.md +43 -0
  56. package/src/components/Stack/Stack.scss +36 -0
  57. package/src/components/Stack/Stack.tsx +52 -0
  58. package/src/components/Table/Table.scss +1 -1
  59. package/src/components/Tag/Tag.scss +2 -2
  60. package/src/components/Text/Text.md +3 -5
  61. package/src/components/Title/Title.scss +6 -6
  62. package/src/components/Tree/Tree.md +5 -5
  63. package/src/css.ts +4 -0
  64. package/src/dialog.ts +47 -0
  65. package/src/icons.ts +117 -0
  66. package/src/index.ts +13 -1
  67. package/src/loader.ts +43 -0
  68. package/src/logo.ts +12 -0
  69. package/src/menu.ts +91 -21
  70. package/src/progress.ts +21 -0
  71. package/src/respawn/FullPageModal.ts +30 -3
  72. package/src/respawn/Grid.ts +41 -0
  73. package/src/respawn/Icon.ts +47 -0
  74. package/src/respawn/Loader.ts +77 -0
  75. package/src/respawn/Menu.ts +138 -34
  76. package/src/respawn/Progress.ts +56 -13
  77. package/src/respawn/Stack.ts +37 -0
  78. package/src/respawn/index.ts +13 -1
  79. package/src/respawn/spawn.ts +5 -3
  80. package/src/styles/breakpoints.scss +3 -0
  81. package/src/styles/theme.scss +55 -55
  82. package/src/styles/type.json +9 -9
@@ -0,0 +1,36 @@
1
+ // Styles for Stack (React and Respawn: same markup).
2
+ @import "../../styles/variables.scss";
3
+ @import "../../styles/breakpoints.scss";
4
+
5
+ $stack-steps: 0, 2, 4, 8, 12, 16, 24, 32, 48, 64;
6
+
7
+ .#{$cls-prefix}.stack {
8
+ display: flex;
9
+ flex-direction: column;
10
+
11
+ &[data-direction="row"] { flex-direction: row; }
12
+
13
+ @each $bp, $width in $nurvus-breakpoints {
14
+ @media (min-width: $width) {
15
+ &[data-direction-#{$bp}="column"] { flex-direction: column; }
16
+ &[data-direction-#{$bp}="row"] { flex-direction: row; }
17
+ }
18
+ }
19
+
20
+ @each $n in $stack-steps {
21
+ &[data-gap="#{$n}"] { gap: var(--space--#{$n}); }
22
+ }
23
+
24
+ &[data-align="start"] { align-items: flex-start; }
25
+ &[data-align="center"] { align-items: center; }
26
+ &[data-align="end"] { align-items: flex-end; }
27
+ &[data-align="stretch"] { align-items: stretch; }
28
+ &[data-align="baseline"] { align-items: baseline; }
29
+
30
+ &[data-justify="start"] { justify-content: flex-start; }
31
+ &[data-justify="center"] { justify-content: center; }
32
+ &[data-justify="end"] { justify-content: flex-end; }
33
+ &[data-justify="between"] { justify-content: space-between; }
34
+
35
+ &[data-wrap="true"] { flex-wrap: wrap; }
36
+ }
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import { Spacing } from '../../spacing';
5
+ import { Responsive, responsiveData } from '../../breakpoints';
6
+ import './Stack.scss';
7
+
8
+ export type StackDirection = 'column' | 'row';
9
+
10
+ export interface StackProps extends React.HTMLAttributes<HTMLDivElement> {
11
+ /** column (top to bottom, the default) or row. Can change with the width: { base: 'column', md: 'row' }. */
12
+ direction?: Responsive<StackDirection>;
13
+ /** Space between the children, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
14
+ gap?: Spacing;
15
+ /** How the children line up across the stack. */
16
+ align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
17
+ /** How the children spread along the stack. */
18
+ justify?: 'start' | 'center' | 'end' | 'between';
19
+ /** Lets a row wrap onto more lines when it runs out of room. */
20
+ wrap?: boolean;
21
+ /** What to lay out. */
22
+ children?: React.ReactNode;
23
+ /** Custom class name. */
24
+ className?: string;
25
+ }
26
+
27
+ /**
28
+ * Puts its children in a column or a row with even space between them, from
29
+ * the 4px grid (CSS gap, so wrapped rows keep their spacing too). The
30
+ * direction can change at a breakpoint: a column on phones, a row from md up.
31
+ */
32
+ export default function Stack({
33
+ direction = 'column',
34
+ gap = 16,
35
+ align,
36
+ justify,
37
+ wrap = false,
38
+ className,
39
+ ...restProps
40
+ }: StackProps) {
41
+ return (
42
+ <div
43
+ className={ classNames(className, 'stack', CONSTANT.CLASS_PREFIX) }
44
+ { ...responsiveData('direction', direction) }
45
+ data-gap={ gap }
46
+ data-align={ align }
47
+ data-justify={ justify }
48
+ data-wrap={ wrap || undefined }
49
+ { ...restProps }
50
+ />
51
+ );
52
+ }
@@ -19,7 +19,7 @@
19
19
  th,
20
20
  td {
21
21
  box-sizing: border-box;
22
- padding: 10px $--space--12;
22
+ padding: 0.625rem $--space--12;
23
23
  text-align: left;
24
24
  vertical-align: middle;
25
25
  border-bottom: 1px solid var(--nv-border);
@@ -12,9 +12,9 @@
12
12
  // The tone mixed with a fifth of the text color: on its own tint (and on a
13
13
  // Panel's surface) every tone keeps 4.5:1 in every theme.
14
14
  color: color-mix(in srgb, var(--tag-color) 80%, var(--nv-text));
15
- font-size: 12px;
15
+ font-size: 0.75rem;
16
16
  font-weight: 500;
17
- line-height: 18px;
17
+ line-height: 1.125rem;
18
18
  white-space: nowrap;
19
19
 
20
20
  &[data-tone="accent"] { --tag-color: var(--nv-accent); }
@@ -31,9 +31,7 @@ import { Text } from '@nurvus/ui';
31
31
 
32
32
  Using Text Overflow
33
33
  ```jsx
34
- import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
35
- import AddIcon from '@material-ui/icons/Add';
36
- import { Button, Layout, Text } from '@nurvus/ui';
34
+ import { Button, Icon, Layout, Text } from '@nurvus/ui';
37
35
 
38
36
  const overflowStyle = {
39
37
  textOverflow: 'ellipsis',
@@ -43,8 +41,8 @@ const overflowStyle = {
43
41
 
44
42
  <Layout display="flex" alignItems="center" justifyContent="space-between">
45
43
  <Text style={ overflowStyle }>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</Text>
46
- <Button>
47
- <AddIcon />
44
+ <Button aria-label="Add">
45
+ <Icon name="add" size="1.25em" />
48
46
  </Button>
49
47
  </Layout>
50
48
  ```
@@ -18,28 +18,28 @@
18
18
 
19
19
  @at-root {
20
20
  h1#{&} {
21
- font-size: 24px;
21
+ font-size: 1.5rem;
22
22
  }
23
23
 
24
24
  h2#{&} {
25
- font-size: 20px;
25
+ font-size: 1.25rem;
26
26
  }
27
27
 
28
28
  h3#{&} {
29
- font-size: 18px;
29
+ font-size: 1.125rem;
30
30
  }
31
31
 
32
32
  h4#{&} {
33
- font-size: 16px;
33
+ font-size: 1rem;
34
34
  }
35
35
 
36
36
  h5#{&} {
37
- font-size: 14px;
37
+ font-size: 0.875rem;
38
38
  font-weight: 500;
39
39
  }
40
40
 
41
41
  h6#{&} {
42
- font-size: 12px;
42
+ font-size: 0.75rem;
43
43
  }
44
44
  }
45
45
  }
@@ -1,3 +1,5 @@
1
+ **Tree is a Menu that picks.** `<Tree />` and `<Menu kind="tree" />` are the same thing: rows to choose from on the page (layers, folders, an outline). For links or commands, use [Menu](#/Components/Menu) with links or actions: the same look, and screen readers hear each as what it is.
2
+
1
3
  A list of rows to pick from, nested like a layers panel. Click a row, or use the keyboard: Tab reaches the active row, ↑ ↓ move, → goes to a child row, ← to its parent, Enter or Space picks.
2
4
  ```jsx
3
5
  import { Tree } from '@nurvus/ui';
@@ -26,16 +28,14 @@ const Layers = () => {
26
28
 
27
29
  Draw your own rows with `itemRenderer`, e.g. a layer's name with its show and lock icons.
28
30
  ```jsx
29
- import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
30
- import LockOpenIcon from '@material-ui/icons/LockOpen';
31
- import { Layout, Text, Tree } from '@nurvus/ui';
31
+ import { Icon, Layout, Text, Tree } from '@nurvus/ui';
32
32
 
33
33
  const itemRenderer = ({ label }) => (
34
34
  <Layout display="flex" alignItems="center" justifyContent="space-between">
35
35
  <Text>{ label }</Text>
36
36
  <Layout display="flex" alignItems="center" itemSpacing={ 4 }>
37
- <RemoveRedEyeIcon fontSize="small" />
38
- <LockOpenIcon fontSize="small" />
37
+ <Icon name="eye" />
38
+ <Icon name="unlock" />
39
39
  </Layout>
40
40
  </Layout>
41
41
  );
package/src/css.ts CHANGED
@@ -6,7 +6,11 @@ import './components/ButtonGroup/ButtonGroup.scss';
6
6
  import './components/FullPageModal/FullPageModal.scss';
7
7
  import './components/HistoryList/HistoryList.scss';
8
8
  import './components/Layout/Layout.scss';
9
+ import './components/Stack/Stack.scss';
10
+ import './components/Grid/Grid.scss';
9
11
  import './components/Link/Link.scss';
12
+ import './components/Icon/Icon.scss';
13
+ import './components/Loader/Loader.scss';
10
14
  import './components/Tree/Tree.scss';
11
15
  import './components/Menu/Menu.scss';
12
16
  import './components/Select/Select.scss';
package/src/dialog.ts ADDED
@@ -0,0 +1,47 @@
1
+ // Dialog rules shared by the React and the Respawn FullPageModal (no React
2
+ // here): what can take focus inside, Tab kept inside, Esc to close.
3
+
4
+ const FOCUSABLE = [
5
+ 'a[href]', 'area[href]', 'button:not([disabled])', 'input:not([disabled]):not([type="hidden"])',
6
+ 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', '[contenteditable="true"]', '[tabindex]',
7
+ ].join(',');
8
+
9
+ /** The elements Tab can reach inside `root`, in order (shown ones, not tabindex="-1"). */
10
+ export function focusables(root: HTMLElement): HTMLElement[] {
11
+ return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE))
12
+ .filter((el) => el.tabIndex >= 0 && el.getClientRects().length > 0);
13
+ }
14
+
15
+ /**
16
+ * The keys of a modal dialog (the WAI-ARIA dialog pattern): Tab and
17
+ * Shift+Tab go round the dialog's own controls and never leave it; Esc calls
18
+ * onClose. Returns true when it used the key.
19
+ */
20
+ export function dialogKeydown(event: KeyboardEvent, dialog: HTMLElement, onClose?: () => void): boolean {
21
+ if (event.key === 'Escape') {
22
+ if (!onClose) return false;
23
+ event.preventDefault();
24
+ onClose();
25
+ return true;
26
+ }
27
+ if (event.key !== 'Tab') return false;
28
+ const stops = focusables(dialog);
29
+ if (!stops.length) { event.preventDefault(); dialog.focus(); return true; }
30
+ const first = stops[0];
31
+ const last = stops[stops.length - 1];
32
+ const at = document.activeElement;
33
+ if (event.shiftKey && (at === first || at === dialog)) { event.preventDefault(); last.focus(); return true; }
34
+ if (!event.shiftKey && at === last) { event.preventDefault(); first.focus(); return true; }
35
+ return false;
36
+ }
37
+
38
+ /** Moves focus to the dialog itself once it shows (screen readers then say its name and "dialog"). */
39
+ export function focusDialog(dialog: HTMLElement): void {
40
+ const go = () => { if (dialog.isConnected) dialog.focus({ preventScroll: true }); };
41
+ if (typeof requestAnimationFrame === 'function') requestAnimationFrame(go); else go();
42
+ }
43
+
44
+ /** Gives focus back to what had it before the dialog opened, if it is still on the page. */
45
+ export function restoreFocus(opener: Element | null): void {
46
+ if (opener && (opener as HTMLElement).focus && opener.isConnected) (opener as HTMLElement).focus({ preventScroll: true });
47
+ }
package/src/icons.ts ADDED
@@ -0,0 +1,117 @@
1
+ // The NURVUS icons, drawn for this library (no icon font, no third-party set).
2
+ // Shared by the React and the Respawn Icon (no React here).
3
+ //
4
+ // The grid: a 24 x 24 artboard with 2 units of padding (a 20 x 20 live area),
5
+ // 2-unit strokes with round caps and joins, corners of radius 2, circles of
6
+ // radius 9. Every shape is a stroke in currentColor unless it says otherwise,
7
+ // so an icon takes the color of the text around it. Icons are 1em by default:
8
+ // next to 16px text they are 16px, in a 22px title 22px.
9
+
10
+ /** One SVG element of an icon: its tag and attributes. */
11
+ export type IconNode = [tag: 'path' | 'circle' | 'rect', attrs: Record<string, string | number>];
12
+
13
+ const path = (d: string): IconNode => ['path', { d }];
14
+ const circle = (cx: number, cy: number, r: number): IconNode => ['circle', { cx, cy, r }];
15
+ const rect = (x: number, y: number, width: number, height: number, rx = 2): IconNode => ['rect', { x, y, width, height, rx }];
16
+ const ring = circle(12, 12, 9);
17
+ const dot = (x: number, y: number) => path(`M${x} ${y}h.01`);
18
+ const bead = (x: number, y: number) => circle(x, y, 1); // a bigger dot: r 1 + the 2-unit line = 4 across
19
+
20
+ const DEFS = {
21
+ // Navigation
22
+ menu: [path('M4 6h16M4 12h16M4 18h16')],
23
+ close: [path('M6 6l12 12M18 6L6 18')],
24
+ 'chevron-down': [path('M6 9l6 6 6-6')],
25
+ 'chevron-up': [path('M6 15l6-6 6 6')],
26
+ 'chevron-left': [path('M15 6l-6 6 6 6')],
27
+ 'chevron-right': [path('M9 6l6 6-6 6')],
28
+ 'arrow-left': [path('M19 12H5M11 6l-6 6 6 6')],
29
+ 'arrow-right': [path('M5 12h14M13 6l6 6-6 6')],
30
+ 'arrow-up': [path('M12 19V5M6 11l6-6 6 6')],
31
+ 'arrow-down': [path('M12 5v14M6 13l6 6 6-6')],
32
+ 'external-link': [path('M14 4h6v6M20 4l-9 9M18 14v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4')],
33
+ home: [path('M4 11l8-7 8 7v8a2 2 0 0 1-2 2h-3v-6H9v6H6a2 2 0 0 1-2-2z')],
34
+ 'panel-left': [rect(3, 4, 18, 16), path('M9 4v16')],
35
+ 'more-horizontal': [bead(5, 12), bead(12, 12), bead(19, 12)],
36
+ 'more-vertical': [bead(12, 5), bead(12, 12), bead(12, 19)],
37
+ maximize: [path('M14 4h6v6M10 20H4v-6M20 4l-6 6M4 20l6-6')],
38
+ minimize: [path('M4 14h6v6M20 10h-6V4M14 10l6-6M4 20l6-6')],
39
+ // Actions
40
+ add: [path('M12 5v14M5 12h14')],
41
+ remove: [path('M5 12h14')],
42
+ edit: [path('M4 20h4L19 9a2.83 2.83 0 0 0-4-4L4 16v4z'), path('M13.5 6.5l4 4')],
43
+ copy: [rect(8, 8, 12, 12), path('M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2')],
44
+ delete: [path('M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M10 11v6M14 11v6')],
45
+ download: [path('M12 4v11M7 10l5 5 5-5M4 20h16')],
46
+ upload: [path('M12 15V4M7 9l5-5 5 5M4 20h16')],
47
+ search: [circle(11, 11, 6.5), path('M16 16l4 4')],
48
+ filter: [path('M4 5h16l-6 7.5V19l-4 2v-8.5z')],
49
+ sliders: [path('M4 7h10M18 7h2M4 17h4M12 17h8'), circle(16, 7, 2), circle(10, 17, 2)],
50
+ refresh: [path('M19 12a7 7 0 1 1-7-7'), path('M9.5 2.5L12 5l-2.5 2.5')],
51
+ undo: [path('M9 14L4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11')],
52
+ redo: [path('M15 14l5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13')],
53
+ settings: [path('M10.01 5.29L10.51 2.62L13.49 2.62L13.99 5.29L15.34 5.85L17.58 4.31L19.69 6.42L18.15 8.66L18.71 10.01L21.38 10.51L21.38 13.49L18.71 13.99L18.15 15.34L19.69 17.58L17.58 19.69L15.34 18.15L13.99 18.71L13.49 21.38L10.51 21.38L10.01 18.71L8.66 18.15L6.42 19.69L4.31 17.58L5.85 15.34L5.29 13.99L2.62 13.49L2.62 10.51L5.29 10.01L5.85 8.66L4.31 6.42L6.42 4.31L8.66 5.85z'), circle(12, 12, 3)],
54
+ share: [circle(18, 5, 2.5), circle(6, 12, 2.5), circle(18, 19, 2.5), path('M8.2 13.3l7.6 4.4M15.8 6.3l-7.6 4.4')],
55
+ play: [path('M7 4.5l12.5 7.5L7 19.5z')],
56
+ pause: [path('M8 5v14M16 5v14')],
57
+ 'sign-out': [path('M10 20H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h4M15 16l4-4-4-4M19 12H9')],
58
+ // Status
59
+ check: [path('M5 12.5l4.5 4.5L19 7.5')],
60
+ info: [ring, path('M12 11v5'), dot(12, 8)],
61
+ warning: [path('M10.27 4.3L2.6 18a2 2 0 0 0 1.73 3h15.34a2 2 0 0 0 1.73-3L13.73 4.3a2 2 0 0 0-3.46 0z'), path('M12 9.5v4'), dot(12, 17)],
62
+ error: [ring, path('M15 9l-6 6M9 9l6 6')],
63
+ help: [ring, path('M9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.7.3-1 .8-1 1.5v.4'), dot(12, 17)],
64
+ // Things
65
+ file: [path('M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z'), path('M14 3v5h5')],
66
+ folder: [path('M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z')],
67
+ image: [rect(3, 4, 18, 16), circle(9, 10, 1.5), path('M21 15l-5-5L6 20')],
68
+ layers: [path('M12 3l9 5-9 5-9-5z'), path('M3 13l9 5 9-5')],
69
+ eye: [path('M2 12s3.6-6 10-6 10 6 10 6-3.6 6-10 6S2 12 2 12z'), circle(12, 12, 3)],
70
+ 'eye-off': [path('M3 3l18 18'), path('M10.6 6.1A9.7 9.7 0 0 1 12 6c6.4 0 10 6 10 6a17 17 0 0 1-2.6 3.4M6.6 6.6C3.9 8.4 2 12 2 12s3.6 6 10 6a9.7 9.7 0 0 0 5.4-1.6'), path('M9.9 9.9a3 3 0 0 0 4.2 4.2')],
71
+ lock: [rect(5, 11, 14, 10), path('M8 11V8a4 4 0 0 1 8 0v3')],
72
+ unlock: [rect(5, 11, 14, 10), path('M8 11V8a4 4 0 0 1 7.75-1.4')],
73
+ user: [circle(12, 8, 4), path('M4 21a8 8 0 0 1 16 0')],
74
+ users: [circle(9, 8, 3.5), path('M2 20a7 7 0 0 1 14 0'), path('M15.5 4.6a3.5 3.5 0 0 1 0 6.8M18 13.6a7 7 0 0 1 4 6.4')],
75
+ mail: [rect(3, 5, 18, 14), path('M3 7.5l9 6 9-6')],
76
+ bell: [path('M18 16v-5a6 6 0 0 0-12 0v5l-2 2h16z'), path('M10 21a2 2 0 0 0 4 0')],
77
+ calendar: [rect(3, 5, 18, 16), path('M3 10h18M8 3v4M16 3v4')],
78
+ clock: [ring, path('M12 7v5l3 2')],
79
+ globe: [ring, path('M3 12h18'), path('M12 3c-2.5 2.5-3.8 5.5-3.8 9s1.3 6.5 3.8 9c2.5-2.5 3.8-5.5 3.8-9S14.5 5.5 12 3z')],
80
+ 'map-pin': [path('M12 21s-7-6-7-11.5a7 7 0 0 1 14 0C19 15 12 21 12 21z'), circle(12, 9.5, 2.5)],
81
+ tag: [path('M3 12V5a2 2 0 0 1 2-2h7l9 9-9 9z'), dot(8, 8)],
82
+ bookmark: [path('M6 5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16l-6-4-6 4z')],
83
+ star: [path('M12 3.3L14.47 9.4L21.04 9.86L15.99 14.1L17.58 20.49L12 17L6.42 20.49L8.01 14.1L2.96 9.86L9.53 9.4z')],
84
+ heart: [path('M12 20s-8-4.6-8-10.2A4.3 4.3 0 0 1 12 7.4a4.3 4.3 0 0 1 8 2.4C20 15.4 12 20 12 20z')],
85
+ grid: [rect(4, 4, 6, 6, 1), rect(14, 4, 6, 6, 1), rect(4, 14, 6, 6, 1), rect(14, 14, 6, 6, 1)],
86
+ list: [path('M9 6h11M9 12h11M9 18h11'), dot(4.5, 6), dot(4.5, 12), dot(4.5, 18)],
87
+ link: [path('M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1'), path('M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1')],
88
+ // Theme
89
+ sun: [circle(12, 12, 4), path('M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41')],
90
+ moon: [path('M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z')],
91
+ palette: [path('M12 3a9 9 0 0 0 0 18c1.1 0 1.6-.8 1.6-1.6 0-1-.9-1.4-.9-2.4 0-.9.7-1.5 1.6-1.5H16a5 5 0 0 0 5-5C21 6.4 17 3 12 3z'), dot(7.5, 11.5), dot(9.5, 7.5), dot(14.5, 7.5)],
92
+ sparkles: [path('M10 4l1.6 4.4L16 10l-4.4 1.6L10 16l-1.6-4.4L4 10l4.4-1.6z'), path('M18 14l.8 2.2L21 17l-2.2.8L18 20l-.8-2.2L15 17l2.2-.8z')],
93
+ zap: [path('M13 2.5L4.5 13.5H11l-1 8 8.5-11H12z')],
94
+ // Code
95
+ code: [path('M8 7l-5 5 5 5M16 7l5 5-5 5')],
96
+ terminal: [path('M4 17l6-5-6-5M12 19h8')],
97
+ };
98
+
99
+ /** Every icon's name. */
100
+ export type IconName = keyof typeof DEFS;
101
+
102
+ /** Every icon: its name and the shapes it is drawn with. */
103
+ export const ICONS: Record<IconName, IconNode[]> = DEFS;
104
+
105
+ /** The names, in the order above (groups: navigation, actions, status, things, theme, code). */
106
+ export const ICON_NAMES = Object.keys(DEFS) as IconName[];
107
+
108
+ let warned = '';
109
+ /** An unknown name draws an empty icon and says so once. */
110
+ export function iconNodes(name: string): IconNode[] {
111
+ const nodes = (ICONS as Record<string, IconNode[]>)[name];
112
+ if (!nodes && warned !== name && typeof console !== 'undefined') {
113
+ warned = name;
114
+ console.warn(`[@nurvus/ui] Icon: there is no icon named "${name}". The names: ${ICON_NAMES.join(', ')}.`);
115
+ }
116
+ return nodes || [];
117
+ }
package/src/index.ts CHANGED
@@ -22,10 +22,22 @@ export { default as Progress } from './components/Progress/Progress';
22
22
  export type { ProgressProps, ProgressSize, ProgressStatus } from './components/Progress/Progress';
23
23
  export { default as Layout } from './components/Layout/Layout';
24
24
  export type { LayoutProps, Spacing, LegacySpacing } from './components/Layout/Layout';
25
+ export { default as Stack } from './components/Stack/Stack';
26
+ export type { StackProps, StackDirection } from './components/Stack/Stack';
27
+ export { default as Grid } from './components/Grid/Grid';
28
+ export type { GridProps, GridColumns } from './components/Grid/Grid';
29
+ export { BREAKPOINTS, isAtLeast } from './breakpoints';
30
+ export type { Breakpoint, Responsive } from './breakpoints';
31
+ export { default as Icon } from './components/Icon/Icon';
32
+ export type { IconProps } from './components/Icon/Icon';
33
+ export { ICONS, ICON_NAMES } from './icons';
34
+ export type { IconName, IconNode } from './icons';
35
+ export { default as Loader } from './components/Loader/Loader';
36
+ export type { LoaderProps } from './components/Loader/Loader';
25
37
  export { default as Tree } from './components/Tree/Tree';
26
38
  export type { TreeProps, TreeItem } from './components/Tree/Tree';
27
39
  export { default as Menu } from './components/Menu/Menu';
28
- export type { MenuProps, MenuItem, MenuSection } from './components/Menu/Menu';
40
+ export type { MenuProps, MenuListProps, MenuTreeProps, MenuItem, MenuSection, MenuKind } from './components/Menu/Menu';
29
41
  export { default as Select } from './components/Select/Select';
30
42
  export type { SelectProps, SelectOption, SelectOptionState } from './components/Select/Select';
31
43
  export { default as FullPageModal } from './components/FullPageModal/FullPageModal';
package/src/loader.ts ADDED
@@ -0,0 +1,43 @@
1
+ // Loader's drawing, shared by the React and the Respawn Loader (no React here).
2
+ import { LOGO_INNER, LOGO_OUTER, LogoSegment } from './logo';
3
+
4
+ export { LOGO_VIEWBOX } from './logo';
5
+
6
+ const hex = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
7
+ /** The middle of a segment's gradient: its one color when there are no gradients. */
8
+ const middle = (from: string, to: string) => `#${hex(from).map((v, i) => Math.round((v + hex(to)[i]) / 2).toString(16).padStart(2, '0')).join('')}`;
9
+
10
+ export interface LoaderSegment {
11
+ d: string;
12
+ /** "url(#<id>-<n>)" with gradients, else one color. */
13
+ fill: string;
14
+ /** Where it sits round the ring, 0 to 1 from the top, clockwise: the pulse reaches it then. */
15
+ angle: number;
16
+ }
17
+
18
+ export interface LoaderGradient {
19
+ id: string;
20
+ x1: number; y1: number; x2: number; y2: number;
21
+ from: string; to: string;
22
+ }
23
+
24
+ /**
25
+ * The two rings' segments. With an `id`, each segment is filled with its own
26
+ * gradient (ids "<id>-0", "<id>-1"…), as in the logo; without one, with its
27
+ * gradient's middle color, so a page can show any number of loaders with no
28
+ * ids at all. They look the same up to about 64 pixels.
29
+ */
30
+ export function loaderRings(id?: string): { inner: LoaderSegment[]; outer: LoaderSegment[]; gradients: LoaderGradient[] } {
31
+ const gradients: LoaderGradient[] = [];
32
+ let n = 0;
33
+ const seg = ([d, from, to, [x1, y1, x2, y2], angle]: LogoSegment): LoaderSegment => {
34
+ if (!id) return { d, fill: middle(from, to), angle };
35
+ const gid = `${id}-${n}`;
36
+ n += 1;
37
+ gradients.push({ id: gid, x1, y1, x2, y2, from, to });
38
+ return { d, fill: `url(#${gid})`, angle };
39
+ };
40
+ const inner = LOGO_INNER.map(seg);
41
+ const outer = LOGO_OUTER.map(seg);
42
+ return { inner, outer, gradients };
43
+ }
package/src/logo.ts ADDED
@@ -0,0 +1,12 @@
1
+ // GENERATED from docs/public/nurvus-logo.svg (via docs/src/components/logoData.js) by
2
+ // tools/build-logo.mjs. The NURVUS mark, for Loader: two rings of segments.
3
+ // Each segment: [path, gradient from, gradient to, [x1, y1, x2, y2] of the gradient, angle round the ring (0 at the top, 0..1 clockwise)].
4
+
5
+ export type LogoSegment = [d: string, from: string, to: string, line: [number, number, number, number], angle: number];
6
+
7
+ /** The artwork's viewBox around the mark alone. */
8
+ export const LOGO_VIEWBOX = '492 149 540 540';
9
+
10
+ export const LOGO_INNER: LogoSegment[] = [["M696 237 C670 244 639 264 620 298 C605 320 607 335 615 342 C632 336 647 329 661 309 C675 293 689 286 705 279 C696 266 693 251 696 237 Z","#141934","#244f70",[707,229,619,338],0.894],["M705 229 C718 222 734 218 746 221 C763 242 785 257 806 267 C776 271 750 285 727 274 C709 266 701 249 705 229 Z","#20174e","#344eaa",[744,221,760,277],0.981],["M787 232 C838 231 894 267 922 305 C932 318 928 328 915 340 C906 348 896 348 891 336 C874 293 845 257 787 232 Z","#453be8","#6284e7",[785,234,915,343],0.12],["M896 343 C901 347 907 347 912 344 C915 358 934 373 943 390 C957 439 942 490 905 532 C924 500 932 461 923 433 C913 409 899 391 896 371 Z","#6686e7","#4cbaf5",[907,344,928,529],0.239],["M725 557 C677 541 639 512 649 469 C653 447 642 434 627 435 C611 436 605 448 610 476 C619 521 665 550 723 562 Z","#30c3b6","#42e2c9",[612,444,708,560],0.658],["M655 575 C622 552 613 527 608 499 C605 482 596 473 585 477 C570 482 573 498 585 518 C601 546 627 563 655 575 Z","#64dfdf","#259cea",[584,479,651,575],0.657],["M680 580 C684 567 708 568 718 576 C731 587 720 599 704 597 C690 596 680 588 680 580 Z","#5ebee8","#4367e8",[697,571,707,597],0.557],["M807 547 C783 550 770 545 752 551 C733 557 727 570 736 581 C746 594 769 592 781 580 C789 571 798 557 807 547 Z","#50ded1","#26a6d8",[744,548,786,589],0.491],["M797 572 C839 550 852 527 860 497 C865 476 878 466 891 472 C912 481 905 505 889 525 C864 552 835 567 797 572 Z","#3c7de7","#20c9e8",[887,471,819,571],0.376],["M755 210 C758 194 785 193 795 206 C805 218 789 227 775 226 C761 225 753 219 755 210 Z","#d5f3f3","#c8b5eb",[761,202,792,225],0.009],["M932 334 C945 326 960 344 964 359 C969 378 951 385 940 370 C930 357 926 341 932 334 Z","#e5b5e9","#92b0f2",[937,336,959,378],0.195]];
11
+
12
+ export const LOGO_OUTER: LogoSegment[] = [["M557 294 C587 234 662 173 718 162 C734 163 744 182 736 198 C725 224 680 231 645 242 C609 253 581 278 568 292 C565 295 561 295 557 294 Z","#78e8de","#5471ee",[600,165,654,300],0.906],["M534 283 C547 307 583 305 609 289 L639 270 C613 302 604 343 601 383 C599 420 606 454 595 464 C577 476 545 443 533 418 C513 379 515 313 534 283 Z","#79e8df","#4664ee",[521,300,625,432],0.798],["M506 382 C509 421 529 452 551 469 C551 526 592 577 659 598 C697 610 699 639 669 655 C579 619 511 540 504 449 C502 420 503 399 506 382 Z","#59cbe9","#5141e9",[508,401,650,654],0.681],["M687 657 L697 646 C736 653 781 641 814 620 L733 625 C787 599 833 572 890 577 C902 578 902 594 894 605 C850 655 771 684 687 657 Z","#3333df","#12a9e7",[750,649,890,566],0.472],["M970 394 C1000 460 989 531 951 580 C937 598 922 610 913 610 C889 583 919 553 942 526 C972 490 983 444 970 394 Z","#82f6dc","#2296d9",[979,419,914,610],0.329],["M975 341 C970 333 988 322 996 327 C1000 329 1002 335 1005 344 C1024 397 1019 449 1000 499 C1012 442 1009 392 975 341 Z","#923ce9","#ed80df",[985,334,1013,493],0.22],["M744 167 C829 154 920 205 974 277 C987 295 979 315 966 322 C947 332 921 316 922 279 C880 207 807 176 744 167 Z","#fff9ef","#ee74b8",[755,167,958,308],0.105]];
package/src/menu.ts CHANGED
@@ -1,37 +1,107 @@
1
- // Menu rules shared by the React and the Respawn Menu (no React here): the
2
- // section ids, which sections start open, and the arrow keys.
1
+ // Menu rules shared by the React and the Respawn Menu (no React here): which
2
+ // kind of menu the props make, the section ids, which sections start open,
3
+ // and the keys.
4
+
5
+ /**
6
+ * What a Menu is, and so what screen readers hear:
7
+ * - 'nav': navigation. A <nav> landmark of links ("link", "current page");
8
+ * an item without an href is a button in it ("button").
9
+ * - 'actions': a menu of commands (the WAI-ARIA menu pattern): role="menu",
10
+ * each item a "menu item"; one Tab stop, the arrow keys move.
11
+ * - 'tree': a tree to pick from (the WAI-ARIA tree pattern), like layers:
12
+ * "tree", each row "level 2, 3 of 5, selected". Drawn by Tree.
13
+ */
14
+ export type MenuKind = 'nav' | 'actions' | 'tree';
15
+
16
+ interface KindProps {
17
+ kind?: MenuKind;
18
+ sections?: { href?: string; items?: { href?: string }[] }[];
19
+ items?: unknown;
20
+ activePath?: unknown;
21
+ }
22
+
23
+ /**
24
+ * The kind to draw: `kind` when given; else a tree for Tree's props (items,
25
+ * activePath), navigation when any item is a link, a menu of actions when
26
+ * none is.
27
+ */
28
+ export function menuKind(props: KindProps): MenuKind {
29
+ if (props.kind) return props.kind;
30
+ if (!props.sections && (props.items !== undefined || props.activePath !== undefined)) return 'tree';
31
+ const sections = props.sections || [];
32
+ const links = sections.some((s) => s.href !== undefined || (s.items || []).some((item) => item.href !== undefined));
33
+ return links || !sections.length ? 'nav' : 'actions';
34
+ }
3
35
 
4
36
  /** A section's id: its own, or its title as a slug ("Get started" -> "get-started"). */
5
- export const sectionId = (section: { id?: string; title: unknown }): string =>
6
- section.id || String(section.title).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
37
+ export const sectionId = (section: { id?: string; title?: unknown }): string =>
38
+ section.id || String(section.title ?? 'section').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
7
39
 
8
40
  /** Whether a section starts open: true / false for all, or a map of id -> open (missing = open). */
9
41
  export const startsOpen = (defaultOpen: boolean | Record<string, boolean> | undefined, id: string): boolean =>
10
42
  typeof defaultOpen === 'boolean' ? defaultOpen : !defaultOpen || defaultOpen[id] !== false;
11
43
 
12
- let warnedOldProps = false;
13
- /** Menu used to be the nested, selectable list that is Tree now: say so once. */
14
- export function warnOldMenuProps(props: { sections?: unknown; items?: unknown; activePath?: unknown }): boolean {
15
- const old = !props.sections && (props.items !== undefined || props.activePath !== undefined);
16
- if (old && !warnedOldProps && typeof console !== 'undefined') {
17
- warnedOldProps = true;
18
- console.warn('[@nurvus/ui] Menu is site navigation now (sections of links). The nested, selectable list it used to be is Tree: import { Tree } from \'@nurvus/ui\'. Drawing a Tree for now.');
19
- }
20
- return old;
44
+ /** Makes `row` the one item of an actions menu that Tab reaches (roving tabindex). */
45
+ export function roveTo(menu: HTMLElement, row: HTMLElement): void {
46
+ menu.querySelectorAll<HTMLElement>('[role="menuitem"]').forEach((item) => item.setAttribute('tabindex', item === row ? '0' : '-1'));
47
+ }
48
+
49
+ /** Focus moved onto an item of an actions menu (a click, say): it becomes the Tab stop. */
50
+ export function menuFocus(event: FocusEvent, menu: HTMLElement): void {
51
+ const row = (event.target as HTMLElement).closest<HTMLElement>('[role="menuitem"]');
52
+ if (row && menu.getAttribute('role') === 'menu') roveTo(menu, row);
21
53
  }
22
54
 
23
55
  /**
24
- * The arrow keys on a Menu (the WAI-ARIA disclosure navigation pattern's
25
- * optional keys). Tab still goes link by link; on top of that:
26
- * - Up / Down: the previous / next row (section titles and the links in open
27
- * sections), going round at the ends;
28
- * - Home / End: the first / last row;
29
- * - Right on a section: opens it, or (when open) goes to its first link;
30
- * - Left on a section: closes it; Left on a link: goes up to its section.
56
+ * The keys on a Menu. Up / Down move to the previous / next item (going round
57
+ * at the ends) and Home / End to the first / last, in every kind.
58
+ * - Navigation (the WAI-ARIA disclosure navigation pattern, with its
59
+ * optional keys): Tab still goes link by link. The rows are the section
60
+ * titles and the links in open sections; Right on a section opens it, or
61
+ * goes to its first link; Left closes it, or goes from a link up to its
62
+ * section. Enter follows a link; Enter or Space opens a section.
63
+ * - Actions (the WAI-ARIA menu pattern): one Tab stop that follows the
64
+ * focus; typing a letter goes to the next item starting with it; Enter or
65
+ * Space runs the item.
31
66
  * Returns true when it used the key.
32
67
  */
33
68
  export function menuKeydown(event: KeyboardEvent, nav: HTMLElement): boolean {
34
- if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return false;
69
+ if (event.altKey || event.ctrlKey || event.metaKey) return false;
70
+ return nav.getAttribute('role') === 'menu' ? actionsKeydown(event, nav) : navKeydown(event, nav);
71
+ }
72
+
73
+ function actionsKeydown(event: KeyboardEvent, menu: HTMLElement): boolean {
74
+ const rows = Array.from(menu.querySelectorAll<HTMLElement>('[role="menuitem"]'));
75
+ const target = (event.target as HTMLElement).closest<HTMLElement>('[role="menuitem"]');
76
+ if (!rows.length || !target) return false;
77
+ const at = rows.indexOf(target);
78
+ let next: HTMLElement | undefined;
79
+ switch (event.key) {
80
+ case 'ArrowDown': next = rows[(at + 1) % rows.length]; break;
81
+ case 'ArrowUp': next = rows[at <= 0 ? rows.length - 1 : at - 1]; break;
82
+ case 'Home': next = rows[0]; break;
83
+ case 'End': next = rows[rows.length - 1]; break;
84
+ default:
85
+ // Type to find: the next item whose text starts with the letter.
86
+ if (event.key.length === 1 && !event.shiftKey && /\S/.test(event.key)) {
87
+ const key = event.key.toLowerCase();
88
+ for (let i = 1; i <= rows.length; i += 1) {
89
+ const row = rows[(at + i) % rows.length];
90
+ if ((row.textContent || '').trim().toLowerCase().startsWith(key)) { next = row; break; }
91
+ }
92
+ if (!next) return false;
93
+ break;
94
+ }
95
+ return false;
96
+ }
97
+ event.preventDefault();
98
+ roveTo(menu, next);
99
+ next.focus();
100
+ return true;
101
+ }
102
+
103
+ function navKeydown(event: KeyboardEvent, nav: HTMLElement): boolean {
104
+ if (event.shiftKey) return false;
35
105
  const target = event.target as HTMLElement;
36
106
  const rows = Array.from(nav.querySelectorAll<HTMLElement>('.menu-title, .menu-item'))
37
107
  .filter((row) => !row.closest('.menu-section[data-open="false"] .menu-items'));
@@ -0,0 +1,21 @@
1
+ // Progress rules shared by the React and the Respawn Progress (no React here).
2
+ import type { IconName } from './icons';
3
+
4
+ export type ProgressStatus = 'active' | 'success' | 'warning' | 'critical';
5
+
6
+ /** What each status means, in words and as an icon, so it never rests on color alone (WCAG 1.4.1). */
7
+ export const PROGRESS_STATUS: Record<ProgressStatus, { word: string; icon?: IconName }> = {
8
+ active: { word: '' },
9
+ success: { word: 'Done', icon: 'check' },
10
+ warning: { word: 'Needs attention', icon: 'warning' },
11
+ critical: { word: 'Failed', icon: 'error' },
12
+ };
13
+
14
+ /** 0 to 100, whole numbers; anything else (NaN, -5, 140) is pulled into range. */
15
+ export const clampPercent = (percent: number): number => (Number.isFinite(percent) ? Math.round(Math.min(100, Math.max(0, percent))) : 0);
16
+
17
+ /** What screen readers say for the value: "40%", or "100%, Done". */
18
+ export const progressValueText = (percent: number, status: ProgressStatus): string => {
19
+ const word = (PROGRESS_STATUS[status] || PROGRESS_STATUS.active).word;
20
+ return word ? `${clampPercent(percent)}%, ${word}` : `${clampPercent(percent)}%`;
21
+ };