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

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 (87) hide show
  1. package/README.md +17 -1
  2. package/dist/icons.svg +74 -0
  3. package/dist/index.js +1 -1
  4. package/dist/nurvus.css +15 -10
  5. package/dist/respawn.js +1 -1
  6. package/dist/types/anchor.d.ts +37 -0
  7. package/dist/types/breakpoints.d.ts +14 -0
  8. package/dist/types/components/Anchor/Anchor.d.ts +30 -0
  9. package/dist/types/components/Dropdown/Dropdown.d.ts +31 -0
  10. package/dist/types/components/FullPageModal/FullPageModal.d.ts +11 -2
  11. package/dist/types/components/Grid/Grid.d.ts +26 -0
  12. package/dist/types/components/Loader/Loader.d.ts +21 -0
  13. package/dist/types/components/Menu/Menu.d.ts +61 -19
  14. package/dist/types/components/Progress/Progress.d.ts +19 -5
  15. package/dist/types/components/Stack/Stack.d.ts +26 -0
  16. package/dist/types/dialog.d.ts +12 -0
  17. package/dist/types/dropdown.d.ts +9 -0
  18. package/dist/types/icons.d.ts +29 -0
  19. package/dist/types/index.d.ts +13 -1
  20. package/dist/types/loader.d.ts +28 -0
  21. package/dist/types/logo.d.ts +5 -0
  22. package/dist/types/menu.d.ts +43 -14
  23. package/dist/types/progress.d.ts +11 -0
  24. package/dist/types/respawn/Anchor.d.ts +28 -0
  25. package/dist/types/respawn/Dropdown.d.ts +27 -0
  26. package/dist/types/respawn/FullPageModal.d.ts +7 -1
  27. package/dist/types/respawn/Grid.d.ts +21 -0
  28. package/dist/types/respawn/Loader.d.ts +18 -0
  29. package/dist/types/respawn/Menu.d.ts +47 -15
  30. package/dist/types/respawn/Progress.d.ts +18 -6
  31. package/dist/types/respawn/Stack.d.ts +21 -0
  32. package/dist/types/respawn/index.d.ts +13 -1
  33. package/package.json +1 -3
  34. package/src/anchor.ts +127 -0
  35. package/src/breakpoints.ts +28 -0
  36. package/src/components/Anchor/Anchor.md +59 -0
  37. package/src/components/Anchor/Anchor.scss +65 -0
  38. package/src/components/Anchor/Anchor.tsx +105 -0
  39. package/src/components/Button/Button.scss +20 -20
  40. package/src/components/Dropdown/Dropdown.md +48 -0
  41. package/src/components/Dropdown/Dropdown.scss +67 -0
  42. package/src/components/Dropdown/Dropdown.tsx +110 -0
  43. package/src/components/FullPageModal/FullPageModal.md +20 -17
  44. package/src/components/FullPageModal/FullPageModal.scss +5 -0
  45. package/src/components/FullPageModal/FullPageModal.tsx +37 -3
  46. package/src/components/Grid/Grid.md +37 -0
  47. package/src/components/Grid/Grid.scss +37 -0
  48. package/src/components/Grid/Grid.tsx +54 -0
  49. package/src/components/HistoryList/HistoryList.scss +2 -2
  50. package/src/components/Loader/Loader.md +30 -0
  51. package/src/components/Loader/Loader.scss +42 -0
  52. package/src/components/Loader/Loader.tsx +68 -0
  53. package/src/components/Menu/Menu.md +67 -3
  54. package/src/components/Menu/Menu.scss +126 -18
  55. package/src/components/Menu/Menu.tsx +159 -40
  56. package/src/components/Progress/Progress.md +27 -26
  57. package/src/components/Progress/Progress.scss +41 -36
  58. package/src/components/Progress/Progress.tsx +50 -6
  59. package/src/components/Select/Select.scss +20 -19
  60. package/src/components/Stack/Stack.md +43 -0
  61. package/src/components/Stack/Stack.scss +36 -0
  62. package/src/components/Stack/Stack.tsx +52 -0
  63. package/src/components/Table/Table.scss +1 -1
  64. package/src/components/Tag/Tag.scss +2 -2
  65. package/src/components/Title/Title.scss +6 -6
  66. package/src/components/Tree/Tree.md +1 -1
  67. package/src/css.ts +5 -0
  68. package/src/dialog.ts +47 -0
  69. package/src/dropdown.ts +24 -0
  70. package/src/icons.ts +31 -0
  71. package/src/index.ts +13 -1
  72. package/src/loader.ts +43 -0
  73. package/src/logo.ts +12 -0
  74. package/src/menu.ts +91 -21
  75. package/src/progress.ts +21 -0
  76. package/src/respawn/Anchor.ts +126 -0
  77. package/src/respawn/Dropdown.ts +90 -0
  78. package/src/respawn/FullPageModal.ts +30 -3
  79. package/src/respawn/Grid.ts +41 -0
  80. package/src/respawn/Loader.ts +77 -0
  81. package/src/respawn/Menu.ts +144 -37
  82. package/src/respawn/Progress.ts +56 -13
  83. package/src/respawn/Stack.ts +37 -0
  84. package/src/respawn/index.ts +13 -1
  85. package/src/styles/breakpoints.scss +3 -0
  86. package/src/styles/theme.scss +55 -55
  87. package/src/styles/type.json +9 -9
