@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
@@ -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
  }
@@ -1,36 +1,80 @@
1
1
  import React from 'react';
2
2
  import classNames from 'classnames';
3
3
  import CONSTANT from '../../constants';
4
+ import Icon from '../Icon/Icon';
5
+ import { PROGRESS_STATUS, clampPercent, progressValueText, ProgressStatus } from '../../progress';
4
6
  import './Progress.scss';
5
7
 
6
8
  export type ProgressSize = 'small' | 'medium' | 'large';
7
- export type ProgressStatus = 'active' | 'success' | 'warning' | 'critical';
9
+ export type { ProgressStatus };
8
10
 
9
- export interface ProgressProps {
11
+ export interface ProgressProps extends React.HTMLAttributes<HTMLDivElement> {
10
12
  /** How far along, 0 to 100. */
11
13
  percent?: number;
12
14
  /** Bar height. */
13
15
  size?: ProgressSize;
14
- /** The bar color: active (accent), success, warning or critical (danger). */
16
+ /** 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. */
15
17
  status?: ProgressStatus;
18
+ /** What is in progress ("Uploading"): shown above the bar, and its name for screen readers. */
19
+ label?: string;
20
+ /** Keeps the label for screen readers only. */
21
+ hideLabel?: boolean;
22
+ /** Shows the percent (and the status, as an icon and a word) at the right, above the bar. */
23
+ showValue?: boolean;
24
+ /** What screen readers say for the value, instead of "40%" (e.g. "3 of 8 files"). */
25
+ valueText?: string;
16
26
  /** Custom class name. */
17
27
  className?: string;
18
28
  }
19
29
 
20
- /** A progress bar. Use it to track progress! */
30
+ /**
31
+ * A progress bar: how far along something is. Screen readers hear it as a
32
+ * progress bar with its label and value ("Uploading, progress bar, 40%").
33
+ * Its status is never color alone: with a label or showValue it shows as an
34
+ * icon and a word too, and screen readers hear the word.
35
+ */
21
36
  export default function Progress({
22
37
  className,
23
38
  percent = 0,
24
39
  size = 'medium',
25
- status = 'active'
40
+ status = 'active',
41
+ label,
42
+ hideLabel = false,
43
+ showValue = false,
44
+ valueText,
45
+ ...restProps
26
46
  }: ProgressProps) {
47
+ const value = clampPercent(percent);
48
+ const meaning = PROGRESS_STATUS[status] || PROGRESS_STATUS.active;
49
+ const head = (label && !hideLabel) || showValue;
27
50
  return (
28
51
  <div
29
52
  className={ classNames(className, 'progress', CONSTANT.CLASS_PREFIX) }
30
53
  data-size={ size }
31
54
  data-status={ status }
55
+ role="progressbar"
56
+ aria-label={ label || 'Progress' }
57
+ aria-valuemin={ 0 }
58
+ aria-valuemax={ 100 }
59
+ aria-valuenow={ value }
60
+ aria-valuetext={ valueText || progressValueText(value, status) }
61
+ { ...restProps }
32
62
  >
33
- <div className="bar" style={ { width: `${percent}%` } } />
63
+ { head && (
64
+ <div className="progress-head">
65
+ { label && !hideLabel && <span className="progress-label">{ label }</span> }
66
+ { showValue && (
67
+ <span className="progress-value">
68
+ { meaning.icon && <Icon name={ meaning.icon } /> }
69
+ { meaning.word && <span className="progress-word">{ meaning.word }</span> }
70
+ <span>{ `${value}%` }</span>
71
+ </span>
72
+ ) }
73
+ </div>
74
+ ) }
75
+ <div className="progress-track">
76
+ <div className="bar" style={ { width: `${value}%` } } />
77
+ </div>
34
78
  </div>
35
79
  );
36
80
  }
@@ -8,18 +8,18 @@ $select-speed: 0.12s;
8
8
  position: relative;
9
9
  display: inline-block;
10
10
  max-width: 100%;
11
- font-size: 14px;
12
- line-height: 20px;
11
+ font-size: 0.875rem;
12
+ line-height: 1.25rem;
13
13
 
14
14
  .select-trigger {
15
15
  display: inline-flex;
16
16
  align-items: center;
17
17
  gap: var(--space--8);
18
18
  max-width: 100%;
19
- min-height: 32px;
19
+ min-height: 2rem;
20
20
  padding: var(--space--4) var(--space--8) var(--space--4) var(--space--12);
21
21
  border: 1px solid var(--nv-border-strong);
22
- border-radius: 8px;
22
+ border-radius: 0.5rem;
23
23
  background: var(--nv-surface);
24
24
  color: var(--nv-text);
25
25
  cursor: pointer;
@@ -47,13 +47,13 @@ $select-speed: 0.12s;
47
47
  .select-chevron {
48
48
  display: inline-flex;
49
49
  flex: none;
50
- width: 16px;
50
+ width: 1rem;
51
51
  justify-content: center;
52
52
 
53
53
  &::after {
54
54
  content: '';
55
- width: 6px;
56
- height: 6px;
55
+ width: 0.375rem;
56
+ height: 0.375rem;
57
57
  border-right: 1.5px solid currentColor;
58
58
  border-bottom: 1.5px solid currentColor;
59
59
  transform: translateY(-2px) rotate(45deg);
@@ -69,17 +69,18 @@ $select-speed: 0.12s;
69
69
  top: calc(100% + var(--space--4));
70
70
  left: 0;
71
71
  min-width: 100%;
72
- max-height: 360px;
72
+ // Set --nurvus-select-list-height to make the list taller or shorter.
73
+ max-height: var(--nurvus-select-list-height, 22.5rem);
73
74
  overflow: auto;
74
75
  padding: var(--space--4);
75
76
  border: 1px solid var(--nv-border);
76
- border-radius: 10px;
77
+ border-radius: 0.625rem;
77
78
  background: var(--nv-surface);
78
79
  color: var(--nv-text);
79
80
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.24);
80
81
  opacity: 0;
81
82
  visibility: hidden;
82
- transform: translateY(-4px) scale(0.98);
83
+ transform: translateY(-0.25rem) scale(0.98);
83
84
  transform-origin: top left;
84
85
  transition: opacity $select-speed ease, transform $select-speed ease, visibility 0s $select-speed;
85
86
  }
@@ -103,8 +104,8 @@ $select-speed: 0.12s;
103
104
  .select-group-label {
104
105
  padding: var(--space--4) var(--space--8);
105
106
  color: var(--nv-text-muted);
106
- font-size: 12px;
107
- line-height: 16px;
107
+ font-size: 0.75rem;
108
+ line-height: 1rem;
108
109
  font-weight: 600;
109
110
  letter-spacing: 0.04em;
110
111
  text-transform: uppercase;
@@ -115,8 +116,8 @@ $select-speed: 0.12s;
115
116
  display: flex;
116
117
  align-items: center;
117
118
  gap: var(--space--8);
118
- padding: 6px 32px 6px var(--space--8); // room on the right for the check
119
- border-radius: 6px;
119
+ padding: 0.375rem 2rem 0.375rem var(--space--8); // room on the right for the check
120
+ border-radius: 0.375rem;
120
121
  cursor: pointer;
121
122
  white-space: nowrap;
122
123
 
@@ -136,9 +137,9 @@ $select-speed: 0.12s;
136
137
  content: '';
137
138
  position: absolute;
138
139
  top: 50%;
139
- right: 12px;
140
- width: 5px;
141
- height: 10px;
140
+ right: 0.75rem;
141
+ width: 0.3125rem;
142
+ height: 0.625rem;
142
143
  border-right: 2px solid var(--nv-accent);
143
144
  border-bottom: 2px solid var(--nv-accent);
144
145
  transform: translateY(-60%) rotate(45deg);
@@ -157,8 +158,8 @@ $select-speed: 0.12s;
157
158
 
158
159
  .select-option-description {
159
160
  color: var(--nv-text-muted);
160
- font-size: 12px;
161
- line-height: 16px;
161
+ font-size: 0.75rem;
162
+ line-height: 1rem;
162
163
  font-weight: 400;
163
164
  }
164
165
 
@@ -0,0 +1,43 @@
1
+ A column or a row with even space between the children, from the [4px grid](#/Foundations/Spacing). It spaces with CSS `gap`, so a row that wraps keeps its spacing on every line.
2
+
3
+ ```jsx
4
+ import { Button, Stack, Tag, Text } from '@nurvus/ui';
5
+
6
+ <Stack gap={ 12 }>
7
+ <Text weight="semibold">Release 2.4</Text>
8
+ <Stack direction="row" gap={ 8 } align="center">
9
+ <Tag tone="success">Ready</Tag>
10
+ <Text tone="muted">All checks passed</Text>
11
+ </Stack>
12
+ <Stack direction="row" gap={ 8 }>
13
+ <Button>Publish</Button>
14
+ <Button type="secondary">Preview</Button>
15
+ </Stack>
16
+ </Stack>
17
+ ```
18
+
19
+ The direction can change with the screen: `{ base: 'column', md: 'row' }` stacks on phones and sits in a row from the md breakpoint (48em, 768 pixels) up. Make the window narrower to see it.
20
+ ```jsx
21
+ import { Panel, Stack, Text } from '@nurvus/ui';
22
+
23
+ <Stack direction={ { base: 'column', md: 'row' } } gap={ 16 }>
24
+ <Panel title="Plan" style={ { flex: 1 } }><Text>Pro, billed yearly</Text></Panel>
25
+ <Panel title="Seats" style={ { flex: 1 } }><Text>12 of 20 used</Text></Panel>
26
+ <Panel title="Renews" style={ { flex: 1 } }><Text>March 3</Text></Panel>
27
+ </Stack>
28
+ ```
29
+
30
+ `justify="between"` pushes the ends apart; `wrap` lets a long row break onto more lines.
31
+ ```jsx
32
+ import { Button, Stack, Tag, Text } from '@nurvus/ui';
33
+
34
+ <Stack gap={ 16 }>
35
+ <Stack direction="row" justify="between" align="center">
36
+ <Text weight="semibold">Filters</Text>
37
+ <Button size="small" type="secondary">Clear</Button>
38
+ </Stack>
39
+ <Stack direction="row" gap={ 8 } wrap>
40
+ { ['React', 'Respawn', 'TypeScript', 'Themes', 'Icons', 'Accessibility', 'Spacing', 'Motion'].map((t) => <Tag key={ t }>{ t }</Tag>) }
41
+ </Stack>
42
+ </Stack>
43
+ ```