@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.
Files changed (82) hide show
  1. package/README.md +13 -0
  2. package/dist/icons.svg +73 -0
  3. package/dist/index.js +1 -1
  4. package/dist/nurvus.css +14 -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/Icon/Icon.d.ts +20 -0
  10. package/dist/types/components/Loader/Loader.d.ts +21 -0
  11. package/dist/types/components/Menu/Menu.d.ts +54 -19
  12. package/dist/types/components/Progress/Progress.d.ts +19 -5
  13. package/dist/types/components/Stack/Stack.d.ts +26 -0
  14. package/dist/types/dialog.d.ts +12 -0
  15. package/dist/types/icons.d.ts +83 -0
  16. package/dist/types/index.d.ts +13 -1
  17. package/dist/types/loader.d.ts +28 -0
  18. package/dist/types/logo.d.ts +5 -0
  19. package/dist/types/menu.d.ts +43 -14
  20. package/dist/types/progress.d.ts +11 -0
  21. package/dist/types/respawn/FullPageModal.d.ts +7 -1
  22. package/dist/types/respawn/Grid.d.ts +21 -0
  23. package/dist/types/respawn/Icon.d.ts +22 -0
  24. package/dist/types/respawn/Loader.d.ts +18 -0
  25. package/dist/types/respawn/Menu.d.ts +45 -15
  26. package/dist/types/respawn/Progress.d.ts +18 -6
  27. package/dist/types/respawn/Stack.d.ts +21 -0
  28. package/dist/types/respawn/index.d.ts +13 -1
  29. package/dist/types/respawn/spawn.d.ts +2 -0
  30. package/package.json +1 -3
  31. package/src/breakpoints.ts +28 -0
  32. package/src/components/Button/Button.scss +20 -20
  33. package/src/components/ButtonGroup/ButtonGroup.md +8 -12
  34. package/src/components/FullPageModal/FullPageModal.md +20 -17
  35. package/src/components/FullPageModal/FullPageModal.scss +5 -0
  36. package/src/components/FullPageModal/FullPageModal.tsx +37 -3
  37. package/src/components/Grid/Grid.md +37 -0
  38. package/src/components/Grid/Grid.scss +37 -0
  39. package/src/components/Grid/Grid.tsx +54 -0
  40. package/src/components/HistoryList/HistoryList.scss +2 -2
  41. package/src/components/Icon/Icon.md +22 -0
  42. package/src/components/Icon/Icon.scss +10 -0
  43. package/src/components/Icon/Icon.tsx +45 -0
  44. package/src/components/Layout/Layout.md +10 -18
  45. package/src/components/Loader/Loader.md +30 -0
  46. package/src/components/Loader/Loader.scss +42 -0
  47. package/src/components/Loader/Loader.tsx +68 -0
  48. package/src/components/Menu/Menu.md +68 -2
  49. package/src/components/Menu/Menu.scss +48 -18
  50. package/src/components/Menu/Menu.tsx +146 -39
  51. package/src/components/Progress/Progress.md +27 -26
  52. package/src/components/Progress/Progress.scss +41 -36
  53. package/src/components/Progress/Progress.tsx +50 -6
  54. package/src/components/Select/Select.scss +20 -19
  55. package/src/components/Stack/Stack.md +43 -0
  56. package/src/components/Stack/Stack.scss +36 -0
  57. package/src/components/Stack/Stack.tsx +52 -0
  58. package/src/components/Table/Table.scss +1 -1
  59. package/src/components/Tag/Tag.scss +2 -2
  60. package/src/components/Text/Text.md +3 -5
  61. package/src/components/Title/Title.scss +6 -6
  62. package/src/components/Tree/Tree.md +5 -5
  63. package/src/css.ts +4 -0
  64. package/src/dialog.ts +47 -0
  65. package/src/icons.ts +117 -0
  66. package/src/index.ts +13 -1
  67. package/src/loader.ts +43 -0
  68. package/src/logo.ts +12 -0
  69. package/src/menu.ts +91 -21
  70. package/src/progress.ts +21 -0
  71. package/src/respawn/FullPageModal.ts +30 -3
  72. package/src/respawn/Grid.ts +41 -0
  73. package/src/respawn/Icon.ts +47 -0
  74. package/src/respawn/Loader.ts +77 -0
  75. package/src/respawn/Menu.ts +138 -34
  76. package/src/respawn/Progress.ts +56 -13
  77. package/src/respawn/Stack.ts +37 -0
  78. package/src/respawn/index.ts +13 -1
  79. package/src/respawn/spawn.ts +5 -3
  80. package/src/styles/breakpoints.scss +3 -0
  81. package/src/styles/theme.scss +55 -55
  82. package/src/styles/type.json +9 -9