@@ -0,0 +1,41 @@
1
+ import classNames from 'classnames';
2
+ import CONSTANT from '../constants';
3
+ import { Spacing } from '../spacing';
4
+ import { Responsive, responsiveData } from '../breakpoints';
5
+ import { spawn, Child, ElementProps, Style } from './spawn';
6
+ import { updatable, NurvusElement } from './update';
7
+ import '../components/Grid/Grid.scss';
8
+
9
+ export type GridColumns = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
10
+
11
+ export interface GridProps extends ElementProps {
12
+ /** How many equal columns: 1 to 12. Can change with the width: { base: 1, md: 2, lg: 3 }. */
13
+ columns?: Responsive<GridColumns>;
14
+ /** Instead of a count: as many columns as fit, each at least this wide (e.g. "15rem" or 240). They fill the row. */
15
+ minItemWidth?: string | number;
16
+ /** Space between cells, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
17
+ gap?: Spacing;
18
+ /** Space between rows when it differs from gap. */
19
+ rowGap?: Spacing;
20
+ /** How cells line up in their row. Defaults to stretch (equal heights). */
21
+ align?: 'start' | 'center' | 'end' | 'stretch';
22
+ /** What to lay out. */
23
+ children?: Child;
24
+ }
25
+
26
+ /** Columns: a count that changes at the breakpoints, or as many as fit. The same markup as the React Grid. */
27
+ export default function Grid(props: GridProps = {}): NurvusElement<HTMLDivElement, GridProps> {
28
+ return updatable(({ columns, minItemWidth, gap = 16, rowGap, align, className, style, ...rest }: GridProps) => {
29
+ const fit = minItemWidth !== undefined;
30
+ const min = typeof minItemWidth === 'number' ? `${minItemWidth}px` : minItemWidth;
31
+ return spawn<HTMLDivElement>({
32
+ className: classNames(className, 'grid', CONSTANT.CLASS_PREFIX),
33
+ ...(fit ? { 'data-fit': true } : responsiveData('columns', columns === undefined ? 1 : columns)),
34
+ 'data-gap': gap,
35
+ 'data-row-gap': rowGap,
36
+ 'data-align': align,
37
+ style: fit ? { '--nurvus-grid-min': min, ...(typeof style === 'object' ? style : {}) } as Style : style,
38
+ ...rest,
39
+ });
40
+ }, props);
41
+ }
@@ -0,0 +1,77 @@
1
+ import classNames from 'classnames';
2
+ import CONSTANT from '../constants';
3
+ import { loaderRings, LOGO_VIEWBOX, LoaderSegment } from '../loader';
4
+ import { spawn, ElementProps } from './spawn';
5
+ import { updatable, NurvusElement } from './update';
6
+ import '../components/Loader/Loader.scss';
7
+
8
+ const SVG = 'http://www.w3.org/2000/svg';
9
+
10
+ export interface LoaderProps extends ElementProps {
11
+ /** Width and height of the mark. Defaults to 2em (twice the text size). A number is pixels. */
12
+ size?: number | string;
13
+ /** What is loading, for screen readers ("Loading photos"). Defaults to "Loading". */
14
+ label?: string;
15
+ /** Shows the label beside the mark, not only to screen readers. */
16
+ showLabel?: boolean;
17
+ /** Fills the segments with the logo's gradients (for big loaders); their ids start with this. Without it, one color each. */
18
+ id?: string;
19
+ }
20
+
21
+ /**
22
+ * Shows that something is loading: the NURVUS mark with a light running round
23
+ * it, the same markup as the React Loader. Screen readers hear the label once
24
+ * (role="status"). Remove it when the thing has loaded.
25
+ */
26
+ export default function Loader(props: LoaderProps = {}): NurvusElement<HTMLDivElement, LoaderProps> {
27
+ return updatable(({ size = '2em', label = 'Loading', showLabel = false, id, className, ...rest }: LoaderProps) => {
28
+ const { inner, outer, gradients } = loaderRings(id);
29
+ const ring = (cls: string, segments: LoaderSegment[]) => spawn<any>({
30
+ tag: 'g',
31
+ namespace: SVG,
32
+ className: `loader-ring ${cls}`,
33
+ children: segments.map((s) => spawn<any>({
34
+ tag: 'path', namespace: SVG, className: 'loader-seg', d: s.d, fill: s.fill, style: { '--nurvus-loader-at': String(s.angle) },
35
+ })),
36
+ });
37
+ return spawn<HTMLDivElement>({
38
+ className: classNames(className, 'loader', CONSTANT.CLASS_PREFIX),
39
+ role: 'status',
40
+ 'data-label': showLabel ? 'shown' : 'hidden',
41
+ id,
42
+ ...rest,
43
+ children: [
44
+ spawn<any>({
45
+ tag: 'svg',
46
+ namespace: SVG,
47
+ className: 'loader-mark',
48
+ viewBox: LOGO_VIEWBOX,
49
+ width: size,
50
+ height: size,
51
+ 'aria-hidden': true,
52
+ focusable: 'false',
53
+ children: [
54
+ gradients.length ? spawn<any>({
55
+ tag: 'defs',
56
+ namespace: SVG,
57
+ children: gradients.map((g) => spawn<any>({
58
+ tag: 'linearGradient',
59
+ namespace: SVG,
60
+ id: g.id,
61
+ gradientUnits: 'userSpaceOnUse',
62
+ x1: g.x1, y1: g.y1, x2: g.x2, y2: g.y2,
63
+ children: [
64
+ spawn<any>({ tag: 'stop', namespace: SVG, 'stop-color': g.from }),
65
+ spawn<any>({ tag: 'stop', namespace: SVG, offset: '1', 'stop-color': g.to }),
66
+ ],
67
+ })),
68
+ }) : null,
69
+ ring('loader-inner', inner),
70
+ ring('loader-outer', outer),
71
+ ],
72
+ }),
73
+ spawn({ tag: 'span', className: 'loader-label', children: label }),
74
+ ],
75
+ });
76
+ }, props);
77
+ }
@@ -1,16 +1,22 @@
1
1
  import classNames from 'classnames';
