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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +11 -1
  2. package/dist/icons.svg +73 -0
  3. package/dist/index.js +1 -1
  4. package/dist/nurvus.css +13 -10
  5. package/dist/respawn.js +1 -1
  6. package/dist/types/breakpoints.d.ts +14 -0
  7. package/dist/types/components/FullPageModal/FullPageModal.d.ts +11 -2
  8. package/dist/types/components/Grid/Grid.d.ts +26 -0
  9. package/dist/types/components/Loader/Loader.d.ts +21 -0
  10. package/dist/types/components/Menu/Menu.d.ts +54 -19
  11. package/dist/types/components/Progress/Progress.d.ts +19 -5
  12. package/dist/types/components/Stack/Stack.d.ts +26 -0
  13. package/dist/types/dialog.d.ts +12 -0
  14. package/dist/types/icons.d.ts +28 -0
  15. package/dist/types/index.d.ts +9 -1
  16. package/dist/types/loader.d.ts +28 -0
  17. package/dist/types/logo.d.ts +5 -0
  18. package/dist/types/menu.d.ts +43 -14
  19. package/dist/types/progress.d.ts +11 -0
  20. package/dist/types/respawn/FullPageModal.d.ts +7 -1
  21. package/dist/types/respawn/Grid.d.ts +21 -0
  22. package/dist/types/respawn/Loader.d.ts +18 -0
  23. package/dist/types/respawn/Menu.d.ts +45 -15
  24. package/dist/types/respawn/Progress.d.ts +18 -6
  25. package/dist/types/respawn/Stack.d.ts +21 -0
  26. package/dist/types/respawn/index.d.ts +9 -1
  27. package/package.json +1 -3
  28. package/src/breakpoints.ts +28 -0
  29. package/src/components/Button/Button.scss +20 -20
  30. package/src/components/FullPageModal/FullPageModal.md +20 -17
  31. package/src/components/FullPageModal/FullPageModal.scss +5 -0
  32. package/src/components/FullPageModal/FullPageModal.tsx +37 -3
  33. package/src/components/Grid/Grid.md +37 -0
  34. package/src/components/Grid/Grid.scss +37 -0
  35. package/src/components/Grid/Grid.tsx +54 -0
  36. package/src/components/HistoryList/HistoryList.scss +2 -2
  37. package/src/components/Loader/Loader.md +30 -0
  38. package/src/components/Loader/Loader.scss +42 -0
  39. package/src/components/Loader/Loader.tsx +68 -0
  40. package/src/components/Menu/Menu.md +67 -3
  41. package/src/components/Menu/Menu.scss +48 -18
  42. package/src/components/Menu/Menu.tsx +146 -39
  43. package/src/components/Progress/Progress.md +27 -26
  44. package/src/components/Progress/Progress.scss +41 -36
  45. package/src/components/Progress/Progress.tsx +50 -6
  46. package/src/components/Select/Select.scss +20 -19
  47. package/src/components/Stack/Stack.md +43 -0
  48. package/src/components/Stack/Stack.scss +36 -0
  49. package/src/components/Stack/Stack.tsx +52 -0
  50. package/src/components/Table/Table.scss +1 -1
  51. package/src/components/Tag/Tag.scss +2 -2
  52. package/src/components/Title/Title.scss +6 -6
  53. package/src/components/Tree/Tree.md +1 -1
  54. package/src/css.ts +3 -0
  55. package/src/dialog.ts +47 -0
  56. package/src/icons.ts +29 -0
  57. package/src/index.ts +9 -1
  58. package/src/loader.ts +43 -0
  59. package/src/logo.ts +12 -0
  60. package/src/menu.ts +91 -21
  61. package/src/progress.ts +21 -0
  62. package/src/respawn/FullPageModal.ts +30 -3
  63. package/src/respawn/Grid.ts +41 -0
  64. package/src/respawn/Loader.ts +77 -0
  65. package/src/respawn/Menu.ts +138 -34
  66. package/src/respawn/Progress.ts +56 -13
  67. package/src/respawn/Stack.ts +37 -0
  68. package/src/respawn/index.ts +9 -1
  69. package/src/styles/breakpoints.scss +3 -0
  70. package/src/styles/theme.scss +55 -55
  71. package/src/styles/type.json +9 -9