@@ -1,26 +1,34 @@
1
+ import { MenuKind } from '../menu';
2
+ import { TreeProps } from './Tree';
1
3
  import { Child, ElementProps } from './spawn';
2
4
  import { NurvusElement } from './update';
5
+ export type { MenuKind };
3
6
  export interface MenuItem {
4
- /** What the link says. */
7
+ /** What the item says. */
5
8
  label: Child;
6
- /** Where it goes. The item whose href equals `current` is marked as the current page. */
7
- href: string;
9
+ /** Makes the item a link to this address. The item whose href equals `current` is marked as the current page. */
10
+ href?: string;
11
+ /** Makes the item a button that calls this (an action: "Duplicate", "Sign out"). */
12
+ onSelect?: (event: MouseEvent) => void;
13
+ /** Shows the item but stops it working (actions only). */
14
+ disabled?: boolean;
8
15
  /** Draws a hairline above this item, to split a section into groups. */
9
16
  divider?: boolean;
10
17
  }
11
18
  export interface MenuSection {
12
19
  /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
13
20
  id?: string;
14
- /** The section heading. */
15
- title: string;
21
+ /** The section heading. Optional for actions. */
22
+ title?: string;
16
23
  /** Makes the heading a link too (e.g. to the section's overview page). */
17
24
  href?: string;
18
- /** The section's links. */
25
+ /** The section's items. */
19
26
  items: MenuItem[];
20
27
  }