2
2
  import CONSTANT from '../constants';
3
- import { sectionId, startsOpen, menuKeydown, warnOldMenuProps } from '../menu';
4
- import Tree from './Tree';
3
+ import { sectionId, startsOpen, menuKeydown, menuFocus, menuKind, MenuKind } from '../menu';
4
+ import Tree, { TreeProps } from './Tree';
5
5
  import { spawn, Child, ElementProps } from './spawn';
6
6
  import { updatable, NurvusElement } from './update';
7
7
  import '../components/Menu/Menu.scss';
8
8
 
9
+ export type { MenuKind };
10
+
9
11
  export interface MenuItem {
10
- /** What the link says. */
12
+ /** What the item says. */
11
13
  label: Child;
12
- /** Where it goes. The item whose href equals `current` is marked as the current page. */
13
- href: string;
14
+ /** Makes the item a link to this address. The item whose href equals `current` is marked as the current page. */
15
+ href?: string;
16
+ /** Makes the item a button that calls this (an action: "Duplicate", "Sign out"). */
17
+ onSelect?: (event: MouseEvent) => void;
18
+ /** Shows the item but stops it working (actions only). */
19
+ disabled?: boolean;
14
20
  /** Draws a hairline above this item, to split a section into groups. */
15
21
  divider?: boolean;
16
22
  }
