@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.
- package/README.md +13 -0
- package/dist/icons.svg +73 -0
- package/dist/index.js +1 -1
- package/dist/nurvus.css +14 -10
- package/dist/respawn.js +1 -1
- package/dist/types/breakpoints.d.ts +14 -0
- package/dist/types/components/FullPageModal/FullPageModal.d.ts +11 -2
- package/dist/types/components/Grid/Grid.d.ts +26 -0
- package/dist/types/components/Icon/Icon.d.ts +20 -0
- package/dist/types/components/Loader/Loader.d.ts +21 -0
- package/dist/types/components/Menu/Menu.d.ts +54 -19
- package/dist/types/components/Progress/Progress.d.ts +19 -5
- package/dist/types/components/Stack/Stack.d.ts +26 -0
- package/dist/types/dialog.d.ts +12 -0
- package/dist/types/icons.d.ts +83 -0
- package/dist/types/index.d.ts +13 -1
- package/dist/types/loader.d.ts +28 -0
- package/dist/types/logo.d.ts +5 -0
- package/dist/types/menu.d.ts +43 -14
- package/dist/types/progress.d.ts +11 -0
- package/dist/types/respawn/FullPageModal.d.ts +7 -1
- package/dist/types/respawn/Grid.d.ts +21 -0
- package/dist/types/respawn/Icon.d.ts +22 -0
- package/dist/types/respawn/Loader.d.ts +18 -0
- package/dist/types/respawn/Menu.d.ts +45 -15
- package/dist/types/respawn/Progress.d.ts +18 -6
- package/dist/types/respawn/Stack.d.ts +21 -0
- package/dist/types/respawn/index.d.ts +13 -1
- package/dist/types/respawn/spawn.d.ts +2 -0
- package/package.json +1 -3
- package/src/breakpoints.ts +28 -0
- package/src/components/Button/Button.scss +20 -20
- package/src/components/ButtonGroup/ButtonGroup.md +8 -12
- package/src/components/FullPageModal/FullPageModal.md +20 -17
- package/src/components/FullPageModal/FullPageModal.scss +5 -0
- package/src/components/FullPageModal/FullPageModal.tsx +37 -3
- package/src/components/Grid/Grid.md +37 -0
- package/src/components/Grid/Grid.scss +37 -0
- package/src/components/Grid/Grid.tsx +54 -0
- package/src/components/HistoryList/HistoryList.scss +2 -2
- package/src/components/Icon/Icon.md +22 -0
- package/src/components/Icon/Icon.scss +10 -0
- package/src/components/Icon/Icon.tsx +45 -0
- package/src/components/Layout/Layout.md +10 -18
- package/src/components/Loader/Loader.md +30 -0
- package/src/components/Loader/Loader.scss +42 -0
- package/src/components/Loader/Loader.tsx +68 -0
- package/src/components/Menu/Menu.md +68 -2
- package/src/components/Menu/Menu.scss +48 -18
- package/src/components/Menu/Menu.tsx +146 -39
- package/src/components/Progress/Progress.md +27 -26
- package/src/components/Progress/Progress.scss +41 -36
- package/src/components/Progress/Progress.tsx +50 -6
- package/src/components/Select/Select.scss +20 -19
- package/src/components/Stack/Stack.md +43 -0
- package/src/components/Stack/Stack.scss +36 -0
- package/src/components/Stack/Stack.tsx +52 -0
- package/src/components/Table/Table.scss +1 -1
- package/src/components/Tag/Tag.scss +2 -2
- package/src/components/Text/Text.md +3 -5
- package/src/components/Title/Title.scss +6 -6
- package/src/components/Tree/Tree.md +5 -5
- package/src/css.ts +4 -0
- package/src/dialog.ts +47 -0
- package/src/icons.ts +117 -0
- package/src/index.ts +13 -1
- package/src/loader.ts +43 -0
- package/src/logo.ts +12 -0
- package/src/menu.ts +91 -21
- package/src/progress.ts +21 -0
- package/src/respawn/FullPageModal.ts +30 -3
- package/src/respawn/Grid.ts +41 -0
- package/src/respawn/Icon.ts +47 -0
- package/src/respawn/Loader.ts +77 -0
- package/src/respawn/Menu.ts +138 -34
- package/src/respawn/Progress.ts +56 -13
- package/src/respawn/Stack.ts +37 -0
- package/src/respawn/index.ts +13 -1
- package/src/respawn/spawn.ts +5 -3
- package/src/styles/breakpoints.scss +3 -0
- package/src/styles/theme.scss +55 -55
- package/src/styles/type.json +9 -9
|
@@ -4,6 +4,7 @@ import { spawn, Child, ElementProps } from './spawn';
|
|
|
4
4
|
import { NurvusElement } from './update';
|
|
5
5
|
import Layout from './Layout';
|
|
6
6
|
import Title from './Title';
|
|
7
|
+
import { dialogKeydown, focusDialog, restoreFocus } from '../dialog';
|
|
7
8
|
import '../components/FullPageModal/FullPageModal.scss';
|
|
8
9
|
|
|
9
10
|
export interface FullPageModalProps extends ElementProps {
|
|
@@ -17,10 +18,16 @@ export interface FullPageModalProps extends ElementProps {
|
|
|
17
18
|
children?: Child;
|
|
18
19
|
/** Appends the modal to this element when it is made, e.g. document.body. */
|
|
19
20
|
mountEl?: Element;
|
|
21
|
+
/** Called when someone presses Esc. Close the modal in it: modal.update({ visible: false }). */
|
|
22
|
+
onClose?: () => void;
|
|
23
|
+
/** Names the modal and its title: the title gets the id "<id>-title", and the modal is labelled by it. */
|
|
24
|
+
id?: string;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/**
|
|
23
|
-
* Shows content over the whole screen
|
|
28
|
+
* Shows content over the whole screen: a modal dialog, like the React one
|
|
29
|
+
* (focus moves in when it opens and back when it closes, Tab stays inside,
|
|
30
|
+
* Esc calls onClose). Returns the modal's outer element
|
|
24
31
|
* (`<div class="portal nurvus">`, the one React puts into `<body>` itself):
|
|
25
32
|
* mount it on document.body, or pass `mountEl: document.body`.
|
|
26
33
|
*
|
|
@@ -42,6 +49,7 @@ export default function FullPageModal(props: FullPageModalProps = {}): NurvusEle
|
|
|
42
49
|
// The React component's two states.
|
|
43
50
|
let isVisible = Boolean(current.visible);
|
|
44
51
|
let animationState = '';
|
|
52
|
+
let opener: Element | null = null;
|
|
45
53
|
|
|
46
54
|
const portal = spawn<HTMLDivElement>({ className: `portal ${CONSTANT.CLASS_PREFIX}` }) as NurvusElement<HTMLDivElement, FullPageModalProps>;
|
|
47
55
|
let mask: HTMLElement | null = null;
|
|
@@ -80,10 +88,24 @@ export default function FullPageModal(props: FullPageModalProps = {}): NurvusEle
|
|
|
80
88
|
};
|
|
81
89
|
|
|
82
90
|
const buildModal = () => {
|
|
83
|
-
const { children, className, headerActions, title, visible: _visible, mountEl: _mountEl, ...rest } = current;
|
|
91
|
+
const { children, className, headerActions, title, visible: _visible, mountEl: _mountEl, onClose, id, events, ...rest } = current;
|
|
92
|
+
const titleId = id && title ? `${id}-title` : undefined;
|
|
84
93
|
const el = spawn({
|
|
85
94
|
className: classNames(className, 'modal', CONSTANT.CLASS_PREFIX),
|
|
95
|
+
role: 'dialog',
|
|
96
|
+
'aria-modal': 'true',
|
|
97
|
+
'aria-labelledby': titleId,
|
|
98
|
+
'aria-label': !id && typeof title === 'string' ? title : undefined,
|
|
99
|
+
tabindex: -1,
|
|
100
|
+
id,
|
|
86
101
|
...rest,
|
|
102
|
+
events: {
|
|
103
|
+
...(events as object),
|
|
104
|
+
keydown: (event: KeyboardEvent, node: HTMLElement) => {
|
|
105
|
+
dialogKeydown(event, node, current.onClose);
|
|
106
|
+
if (events && (events as any).keydown) (events as any).keydown(event, node);
|
|
107
|
+
},
|
|
108
|
+
},
|
|
87
109
|
tag: 'div',
|
|
88
110
|
children: [
|
|
89
111
|
spawn({
|
|
@@ -92,7 +114,7 @@ export default function FullPageModal(props: FullPageModalProps = {}): NurvusEle
|
|
|
92
114
|
display: 'flex',
|
|
93
115
|
alignItems: 'center',
|
|
94
116
|
justifyContent: 'space-between',
|
|
95
|
-
children: [Title({ children: title }), spawn({ className: 'header-actions', children: headerActions })],
|
|
117
|
+
children: [Title({ id: titleId, children: title }), spawn({ className: 'header-actions', children: headerActions })],
|
|
96
118
|
}),
|
|
97
119
|
}),
|
|
98
120
|
children,
|
|
@@ -117,9 +139,14 @@ export default function FullPageModal(props: FullPageModalProps = {}): NurvusEle
|
|
|
117
139
|
const visible = Boolean(current.visible);
|
|
118
140
|
if (visible !== was) start(visible);
|
|
119
141
|
sync();
|
|
142
|
+
// Focus in on open; back to the opener on close.
|
|
143
|
+
if (visible && !was) { opener = document.activeElement; focusDialog(modal); }
|
|
144
|
+
if (!visible && was) { restoreFocus(opener); opener = null; }
|
|
120
145
|
return portal;
|
|
121
146
|
};
|
|
122
147
|
|
|
123
148
|
if (mountEl) mountEl.appendChild(portal);
|
|
149
|
+
// Open from the start: focus goes in once it is on the page.
|
|
150
|
+
if (current.visible) { opener = document.activeElement; focusDialog(modal); }
|
|
124
151
|
return portal;
|
|
125
152
|
}
|
|
@@ -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,47 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import CONSTANT from '../constants';
|
|
3
|
+
import { iconNodes, IconName } from '../icons';
|
|
4
|
+
import { spawn, ElementProps } from './spawn';
|
|
5
|
+
import { updatable } from './update';
|
|
6
|
+
import '../components/Icon/Icon.scss';
|
|
7
|
+
|
|
8
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
9
|
+
|
|
10
|
+
export interface IconProps extends ElementProps {
|
|
11
|
+
/** Which icon (Foundations > Icons lists them all). */
|
|
12
|
+
name: IconName;
|
|
13
|
+
/** Width and height. Defaults to 1em: the icon is as big as the text around it. A number is pixels. */
|
|
14
|
+
size?: number | string;
|
|
15
|
+
/** Says what the icon means, for an icon that stands alone (screen readers read it). Leave it out when text beside it already says it. */
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Line thickness in grid units (the grid is 24). */
|
|
18
|
+
strokeWidth?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The <svg> Icon returns, with update() like every other component. */
|
|
22
|
+
export type IconElement = SVGSVGElement & { update(changes: Partial<IconProps>): IconElement };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An icon from the NURVUS set, as an <svg> element: the same markup as the
|
|
26
|
+
* React Icon. 1em by default, in the text's color; decorative unless it has a
|
|
27
|
+
* label. icon.update({ name: 'check' }) swaps it for another.
|
|
28
|
+
*/
|
|
29
|
+
export default function Icon(props: IconProps): IconElement {
|
|
30
|
+
return updatable(({ name, size = '1em', label, strokeWidth = 2, className, ...rest }: IconProps) => spawn<any>({
|
|
31
|
+
tag: 'svg',
|
|
32
|
+
namespace: SVG,
|
|
33
|
+
className: classNames(className, 'icon', CONSTANT.CLASS_PREFIX),
|
|
34
|
+
'data-icon': name,
|
|
35
|
+
viewBox: '0 0 24 24',
|
|
36
|
+
width: size,
|
|
37
|
+
height: size,
|
|
38
|
+
fill: 'none',
|
|
39
|
+
stroke: 'currentColor',
|
|
40
|
+
'stroke-width': strokeWidth,
|
|
41
|
+
'stroke-linecap': 'round',
|
|
42
|
+
'stroke-linejoin': 'round',
|
|
43
|
+
...(label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true, focusable: 'false' }),
|
|
44
|
+
...rest,
|
|
45
|
+
children: iconNodes(name).map(([tag, attrs]) => spawn({ tag, namespace: SVG, ...attrs })),
|
|
46
|
+
}), props) as unknown as IconElement;
|
|
47
|
+
}
|
|
@@ -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
|
+
}
|
package/src/respawn/Menu.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
import CONSTANT from '../constants';
|
|
3
|
-
import { sectionId, startsOpen, menuKeydown,
|
|
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
|
|
12
|
+
/** What the item says. */
|
|
11
13
|
label: Child;
|
|
12
|
-
/**
|
|
13
|
-
href
|
|
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
|
|
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
|
|
31
|
+
/** The section's items. */
|
|
26
32
|
items: MenuItem[];
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,53 @@ 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
|
-
/**
|
|
47
|
+
/** What screen readers call the menu ("Pages", "Actions"). */
|
|
41
48
|
label?: string;
|
|
42
|
-
/** Prefix for the ids
|
|
49
|
+
/** Prefix for the ids inside (each toggle names its list). Defaults to "menu". */
|
|
43
50
|
id?: string;
|
|
44
51
|
}
|
|
45
52
|
|
|
53
|
+
export interface MenuProps extends MenuBaseProps {
|
|
54
|
+
/** What the menu is: 'nav' (links), 'actions' (commands) or 'tree' (rows to pick from, with Tree's props). Left out, it follows the props. */
|
|
55
|
+
kind?: MenuKind;
|
|
56
|
+
/** Tree: the rows, each with optional child `items`. */
|
|
57
|
+
items?: TreeProps['items'];
|
|
58
|
+
/** Tree: the picked row as a path of indexes. */
|
|
59
|
+
activePath?: number[];
|
|
60
|
+
/** Tree: draws a row's content instead of its label. */
|
|
61
|
+
itemRenderer?: TreeProps['itemRenderer'];
|
|
62
|
+
/** Tree: the deepest level that still indents. */
|
|
63
|
+
maxIndentDepth?: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Menu's props for navigation and actions. */
|
|
67
|
+
export interface MenuListProps extends MenuBaseProps {
|
|
68
|
+
/** 'nav' or 'actions'; left out, it follows the items. */
|
|
69
|
+
kind?: 'nav' | 'actions';
|
|
70
|
+
}
|
|
71
|
+
/** Menu kind: 'tree': Tree's props. */
|
|
72
|
+
export type MenuTreeProps = TreeProps & { kind: 'tree' };
|
|
73
|
+
|
|
46
74
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
75
|
+
* One component for lists of things to go to, do or pick, the same markup as
|
|
76
|
+
* the React Menu. The items decide what it is, and screen readers hear it so:
|
|
77
|
+
* links make navigation (sections open and close in place; update({ current })
|
|
78
|
+
* marks another page), actions make a menu of commands (one Tab stop, the
|
|
79
|
+
* arrow keys move), kind: 'tree' makes a Tree.
|
|
51
80
|
*/
|
|
52
81
|
export default function Menu(props: MenuProps = { sections: [] }): NurvusElement<HTMLElement, MenuProps> {
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
82
|
+
const kind = menuKind(props || {});
|
|
83
|
+
if (kind === 'tree') {
|
|
84
|
+
const { kind: _kind, sections: _s, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, ...tree } = props;
|
|
85
|
+
return Tree(tree as TreeProps) as any;
|
|
86
|
+
}
|
|
87
|
+
if (kind === 'actions') return MenuActions(props as MenuListProps) as any;
|
|
88
|
+
return updatable<HTMLElement, MenuListProps>(({
|
|
89
|
+
kind: _kind, sections = [], current, defaultOpen = true, onToggle, onNavigate, label = 'Pages', id = 'menu', className, ...rest
|
|
90
|
+
}: MenuListProps, keep) => {
|
|
58
91
|
const open: Record<string, boolean> = Object.fromEntries(sections.map((s) => [sectionId(s), startsOpen(defaultOpen, sectionId(s))]));
|
|
59
92
|
// The current page's section always starts open, as in React.
|
|
60
|
-
const home = sections.find((s) => s.items.some((item) => item.href === current));
|
|
93
|
+
const home = sections.find((s) => s.items.some((item) => item.href !== undefined && item.href === current));
|
|
61
94
|
if (home) open[sectionId(home)] = true;
|
|
62
95
|
|
|
63
96
|
const navigate = (href: string) => ({ click: (event: MouseEvent) => { if (onNavigate) onNavigate(href, event); } });
|
|
@@ -72,7 +105,7 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
72
105
|
el.setAttribute('data-open', String(open[sid]));
|
|
73
106
|
toggles.forEach((t) => {
|
|
74
107
|
t.setAttribute('aria-expanded', String(open[sid]));
|
|
75
|
-
if (t.hasAttribute('aria-label')) t.setAttribute('aria-label', `${open[sid] ? 'Hide' : 'Show'} ${section.title}`);
|
|
108
|
+
if (t.hasAttribute('aria-label')) t.setAttribute('aria-label', `${open[sid] ? 'Hide' : 'Show'} ${String(section.title)}`);
|
|
76
109
|
});
|
|
77
110
|
if (onToggle) onToggle(sid, open[sid]);
|
|
78
111
|
};
|
|
@@ -82,7 +115,7 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
82
115
|
const heading = section.href
|
|
83
116
|
? [
|
|
84
117
|
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}` })),
|
|
118
|
+
spawn(toggleProps({ className: 'menu-toggle', 'aria-label': `${open[sid] ? 'Hide' : 'Show'} ${String(section.title)}` })),
|
|
86
119
|
]
|
|
87
120
|
: [spawn(toggleProps({ className: 'menu-title menu-toggle', children: section.title }))];
|
|
88
121
|
heading.forEach((h) => { if (h.tagName === 'BUTTON') toggles.push(h); });
|
|
@@ -101,15 +134,24 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
101
134
|
children: section.items.map((item) => spawn({
|
|
102
135
|
tag: 'li',
|
|
103
136
|
'data-divider': item.divider || undefined,
|
|
104
|
-
children:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
137
|
+
children: item.href !== undefined
|
|
138
|
+
? spawn({
|
|
139
|
+
tag: 'a',
|
|
140
|
+
className: 'menu-item',
|
|
141
|
+
href: item.href,
|
|
142
|
+
'data-active': current === item.href,
|
|
143
|
+
'aria-current': current === item.href ? 'page' : undefined,
|
|
144
|
+
events: navigate(item.href),
|
|
145
|
+
children: item.label,
|
|
146
|
+
})
|
|
147
|
+
: spawn({
|
|
148
|
+
tag: 'button',
|
|
149
|
+
type: 'button',
|
|
150
|
+
className: 'menu-item',
|
|
151
|
+
disabled: item.disabled,
|
|
152
|
+
events: { click: (event: MouseEvent) => { if (item.onSelect) item.onSelect(event); } },
|
|
153
|
+
children: item.label,
|
|
154
|
+
}),
|
|
113
155
|
})),
|
|
114
156
|
}),
|
|
115
157
|
}),
|
|
@@ -123,6 +165,7 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
123
165
|
tag: 'nav',
|
|
124
166
|
className: classNames(className, 'menu', CONSTANT.CLASS_PREFIX),
|
|
125
167
|
'aria-label': label,
|
|
168
|
+
'data-kind': 'nav',
|
|
126
169
|
...others,
|
|
127
170
|
events: {
|
|
128
171
|
...events,
|
|
@@ -133,5 +176,66 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
133
176
|
},
|
|
134
177
|
children: sections.map(renderSection),
|
|
135
178
|
});
|
|
179
|
+
}, props as MenuListProps) as any;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** A menu of actions (role="menu"): one Tab stop that follows the focus, arrow keys, type to find. */
|
|
183
|
+
function MenuActions(props: MenuListProps): NurvusElement<HTMLElement, MenuListProps> {
|
|
184
|
+
return updatable(({
|
|
185
|
+
kind: _kind, sections = [], label = 'Actions', id = 'menu', className, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, ...rest
|
|
186
|
+
}: MenuListProps) => {
|
|
187
|
+
let first = true;
|
|
188
|
+
const { events, ...others } = rest;
|
|
189
|
+
return spawn<HTMLElement>({
|
|
190
|
+
className: classNames(className, 'menu', CONSTANT.CLASS_PREFIX),
|
|
191
|
+
role: 'menu',
|
|
192
|
+
'aria-label': label,
|
|
193
|
+
'data-kind': 'actions',
|
|
194
|
+
...others,
|
|
195
|
+
events: {
|
|
196
|
+
...events,
|
|
197
|
+
keydown: (event: KeyboardEvent, el: HTMLElement) => { menuKeydown(event, el); if (events && events.keydown) events.keydown(event, el); },
|
|
198
|
+
focusin: (event: FocusEvent, el: HTMLElement) => { menuFocus(event, el); if (events && events.focusin) events.focusin(event, el); },
|
|
199
|
+
},
|
|
200
|
+
children: sections.map((section, s) => {
|
|
201
|
+
const sid = sectionId({ id: section.id, title: section.title ?? `section-${s + 1}` });
|
|
202
|
+
const titleId = `${id}-${sid}-title`;
|
|
203
|
+
return spawn({
|
|
204
|
+
className: 'menu-section',
|
|
205
|
+
'data-section': sid,
|
|
206
|
+
role: 'group',
|
|
207
|
+
'aria-labelledby': section.title ? titleId : undefined,
|
|
208
|
+
children: [
|
|
209
|
+
section.title ? spawn({ className: 'menu-heading', children: spawn({ tag: 'span', className: 'menu-title', id: titleId, children: section.title }) }) : null,
|
|
210
|
+
spawn({
|
|
211
|
+
className: 'menu-items',
|
|
212
|
+
children: spawn({
|
|
213
|
+
tag: 'ul',
|
|
214
|
+
role: 'none',
|
|
215
|
+
children: section.items.map((item) => {
|
|
216
|
+
const tabindex = first ? 0 : -1;
|
|
217
|
+
first = false;
|
|
218
|
+
return spawn({
|
|
219
|
+
tag: 'li',
|
|
220
|
+
role: 'none',
|
|
221
|
+
'data-divider': item.divider || undefined,
|
|
222
|
+
children: spawn({
|
|
223
|
+
tag: 'button',
|
|
224
|
+
type: 'button',
|
|
225
|
+
role: 'menuitem',
|
|
226
|
+
className: 'menu-item',
|
|
227
|
+
tabindex,
|
|
228
|
+
'aria-disabled': item.disabled || undefined,
|
|
229
|
+
events: { click: (event: MouseEvent) => { if (!item.disabled && item.onSelect) item.onSelect(event); } },
|
|
230
|
+
children: item.label,
|
|
231
|
+
}),
|
|
232
|
+
});
|
|
233
|
+
}),
|
|
234
|
+
}),
|
|
235
|
+
}),
|
|
236
|
+
],
|
|
237
|
+
});
|
|
238
|
+
}),
|
|
239
|
+
});
|
|
136
240
|
}, props);
|
|
137
241
|
}
|
package/src/respawn/Progress.ts
CHANGED
|
@@ -1,29 +1,72 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
import CONSTANT from '../constants';
|
|
3
|
-
import {
|
|
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
|
|
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
|
-
/**
|
|
18
|
-
|
|
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
|
-
/**
|
|
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(({
|
|
24
|
-
className
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
}
|
package/src/respawn/index.ts
CHANGED
|
@@ -39,10 +39,22 @@ export { default as Progress } from './Progress';
|
|
|
39
39
|
export type { ProgressProps, ProgressSize, ProgressStatus } from './Progress';
|
|
40
40
|
export { default as Layout } from './Layout';
|
|
41
41
|
export type { LayoutProps, Spacing, LegacySpacing } from './Layout';
|
|
42
|
+
export { default as Icon } from './Icon';
|
|
43
|
+
export type { IconProps, IconElement } from './Icon';
|
|
44
|
+
export { ICONS, ICON_NAMES } from '../icons';
|
|
45
|
+
export type { IconName, IconNode } from '../icons';
|
|
42
46
|
export { default as Tree } from './Tree';
|
|
43
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';
|
|
44
56
|
export { default as Menu } from './Menu';
|
|
45
|
-
export type { MenuProps, MenuItem, MenuSection } from './Menu';
|
|
57
|
+
export type { MenuProps, MenuListProps, MenuTreeProps, MenuItem, MenuSection, MenuKind } from './Menu';
|
|
46
58
|
export { default as Select } from './Select';
|
|
47
59
|
export type { SelectProps, SelectOption, SelectOptionState } from './Select';
|
|
48
60
|
export { default as FullPageModal } from './FullPageModal';
|