@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
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
Shows how far along something is. Give it a `label` (what is in progress) and, where the number helps, `showValue`. Screen readers hear "Uploading, progress bar, 40%" and hear it change.
|
|
2
|
+
|
|
2
3
|
```jsx
|
|
3
|
-
import Layout from '
|
|
4
|
+
import { Layout, Progress } from '@nurvus/ui';
|
|
4
5
|
|
|
5
|
-
<Layout itemSpacing={
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<Progress size="small" percent={ 100 } />
|
|
10
|
-
</Layout>
|
|
11
|
-
<Layout itemSpacing={ 12 } style={ { maxWidth: 105 } }>
|
|
12
|
-
<Progress size="medium" />
|
|
13
|
-
<Progress size="medium" percent={ 50 } />
|
|
14
|
-
<Progress size="medium" percent={ 100 } />
|
|
15
|
-
</Layout>
|
|
16
|
-
<Layout itemSpacing={ 12 } style={ { maxWidth: 226 } }>
|
|
17
|
-
<Progress size="large" />
|
|
18
|
-
<Progress size="large" percent={ 50 } />
|
|
19
|
-
<Progress size="large" percent={ 100 } />
|
|
20
|
-
</Layout>
|
|
6
|
+
<Layout itemSpacing={ 24 } style={ { maxWidth: 360 } }>
|
|
7
|
+
<Progress label="Uploading photos" percent={ 40 } showValue />
|
|
8
|
+
<Progress label="Storage used" percent={ 72 } size="large" showValue />
|
|
9
|
+
<Progress label="Step 2 of 5" percent={ 40 } size="small" />
|
|
21
10
|
</Layout>
|
|
22
11
|
```
|
|
23
12
|
|
|
24
|
-
|
|
13
|
+
The status colors the bar, and with `showValue` it is also an icon and a word (Done, Needs attention, Failed), so it never rests on color alone. Screen readers hear the word: "100%, Done".
|
|
25
14
|
```jsx
|
|
26
|
-
import Layout from '
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
import { Layout, Progress } from '@nurvus/ui';
|
|
16
|
+
|
|
17
|
+
<Layout itemSpacing={ 24 } style={ { maxWidth: 360 } }>
|
|
18
|
+
<Progress label="Backup" status="success" percent={ 100 } showValue />
|
|
19
|
+
<Progress label="Disk space" status="warning" percent={ 88 } showValue />
|
|
20
|
+
<Progress label="Import" status="critical" percent={ 35 } showValue />
|
|
21
|
+
</Layout>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Sizes. Where the words around the bar already say what it is, `hideLabel` keeps the label for screen readers only.
|
|
25
|
+
```jsx
|
|
26
|
+
import { Layout, Progress } from '@nurvus/ui';
|
|
27
|
+
|
|
28
|
+
<Layout itemSpacing={ 16 } style={ { maxWidth: 240 } }>
|
|
29
|
+
<Progress size="small" percent={ 50 } label="Small" hideLabel />
|
|
30
|
+
<Progress size="medium" percent={ 50 } label="Medium" hideLabel />
|
|
31
|
+
<Progress size="large" percent={ 50 } label="Large" hideLabel />
|
|
32
|
+
</Layout>
|
|
33
|
+
```
|
|
@@ -1,54 +1,59 @@
|
|
|
1
|
-
// Styles for Progress.
|
|
1
|
+
// Styles for Progress.tsx (and the Respawn Progress: same markup).
|
|
2
2
|
@import "../../styles/variables.scss";
|
|
3
3
|
@import "../../styles/tokens.scss";
|
|
4
4
|
|
|
5
5
|
.#{$cls-prefix}.progress {
|
|
6
|
-
|
|
6
|
+
color: var(--nv-text);
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
.progress-head {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: baseline;
|
|
11
|
+
justify-content: space-between;
|
|
12
|
+
gap: var(--space--8);
|
|
13
|
+
margin-bottom: var(--space--4);
|
|
14
|
+
font-size: var(--nv-type-caption-size);
|
|
15
|
+
line-height: var(--nv-type-caption-line);
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
height: 100%;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Size
|
|
18
|
-
&[data-size="small"] {
|
|
19
|
-
height: 4px;
|
|
20
|
-
}
|
|
18
|
+
.progress-label { font-weight: 500; }
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
.progress-value {
|
|
21
|
+
display: inline-flex;
|
|
22
|
+
align-items: center;
|
|
23
|
+
gap: var(--space--4);
|
|
24
|
+
margin-left: auto;
|
|
25
|
+
color: var(--nv-text-muted);
|
|
26
|
+
font-variant-numeric: tabular-nums;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
.progress-track {
|
|
30
|
+
background: var(--nv-surface);
|
|
31
|
+
// A hairline edge, so the empty track shows on any background (WCAG 1.4.11).
|
|
32
|
+
box-shadow: inset 0 0 0 1px var(--nv-border);
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
background-color: var(--nv-accent-fill);
|
|
34
|
-
}
|
|
35
|
+
.progress-track,
|
|
36
|
+
.bar {
|
|
37
|
+
border-radius: 0.75rem;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
40
|
+
.bar {
|
|
41
|
+
height: 100%;
|
|
42
|
+
transition: width 0.3s ease;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
// Size
|
|
46
|
+
&[data-size="small"] .progress-track { height: 0.25rem; }
|
|
47
|
+
&[data-size="medium"] .progress-track { height: 0.375rem; }
|
|
48
|
+
&[data-size="large"] .progress-track { height: 0.5rem; }
|
|
49
|
+
|
|
50
|
+
// Status: the bar's color, and the icon and word beside the value.
|
|
51
|
+
&[data-status="active"] .bar { background-color: var(--nv-accent-fill); }
|
|
52
|
+
&[data-status="success"] { .bar { background-color: var(--nv-success); } .progress-value { color: var(--nv-success); } }
|
|
53
|
+
&[data-status="warning"] { .bar { background-color: var(--nv-warning); } .progress-value { color: var(--nv-warning); } }
|
|
54
|
+
&[data-status="critical"] { .bar { background-color: var(--nv-danger); } .progress-value { color: var(--nv-danger); } }
|
|
55
|
+
}
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
background-color: var(--nv-danger);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
57
|
+
@media (prefers-reduced-motion: reduce) {
|
|
58
|
+
.#{$cls-prefix}.progress .bar { transition: none; }
|
|
54
59
|
}
|
|
@@ -1,36 +1,80 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import CONSTANT from '../../constants';
|
|
4
|
+
import Icon from '../Icon/Icon';
|
|
5
|
+
import { PROGRESS_STATUS, clampPercent, progressValueText, ProgressStatus } from '../../progress';
|
|
4
6
|
import './Progress.scss';
|
|
5
7
|
|
|
6
8
|
export type ProgressSize = 'small' | 'medium' | 'large';
|
|
7
|
-
export type ProgressStatus
|
|
9
|
+
export type { ProgressStatus };
|
|
8
10
|
|
|
9
|
-
export interface ProgressProps {
|
|
11
|
+
export interface ProgressProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
10
12
|
/** How far along, 0 to 100. */
|
|
11
13
|
percent?: number;
|
|
12
14
|
/** Bar height. */
|
|
13
15
|
size?: ProgressSize;
|
|
14
|
-
/** The bar color: active (accent), success, warning or critical (danger). */
|
|
16
|
+
/** The bar color: active (accent), success, warning or critical (danger). With a label or showValue, a status also shows as an icon and a word. */
|
|
15
17
|
status?: ProgressStatus;
|
|
18
|
+
/** What is in progress ("Uploading"): shown above the bar, and its name for screen readers. */
|
|
19
|
+
label?: string;
|
|
20
|
+
/** Keeps the label for screen readers only. */
|
|
21
|
+
hideLabel?: boolean;
|
|
22
|
+
/** Shows the percent (and the status, as an icon and a word) at the right, above the bar. */
|
|
23
|
+
showValue?: boolean;
|
|
24
|
+
/** What screen readers say for the value, instead of "40%" (e.g. "3 of 8 files"). */
|
|
25
|
+
valueText?: string;
|
|
16
26
|
/** Custom class name. */
|
|
17
27
|
className?: string;
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* A progress bar: how far along something is. Screen readers hear it as a
|
|
32
|
+
* progress bar with its label and value ("Uploading, progress bar, 40%").
|
|
33
|
+
* Its status is never color alone: with a label or showValue it shows as an
|
|
34
|
+
* icon and a word too, and screen readers hear the word.
|
|
35
|
+
*/
|
|
21
36
|
export default function Progress({
|
|
22
37
|
className,
|
|
23
38
|
percent = 0,
|
|
24
39
|
size = 'medium',
|
|
25
|
-
status = 'active'
|
|
40
|
+
status = 'active',
|
|
41
|
+
label,
|
|
42
|
+
hideLabel = false,
|
|
43
|
+
showValue = false,
|
|
44
|
+
valueText,
|
|
45
|
+
...restProps
|
|
26
46
|
}: ProgressProps) {
|
|
47
|
+
const value = clampPercent(percent);
|
|
48
|
+
const meaning = PROGRESS_STATUS[status] || PROGRESS_STATUS.active;
|
|
49
|
+
const head = (label && !hideLabel) || showValue;
|
|
27
50
|
return (
|
|
28
51
|
<div
|
|
29
52
|
className={ classNames(className, 'progress', CONSTANT.CLASS_PREFIX) }
|
|
30
53
|
data-size={ size }
|
|
31
54
|
data-status={ status }
|
|
55
|
+
role="progressbar"
|
|
56
|
+
aria-label={ label || 'Progress' }
|
|
57
|
+
aria-valuemin={ 0 }
|
|
58
|
+
aria-valuemax={ 100 }
|
|
59
|
+
aria-valuenow={ value }
|
|
60
|
+
aria-valuetext={ valueText || progressValueText(value, status) }
|
|
61
|
+
{ ...restProps }
|
|
32
62
|
>
|
|
33
|
-
|
|
63
|
+
{ head && (
|
|
64
|
+
<div className="progress-head">
|
|
65
|
+
{ label && !hideLabel && <span className="progress-label">{ label }</span> }
|
|
66
|
+
{ showValue && (
|
|
67
|
+
<span className="progress-value">
|
|
68
|
+
{ meaning.icon && <Icon name={ meaning.icon } /> }
|
|
69
|
+
{ meaning.word && <span className="progress-word">{ meaning.word }</span> }
|
|
70
|
+
<span>{ `${value}%` }</span>
|
|
71
|
+
</span>
|
|
72
|
+
) }
|
|
73
|
+
</div>
|
|
74
|
+
) }
|
|
75
|
+
<div className="progress-track">
|
|
76
|
+
<div className="bar" style={ { width: `${value}%` } } />
|
|
77
|
+
</div>
|
|
34
78
|
</div>
|
|
35
79
|
);
|
|
36
80
|
}
|
|
@@ -8,18 +8,18 @@ $select-speed: 0.12s;
|
|
|
8
8
|
position: relative;
|
|
9
9
|
display: inline-block;
|
|
10
10
|
max-width: 100%;
|
|
11
|
-
font-size:
|
|
12
|
-
line-height:
|
|
11
|
+
font-size: 0.875rem;
|
|
12
|
+
line-height: 1.25rem;
|
|
13
13
|
|
|
14
14
|
.select-trigger {
|
|
15
15
|
display: inline-flex;
|
|
16
16
|
align-items: center;
|
|
17
17
|
gap: var(--space--8);
|
|
18
18
|
max-width: 100%;
|
|
19
|
-
min-height:
|
|
19
|
+
min-height: 2rem;
|
|
20
20
|
padding: var(--space--4) var(--space--8) var(--space--4) var(--space--12);
|
|
21
21
|
border: 1px solid var(--nv-border-strong);
|
|
22
|
-
border-radius:
|
|
22
|
+
border-radius: 0.5rem;
|
|
23
23
|
background: var(--nv-surface);
|
|
24
24
|
color: var(--nv-text);
|
|
25
25
|
cursor: pointer;
|
|
@@ -47,13 +47,13 @@ $select-speed: 0.12s;
|
|
|
47
47
|
.select-chevron {
|
|
48
48
|
display: inline-flex;
|
|
49
49
|
flex: none;
|
|
50
|
-
width:
|
|
50
|
+
width: 1rem;
|
|
51
51
|
justify-content: center;
|
|
52
52
|
|
|
53
53
|
&::after {
|
|
54
54
|
content: '';
|
|
55
|
-
width:
|
|
56
|
-
height:
|
|
55
|
+
width: 0.375rem;
|
|
56
|
+
height: 0.375rem;
|
|
57
57
|
border-right: 1.5px solid currentColor;
|
|
58
58
|
border-bottom: 1.5px solid currentColor;
|
|
59
59
|
transform: translateY(-2px) rotate(45deg);
|
|
@@ -69,17 +69,18 @@ $select-speed: 0.12s;
|
|
|
69
69
|
top: calc(100% + var(--space--4));
|
|
70
70
|
left: 0;
|
|
71
71
|
min-width: 100%;
|
|
72
|
-
|
|
72
|
+
// Set --nurvus-select-list-height to make the list taller or shorter.
|
|
73
|
+
max-height: var(--nurvus-select-list-height, 22.5rem);
|
|
73
74
|
overflow: auto;
|
|
74
75
|
padding: var(--space--4);
|
|
75
76
|
border: 1px solid var(--nv-border);
|
|
76
|
-
border-radius:
|
|
77
|
+
border-radius: 0.625rem;
|
|
77
78
|
background: var(--nv-surface);
|
|
78
79
|
color: var(--nv-text);
|
|
79
80
|
box-shadow: 0 12px 32px rgb(0 0 0 / 0.24);
|
|
80
81
|
opacity: 0;
|
|
81
82
|
visibility: hidden;
|
|
82
|
-
transform: translateY(-
|
|
83
|
+
transform: translateY(-0.25rem) scale(0.98);
|
|
83
84
|
transform-origin: top left;
|
|
84
85
|
transition: opacity $select-speed ease, transform $select-speed ease, visibility 0s $select-speed;
|
|
85
86
|
}
|
|
@@ -103,8 +104,8 @@ $select-speed: 0.12s;
|
|
|
103
104
|
.select-group-label {
|
|
104
105
|
padding: var(--space--4) var(--space--8);
|
|
105
106
|
color: var(--nv-text-muted);
|
|
106
|
-
font-size:
|
|
107
|
-
line-height:
|
|
107
|
+
font-size: 0.75rem;
|
|
108
|
+
line-height: 1rem;
|
|
108
109
|
font-weight: 600;
|
|
109
110
|
letter-spacing: 0.04em;
|
|
110
111
|
text-transform: uppercase;
|
|
@@ -115,8 +116,8 @@ $select-speed: 0.12s;
|
|
|
115
116
|
display: flex;
|
|
116
117
|
align-items: center;
|
|
117
118
|
gap: var(--space--8);
|
|
118
|
-
padding:
|
|
119
|
-
border-radius:
|
|
119
|
+
padding: 0.375rem 2rem 0.375rem var(--space--8); // room on the right for the check
|
|
120
|
+
border-radius: 0.375rem;
|
|
120
121
|
cursor: pointer;
|
|
121
122
|
white-space: nowrap;
|
|
122
123
|
|
|
@@ -136,9 +137,9 @@ $select-speed: 0.12s;
|
|
|
136
137
|
content: '';
|
|
137
138
|
position: absolute;
|
|
138
139
|
top: 50%;
|
|
139
|
-
right:
|
|
140
|
-
width:
|
|
141
|
-
height:
|
|
140
|
+
right: 0.75rem;
|
|
141
|
+
width: 0.3125rem;
|
|
142
|
+
height: 0.625rem;
|
|
142
143
|
border-right: 2px solid var(--nv-accent);
|
|
143
144
|
border-bottom: 2px solid var(--nv-accent);
|
|
144
145
|
transform: translateY(-60%) rotate(45deg);
|
|
@@ -157,8 +158,8 @@ $select-speed: 0.12s;
|
|
|
157
158
|
|
|
158
159
|
.select-option-description {
|
|
159
160
|
color: var(--nv-text-muted);
|
|
160
|
-
font-size:
|
|
161
|
-
line-height:
|
|
161
|
+
font-size: 0.75rem;
|
|
162
|
+
line-height: 1rem;
|
|
162
163
|
font-weight: 400;
|
|
163
164
|
}
|
|
164
165
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
A column or a row with even space between the children, from the [4px grid](#/Foundations/Spacing). It spaces with CSS `gap`, so a row that wraps keeps its spacing on every line.
|
|
2
|
+
|
|
3
|
+
```jsx
|
|
4
|
+
import { Button, Stack, Tag, Text } from '@nurvus/ui';
|
|
5
|
+
|
|
6
|
+
<Stack gap={ 12 }>
|
|
7
|
+
<Text weight="semibold">Release 2.4</Text>
|
|
8
|
+
<Stack direction="row" gap={ 8 } align="center">
|
|
9
|
+
<Tag tone="success">Ready</Tag>
|
|
10
|
+
<Text tone="muted">All checks passed</Text>
|
|
11
|
+
</Stack>
|
|
12
|
+
<Stack direction="row" gap={ 8 }>
|
|
13
|
+
<Button>Publish</Button>
|
|
14
|
+
<Button type="secondary">Preview</Button>
|
|
15
|
+
</Stack>
|
|
16
|
+
</Stack>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The direction can change with the screen: `{ base: 'column', md: 'row' }` stacks on phones and sits in a row from the md breakpoint (48em, 768 pixels) up. Make the window narrower to see it.
|
|
20
|
+
```jsx
|
|
21
|
+
import { Panel, Stack, Text } from '@nurvus/ui';
|
|
22
|
+
|
|
23
|
+
<Stack direction={ { base: 'column', md: 'row' } } gap={ 16 }>
|
|
24
|
+
<Panel title="Plan" style={ { flex: 1 } }><Text>Pro, billed yearly</Text></Panel>
|
|
25
|
+
<Panel title="Seats" style={ { flex: 1 } }><Text>12 of 20 used</Text></Panel>
|
|
26
|
+
<Panel title="Renews" style={ { flex: 1 } }><Text>March 3</Text></Panel>
|
|
27
|
+
</Stack>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`justify="between"` pushes the ends apart; `wrap` lets a long row break onto more lines.
|
|
31
|
+
```jsx
|
|
32
|
+
import { Button, Stack, Tag, Text } from '@nurvus/ui';
|
|
33
|
+
|
|
34
|
+
<Stack gap={ 16 }>
|
|
35
|
+
<Stack direction="row" justify="between" align="center">
|
|
36
|
+
<Text weight="semibold">Filters</Text>
|
|
37
|
+
<Button size="small" type="secondary">Clear</Button>
|
|
38
|
+
</Stack>
|
|
39
|
+
<Stack direction="row" gap={ 8 } wrap>
|
|
40
|
+
{ ['React', 'Respawn', 'TypeScript', 'Themes', 'Icons', 'Accessibility', 'Spacing', 'Motion'].map((t) => <Tag key={ t }>{ t }</Tag>) }
|
|
41
|
+
</Stack>
|
|
42
|
+
</Stack>
|
|
43
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Styles for Stack (React and Respawn: same markup).
|
|
2
|
+
@import "../../styles/variables.scss";
|
|
3
|
+
@import "../../styles/breakpoints.scss";
|
|
4
|
+
|
|
5
|
+
$stack-steps: 0, 2, 4, 8, 12, 16, 24, 32, 48, 64;
|
|
6
|
+
|
|
7
|
+
.#{$cls-prefix}.stack {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
|
|
11
|
+
&[data-direction="row"] { flex-direction: row; }
|
|
12
|
+
|
|
13
|
+
@each $bp, $width in $nurvus-breakpoints {
|
|
14
|
+
@media (min-width: $width) {
|
|
15
|
+
&[data-direction-#{$bp}="column"] { flex-direction: column; }
|
|
16
|
+
&[data-direction-#{$bp}="row"] { flex-direction: row; }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@each $n in $stack-steps {
|
|
21
|
+
&[data-gap="#{$n}"] { gap: var(--space--#{$n}); }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&[data-align="start"] { align-items: flex-start; }
|
|
25
|
+
&[data-align="center"] { align-items: center; }
|
|
26
|
+
&[data-align="end"] { align-items: flex-end; }
|
|
27
|
+
&[data-align="stretch"] { align-items: stretch; }
|
|
28
|
+
&[data-align="baseline"] { align-items: baseline; }
|
|
29
|
+
|
|
30
|
+
&[data-justify="start"] { justify-content: flex-start; }
|
|
31
|
+
&[data-justify="center"] { justify-content: center; }
|
|
32
|
+
&[data-justify="end"] { justify-content: flex-end; }
|
|
33
|
+
&[data-justify="between"] { justify-content: space-between; }
|
|
34
|
+
|
|
35
|
+
&[data-wrap="true"] { flex-wrap: wrap; }
|
|
36
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 './Stack.scss';
|
|
7
|
+
|
|
8
|
+
export type StackDirection = 'column' | 'row';
|
|
9
|
+
|
|
10
|
+
export interface StackProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
11
|
+
/** column (top to bottom, the default) or row. Can change with the width: { base: 'column', md: 'row' }. */
|
|
12
|
+
direction?: Responsive<StackDirection>;
|
|
13
|
+
/** Space between the children, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
|
|
14
|
+
gap?: Spacing;
|
|
15
|
+
/** How the children line up across the stack. */
|
|
16
|
+
align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
|
|
17
|
+
/** How the children spread along the stack. */
|
|
18
|
+
justify?: 'start' | 'center' | 'end' | 'between';
|
|
19
|
+
/** Lets a row wrap onto more lines when it runs out of room. */
|
|
20
|
+
wrap?: boolean;
|
|
21
|
+
/** What to lay out. */
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
/** Custom class name. */
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Puts its children in a column or a row with even space between them, from
|
|
29
|
+
* the 4px grid (CSS gap, so wrapped rows keep their spacing too). The
|
|
30
|
+
* direction can change at a breakpoint: a column on phones, a row from md up.
|
|
31
|
+
*/
|
|
32
|
+
export default function Stack({
|
|
33
|
+
direction = 'column',
|
|
34
|
+
gap = 16,
|
|
35
|
+
align,
|
|
36
|
+
justify,
|
|
37
|
+
wrap = false,
|
|
38
|
+
className,
|
|
39
|
+
...restProps
|
|
40
|
+
}: StackProps) {
|
|
41
|
+
return (
|
|
42
|
+
<div
|
|
43
|
+
className={ classNames(className, 'stack', CONSTANT.CLASS_PREFIX) }
|
|
44
|
+
{ ...responsiveData('direction', direction) }
|
|
45
|
+
data-gap={ gap }
|
|
46
|
+
data-align={ align }
|
|
47
|
+
data-justify={ justify }
|
|
48
|
+
data-wrap={ wrap || undefined }
|
|
49
|
+
{ ...restProps }
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
// The tone mixed with a fifth of the text color: on its own tint (and on a
|
|
13
13
|
// Panel's surface) every tone keeps 4.5:1 in every theme.
|
|
14
14
|
color: color-mix(in srgb, var(--tag-color) 80%, var(--nv-text));
|
|
15
|
-
font-size:
|
|
15
|
+
font-size: 0.75rem;
|
|
16
16
|
font-weight: 500;
|
|
17
|
-
line-height:
|
|
17
|
+
line-height: 1.125rem;
|
|
18
18
|
white-space: nowrap;
|
|
19
19
|
|
|
20
20
|
&[data-tone="accent"] { --tag-color: var(--nv-accent); }
|
|
@@ -18,28 +18,28 @@
|
|
|
18
18
|
|
|
19
19
|
@at-root {
|
|
20
20
|
h1#{&} {
|
|
21
|
-
font-size:
|
|
21
|
+
font-size: 1.5rem;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
h2#{&} {
|
|
25
|
-
font-size:
|
|
25
|
+
font-size: 1.25rem;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
h3#{&} {
|
|
29
|
-
font-size:
|
|
29
|
+
font-size: 1.125rem;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
h4#{&} {
|
|
33
|
-
font-size:
|
|
33
|
+
font-size: 1rem;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
h5#{&} {
|
|
37
|
-
font-size:
|
|
37
|
+
font-size: 0.875rem;
|
|
38
38
|
font-weight: 500;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
h6#{&} {
|
|
42
|
-
font-size:
|
|
42
|
+
font-size: 0.75rem;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
**Tree
|
|
1
|
+
**Tree is a Menu that picks.** `<Tree />` and `<Menu kind="tree" />` are the same thing: rows to choose from on the page (layers, folders, an outline). For links or commands, use [Menu](#/Components/Menu) with links or actions: the same look, and screen readers hear each as what it is.
|
|
2
2
|
|
|
3
3
|
A list of rows to pick from, nested like a layers panel. Click a row, or use the keyboard: Tab reaches the active row, ↑ ↓ move, → goes to a child row, ← to its parent, Enter or Space picks.
|
|
4
4
|
```jsx
|
package/src/css.ts
CHANGED
|
@@ -6,10 +6,15 @@ import './components/ButtonGroup/ButtonGroup.scss';
|
|
|
6
6
|
import './components/FullPageModal/FullPageModal.scss';
|
|
7
7
|
import './components/HistoryList/HistoryList.scss';
|
|
8
8
|
import './components/Layout/Layout.scss';
|
|
9
|
+
import './components/Stack/Stack.scss';
|
|
10
|
+
import './components/Grid/Grid.scss';
|
|
9
11
|
import './components/Link/Link.scss';
|
|
10
12
|
import './components/Icon/Icon.scss';
|
|
13
|
+
import './components/Loader/Loader.scss';
|
|
11
14
|
import './components/Tree/Tree.scss';
|
|
12
15
|
import './components/Menu/Menu.scss';
|
|
16
|
+
import './components/Dropdown/Dropdown.scss';
|
|
17
|
+
import './components/Anchor/Anchor.scss';
|
|
13
18
|
import './components/Select/Select.scss';
|
|
14
19
|
import './components/Panel/Panel.scss';
|
|
15
20
|
import './components/Progress/Progress.scss';
|
package/src/dialog.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Dialog rules shared by the React and the Respawn FullPageModal (no React
|
|
2
|
+
// here): what can take focus inside, Tab kept inside, Esc to close.
|
|
3
|
+
|
|
4
|
+
const FOCUSABLE = [
|
|
5
|
+
'a[href]', 'area[href]', 'button:not([disabled])', 'input:not([disabled]):not([type="hidden"])',
|
|
6
|
+
'select:not([disabled])', 'textarea:not([disabled])', 'iframe', '[contenteditable="true"]', '[tabindex]',
|
|
7
|
+
].join(',');
|
|
8
|
+
|
|
9
|
+
/** The elements Tab can reach inside `root`, in order (shown ones, not tabindex="-1"). */
|
|
10
|
+
export function focusables(root: HTMLElement): HTMLElement[] {
|
|
11
|
+
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE))
|
|
12
|
+
.filter((el) => el.tabIndex >= 0 && el.getClientRects().length > 0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The keys of a modal dialog (the WAI-ARIA dialog pattern): Tab and
|
|
17
|
+
* Shift+Tab go round the dialog's own controls and never leave it; Esc calls
|
|
18
|
+
* onClose. Returns true when it used the key.
|
|
19
|
+
*/
|
|
20
|
+
export function dialogKeydown(event: KeyboardEvent, dialog: HTMLElement, onClose?: () => void): boolean {
|
|
21
|
+
if (event.key === 'Escape') {
|
|
22
|
+
if (!onClose) return false;
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
onClose();
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (event.key !== 'Tab') return false;
|
|
28
|
+
const stops = focusables(dialog);
|
|
29
|
+
if (!stops.length) { event.preventDefault(); dialog.focus(); return true; }
|
|
30
|
+
const first = stops[0];
|
|
31
|
+
const last = stops[stops.length - 1];
|
|
32
|
+
const at = document.activeElement;
|
|
33
|
+
if (event.shiftKey && (at === first || at === dialog)) { event.preventDefault(); last.focus(); return true; }
|
|
34
|
+
if (!event.shiftKey && at === last) { event.preventDefault(); first.focus(); return true; }
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Moves focus to the dialog itself once it shows (screen readers then say its name and "dialog"). */
|
|
39
|
+
export function focusDialog(dialog: HTMLElement): void {
|
|
40
|
+
const go = () => { if (dialog.isConnected) dialog.focus({ preventScroll: true }); };
|
|
41
|
+
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(go); else go();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Gives focus back to what had it before the dialog opened, if it is still on the page. */
|
|
45
|
+
export function restoreFocus(opener: Element | null): void {
|
|
46
|
+
if (opener && (opener as HTMLElement).focus && opener.isConnected) (opener as HTMLElement).focus({ preventScroll: true });
|
|
47
|
+
}
|
package/src/dropdown.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Dropdown rules shared by the React and the Respawn Dropdown (no React here):
|
|
2
|
+
// the WAI-ARIA menu button pattern's keys and focus.
|
|
3
|
+
|
|
4
|
+
/** The menu's items, in order. */
|
|
5
|
+
export const menuItems = (root: HTMLElement): HTMLElement[] => Array.from(root.querySelectorAll<HTMLElement>('.dropdown-popup [role="menuitem"]'));
|
|
6
|
+
|
|
7
|
+
/** Moves focus to the first or last item (and makes it the menu's Tab stop). */
|
|
8
|
+
export function focusItem(root: HTMLElement, which: 'first' | 'last'): void {
|
|
9
|
+
const items = menuItems(root);
|
|
10
|
+
const item = which === 'first' ? items[0] : items[items.length - 1];
|
|
11
|
+
if (!item) return;
|
|
12
|
+
items.forEach((i) => i.setAttribute('tabindex', i === item ? '0' : '-1'));
|
|
13
|
+
item.focus();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Keys on the button: ↓ (or Enter / Space, which click it) opens the menu on
|
|
18
|
+
* its first item, ↑ on its last. Returns which item to focus, or null.
|
|
19
|
+
*/
|
|
20
|
+
export function triggerKey(event: KeyboardEvent): 'first' | 'last' | null {
|
|
21
|
+
if (event.key === 'ArrowDown') return 'first';
|
|
22
|
+
if (event.key === 'ArrowUp') return 'last';
|
|
23
|
+
return null;
|
|
24
|
+
}
|