@@ -18,17 +24,18 @@ export interface MenuItem {
18
24
  export interface MenuSection {
19
25
  /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
20
26
  id?: string;
21
- /** The section heading. */
22
- title: string;
27
+ /** The section heading. Optional for actions. */
28
+ title?: string;
23
29
  /** Makes the heading a link too (e.g. to the section's overview page). */
24
30
  href?: string;
25
- /** The section's links. */
31
+ /** The section's items. */
26
32
  items: MenuItem[];
27
33
  }
28
34
 
29
- export interface MenuProps extends ElementProps {
30
- /** The sections, in order. */
31
- sections: MenuSection[];
35
+ /** What navigation and actions take. */
36
+ interface MenuBaseProps extends ElementProps {
37
+ /** Navigation and actions: the sections, in order. */
38
+ sections?: MenuSection[];
32
39
  /** The href of the page being shown: its link is marked, and its section opens. */
33
40
  current?: string;
34
41
  /** Which sections start open: true (all), false (none) or a map of section id -> open. Defaults to all. */
@@ -37,27 +44,55 @@ export interface MenuProps extends ElementProps {
37
44
  onToggle?: (id: string, open: boolean) => void;
38
45
  /** Called when any link is clicked, with its href (e.g. to close a drawer). */
39
46
  onNavigate?: (href: string, event: MouseEvent) => void;
40
- /** Accessible name of the navigation landmark. */
47
+ /** What screen readers call the menu ("Pages", "Actions"). */
41
48
  label?: string;
42
- /** Prefix for the ids that link each toggle to its list. Defaults to "menu". */
49
+ /** Prefix for the ids inside (each toggle names its list). Defaults to "menu". */
43
50
  id?: string;
51
+ /** Navigation: the chevron before the title ('start', the default: right when closed, down when open, a guide line down the items) or after it ('end'). */
52
+ chevron?: 'start' | 'end';
53
+ }
54
+
55
+ export interface MenuProps extends MenuBaseProps {
56
+ /** What the menu is: 'nav' (links), 'actions' (commands) or 'tree' (rows to pick from, with Tree's props). Left out, it follows the props. */
57
+ kind?: MenuKind;
58
+ /** Tree: the rows, each with optional child `items`. */
59
+ items?: TreeProps['items'];
60
+ /** Tree: the picked row as a path of indexes. */
61
+ activePath?: number[];
62
+ /** Tree: draws a row's content instead of its label. */
63
+ itemRenderer?: TreeProps['itemRenderer'];
64
+ /** Tree: the deepest level that still indents. */
65
+ maxIndentDepth?: number;
66
+ }
67
+
68
+ /** Menu's props for navigation and actions. */
69
+ export interface MenuListProps extends MenuBaseProps {
70
+ /** 'nav' or 'actions'; left out, it follows the items. */
71
+ kind?: 'nav' | 'actions';
44
72
  }
73
+ /** Menu kind: 'tree': Tree's props. */
74
+ export type MenuTreeProps = TreeProps & { kind: 'tree' };
45
75
 
46
76
  /**
47
- * Site navigation: sections of links that open and close (an accordion, with
48
- * a smooth animation), and the current page marked by a bar beside it. A
49
- * click on a toggle opens or closes its section in place (the element stays
50
- * the same); update({ current }) marks another page and opens its section.
77
+ * One component for lists of things to go to, do or pick, the same markup as
78
+ * the React Menu. The items decide what it is, and screen readers hear it so:
79
+ * links make navigation (sections open and close in place; update({ current })
80
+ * marks another page), actions make a menu of commands (one Tab stop, the
81
+ * arrow keys move), kind: 'tree' makes a Tree.
51
82
  */
52
83
  export default function Menu(props: MenuProps = { sections: [] }): NurvusElement<HTMLElement, 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) as any;
55
- return updatable(({
56
- sections = [], current, defaultOpen = true, onToggle, onNavigate, label = 'Pages', id = 'menu', className, ...rest
57
- }: MenuProps, keep) => {
84
+ const kind = menuKind(props || {});
85
+ if (kind === 'tree') {
86
+ const { kind: _kind, sections: _s, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, chevron: _ch, ...tree } = props;
87
+ return Tree(tree as TreeProps) as any;
88
+ }
89
+ if (kind === 'actions') return MenuActions(props as MenuListProps) as any;
90
+ return updatable<HTMLElement, MenuListProps>(({
91
+ kind: _kind, sections = [], current, defaultOpen = true, onToggle, onNavigate, chevron = 'start', label = 'Pages', id = 'menu', className, ...rest
92
+ }: MenuListProps, keep) => {
58
93
  const open: Record<string, boolean> = Object.fromEntries(sections.map((s) => [sectionId(s), startsOpen(defaultOpen, sectionId(s))]));
59
94
  // The current page's section always starts open, as in React.
60
- const home = sections.find((s) => s.items.some((item) => item.href === current));
95
+ const home = sections.find((s) => s.items.some((item) => item.href !== undefined && item.href === current));
61
96
  if (home) open[sectionId(home)] = true;
62
97
 
63
98
  const navigate = (href: string) => ({ click: (event: MouseEvent) => { if (onNavigate) onNavigate(href, event); } });
@@ -72,18 +107,17 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
72
107
  el.setAttribute('data-open', String(open[sid]));
73
108
  toggles.forEach((t) => {
74
109
  t.setAttribute('aria-expanded', String(open[sid]));
75
- if (t.hasAttribute('aria-label')) t.setAttribute('aria-label', `${open[sid] ? 'Hide' : 'Show'} ${section.title}`);
110
+ if (t.hasAttribute('aria-label')) t.setAttribute('aria-label', `${open[sid] ? 'Hide' : 'Show'} ${String(section.title)}`);
76
111
  });
77
112
  if (onToggle) onToggle(sid, open[sid]);
78
113
  };
79
114
  const toggleProps = (extra: Record<string, unknown>) => ({
80
115
  tag: 'button', type: 'button', 'aria-expanded': open[sid], 'aria-controls': listId, events: { click: toggle }, ...extra,
81
116
  });
117
+ const link = () => spawn({ tag: 'a', className: 'menu-title', href: section.href, 'data-active': current === section.href, events: navigate(section.href as string), children: section.title });
118
+ const chev = () => spawn(toggleProps({ className: 'menu-toggle', 'aria-label': `${open[sid] ? 'Hide' : 'Show'} ${String(section.title)}` }));
82
119
  const heading = section.href
83
- ? [
84
- spawn({ tag: 'a', className: 'menu-title', href: section.href, 'data-active': current === section.href, events: navigate(section.href), children: section.title }),
85
- spawn(toggleProps({ className: 'menu-toggle', 'aria-label': `${open[sid] ? 'Hide' : 'Show'} ${section.title}` })),
86
- ]
120
+ ? (chevron === 'start' ? [chev(), link()] : [link(), chev()])
87
121
  : [spawn(toggleProps({ className: 'menu-title menu-toggle', children: section.title }))];
88
122
  heading.forEach((h) => { if (h.tagName === 'BUTTON') toggles.push(h); });
89
123
 
@@ -101,15 +135,24 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
101
135
  children: section.items.map((item) => spawn({
102
136
  tag: 'li',
103
137
  'data-divider': item.divider || undefined,
104
- children: spawn({
105
- tag: 'a',
106
- className: 'menu-item',
107
- href: item.href,
108
- 'data-active': current === item.href,
109
- 'aria-current': current === item.href ? 'page' : undefined,
110
- events: navigate(item.href),
111
- children: item.label,
112
- }),
138
+ children: item.href !== undefined
139
+ ? spawn({
140
+ tag: 'a',
141
+ className: 'menu-item',
142
+ href: item.href,
143
+ 'data-active': current === item.href,
144
+ 'aria-current': current === item.href ? 'page' : undefined,
145
+ events: navigate(item.href),
146
+ children: item.label,
147
+ })
148
+ : spawn({
149
+ tag: 'button',
150
+ type: 'button',
151
+ className: 'menu-item',
152
+ disabled: item.disabled,
153
+ events: { click: (event: MouseEvent) => { if (item.onSelect) item.onSelect(event); } },
154
+ children: item.label,
155
+ }),
113
156
  })),
114
157
  }),
115
158
  }),
@@ -123,6 +166,8 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
123
166
  tag: 'nav',
124
167
  className: classNames(className, 'menu', CONSTANT.CLASS_PREFIX),
125
168
  'aria-label': label,
169
+ 'data-kind': 'nav',
170
+ 'data-chevron': chevron,
126
171
  ...others,
127
172
  events: {
128
173
  ...events,
@@ -133,5 +178,67 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
133
178
  },
134
179
  children: sections.map(renderSection),
135
180
  });
