@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.
- package/README.md +17 -1
- package/dist/icons.svg +74 -0
- package/dist/index.js +1 -1
- package/dist/nurvus.css +15 -10
- package/dist/respawn.js +1 -1
- package/dist/types/anchor.d.ts +37 -0
- package/dist/types/breakpoints.d.ts +14 -0
- package/dist/types/components/Anchor/Anchor.d.ts +30 -0
- package/dist/types/components/Dropdown/Dropdown.d.ts +31 -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/Loader/Loader.d.ts +21 -0
- package/dist/types/components/Menu/Menu.d.ts +61 -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/dropdown.d.ts +9 -0
- package/dist/types/icons.d.ts +29 -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/Anchor.d.ts +28 -0
- package/dist/types/respawn/Dropdown.d.ts +27 -0
- package/dist/types/respawn/FullPageModal.d.ts +7 -1
- package/dist/types/respawn/Grid.d.ts +21 -0
- package/dist/types/respawn/Loader.d.ts +18 -0
- package/dist/types/respawn/Menu.d.ts +47 -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/package.json +1 -3
- package/src/anchor.ts +127 -0
- package/src/breakpoints.ts +28 -0
- package/src/components/Anchor/Anchor.md +59 -0
- package/src/components/Anchor/Anchor.scss +65 -0
- package/src/components/Anchor/Anchor.tsx +105 -0
- package/src/components/Button/Button.scss +20 -20
- package/src/components/Dropdown/Dropdown.md +48 -0
- package/src/components/Dropdown/Dropdown.scss +67 -0
- package/src/components/Dropdown/Dropdown.tsx +110 -0
- 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/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 +67 -3
- package/src/components/Menu/Menu.scss +126 -18
- package/src/components/Menu/Menu.tsx +159 -40
- 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/Title/Title.scss +6 -6
- package/src/components/Tree/Tree.md +1 -1
- package/src/css.ts +5 -0
- package/src/dialog.ts +47 -0
- package/src/dropdown.ts +24 -0
- package/src/icons.ts +31 -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/Anchor.ts +126 -0
- package/src/respawn/Dropdown.ts +90 -0
- package/src/respawn/FullPageModal.ts +30 -3
- package/src/respawn/Grid.ts +41 -0
- package/src/respawn/Loader.ts +77 -0
- package/src/respawn/Menu.ts +144 -37
- package/src/respawn/Progress.ts +56 -13
- package/src/respawn/Stack.ts +37 -0
- package/src/respawn/index.ts +13 -1
- package/src/styles/breakpoints.scss +3 -0
- package/src/styles/theme.scss +55 -55
- package/src/styles/type.json +9 -9
|
@@ -64,47 +64,47 @@
|
|
|
64
64
|
|
|
65
65
|
// Sizes
|
|
66
66
|
&[data-size="extra-large"] {
|
|
67
|
-
height:
|
|
68
|
-
border-radius:
|
|
69
|
-
padding: 0
|
|
67
|
+
height: 3.5rem;
|
|
68
|
+
border-radius: 0.75rem;
|
|
69
|
+
padding: 0 1rem 0 1rem;
|
|
70
70
|
font-size: $--14--medium;
|
|
71
71
|
font-weight: 500;
|
|
72
|
-
line-height:
|
|
72
|
+
line-height: 1.225rem;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
&[data-size="large"] {
|
|
76
|
-
height:
|
|
77
|
-
border-radius:
|
|
78
|
-
padding: 0
|
|
76
|
+
height: 3rem;
|
|
77
|
+
border-radius: 0.75rem;
|
|
78
|
+
padding: 0 1rem 0 1rem;
|
|
79
79
|
font-size: $--14--medium;
|
|
80
80
|
font-weight: 500;
|
|
81
|
-
line-height:
|
|
81
|
+
line-height: 1.225rem;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
&[data-size="medium"] {
|
|
85
|
-
height:
|
|
86
|
-
border-radius:
|
|
87
|
-
padding: 0
|
|
85
|
+
height: 2.5rem;
|
|
86
|
+
border-radius: 0.75rem;
|
|
87
|
+
padding: 0 0.875rem 0 0.875rem;
|
|
88
88
|
font-size: $--14--medium;
|
|
89
89
|
font-weight: 500;
|
|
90
|
-
line-height:
|
|
90
|
+
line-height: 1.225rem;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
&[data-size="small"] {
|
|
94
|
-
height:
|
|
95
|
-
border-radius:
|
|
96
|
-
padding: 0
|
|
94
|
+
height: 2rem;
|
|
95
|
+
border-radius: 0.625rem;
|
|
96
|
+
padding: 0 0.75rem 0 0.75rem;
|
|
97
97
|
font-size: $--14--medium;
|
|
98
98
|
font-weight: 500;
|
|
99
|
-
line-height:
|
|
99
|
+
line-height: 1.225rem;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
&[data-size="mini"] {
|
|
103
|
-
height:
|
|
104
|
-
border-radius:
|
|
105
|
-
padding: 0
|
|
103
|
+
height: 1.5rem;
|
|
104
|
+
border-radius: 0.5rem;
|
|
105
|
+
padding: 0 0.625rem 0 0.625rem;
|
|
106
106
|
font-size: $--12--medium;
|
|
107
107
|
font-weight: 500;
|
|
108
|
-
line-height:
|
|
108
|
+
line-height: 1.05rem;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Screen readers hear "Actions, menu button, collapsed"; once it opens, the menu and its items ("Duplicate, menu item"). A disabled action stays in the list, so people still find it, but does nothing.
|
|
2
|
+
|
|
3
|
+
```jsx
|
|
4
|
+
import { Dropdown, Text } from '@nurvus/ui';
|
|
5
|
+
|
|
6
|
+
const Demo = () => {
|
|
7
|
+
const [done, setDone] = React.useState('Nothing yet');
|
|
8
|
+
const run = (what) => () => setDone(what);
|
|
9
|
+
return (
|
|
10
|
+
<div style={ { display: 'flex', alignItems: 'center', gap: 16 } }>
|
|
11
|
+
<Dropdown
|
|
12
|
+
id="file-actions"
|
|
13
|
+
label="Actions"
|
|
14
|
+
sections={ [
|
|
15
|
+
{ title: 'File', items: [
|
|
16
|
+
{ label: 'Duplicate', onSelect: run('Duplicated') },
|
|
17
|
+
{ label: 'Rename', onSelect: run('Renamed') },
|
|
18
|
+
{ label: 'Move to…', onSelect: run('Moved'), disabled: true },
|
|
19
|
+
] },
|
|
20
|
+
{ items: [{ label: 'Delete', onSelect: run('Deleted') }] },
|
|
21
|
+
] }
|
|
22
|
+
/>
|
|
23
|
+
<Text tone="muted">{ done }</Text>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
<Demo />
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
A flat list with `items`, lined up with the button's right edge (`align="end"`), and an icon-only button: give the icon a `label` so the button has a name.
|
|
31
|
+
```jsx
|
|
32
|
+
import { Dropdown, Icon } from '@nurvus/ui';
|
|
33
|
+
|
|
34
|
+
<div style={ { display: 'flex', justifyContent: 'flex-end' } }>
|
|
35
|
+
<Dropdown
|
|
36
|
+
id="row-actions"
|
|
37
|
+
label={ <Icon name="more-horizontal" label="More actions" size="1.25em" /> }
|
|
38
|
+
align="end"
|
|
39
|
+
type="secondary"
|
|
40
|
+
size="small"
|
|
41
|
+
items={ [
|
|
42
|
+
{ label: 'Share', onSelect: () => {} },
|
|
43
|
+
{ label: 'Download', onSelect: () => {} },
|
|
44
|
+
{ label: 'Archive', onSelect: () => {} },
|
|
45
|
+
] }
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
```
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Styles for Dropdown (React and Respawn: same markup). The popup opens
|
|
2
|
+
// under the button like Select's list.
|
|
3
|
+
@import "../../styles/variables.scss";
|
|
4
|
+
|
|
5
|
+
$dropdown-speed: 0.15s;
|
|
6
|
+
|
|
7
|
+
.#{$cls-prefix}.dropdown {
|
|
8
|
+
position: relative;
|
|
9
|
+
display: inline-block;
|
|
10
|
+
|
|
11
|
+
.dropdown-trigger {
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: var(--space--8);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A turned corner: down while closed, up while open.
|
|
18
|
+
.dropdown-chevron {
|
|
19
|
+
width: 0.375rem;
|
|
20
|
+
height: 0.375rem;
|
|
21
|
+
margin-left: var(--space--2);
|
|
22
|
+
border-right: 1.5px solid currentColor;
|
|
23
|
+
border-bottom: 1.5px solid currentColor;
|
|
24
|
+
transform: translateY(-2px) rotate(45deg);
|
|
25
|
+
transition: transform $dropdown-speed ease;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&[data-open="true"] .dropdown-chevron { transform: translateY(2px) rotate(225deg); }
|
|
29
|
+
|
|
30
|
+
.dropdown-popup {
|
|
31
|
+
position: absolute;
|
|
32
|
+
z-index: 1000;
|
|
33
|
+
top: calc(100% + var(--space--4));
|
|
34
|
+
left: 0;
|
|
35
|
+
min-width: max(100%, 12rem);
|
|
36
|
+
max-width: 20rem;
|
|
37
|
+
padding: var(--space--4);
|
|
38
|
+
border: 1px solid var(--nv-border);
|
|
39
|
+
border-radius: 0.625rem;
|
|
40
|
+
background: var(--nv-surface);
|
|
41
|
+
box-shadow: 0 12px 32px rgb(0 0 0 / 0.24);
|
|
42
|
+
opacity: 0;
|
|
43
|
+
visibility: hidden;
|
|
44
|
+
transform: translateY(-0.25rem) scale(0.98);
|
|
45
|
+
transform-origin: top left;
|
|
46
|
+
transition: opacity $dropdown-speed ease, transform $dropdown-speed ease, visibility 0s $dropdown-speed;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&[data-align="end"] .dropdown-popup { left: auto; right: 0; transform-origin: top right; }
|
|
50
|
+
|
|
51
|
+
&[data-open="true"] .dropdown-popup {
|
|
52
|
+
opacity: 1;
|
|
53
|
+
visibility: visible;
|
|
54
|
+
transform: none;
|
|
55
|
+
transition: opacity $dropdown-speed ease, transform $dropdown-speed ease, visibility 0s 0s;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.menu-section + .menu-section { margin-top: var(--space--4); padding-top: var(--space--4); border-top: 1px solid var(--nv-border); }
|
|
59
|
+
.menu-heading { padding: var(--space--4) 0 0; }
|
|
60
|
+
.menu-title { padding: var(--space--2) var(--space--8); }
|
|
61
|
+
.menu-item { min-height: 1.75rem; padding-left: var(--space--8); }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@media (prefers-reduced-motion: reduce) {
|
|
65
|
+
.#{$cls-prefix}.dropdown .dropdown-popup,
|
|
66
|
+
.#{$cls-prefix}.dropdown .dropdown-chevron { transition: none; }
|
|
67
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import CONSTANT from '../../constants';
|
|
4
|
+
import Button, { ButtonSize, ButtonType } from '../Button/Button';
|
|
5
|
+
import Menu, { MenuItem, MenuSection } from '../Menu/Menu';
|
|
6
|
+
import { focusItem, triggerKey } from '../../dropdown';
|
|
7
|
+
import './Dropdown.scss';
|
|
8
|
+
|
|
9
|
+
export interface DropdownProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect'> {
|
|
10
|
+
/** What the button says (text, or an Icon with a label for an icon-only button). */
|
|
11
|
+
label: React.ReactNode;
|
|
12
|
+
/** The actions, in groups (each may have a title). */
|
|
13
|
+
sections?: MenuSection[];
|
|
14
|
+
/** Or the actions as one flat list. */
|
|
15
|
+
items?: MenuItem[];
|
|
16
|
+
/** Which edge of the button the menu lines up with. */
|
|
17
|
+
align?: 'start' | 'end';
|
|
18
|
+
/** The button's look. Defaults to secondary. */
|
|
19
|
+
type?: ButtonType;
|
|
20
|
+
/** The button's size. */
|
|
21
|
+
size?: ButtonSize;
|
|
22
|
+
/** Stops the button working. */
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/** Names the button and the menu ("<id>-button", "<id>-menu"). */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Custom class name. */
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A button that opens a menu of actions (the WAI-ARIA menu button pattern).
|
|
32
|
+
* A click, Enter, Space or ↓ opens it on its first item, ↑ on its last; inside,
|
|
33
|
+
* the Menu's keys work (↑ ↓ Home End, type a letter); choosing an action runs
|
|
34
|
+
* it, closes the menu and puts focus back on the button; Esc does the same
|
|
35
|
+
* without choosing; Tab or a click outside closes it.
|
|
36
|
+
*/
|
|
37
|
+
export default function Dropdown({
|
|
38
|
+
label,
|
|
39
|
+
sections,
|
|
40
|
+
items,
|
|
41
|
+
align = 'start',
|
|
42
|
+
type = 'secondary',
|
|
43
|
+
size = 'medium',
|
|
44
|
+
disabled = false,
|
|
45
|
+
id,
|
|
46
|
+
className,
|
|
47
|
+
...restProps
|
|
48
|
+
}: DropdownProps) {
|
|
49
|
+
const [open, setOpen] = React.useState(false);
|
|
50
|
+
const root = React.useRef<HTMLDivElement>(null);
|
|
51
|
+
const button = React.useRef<HTMLButtonElement>(null);
|
|
52
|
+
const pending = React.useRef<'first' | 'last' | null>(null);
|
|
53
|
+
|
|
54
|
+
// Focus goes into the menu once it shows.
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (open && pending.current && root.current) { focusItem(root.current, pending.current); pending.current = null; }
|
|
57
|
+
}, [open]);
|
|
58
|
+
|
|
59
|
+
// A press anywhere outside closes it.
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
if (!open) return undefined;
|
|
62
|
+
const away = (event: MouseEvent) => { if (root.current && !root.current.contains(event.target as Node)) setOpen(false); };
|
|
63
|
+
document.addEventListener('mousedown', away);
|
|
64
|
+
return () => document.removeEventListener('mousedown', away);
|
|
65
|
+
}, [open]);
|
|
66
|
+
|
|
67
|
+
const show = (which: 'first' | 'last') => { pending.current = which; setOpen(true); };
|
|
68
|
+
const close = (refocus: boolean) => { setOpen(false); if (refocus && button.current) button.current.focus(); };
|
|
69
|
+
|
|
70
|
+
// Choosing an action runs it, then closes the menu with focus on the button.
|
|
71
|
+
const wrap = (list: MenuItem[]): MenuItem[] => list.map((item) => ({
|
|
72
|
+
...item,
|
|
73
|
+
onSelect: (event) => { if (item.onSelect) item.onSelect(event); close(true); },
|
|
74
|
+
}));
|
|
75
|
+
const groups: MenuSection[] = (sections || [{ items: items || [] }]).map((s) => ({ ...s, items: wrap(s.items) }));
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div
|
|
79
|
+
ref={ root }
|
|
80
|
+
className={ classNames(className, 'dropdown', CONSTANT.CLASS_PREFIX) }
|
|
81
|
+
data-open={ open }
|
|
82
|
+
data-align={ align }
|
|
83
|
+
{ ...restProps }
|
|
84
|
+
onKeyDown={ (event) => {
|
|
85
|
+
if (event.key === 'Escape' && open) { event.preventDefault(); close(true); }
|
|
86
|
+
} }
|
|
87
|
+
onBlur={ (event) => { if (open && root.current && !root.current.contains(event.relatedTarget as Node)) setOpen(false); } }
|
|
88
|
+
>
|
|
89
|
+
<Button
|
|
90
|
+
ref={ button }
|
|
91
|
+
id={ `${id}-button` }
|
|
92
|
+
className="dropdown-trigger"
|
|
93
|
+
type={ type }
|
|
94
|
+
size={ size }
|
|
95
|
+
disabled={ disabled }
|
|
96
|
+
aria-haspopup="menu"
|
|
97
|
+
aria-expanded={ open }
|
|
98
|
+
aria-controls={ `${id}-menu` }
|
|
99
|
+
onClick={ () => (open ? close(false) : show('first')) }
|
|
100
|
+
onKeyDown={ (event) => { const which = triggerKey(event.nativeEvent); if (which) { event.preventDefault(); show(which); } } }
|
|
101
|
+
>
|
|
102
|
+
{ label }
|
|
103
|
+
<span className="dropdown-chevron" aria-hidden="true" />
|
|
104
|
+
</Button>
|
|
105
|
+
<div className="dropdown-popup">
|
|
106
|
+
<Menu kind="actions" id={ `${id}-menu` } aria-labelledby={ `${id}-button` } sections={ groups } />
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -1,32 +1,35 @@
|
|
|
1
|
+
A modal dialog over the whole screen. When it opens, focus moves into it and screen readers say its title and "dialog"; Tab stays inside it; Esc calls `onClose`; when it closes, focus goes back to the button that opened it. Close buttons belong in `headerActions`, and they should be real buttons.
|
|
2
|
+
|
|
1
3
|
```jsx
|
|
2
4
|
import React, { useState } from 'react';
|
|
3
|
-
import { Button, FullPageModal, Layout } from '@nurvus/ui';
|
|
5
|
+
import { Button, FullPageModal, Layout, Panel, Text } from '@nurvus/ui';
|
|
4
6
|
|
|
5
7
|
const MyApp = () => {
|
|
6
8
|
const [visible, setVisible] = useState(false);
|
|
7
|
-
|
|
8
|
-
const actions = (
|
|
9
|
-
<Layout display="flex">
|
|
10
|
-
<span>SAVE</span>
|
|
11
|
-
<span onClick={ () => setVisible(false) }>CLOSE</span>
|
|
12
|
-
</Layout>
|
|
13
|
-
);
|
|
9
|
+
const close = () => setVisible(false);
|
|
14
10
|
|
|
15
11
|
return (
|
|
16
12
|
<div>
|
|
17
|
-
<Button onClick={ () => setVisible(true) }>
|
|
18
|
-
Show Modal
|
|
19
|
-
</Button>
|
|
13
|
+
<Button onClick={ () => setVisible(true) }>Show the modal</Button>
|
|
20
14
|
<FullPageModal
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
id="settings-modal"
|
|
16
|
+
title="Settings"
|
|
23
17
|
visible={ visible }
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
onClose={ close }
|
|
19
|
+
headerActions={
|
|
20
|
+
<Layout display="flex" itemSpacing={ 8 }>
|
|
21
|
+
<Button size="small" onClick={ close }>Save</Button>
|
|
22
|
+
<Button size="small" type="secondary" onClick={ close }>Close</Button>
|
|
23
|
+
</Layout>
|
|
24
|
+
}
|
|
25
|
+
>
|
|
26
|
+
<Panel style={ { margin: 16 } }>
|
|
27
|
+
<Text>Press Tab: focus stays in here. Press Esc to close.</Text>
|
|
28
|
+
</Panel>
|
|
26
29
|
</FullPageModal>
|
|
27
30
|
</div>
|
|
28
31
|
);
|
|
29
|
-
}
|
|
32
|
+
};
|
|
30
33
|
|
|
31
34
|
<MyApp />
|
|
32
|
-
```
|
|
35
|
+
```
|
|
@@ -82,6 +82,11 @@
|
|
|
82
82
|
// Theme roles (it had fixed purples, so its title was dark on dark in light themes).
|
|
83
83
|
background-color: var(--nv-bg);
|
|
84
84
|
color: var(--nv-text);
|
|
85
|
+
overflow: auto;
|
|
86
|
+
|
|
87
|
+
// Focus lands on the whole modal when it opens (so screen readers say its
|
|
88
|
+
// name); a ring around the entire screen would only be noise.
|
|
89
|
+
&:focus { outline: none; }
|
|
85
90
|
|
|
86
91
|
.header {
|
|
87
92
|
padding: var(--space--12) var(--space--16);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import CONSTANT from '../../constants';
|
|
5
5
|
import Layout from '../Layout/Layout';
|
|
6
6
|
import Title from '../Title/Title';
|
|
7
|
+
import { dialogKeydown, focusDialog, restoreFocus } from '../../dialog';
|
|
7
8
|
import './FullPageModal.scss';
|
|
8
9
|
|
|
9
10
|
export interface FullPageModalProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
@@ -15,21 +16,46 @@ export interface FullPageModalProps extends Omit<React.HTMLAttributes<HTMLDivEle
|
|
|
15
16
|
headerActions?: React.ReactNode;
|
|
16
17
|
/** The modal's content. */
|
|
17
18
|
children?: React.ReactNode;
|
|
19
|
+
/** Called when someone presses Esc. Set visible to false in it to close the modal. */
|
|
20
|
+
onClose?: () => void;
|
|
21
|
+
/** Names the modal and its title: the title gets the id "<id>-title", and the modal is labelled by it. */
|
|
22
|
+
id?: string;
|
|
18
23
|
/** Custom class name. */
|
|
19
24
|
className?: string;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Shows content over the whole screen, rendered into `<body>`: a modal dialog
|
|
29
|
+
* (the WAI-ARIA dialog pattern). Opening it moves focus into it, and screen
|
|
30
|
+
* readers say its title and "dialog"; Tab stays inside; Esc calls onClose;
|
|
31
|
+
* closing it gives focus back to where it was.
|
|
32
|
+
*/
|
|
23
33
|
export default function FullPageModal({
|
|
24
34
|
children,
|
|
25
35
|
className,
|
|
26
36
|
headerActions,
|
|
27
37
|
title,
|
|
28
38
|
visible = false,
|
|
39
|
+
onClose,
|
|
40
|
+
id,
|
|
41
|
+
onKeyDown,
|
|
29
42
|
...restProps
|
|
30
43
|
}: FullPageModalProps) {
|
|
31
44
|
const [animationState, setAnimationState] = useState('');
|
|
32
45
|
const [isVisible, setIsVisible] = useState(visible);
|
|
46
|
+
const modalRef = useRef<HTMLDivElement>(null);
|
|
47
|
+
const openerRef = useRef<Element | null>(null);
|
|
48
|
+
|
|
49
|
+
// Focus in on open; back to the opener on close.
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (visible) {
|
|
52
|
+
openerRef.current = document.activeElement;
|
|
53
|
+
if (modalRef.current) focusDialog(modalRef.current);
|
|
54
|
+
} else if (openerRef.current) {
|
|
55
|
+
restoreFocus(openerRef.current);
|
|
56
|
+
openerRef.current = null;
|
|
57
|
+
}
|
|
58
|
+
}, [visible]);
|
|
33
59
|
|
|
34
60
|
// Clear animation and sync visibility states
|
|
35
61
|
function clearAnimation() {
|
|
@@ -53,15 +79,23 @@ export default function FullPageModal({
|
|
|
53
79
|
<div className={ `portal ${CONSTANT.CLASS_PREFIX}` } data-visible={ visible }>
|
|
54
80
|
{ isVisible ? <div className="mask" data-animate={ animationState } /> : null }
|
|
55
81
|
<div
|
|
82
|
+
ref={ modalRef }
|
|
56
83
|
className={ classNames(className, 'modal', CONSTANT.CLASS_PREFIX) }
|
|
57
84
|
data-visible={ isVisible }
|
|
58
85
|
data-animate={ animationState }
|
|
86
|
+
role="dialog"
|
|
87
|
+
aria-modal="true"
|
|
88
|
+
aria-labelledby={ id && title ? `${id}-title` : undefined }
|
|
89
|
+
aria-label={ !id && typeof title === 'string' ? title : undefined }
|
|
90
|
+
tabIndex={ -1 }
|
|
91
|
+
id={ id }
|
|
59
92
|
onAnimationEnd={ clearAnimation }
|
|
60
93
|
{ ...restProps }
|
|
94
|
+
onKeyDown={ (e) => { dialogKeydown(e.nativeEvent, e.currentTarget, onClose); if (onKeyDown) onKeyDown(e); } }
|
|
61
95
|
>
|
|
62
96
|
<div className="header">
|
|
63
97
|
<Layout display="flex" alignItems="center" justifyContent="space-between">
|
|
64
|
-
<Title>{ title }</Title>
|
|
98
|
+
<Title id={ id && title ? `${id}-title` : undefined }>{ title }</Title>
|
|
65
99
|
<div className="header-actions">{ headerActions }</div>
|
|
66
100
|
</Layout>
|
|
67
101
|
</div>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Lays its children out in equal columns. Columns never overflow the grid: a long word or a wide child shrinks its cell instead of pushing the page sideways.
|
|
2
|
+
|
|
3
|
+
`columns` can change at the breakpoints: `{ base: 1, sm: 2, lg: 3 }` is one column on phones, two from sm (40em, 640 pixels) and three from lg (64em, 1024 pixels). Make the window narrower to see it.
|
|
4
|
+
```jsx
|
|
5
|
+
import { Grid, Panel, Text } from '@nurvus/ui';
|
|
6
|
+
|
|
7
|
+
<Grid columns={ { base: 1, sm: 2, lg: 3 } } gap={ 16 }>
|
|
8
|
+
{ ['Checkout API', 'Search', 'Billing jobs', 'Images', 'Email', 'Webhooks'].map((name) => (
|
|
9
|
+
<Panel key={ name } title={ name }><Text tone="muted">Healthy</Text></Panel>
|
|
10
|
+
)) }
|
|
11
|
+
</Grid>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or no count at all: `minItemWidth` fits as many columns as there is room for, each at least that wide, and they share what is left. Good for cards and galleries.
|
|
15
|
+
```jsx
|
|
16
|
+
import { Grid, Icon, Stack, Text } from '@nurvus/ui';
|
|
17
|
+
|
|
18
|
+
<Grid minItemWidth="9rem" gap={ 12 }>
|
|
19
|
+
{ ['home', 'search', 'settings', 'user', 'bell', 'calendar', 'mail', 'star'].map((name) => (
|
|
20
|
+
<Stack key={ name } align="center" gap={ 4 } style={ { padding: 12, border: '1px solid var(--nv-border)', borderRadius: 8 } }>
|
|
21
|
+
<Icon name={ name } size="1.5em" />
|
|
22
|
+
<Text variant="caption">{ name }</Text>
|
|
23
|
+
</Stack>
|
|
24
|
+
)) }
|
|
25
|
+
</Grid>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
A fixed count, and a child that spans two columns with `style={ { gridColumn: 'span 2' } }`.
|
|
29
|
+
```jsx
|
|
30
|
+
import { Grid, Panel, Text } from '@nurvus/ui';
|
|
31
|
+
|
|
32
|
+
<Grid columns={ 4 } gap={ 12 }>
|
|
33
|
+
<Panel title="Revenue" style={ { gridColumn: 'span 2' } }><Text>$48,200</Text></Panel>
|
|
34
|
+
<Panel title="Orders"><Text>1,284</Text></Panel>
|
|
35
|
+
<Panel title="Refunds"><Text>12</Text></Panel>
|
|
36
|
+
</Grid>
|
|
37
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Styles for Grid (React and Respawn: same markup).
|
|
2
|
+
@import "../../styles/variables.scss";
|
|
3
|
+
@import "../../styles/breakpoints.scss";
|
|
4
|
+
|
|
5
|
+
$grid-steps: 0, 2, 4, 8, 12, 16, 24, 32, 48, 64;
|
|
6
|
+
|
|
7
|
+
.#{$cls-prefix}.grid {
|
|
8
|
+
display: grid;
|
|
9
|
+
grid-template-columns: minmax(0, 1fr);
|
|
10
|
+
|
|
11
|
+
// minmax(0, 1fr): equal columns that can shrink below their content, so a
|
|
12
|
+
// long word or a wide table can't push the grid off the screen.
|
|
13
|
+
@for $n from 1 through 12 {
|
|
14
|
+
&[data-columns="#{$n}"] { grid-template-columns: repeat($n, minmax(0, 1fr)); }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@each $bp, $width in $nurvus-breakpoints {
|
|
18
|
+
@media (min-width: $width) {
|
|
19
|
+
@for $n from 1 through 12 {
|
|
20
|
+
&[data-columns-#{$bp}="#{$n}"] { grid-template-columns: repeat($n, minmax(0, 1fr)); }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// As many columns as fit, each at least --nurvus-grid-min (never wider than the grid).
|
|
26
|
+
&[data-fit="true"] { grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--nurvus-grid-min, 15rem)), 1fr)); }
|
|
27
|
+
|
|
28
|
+
@each $n in $grid-steps {
|
|
29
|
+
&[data-gap="#{$n}"] { gap: var(--space--#{$n}); }
|
|
30
|
+
&[data-row-gap="#{$n}"] { row-gap: var(--space--#{$n}); }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&[data-align="start"] { align-items: start; }
|
|
34
|
+
&[data-align="center"] { align-items: center; }
|
|
35
|
+
&[data-align="end"] { align-items: end; }
|
|
36
|
+
&[data-align="stretch"] { align-items: stretch; }
|
|
37
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import CONSTANT from '../../constants';
|
|
4
|
+
import { Spacing } from '../../spacing';
|
|
5
|
+
import { Responsive, responsiveData } from '../../breakpoints';
|
|
6
|
+
import './Grid.scss';
|
|
7
|
+
|
|
8
|
+
export type GridColumns = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
9
|
+
|
|
10
|
+
export interface GridProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
11
|
+
/** How many equal columns: 1 to 12. Can change with the width: { base: 1, md: 2, lg: 3 }. */
|
|
12
|
+
columns?: Responsive<GridColumns>;
|
|
13
|
+
/** Instead of a count: as many columns as fit, each at least this wide (e.g. "15rem" or 240). They fill the row. */
|
|
14
|
+
minItemWidth?: string | number;
|
|
15
|
+
/** Space between cells, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
|
|
16
|
+
gap?: Spacing;
|
|
17
|
+
/** Space between rows when it differs from gap. */
|
|
18
|
+
rowGap?: Spacing;
|
|
19
|
+
/** How cells line up in their row. Defaults to stretch (equal heights). */
|
|
20
|
+
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
21
|
+
/** What to lay out. A child spans more columns with style={{ gridColumn: 'span 2' }}. */
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
/** Custom class name. */
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Lays its children out in columns: a fixed count that changes at the
|
|
29
|
+
* breakpoints (1 on phones, 3 on desktops), or as many as fit at a minimum
|
|
30
|
+
* width. Columns share the width equally and never overflow it.
|
|
31
|
+
*/
|
|
32
|
+
export default function Grid({
|
|
33
|
+
columns,
|
|
34
|
+
minItemWidth,
|
|
35
|
+
gap = 16,
|
|
36
|
+
rowGap,
|
|
37
|
+
align,
|
|
38
|
+
className,
|
|
39
|
+
style,
|
|
40
|
+
...restProps
|
|
41
|
+
}: GridProps) {
|
|
42
|
+
const fit = minItemWidth !== undefined;
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
className={ classNames(className, 'grid', CONSTANT.CLASS_PREFIX) }
|
|
46
|
+
{ ...(fit ? { 'data-fit': true } : responsiveData('columns', columns === undefined ? 1 : columns)) }
|
|
47
|
+
data-gap={ gap }
|
|
48
|
+
data-row-gap={ rowGap }
|
|
49
|
+
data-align={ align }
|
|
50
|
+
style={ fit ? { '--nurvus-grid-min': typeof minItemWidth === 'number' ? `${minItemWidth}px` : minItemWidth, ...style } as React.CSSProperties : style }
|
|
51
|
+
{ ...restProps }
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
min-width: $--space--24;
|
|
57
57
|
padding: 1px $--space--4;
|
|
58
58
|
text-align: center;
|
|
59
|
-
font-size:
|
|
59
|
+
font-size: 0.6875rem;
|
|
60
60
|
color: var(--nv-text-muted);
|
|
61
61
|
border: 1px solid var(--nv-border);
|
|
62
62
|
border-radius: $--radius--4;
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
.history-list-detail,
|
|
80
80
|
.history-list-time {
|
|
81
81
|
color: var(--nv-text-muted);
|
|
82
|
-
font-size:
|
|
82
|
+
font-size: 0.6875rem;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
.history-list-time {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
The light is the logo's Pulse (see [Brand](#/Foundations/Brand)). It is 2em by default, so it sizes with the text around it.
|
|
2
|
+
|
|
3
|
+
```jsx
|
|
4
|
+
import { Layout, Loader } from '@nurvus/ui';
|
|
5
|
+
|
|
6
|
+
<Layout display="flex" alignItems="center" itemSpacing={ 32 }>
|
|
7
|
+
<Loader size="1em" />
|
|
8
|
+
<Loader />
|
|
9
|
+
<Loader size={ 48 } />
|
|
10
|
+
<Loader size={ 96 } id="big-loader" label="Loading your workspace" />
|
|
11
|
+
</Layout>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
With `showLabel` the label shows beside it. Name what is loading where it helps: "Loading photos" says more than "Loading".
|
|
15
|
+
```jsx
|
|
16
|
+
import { Button, Layout, Loader, Text } from '@nurvus/ui';
|
|
17
|
+
|
|
18
|
+
const Fetch = () => {
|
|
19
|
+
const [loading, setLoading] = React.useState(true);
|
|
20
|
+
return (
|
|
21
|
+
<Layout itemSpacing={ 12 }>
|
|
22
|
+
{ loading ? <Loader label="Loading photos" showLabel /> : <Text>12 photos</Text> }
|
|
23
|
+
<div><Button size="small" type="secondary" onClick={ () => setLoading(!loading) }>{ loading ? 'Finish' : 'Load again' }</Button></div>
|
|
24
|
+
</Layout>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
<Fetch />
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
From about 64 pixels the segments look better with the logo's gradients: give it an `id` and they are drawn with gradients named after it.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Styles for Loader.tsx (and the Respawn Loader: same markup). The logo's
|
|
2
|
+
// Pulse: each segment brightens as a light runs round the ring.
|
|
3
|
+
@import "../../styles/variables.scss";
|
|
4
|
+
|
|
5
|
+
$loader-turn: 1.6s;
|
|
6
|
+
|
|
7
|
+
.#{$cls-prefix}.loader {
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: var(--space--8);
|
|
11
|
+
color: var(--nv-text-muted);
|
|
12
|
+
vertical-align: middle;
|
|
13
|
+
|
|
14
|
+
.loader-mark {
|
|
15
|
+
display: block;
|
|
16
|
+
flex: none;
|
|
17
|
+
overflow: visible;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.loader-seg {
|
|
21
|
+
opacity: 0.35;
|
|
22
|
+
animation: nurvus-loader-glint $loader-turn ease-in-out infinite;
|
|
23
|
+
// Each segment lights up when the light reaches its place on the ring.
|
|
24
|
+
animation-delay: calc(var(--nurvus-loader-at, 0) * #{$loader-turn} - #{$loader-turn});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Shown only to screen readers unless showLabel.
|
|
28
|
+
&[data-label="hidden"] .loader-label {
|
|
29
|
+
position: absolute;
|
|
30
|
+
width: 1px;
|
|
31
|
+
height: 1px;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
clip: rect(0 0 0 0);
|
|
34
|
+
white-space: nowrap;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@keyframes nurvus-loader-glint {
|
|
39
|
+
0%, 100% { opacity: 0.35; }
|
|
40
|
+
14% { opacity: 1; }
|
|
41
|
+
45% { opacity: 0.35; }
|
|
42
|
+
}
|