@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
@@ -1,8 +1,15 @@
1
- **Menu or Tree?** Menu takes people to pages: its rows are links (a `<nav>`), Tab visits each one, and the current page is marked. [Tree](#/Components/Tree) picks an item in a list on the same page, like layers in an editor: one Tab stop, the arrow keys move, and the picked row is selected. Screen readers announce them differently (links in a navigation area versus a tree you choose from), so they are two components with the same look.
1
+ **The items decide what it is**, and screen readers hear it that way:
2
2
 
3
- Sections open and close with the chevron (or the whole heading, when it isn't a link). The current page is marked with a bar beside it, and its section opens by itself.
3
+ | Items | It becomes | Screen readers say | Keys |
4
+ |---|---|---|---|
5
+ | Links (`href`) | Navigation: a `<nav>` landmark | "Pages, navigation… Billing, link, current page" | Tab goes link by link; ↑ ↓ Home End move too; → ← open and close sections |
6
+ | Actions (`onSelect`) | A menu of commands (`role="menu"`) | "Actions, menu… Duplicate, menu item" | One Tab stop; ↑ ↓ Home End move; type a letter to jump; Enter or Space runs it |
7
+ | Rows to pick, `kind="tree"` | A tree (the same as [Tree](#/Components/Tree)) | "Layers, tree… Header, level 1, 1 of 3, selected" | One Tab stop; ↑ ↓ move, → ← go in and out, Enter or Space picks |
8
+
9
+ Left out, `kind` follows the items: navigation when any item has an `href`, actions when none has. An item without an `href` inside navigation is a button there ("Sign out"). Links take Enter only, as everywhere on the web (Space scrolls the page); buttons, chevrons and tree rows take Enter and Space.
10
+
11
+ **Navigation.** Sections open and close with the chevron (or the whole heading, when it isn't a link). The current page is marked with a bar beside it, and its section opens by itself.
4
12
 
5
- By keyboard: Tab goes link by link as usual, and inside the menu ↑ ↓ move between rows (going round at the ends), Home and End jump to the first and last, → opens a section and ← closes it. Enter follows a link; Enter or Space opens and closes a section (its chevron is a button). Links take Enter only, as everywhere on the web: Space scrolls the page.
6
13
  ```jsx
7
14
  import { Menu } from '@nurvus/ui';
8
15
 
@@ -41,3 +48,60 @@ import { Menu } from '@nurvus/ui';
41
48
  />
42
49
  </div>
43
50
  ```
51
+
52
+ **Actions.** Items with `onSelect` and no `href`: a menu of commands. Tab reaches it once (the item you were last on), then ↑ ↓ move and typing a letter jumps to the next item that starts with it. A disabled item stays in the list, so people still find it, but does nothing.
53
+ ```jsx
54
+ import { Menu, Text } from '@nurvus/ui';
55
+
56
+ const Actions = () => {
57
+ const [done, setDone] = React.useState('Nothing yet');
58
+ const run = (what) => () => setDone(what);
59
+ return (
60
+ <div style={ { maxWidth: 260 } }>
61
+ <Menu
62
+ id="layer-actions"
63
+ label="Layer actions"
64
+ sections={ [
65
+ { title: 'Edit', items: [
66
+ { label: 'Duplicate', onSelect: run('Duplicated') },
67
+ { label: 'Rename', onSelect: run('Renamed') },
68
+ { label: 'Group', onSelect: run('Grouped'), disabled: true },
69
+ ] },
70
+ { title: 'Arrange', items: [
71
+ { label: 'Bring to front', onSelect: run('Brought to front') },
72
+ { label: 'Send to back', onSelect: run('Sent to back') },
73
+ { label: 'Delete', onSelect: run('Deleted'), divider: true },
74
+ ] },
75
+ ] }
76
+ />
77
+ <Text variant="caption" tone="muted">{ done }</Text>
78
+ </div>
79
+ );
80
+ };
81
+ <Actions />
82
+ ```
83
+
84
+ **A tree.** `kind="tree"` takes Tree's props: nested `items`, the `activePath` of the picked row, and `onClick(event, path)`.
85
+ ```jsx
86
+ import { Menu } from '@nurvus/ui';
87
+
88
+ const Layers = () => {
89
+ const [path, setPath] = React.useState([1, 0]);
90
+ return (
91
+ <div style={ { maxWidth: 260 } }>
92
+ <Menu
93
+ kind="tree"
94
+ label="Layers"
95
+ activePath={ path }
96
+ onClick={ (event, next) => setPath(next) }
97
+ items={ [
98
+ { label: 'Header' },
99
+ { label: 'Hero', items: [{ label: 'Title' }, { label: 'Image' }] },
100
+ { label: 'Footer' },
101
+ ] }
102
+ />
103
+ </div>
104
+ );
105
+ };
106
+ <Layers />
107
+ ```
@@ -1,12 +1,13 @@
1
1
  @import "../../styles/variables.scss";
2
2
 
3
- // Site navigation. Sections open and close by animating the list's row
4
- // (grid-template-rows 1fr <-> 0fr): smooth, no height measuring, any length.
3
+ // Menu: navigation (links; sections open and close by animating the list's
4
+ // row, grid-template-rows 1fr <-> 0fr: smooth, no height measuring) or a menu
5
+ // of actions (buttons, data-kind="actions").
5
6
  $menu-speed: 0.2s;
6
7
 
7
8
  .#{$cls-prefix}.menu {
8
- font-size: 14px;
9
- line-height: 20px;
9
+ font-size: 0.875rem;
10
+ line-height: 1.25rem;
10
11
 
11
12
  .menu-section + .menu-section { margin-top: var(--space--8); }
12
13
 
@@ -19,9 +20,9 @@ $menu-speed: 0.2s;
19
20
  .menu-title {
20
21
  flex: 1;
21
22
  min-width: 0;
22
- padding: var(--space--4) 10px;
23
+ padding: var(--space--4) 0.625rem;
23
24
  border: 0;
24
- border-radius: 6px;
25
+ border-radius: 0.375rem;
25
26
  background: none;
26
27
  color: var(--nv-text);
27
28
  font: inherit;
@@ -44,8 +45,8 @@ $menu-speed: 0.2s;
44
45
 
45
46
  &::after {
46
47
  content: '';
47
- width: 6px;
48
- height: 6px;
48
+ width: 0.375rem;
49
+ height: 0.375rem;
49
50
  margin: 0 var(--space--4);
50
51
  border-right: 1.5px solid currentColor;
51
52
  border-bottom: 1.5px solid currentColor;
@@ -57,11 +58,11 @@ $menu-speed: 0.2s;
57
58
  // The icon-only toggle beside a heading that is a link.
58
59
  .menu-toggle:not(.menu-title) {
59
60
  flex: none;
60
- width: 24px;
61
- height: 24px;
61
+ width: 1.5rem;
62
+ height: 1.5rem;
62
63
  padding: 0;
63
64
  border: 0;
64
- border-radius: 6px;
65
+ border-radius: 0.375rem;
65
66
  background: none;
66
67
  color: var(--nv-text-muted);
67
68
  cursor: pointer;
@@ -88,8 +89,8 @@ $menu-speed: 0.2s;
88
89
  min-height: 0;
89
90
  overflow: hidden;
90
91
  // Room on the left for the current-page bar, which sits outside the item.
91
- margin: 0 0 0 -12px;
92
- padding: 0 0 0 12px; // no vertical padding: it would stay when the row closes to 0
92
+ margin: 0 0 0 -0.75rem;
93
+ padding: 0 0 0 0.75rem; // no vertical padding: it would stay when the row closes to 0
93
94
  list-style: none;
94
95
  }
95
96
 
@@ -113,10 +114,22 @@ $menu-speed: 0.2s;
113
114
  .menu-item {
114
115
  position: relative;
115
116
  display: block;
116
- padding: var(--space--4) 10px var(--space--4) 20px;
117
- border-radius: 6px;
117
+ box-sizing: border-box;
118
+ width: 100%;
119
+ padding: var(--space--4) 0.625rem var(--space--4) 1.25rem;
120
+ border: 0;
121
+ border-radius: 0.375rem;
122
+ background: none;
118
123
  color: var(--nv-text-muted);
124
+ font: inherit;
125
+ text-align: left;
119
126
  text-decoration: none;
127
+ cursor: pointer;
128
+
129
+ &:disabled,
130
+ &[aria-disabled="true"] { color: var(--nv-text-subtle); cursor: not-allowed; }
131
+ &:disabled:hover,
132
+ &[aria-disabled="true"]:hover { background: none; color: var(--nv-text-subtle); }
120
133
 
121
134
  &:hover { background: var(--nv-surface-hover); color: var(--nv-text); }
122
135
  &:focus-visible { outline: 2px solid var(--nv-accent); outline-offset: -2px; }
@@ -133,15 +146,32 @@ $menu-speed: 0.2s;
133
146
  content: '';
134
147
  position: absolute;
135
148
  top: 50%;
136
- left: -8px;
137
- width: 4px;
138
- height: 18px;
149
+ left: -0.5rem;
150
+ width: 0.25rem;
151
+ height: 1.125rem;
139
152
  border-radius: 2px;
140
153
  background: var(--nv-accent);
141
154
  transform: translateY(-50%);
142
155
  }
143
156
  }
144
157
 
158
+ // Actions: always open; section titles are labels, not buttons; items in the text color.
159
+ &[data-kind="actions"] {
160
+ .menu-title {
161
+ cursor: default;
162
+ color: var(--nv-text-muted);
163
+ font-size: 0.75rem;
164
+ line-height: 1rem;
165
+ letter-spacing: 0.04em;
166
+ text-transform: uppercase;
167
+
168
+ &:hover { background: none; }
169
+ }
170
+
171
+ .menu-item { padding-left: 0.625rem; color: var(--nv-text); }
172
+ li:last-child { margin-bottom: 0; }
173
+ }
174
+
145
175
  @media (prefers-reduced-motion: reduce) {
146
176
  .menu-items,
147
177
  .menu-toggle::after,
@@ -1,15 +1,21 @@
1
1
  import React from 'react';
2
2
  import classNames from 'classnames';
3
3
  import CONSTANT from '../../constants';
4
- import { sectionId, startsOpen, menuKeydown, warnOldMenuProps } from '../../menu';
5
- import Tree from '../Tree/Tree';
4
+ import { sectionId, startsOpen, menuKeydown, menuFocus, menuKind, MenuKind } from '../../menu';
5
+ import Tree, { TreeProps, TreeItem } from '../Tree/Tree';
6
6
  import './Menu.scss';
7
7
 
8
+ export type { MenuKind };
9
+
8
10
  export interface MenuItem {
9
- /** What the link says. */
11
+ /** What the item says. */
10
12
  label: React.ReactNode;
11
- /** Where it goes. The item whose href equals `current` is marked as the current page. */
12
- href: string;
13
+ /** Makes the item a link to this address. The item whose href equals `current` is marked as the current page. */
14
+ href?: string;
15
+ /** Makes the item a button that calls this (an action: "Duplicate", "Sign out"). */
16
+ onSelect?: (event: React.MouseEvent<HTMLElement>) => void;
17
+ /** Shows the item but stops it working (actions only). */
18
+ disabled?: boolean;
13
19
  /** Draws a hairline above this item, to split a section into groups. */
14
20
  divider?: boolean;
15
21
  }
@@ -17,48 +23,80 @@ export interface MenuItem {
17
23
  export interface MenuSection {
18
24
  /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
19
25
  id?: string;
20
- /** The section heading. */
21
- title: React.ReactNode;
26
+ /** The section heading. Optional for actions. */
27
+ title?: React.ReactNode;
22
28
  /** Makes the heading a link too (e.g. to the section's overview page). */
23
29
  href?: string;
24
- /** The section's links. */
30
+ /** The section's items. */
25
31
  items: MenuItem[];
26
32
  }
27
33
 
28
- export interface MenuProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onToggle'> {
29
- /** The sections, in order. */
30
- sections: MenuSection[];
31
- /** The href of the page being shown: its link is marked, and its section opens. */
34
+ export interface MenuProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onToggle' | 'onClick'> {
35
+ /**
36
+ * What the menu is, which decides what screen readers hear and which keys
37
+ * work: 'nav' (links: a navigation landmark), 'actions' (commands: a menu
38
+ * of buttons) or 'tree' (rows to pick from, with Tree's props). Left out,
39
+ * it follows the props: navigation if any item has an href, actions if none
40
+ * has, a tree for `items`.
41
+ */
42
+ kind?: MenuKind;
43
+ /** Navigation and actions: the sections, in order. */
44
+ sections?: MenuSection[];
45
+ /** Navigation: the href of the page being shown. Its link is marked, and its section opens. */
32
46
  current?: string;
33
- /** Which sections start open: true (all), false (none) or a map of section id → open. Defaults to all. */
47
+ /** Navigation: which sections start open: true (all), false (none) or a map of section id → open. Defaults to all. */
34
48
  defaultOpen?: boolean | Record<string, boolean>;
35
- /** Called when a section opens or closes (e.g. to remember it). */
49
+ /** Navigation: called when a section opens or closes (e.g. to remember it). */
36
50
  onToggle?: (id: string, open: boolean) => void;
37
- /** Called when any link is clicked, with its href (e.g. to close a drawer). */
51
+ /** Navigation: called when any link is clicked, with its href (e.g. to close a drawer). */
38
52
  onNavigate?: (href: string, event: React.MouseEvent<HTMLAnchorElement>) => void;
39
- /** Accessible name of the navigation landmark. */
53
+ /** Tree: the rows, each with optional child `items`. */
54
+ items?: TreeItem[];
55
+ /** Tree: the picked row as a path of indexes, e.g. [2, 0] = the first child of the third row. */
56
+ activePath?: number[];
57
+ /** Tree: called when a row is picked (a click, Enter or Space), with the event and the row's path. */
58
+ onClick?: (event: React.MouseEvent<HTMLDivElement>, path: number[]) => void;
59
+ /** Tree: draws a row's content instead of its label. */
60
+ itemRenderer?: (item: TreeItem) => React.ReactNode;
61
+ /** Tree: the deepest level that still indents. */
62
+ maxIndentDepth?: number;
63
+ /** What screen readers call the menu ("Pages", "Actions", "Layers"). */
40
64
  label?: string;
41
- /** Prefix for the ids that link each toggle to its list. Defaults to "menu". */
65
+ /** Prefix for the ids inside (each toggle names its list). Defaults to "menu". */
42
66
  id?: string;
43
67
  /** Custom class name. */
44
68
  className?: string;
45
69
  }
46
70
 
71
+ /** Menu's props for navigation and actions. */
72
+ export type MenuListProps = Omit<MenuProps, 'items' | 'activePath' | 'onClick' | 'itemRenderer' | 'maxIndentDepth'>;
73
+ /** Menu kind="tree": Tree's props (Tree is the same thing under its own name). */
74
+ export type MenuTreeProps = TreeProps & { kind: 'tree' };
75
+
47
76
  /**
48
- * Site navigation: sections of links that open and close (an accordion, with
49
- * a smooth animation), and the current page marked by a bar beside it.
50
- * A section opens by itself when the current page is in it.
77
+ * One component for lists of things to go to, do or pick. The items decide
78
+ * what it is, and screen readers hear it that way:
79
+ * - links: site navigation (sections that open and close, the current page
80
+ * marked), and Tab goes link by link;
81
+ * - actions: a menu of commands, one Tab stop, the arrow keys move;
82
+ * - kind="tree": a tree to pick a row from, like layers (see Tree).
83
+ * Up and Down move between items in all three.
51
84
  */
52
- export default function Menu({ defaultOpen = true, label = 'Pages', ...props }: MenuProps) {
53
- // The props Menu took before it was navigation (Tree's) still draw a Tree, with a warning.
54
- if (warnOldMenuProps(props)) return <Tree { ...(props as any) } />;
55
- return <MenuNav defaultOpen={ defaultOpen } label={ label } { ...props } />;
85
+ export default function Menu(props: MenuProps) {
86
+ const kind = menuKind(props);
87
+ if (kind === 'tree') {
88
+ const { kind: _kind, sections: _s, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, ...tree } = props;
89
+ return <Tree { ...(tree as TreeProps) } />;
90
+ }
91
+ const { label = kind === 'actions' ? 'Actions' : 'Pages', items: _i, activePath: _a, onClick: _o, itemRenderer: _r, maxIndentDepth: _m, ...rest } = props;
92
+ return kind === 'actions' ? <MenuActions label={ label } { ...rest } /> : <MenuNav label={ label } { ...rest } />;
56
93
  }
57
94
 
58
95
  function MenuNav({
96
+ kind: _kind,
59
97
  sections = [],
60
98
  current,
61
- defaultOpen,
99
+ defaultOpen = true,
62
100
  onToggle,
63
101
  onNavigate,
64
102
  label,
@@ -66,16 +104,16 @@ function MenuNav({
66
104
  className,
67
105
  onKeyDown,
68
106
  ...restProps
69
- }: MenuProps) {
107
+ }: MenuListProps) {
70
108
  // The current page's section starts open, whatever defaultOpen says.
71
109
  const [open, setOpen] = React.useState<Record<string, boolean>>(() => {
72
- const home = sections.find((s) => s.items.some((item) => item.href === current));
110
+ const home = sections.find((s) => s.items.some((item) => item.href !== undefined && item.href === current));
73
111
  return Object.fromEntries(sections.map((s) => [sectionId(s), s === home || startsOpen(defaultOpen, sectionId(s))]));
74
112
  });
75
113
 
76
114
  // Navigating into a closed section opens it, so the current page is always visible.
77
115
  React.useEffect(() => {
78
- const home = sections.find((s) => s.items.some((item) => item.href === current));
116
+ const home = sections.find((s) => s.items.some((item) => item.href !== undefined && item.href === current));
79
117
  if (home && open[sectionId(home)] === false) setOpen((was) => ({ ...was, [sectionId(home)]: true }));
80
118
  }, [current]); // eslint-disable-line react-hooks/exhaustive-deps
81
119
 
@@ -89,6 +127,7 @@ function MenuNav({
89
127
  return (
90
128
  <nav className={ classNames(className, 'menu', CONSTANT.CLASS_PREFIX) }
91
129
  aria-label={ label }
130
+ data-kind="nav"
92
131
  { ...restProps }
93
132
  onKeyDown={ (e) => { menuKeydown(e.nativeEvent, e.currentTarget); if (onKeyDown) onKeyDown(e); } }
94
133
  >
@@ -118,17 +157,23 @@ function MenuNav({
118
157
  </div>
119
158
  <div className="menu-items" id={ listId }>
120
159
  <ul>
121
- { section.items.map((item) => (
122
- <li key={ item.href } data-divider={ item.divider || undefined }>
123
- <a
124
- className="menu-item"
125
- href={ item.href }
126
- data-active={ current === item.href }
127
- aria-current={ current === item.href ? 'page' : undefined }
128
- onClick={ navigate(item.href) }
129
- >
130
- { item.label }
131
- </a>
160
+ { section.items.map((item, i) => (
161
+ <li key={ item.href || i } data-divider={ item.divider || undefined }>
162
+ { item.href !== undefined ? (
163
+ <a
164
+ className="menu-item"
165
+ href={ item.href }
166
+ data-active={ current === item.href }
167
+ aria-current={ current === item.href ? 'page' : undefined }
168
+ onClick={ navigate(item.href) }
169
+ >
170
+ { item.label }
171
+ </a>
172
+ ) : (
173
+ <button type="button" className="menu-item" disabled={ item.disabled } onClick={ item.onSelect }>
174
+ { item.label }
175
+ </button>
176
+ ) }
132
177
  </li>
133
178
  )) }
134
179
  </ul>
@@ -139,3 +184,65 @@ function MenuNav({
139
184
  </nav>
140
185
  );
141
186
  }
187
+
188
+ function MenuActions({
189
+ kind: _kind,
190
+ sections = [],
191
+ label,
192
+ id = 'menu',
193
+ className,
194
+ onKeyDown,
195
+ onFocus,
196
+ current: _current,
197
+ defaultOpen: _defaultOpen,
198
+ onToggle: _onToggle,
199
+ onNavigate: _onNavigate,
200
+ ...restProps
201
+ }: MenuListProps) {
202
+ let first = true;
203
+ return (
204
+ <div
205
+ className={ classNames(className, 'menu', CONSTANT.CLASS_PREFIX) }
206
+ role="menu"
207
+ aria-label={ label }
208
+ data-kind="actions"
209
+ { ...restProps }
210
+ onKeyDown={ (e) => { menuKeydown(e.nativeEvent, e.currentTarget); if (onKeyDown) onKeyDown(e); } }
211
+ onFocus={ (e) => { menuFocus(e.nativeEvent, e.currentTarget); if (onFocus) onFocus(e); } }
212
+ >
213
+ { sections.map((section, s) => {
214
+ const sid = sectionId({ id: section.id, title: section.title ?? `section-${s + 1}` });
215
+ const titleId = `${id}-${sid}-title`;
216
+ return (
217
+ <div key={ sid } className="menu-section" data-section={ sid } role="group" aria-labelledby={ section.title ? titleId : undefined }>
218
+ { section.title && (
219
+ <div className="menu-heading"><span className="menu-title" id={ titleId }>{ section.title }</span></div>
220
+ ) }
221
+ <div className="menu-items">
222
+ <ul role="none">
223
+ { section.items.map((item, i) => {
224
+ const tabIndex = first ? 0 : -1;
225
+ first = false;
226
+ return (
227
+ <li key={ i } role="none" data-divider={ item.divider || undefined }>
228
+ <button
229
+ type="button"
230
+ role="menuitem"
231
+ className="menu-item"
232
+ tabIndex={ tabIndex }
233
+ aria-disabled={ item.disabled || undefined }
234
+ onClick={ (event) => { if (!item.disabled && item.onSelect) item.onSelect(event); } }
235
+ >
236
+ { item.label }
237
+ </button>
238
+ </li>
239
+ );
240
+ }) }
241
+ </ul>
242
+ </div>
243
+ </div>
244
+ );
245
+ }) }
246
+ </div>
247
+ );
248
+ }
@@ -1,32 +1,33 @@
1
- Basic Example
1
+ Shows how far along something is. Give it a `label` (what is in progress) and, where the number helps, `showValue`. Screen readers hear "Uploading, progress bar, 40%" and hear it change.
2
+
2
3
  ```jsx
3
- import Layout from '../Layout/Layout.jsx';
4
+ import { Layout, Progress } from '@nurvus/ui';
4
5
 
5
- <Layout itemSpacing={ 32 }>
6
- <Layout itemSpacing={ 12 } style={ { maxWidth: 90 } }>
7
- <Progress size="small" />
8
- <Progress size="small" percent={ 50 } />
9
- <Progress size="small" percent={ 100 } />
10
- </Layout>
11
- <Layout itemSpacing={ 12 } style={ { maxWidth: 105 } }>
12
- <Progress size="medium" />
13
- <Progress size="medium" percent={ 50 } />
14
- <Progress size="medium" percent={ 100 } />
15
- </Layout>
16
- <Layout itemSpacing={ 12 } style={ { maxWidth: 226 } }>
17
- <Progress size="large" />
18
- <Progress size="large" percent={ 50 } />
19
- <Progress size="large" percent={ 100 } />
20
- </Layout>
6
+ <Layout itemSpacing={ 24 } style={ { maxWidth: 360 } }>
7
+ <Progress label="Uploading photos" percent={ 40 } showValue />
8
+ <Progress label="Storage used" percent={ 72 } size="large" showValue />
9
+ <Progress label="Step 2 of 5" percent={ 40 } size="small" />
21
10
  </Layout>
22
11
  ```
23
12
 
24
- Status Example
13
+ The status colors the bar, and with `showValue` it is also an icon and a word (Done, Needs attention, Failed), so it never rests on color alone. Screen readers hear the word: "100%, Done".
25
14
  ```jsx
26
- import Layout from '../Layout/Layout.jsx';
27
- <Layout itemSpacing={ 12 } style={ { maxWidth: 90 } }>
28
- <Progress status="critical" percent={ 10 } />
29
- <Progress status="warning" percent={ 50 } />
30
- <Progress status="success" percent={ 100 } />
31
- </Layout>
32
- ```
15
+ import { Layout, Progress } from '@nurvus/ui';
16
+
17
+ <Layout itemSpacing={ 24 } style={ { maxWidth: 360 } }>
18
+ <Progress label="Backup" status="success" percent={ 100 } showValue />
19
+ <Progress label="Disk space" status="warning" percent={ 88 } showValue />
20
+ <Progress label="Import" status="critical" percent={ 35 } showValue />
21
+ </Layout>
22
+ ```
23
+
24
+ Sizes. Where the words around the bar already say what it is, `hideLabel` keeps the label for screen readers only.
25
+ ```jsx
26
+ import { Layout, Progress } from '@nurvus/ui';
27
+
28
+ <Layout itemSpacing={ 16 } style={ { maxWidth: 240 } }>
29
+ <Progress size="small" percent={ 50 } label="Small" hideLabel />
30
+ <Progress size="medium" percent={ 50 } label="Medium" hideLabel />
31
+ <Progress size="large" percent={ 50 } label="Large" hideLabel />
32
+ </Layout>
33
+ ```
@@ -1,54 +1,59 @@
1
- // Styles for Progress.jsx
1
+ // Styles for Progress.tsx (and the Respawn Progress: same markup).
2
2
  @import "../../styles/variables.scss";
3
3
  @import "../../styles/tokens.scss";
4
4
 
5
5
  .#{$cls-prefix}.progress {
6
- background: var(--nv-surface);
6
+ color: var(--nv-text);
7
7
 
8
- &,
9
- > .bar {
10
- border-radius: 12px;
8
+ .progress-head {
9
+ display: flex;
10
+ align-items: baseline;
11
+ justify-content: space-between;
12
+ gap: var(--space--8);
13
+ margin-bottom: var(--space--4);
14
+ font-size: var(--nv-type-caption-size);
15
+ line-height: var(--nv-type-caption-line);
11
16
  }
12
17
 
13
- > .bar {
14
- height: 100%;
15
- }
16
-
17
- // Size
18
- &[data-size="small"] {
19
- height: 4px;
20
- }
18
+ .progress-label { font-weight: 500; }
21
19
 
22
- &[data-size="medium"] {
23
- height: 6px;
20
+ .progress-value {
21
+ display: inline-flex;
22
+ align-items: center;
23
+ gap: var(--space--4);
24
+ margin-left: auto;
25
+ color: var(--nv-text-muted);
26
+ font-variant-numeric: tabular-nums;
24
27
  }
25
28
 
26
- &[data-size="large"] {
27
- height: 8px;
29
+ .progress-track {
30
+ background: var(--nv-surface);
31
+ // A hairline edge, so the empty track shows on any background (WCAG 1.4.11).
32
+ box-shadow: inset 0 0 0 1px var(--nv-border);
28
33
  }
29
34
 
30
- // Status
31
- &[data-status="active"] {
32
- > .bar {
33
- background-color: var(--nv-accent-fill);
34
- }
35
+ .progress-track,
36
+ .bar {
37
+ border-radius: 0.75rem;
35
38
  }
36
39
 
37
- &[data-status="success"] {
38
- > .bar {
39
- background-color: var(--nv-success);
40
- }
40
+ .bar {
41
+ height: 100%;
42
+ transition: width 0.3s ease;
41
43
  }
42
44
 
43
- &[data-status="warning"] {
44
- > .bar {
45
- background-color: var(--nv-warning);
46
- }
47
- }
45
+ // Size
46
+ &[data-size="small"] .progress-track { height: 0.25rem; }
47
+ &[data-size="medium"] .progress-track { height: 0.375rem; }
48
+ &[data-size="large"] .progress-track { height: 0.5rem; }
49
+
50
+ // Status: the bar's color, and the icon and word beside the value.
51
+ &[data-status="active"] .bar { background-color: var(--nv-accent-fill); }
52
+ &[data-status="success"] { .bar { background-color: var(--nv-success); } .progress-value { color: var(--nv-success); } }
53
+ &[data-status="warning"] { .bar { background-color: var(--nv-warning); } .progress-value { color: var(--nv-warning); } }
54
+ &[data-status="critical"] { .bar { background-color: var(--nv-danger); } .progress-value { color: var(--nv-danger); } }
55
+ }
48
56
 
49
- &[data-status="critical"] {
50
- > .bar {
51
- background-color: var(--nv-danger);
52
- }
53
- }
57
+ @media (prefers-reduced-motion: reduce) {
58
+ .#{$cls-prefix}.progress .bar { transition: none; }
54
59
  }