181
+ }, props as MenuListProps) as any;
182
+ }
183
+
184
+ /** A menu of actions (role="menu"): one Tab stop that follows the focus, arrow keys, type to find. */
185
+ function MenuActions(props: MenuListProps): NurvusElement<HTMLElement, MenuListProps> {
186
+ return updatable(({
187
+ kind: _kind, sections = [], label = 'Actions', id = 'menu', className, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, chevron: _ch, ...rest
188
+ }: MenuListProps) => {
189
+ let first = true;
190
+ const { events, ...others } = rest;
191
+ return spawn<HTMLElement>({
192
+ className: classNames(className, 'menu', CONSTANT.CLASS_PREFIX),
193
+ role: 'menu',
194
+ id,
195
+ 'aria-label': label,
196
+ 'data-kind': 'actions',
197
+ ...others,
198
+ events: {
199
+ ...events,
200
+ keydown: (event: KeyboardEvent, el: HTMLElement) => { menuKeydown(event, el); if (events && events.keydown) events.keydown(event, el); },
201
+ focusin: (event: FocusEvent, el: HTMLElement) => { menuFocus(event, el); if (events && events.focusin) events.focusin(event, el); },
202
+ },
203
+ children: sections.map((section, s) => {
204
+ const sid = sectionId({ id: section.id, title: section.title ?? `section-${s + 1}` });
205
+ const titleId = `${id}-${sid}-title`;
206
+ return spawn({
207
+ className: 'menu-section',
208
+ 'data-section': sid,
209
+ role: 'group',
210
+ 'aria-labelledby': section.title ? titleId : undefined,
211
+ children: [
212
+ section.title ? spawn({ className: 'menu-heading', children: spawn({ tag: 'span', className: 'menu-title', id: titleId, children: section.title }) }) : null,
213
+ spawn({
214
+ className: 'menu-items',
215
+ children: spawn({
216
+ tag: 'ul',
217
+ role: 'none',
218
+ children: section.items.map((item) => {
219
+ const tabindex = first ? 0 : -1;
220
+ first = false;
221
+ return spawn({
222
+ tag: 'li',
223
+ role: 'none',
224
+ 'data-divider': item.divider || undefined,
225
+ children: spawn({
226
+ tag: 'button',
227
+ type: 'button',
228
+ role: 'menuitem',
229
+ className: 'menu-item',
230
+ tabindex,
231
+ 'aria-disabled': item.disabled || undefined,
232
+ events: { click: (event: MouseEvent) => { if (!item.disabled && item.onSelect) item.onSelect(event); } },
233
+ children: item.label,
234
+ }),
235
+ });
236
+ }),
237
+ }),
238
+ }),
239
+ ],
240
+ });
241
+ }),
242
+ });
136
243
  }, props);
137
244
  }