21
- export interface MenuProps extends ElementProps {
22
- /** The sections, in order. */
23
- sections: MenuSection[];
28
+ /** What navigation and actions take. */
29
+ interface MenuBaseProps extends ElementProps {
30
+ /** Navigation and actions: the sections, in order. */
31
+ sections?: MenuSection[];
24
32
  /** The href of the page being shown: its link is marked, and its section opens. */
25
33
  current?: string;
26
34
  /** Which sections start open: true (all), false (none) or a map of section id -> open. Defaults to all. */
@@ -29,15 +37,37 @@ export interface MenuProps extends ElementProps {
29
37
  onToggle?: (id: string, open: boolean) => void;
30
38
  /** Called when any link is clicked, with its href (e.g. to close a drawer). */
31
39
  onNavigate?: (href: string, event: MouseEvent) => void;
32
- /** Accessible name of the navigation landmark. */
40
+ /** What screen readers call the menu ("Pages", "Actions"). */
33
41
  label?: string;
34
- /** Prefix for the ids that link each toggle to its list. Defaults to "menu". */
42
+ /** Prefix for the ids inside (each toggle names its list). Defaults to "menu". */
35
43
  id?: string;
36
44
  }
45
+ export interface MenuProps extends MenuBaseProps {
46
+ /** What the menu is: 'nav' (links), 'actions' (commands) or 'tree' (rows to pick from, with Tree's props). Left out, it follows the props. */
47
+ kind?: MenuKind;
48
+ /** Tree: the rows, each with optional child `items`. */
49
+ items?: TreeProps['items'];
50
+ /** Tree: the picked row as a path of indexes. */
51
+ activePath?: number[];
52
+ /** Tree: draws a row's content instead of its label. */
53
+ itemRenderer?: TreeProps['itemRenderer'];
54
+ /** Tree: the deepest level that still indents. */
55
+ maxIndentDepth?: number;
56
+ }
57
+ /** Menu's props for navigation and actions. */
58
+ export interface MenuListProps extends MenuBaseProps {
59
+ /** 'nav' or 'actions'; left out, it follows the items. */
60
+ kind?: 'nav' | 'actions';
61
+ }
62
+ /** Menu kind: 'tree': Tree's props. */
63
+ export type MenuTreeProps = TreeProps & {
64
+ kind: 'tree';
65
+ };
37
66
  /**
38
- * Site navigation: sections of links that open and close (an accordion, with
39
- * a smooth animation), and the current page marked by a bar beside it. A
40
- * click on a toggle opens or closes its section in place (the element stays
41
- * the same); update({ current }) marks another page and opens its section.
67
+ * One component for lists of things to go to, do or pick, the same markup as
68
+ * the React Menu. The items decide what it is, and screen readers hear it so:
69
+ * links make navigation (sections open and close in place; update({ current })
70
+ * marks another page), actions make a menu of commands (one Tab stop, the
71
+ * arrow keys move), kind: 'tree' makes a Tree.
42
72
  */
43
73
  export default function Menu(props?: MenuProps): NurvusElement<HTMLElement, MenuProps>;
@@ -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>;
@@ -15,10 +15,22 @@ export { default as Progress } from './Progress';
15
15
  export type { ProgressProps, ProgressSize, ProgressStatus } from './Progress';
16
16
  export { default as Layout } from './Layout';
17
17
  export type { LayoutProps, Spacing, LegacySpacing } from './Layout';
18
+ export { default as Icon } from './Icon';
19
+ export type { IconProps, IconElement } from './Icon';
20
+ export { ICONS, ICON_NAMES } from '../icons';
21
+ export type { IconName, IconNode } from '../icons';
18
22
  export { default as Tree } from './Tree';
19
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';
20
32
  export { default as Menu } from './Menu';
21
- export type { MenuProps, MenuItem, MenuSection } from './Menu';
33
+ export type { MenuProps, MenuListProps, MenuTreeProps, MenuItem, MenuSection, MenuKind } from './Menu';
22
34
  export { default as Select } from './Select';
23
35
  export type { SelectProps, SelectOption, SelectOptionState } from './Select';
24
36
  export { default as FullPageModal } from './FullPageModal';
@@ -33,6 +33,8 @@ export interface SpawnProps extends ElementProps {
33
33
  children?: Child | ((el: HTMLElement) => void);
34
34
  /** Appends the new element to this one. */
35
35
  mountEl?: Element;
36
+ /** Makes the element in this namespace, e.g. 'http://www.w3.org/2000/svg' for SVG (Icon uses it). */
37
+ namespace?: string;
36
38
  }
37
39
  /** Appends `child` (any Child) to `parent`. */
38
40
  export declare function append(parent: Node, child: Child): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nurvus/ui",
3
- "version": "0.1.0-alpha.14",
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,25 +1,21 @@
1
1
  ```jsx
2
- import { Button, ButtonGroup, Layout } from '@nurvus/ui';
3
- import AddIcon from '@material-ui/icons/Add';
4
- import FileCopyIcon from '@material-ui/icons/FileCopy';
5
- import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
6
- import LockOpenIcon from '@material-ui/icons/LockOpen';
2
+ import { Button, ButtonGroup, Icon, Layout } from '@nurvus/ui';
7
3
 
8
4
  <Layout>
9
5
  <ButtonGroup>
10
- <Button><AddIcon /></Button>
11
- <Button><FileCopyIcon /></Button>
12
- <Button disabled={ true }><RemoveRedEyeIcon /></Button>
13
- <Button><LockOpenIcon /></Button>
6
+ <Button aria-label="Add"><Icon name="add" size="1.25em" /></Button>
7
+ <Button aria-label="Copy"><Icon name="copy" size="1.25em" /></Button>
8
+ <Button disabled={ true } aria-label="Show"><Icon name="eye" size="1.25em" /></Button>
9
+ <Button aria-label="Unlock"><Icon name="unlock" size="1.25em" /></Button>
14
10
  </ButtonGroup>
15
11
 
16
12
  <ButtonGroup>
17
- <Button disabled={ true }><RemoveRedEyeIcon /></Button>
18
- <Button><LockOpenIcon /></Button>
13
+ <Button disabled={ true } aria-label="Show"><Icon name="eye" size="1.25em" /></Button>
14
+ <Button aria-label="Unlock"><Icon name="unlock" size="1.25em" /></Button>
19
15
  </ButtonGroup>
20
16
 
21
17
  <ButtonGroup>
22
- <Button><LockOpenIcon /></Button>
18
+ <Button aria-label="Unlock"><Icon name="unlock" size="1.25em" /></Button>
23
19
  </ButtonGroup>
24
20
  </Layout>
25
21
  ```
@@ -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 {