@@ -1,15 +1,27 @@
1
+ import { ProgressStatus } from '../progress';
2
+ import { ElementProps } from './spawn';
1
3
  import { NurvusElement } from './update';
2
4
  export type ProgressSize = 'small' | 'medium' | 'large';
3
- export type ProgressStatus = 'active' | 'success' | 'warning' | 'critical';
4
- export interface ProgressProps {
5
+ export type { ProgressStatus };
6
+ export interface ProgressProps extends ElementProps {
5
7
  /** How far along, 0 to 100. */
6
8
  percent?: number;
7
9
  /** Bar height. */
8
10
  size?: ProgressSize;
9
- /** The bar color: active (accent), success, warning or critical (danger). */
11
+ /** 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. */
10
12
  status?: ProgressStatus;
11
- /** Custom class name. */
12
- className?: string;
13
+ /** What is in progress ("Uploading"): shown above the bar, and its name for screen readers. */
14
+ label?: string;
15
+ /** Keeps the label for screen readers only. */
16
+ hideLabel?: boolean;
17
+ /** Shows the percent (and the status, as an icon and a word) at the right, above the bar. */
18
+ showValue?: boolean;
19
+ /** What screen readers say for the value, instead of "40%" (e.g. "3 of 8 files"). */
20
+ valueText?: string;
13
21
  }
14
- /** A progress bar. Like the React one, it takes no other attributes. */
22
+ /**
23
+ * A progress bar, the same markup as the React one: a progressbar with its
24
+ * label and value for screen readers, and the status as an icon and a word
25
+ * when it has a label or showValue. bar.update({ percent: 60 }) moves it.
26
+ */
15
27
  export default function Progress(props?: ProgressProps): NurvusElement<HTMLDivElement, ProgressProps>;
@@ -0,0 +1,21 @@
1
+ import { Spacing } from '../spacing';
2
+ import { Responsive } from '../breakpoints';
3
+ import { Child, ElementProps } from './spawn';
4
+ import { NurvusElement } from './update';
5
+ export type StackDirection = 'column' | 'row';
6
+ export interface StackProps extends ElementProps {
7
+ /** column (top to bottom, the default) or row. Can change with the width: { base: 'column', md: 'row' }. */
8
+ direction?: Responsive<StackDirection>;
9
+ /** Space between the children, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. */
10
+ gap?: Spacing;
11
+ /** How the children line up across the stack. */
12
+ align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
13
+ /** How the children spread along the stack. */
14
+ justify?: 'start' | 'center' | 'end' | 'between';
15
+ /** Lets a row wrap onto more lines when it runs out of room. */
16
+ wrap?: boolean;
17
+ /** What to lay out. */
18
+ children?: Child;
19
+ }
20
+ /** A column or a row with even space between the children, the same markup as the React Stack. */
21
+ export default function Stack(props?: StackProps): NurvusElement<HTMLDivElement, StackProps>;
@@ -21,8 +21,16 @@ export { ICONS, ICON_NAMES } from '../icons';
21
21
  export type { IconName, IconNode } from '../icons';
22
22
  export { default as Tree } from './Tree';
23
23
  export type { TreeProps, TreeItem } from './Tree';
24
+ export { default as Stack } from './Stack';
25
+ export type { StackProps, StackDirection } from './Stack';
26
+ export { default as Grid } from './Grid';
27
+ export type { GridProps, GridColumns } from './Grid';
28
+ export { BREAKPOINTS, isAtLeast } from '../breakpoints';
29
+ export type { Breakpoint, Responsive } from '../breakpoints';
30
+ export { default as Loader } from './Loader';
31
+ export type { LoaderProps } from './Loader';
24
32
  export { default as Menu } from './Menu';
25
- export type { MenuProps, MenuItem, MenuSection } from './Menu';
33
+ export type { MenuProps, MenuListProps, MenuTreeProps, MenuItem, MenuSection, MenuKind } from './Menu';
26
34
  export { default as Select } from './Select';
27
35
  export type { SelectProps, SelectOption, SelectOptionState } from './Select';
28
36
  export { default as FullPageModal } from './FullPageModal';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nurvus/ui",
3
- "version": "0.1.0-alpha.15",
3
+ "version": "0.1.0-alpha.16",
4
4
  "description": "NURVUS Design System",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -68,8 +68,6 @@
68
68
  "@fontsource-variable/inter": "^5.3.0",
69
69
  "@fontsource/jetbrains-mono": "^5.3.0",
70
70
  "@lezer/highlight": "^1.2.5",
71
- "@material-ui/core": "^4.12.3",
72
- "@material-ui/icons": "^4.11.2",
73
71
  "@types/react": "^17.0.94",
74
72
  "@types/react-dom": "^17.0.26",
75
73
  "@vitejs/plugin-react": "^6.3.0",
@@ -0,0 +1,28 @@
1
+ // The breakpoints: where layouts change as the screen widens. In em, so they
2
+ // follow the reader's text size (at the default 16px: 640, 768, 1024, 1280).
3
+ // Shared by Grid, Stack and your own code (no React here).
4
+
5
+ export type Breakpoint = 'sm' | 'md' | 'lg' | 'xl';
6
+
7
+ /** Each breakpoint's min-width: from this width up, the `sm`/`md`/`lg`/`xl` value applies. */
8
+ export const BREAKPOINTS: Record<Breakpoint, string> = { sm: '40em', md: '48em', lg: '64em', xl: '80em' };
9
+
10
+ /** A value for every width (`base`), changing from a breakpoint up: { base: 1, md: 2, lg: 3 }. */
11
+ export type Responsive<T> = T | ({ base?: T } & Partial<Record<Breakpoint, T>>);
12
+
13
+ /** `true` once the window is at least as wide as `breakpoint` (for your own code). */
14
+ export const isAtLeast = (breakpoint: Breakpoint): boolean =>
15
+ typeof window !== 'undefined' && !!window.matchMedia && window.matchMedia(`(min-width: ${BREAKPOINTS[breakpoint]})`).matches;
16
+
17
+ /**
18
+ * The data attributes for a responsive value: data-<name>="base value" and
19
+ * data-<name>-md="…" for each breakpoint given. The CSS reads them.
20
+ */
21
+ export function responsiveData<T>(name: string, value: Responsive<T> | undefined): Record<string, T | undefined> {
22
+ if (value === undefined || value === null) return {};
23
+ if (typeof value !== 'object') return { [`data-${name}`]: value as T };
24
+ const v = value as { base?: T } & Partial<Record<Breakpoint, T>>;
25
+ const out: Record<string, T | undefined> = { [`data-${name}`]: v.base };
26
+ (Object.keys(BREAKPOINTS) as Breakpoint[]).forEach((bp) => { if (v[bp] !== undefined) out[`data-${name}-${bp}`] = v[bp]; });
27
+ return out;
28
+ }
@@ -64,47 +64,47 @@
64
64
 
65
65
  // Sizes
66
66
  &[data-size="extra-large"] {
67
- height: 56px;
68
- border-radius: 12px;
69
- padding: 0 16px 0 16px;
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: 19.6px;
72
+ line-height: 1.225rem;
73
73
  }
74
74
 
75
75
  &[data-size="large"] {
76
- height: 48px;
77
- border-radius: 12px;
78
- padding: 0 16px 0 16px;
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: 19.6px;
81
+ line-height: 1.225rem;
82
82
  }
83
83
 
84
84
  &[data-size="medium"] {
85
- height: 40px;
86
- border-radius: 12px;
87
- padding: 0 14px 0 14px;
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: 19.6px;
90
+ line-height: 1.225rem;
91
91
  }
92
92
 
93
93
  &[data-size="small"] {
94
- height: 32px;
95
- border-radius: 10px;
96
- padding: 0 12px 0 12px;
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: 19.6px;
99
+ line-height: 1.225rem;
100
100
  }
101
101
 
102
102
  &[data-size="mini"] {
103
- height: 24px;
104
- border-radius: 8px;
105
- padding: 0 10px 0 10px;
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: 16.8px;
108
+ line-height: 1.05rem;
109
109
  }
110
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
- title="My Modal"
22
- headerActions={ actions }
15
+ id="settings-modal"
16
+ title="Settings"
23
17
  visible={ visible }
24
- >
25
- Modal Stuff
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
- /** Shows additional content over the whole screen, rendered into `<body>`. */
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: 11px;
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: 11px;
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
+ }
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import { loaderRings, LOGO_VIEWBOX } from '../../loader';
5
+ import './Loader.scss';
6
+
7
+ export interface LoaderProps extends React.HTMLAttributes<HTMLDivElement> {
8
+ /** Width and height of the mark. Defaults to 2em (twice the text size). A number is pixels. */
9
+ size?: number | string;
10
+ /** What is loading, for screen readers ("Loading photos"). Defaults to "Loading". */
11
+ label?: string;
12
+ /** Shows the label beside the mark, not only to screen readers. */
13
+ showLabel?: boolean;
14
+ /** Fills the segments with the logo's gradients (for big loaders); their ids start with this. Without it, one color each. */
15
+ id?: string;
16
+ /** Custom class name. */
17
+ className?: string;
18
+ }
19
+
20
+ /**
21
+ * Shows that something is loading: the NURVUS mark with a light running round
22
+ * it (the logo's Pulse). Screen readers hear the label once, politely
23
+ * (role="status"). The light keeps running with reduced motion: it only
24
+ * changes brightness, nothing moves, and a loader that stopped would look
25
+ * stuck (WCAG 2.2.2 counts a loading animation as essential).
26
+ */
27
+ export default function Loader({
28
+ size = '2em',
29
+ label = 'Loading',
30
+ showLabel = false,
31
+ id,
32
+ className,
33
+ ...restProps
34
+ }: LoaderProps) {
35
+ const { inner, outer, gradients } = loaderRings(id);
36
+ const ring = (cls: string, segments: typeof inner) => (
37
+ <g className={ `loader-ring ${cls}` }>
38
+ { segments.map((s, i) => (
39
+ <path key={ i } className="loader-seg" d={ s.d } fill={ s.fill } style={ { '--nurvus-loader-at': String(s.angle) } as React.CSSProperties } />
40
+ )) }
41
+ </g>
42
+ );
43
+ return (
44
+ <div
45
+ className={ classNames(className, 'loader', CONSTANT.CLASS_PREFIX) }
46
+ role="status"
47
+ data-label={ showLabel ? 'shown' : 'hidden' }
48
+ id={ id }
49
+ { ...restProps }
50
+ >
51
+ <svg className="loader-mark" viewBox={ LOGO_VIEWBOX } width={ size } height={ size } aria-hidden="true" focusable="false">
52
+ { gradients.length > 0 && (
53
+ <defs>
54
+ { gradients.map((g) => (
55
+ <linearGradient key={ g.id } id={ g.id } gradientUnits="userSpaceOnUse" x1={ g.x1 } y1={ g.y1 } x2={ g.x2 } y2={ g.y2 }>
56
+ <stop stopColor={ g.from } />
57
+ <stop offset="1" stopColor={ g.to } />
58
+ </linearGradient>
59
+ )) }
60
+ </defs>
61
+ ) }
62
+ { ring('loader-inner', inner) }
63
+ { ring('loader-outer', outer) }
64
+ </svg>
65
+ <span className="loader-label">{ label }</span>
66
+ </div>
67
+ );
68
+ }