@@ -1,29 +1,72 @@
1
1
  import classNames from 'classnames';
2
2
  import CONSTANT from '../constants';
3
- import { spawn } from './spawn';
3
+ import { PROGRESS_STATUS, clampPercent, progressValueText, ProgressStatus } from '../progress';
4
+ import Icon from './Icon';
5
+ import { spawn, ElementProps } from './spawn';
4
6
  import { updatable, NurvusElement } from './update';
5
7
  import '../components/Progress/Progress.scss';
6
8
 
7
9
  export type ProgressSize = 'small' | 'medium' | 'large';
8
- export type ProgressStatus = 'active' | 'success' | 'warning' | 'critical';
10
+ export type { ProgressStatus };
9
11
 
10
- export interface ProgressProps {
12
+ export interface ProgressProps extends ElementProps {
11
13
  /** How far along, 0 to 100. */
12
14
  percent?: number;
13
15
  /** Bar height. */
14
16
  size?: ProgressSize;
15
- /** The bar color: active (accent), success, warning or critical (danger). */
17
+ /** 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. */
16
18
  status?: ProgressStatus;
17
- /** Custom class name. */
18
- className?: string;
19
+ /** What is in progress ("Uploading"): shown above the bar, and its name for screen readers. */
20
+ label?: string;
21
+ /** Keeps the label for screen readers only. */
22
+ hideLabel?: boolean;
23
+ /** Shows the percent (and the status, as an icon and a word) at the right, above the bar. */
24
+ showValue?: boolean;
25
+ /** What screen readers say for the value, instead of "40%" (e.g. "3 of 8 files"). */
26
+ valueText?: string;
19
27
  }
20
28
 
21
- /** A progress bar. Like the React one, it takes no other attributes. */
29
+ /**
30
+ * A progress bar, the same markup as the React one: a progressbar with its
31
+ * label and value for screen readers, and the status as an icon and a word
32
+ * when it has a label or showValue. bar.update({ percent: 60 }) moves it.
33
+ */
22
34
  export default function Progress(props: ProgressProps = {}): NurvusElement<HTMLDivElement, ProgressProps> {
23
- return updatable(({ className, percent = 0, size = 'medium', status = 'active' }: ProgressProps) => spawn<HTMLDivElement>({
24
- className: classNames(className, 'progress', CONSTANT.CLASS_PREFIX),
25
- 'data-size': size,
26
- 'data-status': status,
27
- children: spawn({ className: 'bar', style: { width: `${percent}%` } }),
28
- }), props);
35
+ return updatable(({
36
+ className, percent = 0, size = 'medium', status = 'active', label, hideLabel = false, showValue = false, valueText, ...rest
37
+ }: ProgressProps) => {
38
+ const value = clampPercent(percent);
39
+ const meaning = PROGRESS_STATUS[status] || PROGRESS_STATUS.active;
40
+ const head = (label && !hideLabel) || showValue;
41
+ return spawn<HTMLDivElement>({
42
+ className: classNames(className, 'progress', CONSTANT.CLASS_PREFIX),
43
+ 'data-size': size,
44
+ 'data-status': status,
45
+ role: 'progressbar',
46
+ 'aria-label': label || 'Progress',
47
+ 'aria-valuemin': 0,
48
+ 'aria-valuemax': 100,
49
+ 'aria-valuenow': value,
50
+ 'aria-valuetext': valueText || progressValueText(value, status),
51
+ ...rest,
52
+ children: [
53
+ head ? spawn({
54
+ className: 'progress-head',
55
+ children: [
56
+ label && !hideLabel ? spawn({ tag: 'span', className: 'progress-label', children: label }) : null,
57
+ showValue ? spawn({
58
+ tag: 'span',
59
+ className: 'progress-value',
60
+ children: [
61
+ meaning.icon ? Icon({ name: meaning.icon }) : null,
62
+ meaning.word ? spawn({ tag: 'span', className: 'progress-word', children: meaning.word }) : null,
63
+ spawn({ tag: 'span', children: `${value}%` }),
64
+ ],
65
+ }) : null,
66
+ ],
67
+ }) : null,
68
+ spawn({ className: 'progress-track', children: spawn({ className: 'bar', style: { width: `${value}%` } }) }),
69
+ ],
70
+ });
71
+ }, props);
29
72
  }
@@ -0,0 +1,37 @@
1
+ import classNames from 'classnames';
2
+ import CONSTANT from '../constants';
3
+ import { Spacing } from '../spacing';
4
+ import { Responsive, responsiveData } from '../breakpoints';
5
+ import { spawn, Child, ElementProps } from './spawn';
6
+ import { updatable, NurvusElement } from './update';
7
+ import '../components/Stack/Stack.scss';
8
+
9
+ export type StackDirection = 'column' | 'row';
10
+
11
+ export interface StackProps extends ElementProps {
12
+ /** column (top to bottom, the default) or row. Can change with the width: { base: 'column', md: 'row' }. */
13
+ direction?: Responsive<StackDirection>;
14
+ /** Space between the children, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
15
+ gap?: Spacing;
16
+ /** How the children line up across the stack. */
17
+ align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
18
+ /** How the children spread along the stack. */
19
+ justify?: 'start' | 'center' | 'end' | 'between';
20
+ /** Lets a row wrap onto more lines when it runs out of room. */
21
+ wrap?: boolean;
22
+ /** What to lay out. */
23
+ children?: Child;
24
+ }
25
+
26
+ /** A column or a row with even space between the children, the same markup as the React Stack. */
27
+ export default function Stack(props: StackProps = {}): NurvusElement<HTMLDivElement, StackProps> {
28
+ return updatable(({ direction = 'column', gap = 16, align, justify, wrap = false, className, ...rest }: StackProps) => spawn<HTMLDivElement>({
29
+ className: classNames(className, 'stack', CONSTANT.CLASS_PREFIX),
30
+ ...responsiveData('direction', direction),
31
+ 'data-gap': gap,
32
+ 'data-align': align,
33
+ 'data-justify': justify,
34
+ 'data-wrap': wrap || undefined,
35
+ ...rest,
36
+ }), props);
37
+ }
@@ -45,8 +45,20 @@ export { ICONS, ICON_NAMES } from '../icons';
45
45
  export type { IconName, IconNode } from '../icons';
46
46
  export { default as Tree } from './Tree';
47
47
  export type { TreeProps, TreeItem } from './Tree';
48
+ export { default as Stack } from './Stack';
49
+ export type { StackProps, StackDirection } from './Stack';
50
+ export { default as Grid } from './Grid';
51
+ export type { GridProps, GridColumns } from './Grid';
52
+ export { BREAKPOINTS, isAtLeast } from '../breakpoints';
53
+ export type { Breakpoint, Responsive } from '../breakpoints';
54
+ export { default as Loader } from './Loader';
55
+ export type { LoaderProps } from './Loader';
56
+ export { default as Anchor } from './Anchor';
57
+ export type { AnchorProps, AnchorItem } from './Anchor';
58
+ export { default as Dropdown } from './Dropdown';
59
+ export type { DropdownProps } from './Dropdown';
48
60
  export { default as Menu } from './Menu';
49
- export type { MenuProps, MenuItem, MenuSection } from './Menu';
61
+ export type { MenuProps, MenuListProps, MenuTreeProps, MenuItem, MenuSection, MenuKind } from './Menu';
50
62
  export { default as Select } from './Select';
51
63
  export type { SelectProps, SelectOption, SelectOptionState } from './Select';
52
64
  export { default as FullPageModal } from './FullPageModal';
@@ -0,0 +1,3 @@
1
+ // The breakpoints (src/breakpoints.ts has the same numbers for JavaScript).
2
+ // em, so a reader who sets bigger text gets the narrower layout sooner.
3
+ $nurvus-breakpoints: (sm: 40em, md: 48em, lg: 64em, xl: 80em);