@nurvus/ui 0.1.0-alpha.11 → 0.1.0-alpha.13

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 (135) hide show
  1. package/README.md +20 -9
  2. package/dist/index.js +1 -1
  3. package/dist/nurvus.css +15 -0
  4. package/dist/respawn.js +2 -0
  5. package/dist/respawn.js.LICENSE.txt +5 -0
  6. package/dist/theme.js +1 -0
  7. package/dist/themes/all.css +231 -0
  8. package/dist/themes/apollo-white.css +33 -0
  9. package/dist/themes/apollo-white.json +52 -0
  10. package/dist/themes/arcane.css +33 -0
  11. package/dist/themes/arcane.json +52 -0
  12. package/dist/themes/dopamine.css +33 -0
  13. package/dist/themes/dopamine.json +52 -0
  14. package/dist/themes/nether-neon.css +33 -0
  15. package/dist/themes/nether-neon.json +52 -0
  16. package/dist/themes/nether.css +33 -0
  17. package/dist/themes/nether.json +52 -0
  18. package/dist/themes/outworld.css +33 -0
  19. package/dist/themes/outworld.json +52 -0
  20. package/dist/themes/roles.json +29 -0
  21. package/dist/themes/tokyo-neon.css +33 -0
  22. package/dist/themes/tokyo-neon.json +52 -0
  23. package/dist/types/components/Button/Button.d.ts +19 -0
  24. package/dist/types/components/ButtonGroup/ButtonGroup.d.ts +12 -0
  25. package/dist/types/components/FullPageModal/FullPageModal.d.ts +15 -0
  26. package/dist/types/components/HistoryList/HistoryList.d.ts +40 -0
  27. package/dist/types/components/Layout/Layout.d.ts +27 -0
  28. package/dist/types/components/Link/Link.d.ts +9 -0
  29. package/dist/types/components/Menu/Menu.d.ts +35 -0
  30. package/dist/types/components/NavList/NavList.d.ts +43 -0
  31. package/dist/types/components/Panel/Panel.d.ts +19 -0
  32. package/dist/types/components/Progress/Progress.d.ts +15 -0
  33. package/dist/types/components/Table/Table.d.ts +25 -0
  34. package/dist/types/components/Tag/Tag.d.ts +15 -0
  35. package/dist/types/components/Text/Text.d.ts +28 -0
  36. package/dist/types/components/Title/Title.d.ts +288 -0
  37. package/dist/types/constants.d.ts +5 -0
  38. package/dist/types/index.d.ts +32 -0
  39. package/dist/types/navList.d.ts +7 -0
  40. package/dist/types/respawn/Button.d.ts +16 -0
  41. package/dist/types/respawn/ButtonGroup.d.ts +8 -0
  42. package/dist/types/respawn/FullPageModal.d.ts +32 -0
  43. package/dist/types/respawn/HistoryList.d.ts +36 -0
  44. package/dist/types/respawn/Layout.d.ts +22 -0
  45. package/dist/types/respawn/Link.d.ts +12 -0
  46. package/dist/types/respawn/Menu.d.ts +33 -0
  47. package/dist/types/respawn/NavList.d.ts +43 -0
  48. package/dist/types/respawn/Panel.d.ts +15 -0
  49. package/dist/types/respawn/Progress.d.ts +15 -0
  50. package/dist/types/respawn/Table.d.ts +22 -0
  51. package/dist/types/respawn/Tag.d.ts +11 -0
  52. package/dist/types/respawn/Text.d.ts +19 -0
  53. package/dist/types/respawn/Title.d.ts +14 -0
  54. package/dist/types/respawn/index.d.ts +35 -0
  55. package/dist/types/respawn/spawn.d.ts +50 -0
  56. package/dist/types/respawn/update.d.ts +13 -0
  57. package/dist/types/spacing.d.ts +8 -0
  58. package/dist/types/theme.d.ts +32 -0
  59. package/dist/types/themes/index.d.ts +45 -0
  60. package/package.json +40 -12
  61. package/src/components/Button/Button.md +5 -5
  62. package/src/components/Button/Button.tsx +44 -0
  63. package/src/components/ButtonGroup/ButtonGroup.tsx +23 -0
  64. package/src/components/FullPageModal/FullPageModal.scss +9 -5
  65. package/src/components/FullPageModal/FullPageModal.tsx +74 -0
  66. package/src/components/HistoryList/{HistoryList.jsx → HistoryList.tsx} +45 -58
  67. package/src/components/Layout/Layout.md +4 -4
  68. package/src/components/Layout/Layout.scss +14 -47
  69. package/src/components/Layout/Layout.tsx +56 -0
  70. package/src/components/Link/Link.scss +9 -9
  71. package/src/components/Link/Link.tsx +23 -0
  72. package/src/components/Menu/Menu.tsx +90 -0
  73. package/src/components/NavList/NavList.md +39 -0
  74. package/src/components/NavList/NavList.scss +149 -0
  75. package/src/components/NavList/NavList.tsx +129 -0
  76. package/src/components/Panel/{Panel.jsx → Panel.tsx} +17 -26
  77. package/src/components/Progress/Progress.md +5 -5
  78. package/src/components/Progress/Progress.tsx +36 -0
  79. package/src/components/Table/Table.tsx +59 -0
  80. package/src/components/Tag/{Tag.jsx → Tag.tsx} +13 -18
  81. package/src/components/Text/Text.md +13 -0
  82. package/src/components/Text/Text.scss +6 -0
  83. package/src/components/Text/Text.tsx +54 -0
  84. package/src/components/Title/Title.tsx +42 -0
  85. package/src/constants.ts +6 -0
  86. package/src/css.ts +17 -0
  87. package/src/global.d.ts +3 -0
  88. package/src/index.ts +42 -0
  89. package/src/navList.ts +9 -0
  90. package/src/respawn/Button.ts +31 -0
  91. package/src/respawn/ButtonGroup.ts +19 -0
  92. package/src/respawn/FullPageModal.ts +125 -0
  93. package/src/respawn/HistoryList.ts +100 -0
  94. package/src/respawn/Layout.ts +44 -0
  95. package/src/respawn/Link.ts +24 -0
  96. package/src/respawn/Menu.ts +86 -0
  97. package/src/respawn/NavList.ts +126 -0
  98. package/src/respawn/Panel.ts +36 -0
  99. package/src/respawn/Progress.ts +29 -0
  100. package/src/respawn/Table.ts +54 -0
  101. package/src/respawn/Tag.ts +25 -0
  102. package/src/respawn/Text.ts +35 -0
  103. package/src/respawn/Title.ts +30 -0
  104. package/src/respawn/index.ts +59 -0
  105. package/src/respawn/spawn.ts +155 -0
  106. package/src/respawn/update.ts +49 -0
  107. package/src/spacing.ts +23 -0
  108. package/src/styles/theme.scss +6 -197
  109. package/src/styles/type.json +35 -5
  110. package/src/theme.ts +92 -0
  111. package/src/themes/css/all.css +231 -0
  112. package/src/themes/css/apollo-white.css +33 -0
  113. package/src/themes/css/arcane.css +33 -0
  114. package/src/themes/css/dopamine.css +33 -0
  115. package/src/themes/css/nether-neon.css +33 -0
  116. package/src/themes/css/nether.css +33 -0
  117. package/src/themes/css/outworld.css +33 -0
  118. package/src/themes/css/tokyo-neon.css +33 -0
  119. package/src/themes/index.ts +61 -0
  120. package/src/themes/roles.json +1 -1
  121. package/src/app.js +0 -29
  122. package/src/components/Button/Button.jsx +0 -59
  123. package/src/components/ButtonGroup/ButtonGroup.jsx +0 -28
  124. package/src/components/FullPageModal/FullPageModal.jsx +0 -106
  125. package/src/components/Layout/Layout.jsx +0 -68
  126. package/src/components/Link/Link.jsx +0 -39
  127. package/src/components/Menu/Menu.jsx +0 -120
  128. package/src/components/Progress/Progress.jsx +0 -56
  129. package/src/components/Table/Table.jsx +0 -94
  130. package/src/components/Text/Text.jsx +0 -54
  131. package/src/components/Title/Title.jsx +0 -48
  132. package/src/constants.js +0 -3
  133. package/src/index.js +0 -20
  134. package/src/theme.js +0 -64
  135. package/src/themes/index.js +0 -22
@@ -0,0 +1,74 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import classNames from 'classnames';
4
+ import CONSTANT from '../../constants';
5
+ import Layout from '../Layout/Layout';
6
+ import Title from '../Title/Title';
7
+ import './FullPageModal.scss';
8
+
9
+ export interface FullPageModalProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
10
+ /** Shows the modal (animates in), or hides it (animates out). */
11
+ visible?: boolean;
12
+ /** Title in the modal's header. */
13
+ title?: React.ReactNode;
14
+ /** Buttons at the right of the header, e.g. Close. */
15
+ headerActions?: React.ReactNode;
16
+ /** The modal's content. */
17
+ children?: React.ReactNode;
18
+ /** Custom class name. */
19
+ className?: string;
20
+ }
21
+
22
+ /** Shows additional content over the whole screen, rendered into `<body>`. */
23
+ export default function FullPageModal({
24
+ children,
25
+ className,
26
+ headerActions,
27
+ title,
28
+ visible = false,
29
+ ...restProps
30
+ }: FullPageModalProps) {
31
+ const [animationState, setAnimationState] = useState('');
32
+ const [isVisible, setIsVisible] = useState(visible);
33
+
34
+ // Clear animation and sync visibility states
35
+ function clearAnimation() {
36
+ if (animationState && visible !== isVisible) {
37
+ setIsVisible(visible);
38
+ setAnimationState('');
39
+ }
40
+ }
41
+
42
+ // Trigger animation when visibility changes
43
+ useEffect(() => {
44
+ if (visible !== isVisible) {
45
+ setAnimationState(visible ? 'reveal-in' : 'reveal-out');
46
+ }
47
+ if (visible && !animationState) {
48
+ setIsVisible(visible);
49
+ }
50
+ }, [visible]); // eslint-disable-line react-hooks/exhaustive-deps
51
+
52
+ const modalEl = (
53
+ <div className={ `portal ${CONSTANT.CLASS_PREFIX}` } data-visible={ visible }>
54
+ { isVisible ? <div className="mask" data-animate={ animationState } /> : null }
55
+ <div
56
+ className={ classNames(className, 'modal', CONSTANT.CLASS_PREFIX) }
57
+ data-visible={ isVisible }
58
+ data-animate={ animationState }
59
+ onAnimationEnd={ clearAnimation }
60
+ { ...restProps }
61
+ >
62
+ <div className="header">
63
+ <Layout display="flex" alignItems="center" justifyContent="space-between">
64
+ <Title>{ title }</Title>
65
+ <div className="header-actions">{ headerActions }</div>
66
+ </Layout>
67
+ </div>
68
+ { children }
69
+ </div>
70
+ </div>
71
+ );
72
+
73
+ return <React.Fragment>{ ReactDOM.createPortal(modalEl, document.body) }</React.Fragment>;
74
+ }
@@ -1,10 +1,40 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
- import CONSTANT from '../../constants.js';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
5
4
  import './HistoryList.scss';
6
5
 
7
- const defaultFormatTime = (time) => new Date(time).toLocaleTimeString([], {
6
+ export interface HistoryStep {
7
+ /** Unique id: keys the row. */
8
+ id: string | number;
9
+ /** What the step did. */
10
+ label: React.ReactNode;
11
+ /** A second line. */
12
+ detail?: React.ReactNode;
13
+ /** When it happened, as a timestamp in ms. */
14
+ time?: number;
15
+ }
16
+
17
+ export interface HistoryListProps extends React.OlHTMLAttributes<HTMLOListElement> {
18
+ /** Every step, OLDEST first. */
19
+ steps: HistoryStep[];
20
+ /**
21
+ * How many steps are applied: step N (1-based) is current when N === index,
22
+ * and 0 means everything is undone.
23
+ */
24
+ index: number;
25
+ /** Called with the step number to jump to (0 = the start row). */
26
+ onJump?: (step: number) => void;
27
+ /** Label of the bottom row, the state before any step. */
28
+ startLabel?: React.ReactNode;
29
+ /** Second line of the bottom row. */
30
+ startDetail?: React.ReactNode;
31
+ /** Formats a step's `time` for its row. Defaults to the locale time with seconds. */
32
+ formatTime?: (time: number) => React.ReactNode;
33
+ /** Custom class name. */
34
+ className?: string;
35
+ }
36
+
37
+ const defaultFormatTime = (time: number) => new Date(time).toLocaleTimeString([], {
8
38
  hour: '2-digit',
9
39
  minute: '2-digit',
10
40
  second: '2-digit'
@@ -18,25 +48,22 @@ const defaultFormatTime = (time) => new Date(time).toLocaleTimeString([], {
18
48
  *
19
49
  * Purely presentational: the app owns the history and passes `steps` (oldest
20
50
  * first) plus `index`, the number of steps currently applied.
21
- * @returns {ReactElement} of HistoryList component.
22
51
  */
23
- export default function HistoryList(props) {
24
- const {
25
- className,
26
- formatTime,
27
- index,
28
- onJump,
29
- startDetail,
30
- startLabel,
31
- steps,
32
- ...restProps
33
- } = props;
34
-
52
+ export default function HistoryList({
53
+ className,
54
+ formatTime = defaultFormatTime,
55
+ index,
56
+ onJump,
57
+ startDetail = 'Before any changes',
58
+ startLabel = 'Start',
59
+ steps,
60
+ ...restProps
61
+ }: HistoryListProps) {
35
62
  if (!steps.length) {
36
63
  return null;
37
64
  }
38
65
 
39
- const renderRow = (number, label, detail, time, key) => {
66
+ const renderRow = (number: number, label: React.ReactNode, detail: React.ReactNode, time: number | null | undefined, key: string | number) => {
40
67
  const isCurrent = number === index;
41
68
  const isFuture = number > index;
42
69
  let title = 'Jump to this step (undo to here)';
@@ -78,43 +105,3 @@ export default function HistoryList(props) {
78
105
  </ol>
79
106
  );
80
107
  }
81
-
82
- HistoryList.propTypes = {
83
- /**
84
- * Every step, OLDEST first: `{ id, label, detail?, time? }`. `time` is a
85
- * timestamp in ms.
86
- */
87
- steps: PropTypes.arrayOf(PropTypes.shape({
88
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
89
- label: PropTypes.node.isRequired,
90
- detail: PropTypes.node,
91
- time: PropTypes.number
92
- })).isRequired,
93
- /**
94
- * How many steps are applied: step N (1-based) is current when N === index,
95
- * and 0 means everything is undone.
96
- */
97
- index: PropTypes.number.isRequired,
98
- /**
99
- * Called with the step number to jump to (0 = the start row).
100
- */
101
- onJump: PropTypes.func,
102
- /**
103
- * Label of the bottom row, the state before any step.
104
- */
105
- startLabel: PropTypes.node,
106
- /**
107
- * Second line of the bottom row.
108
- */
109
- startDetail: PropTypes.node,
110
- /**
111
- * Formats a step's `time` for its row. Defaults to the locale time with seconds.
112
- */
113
- formatTime: PropTypes.func
114
- };
115
-
116
- HistoryList.defaultProps = {
117
- startLabel: 'Start',
118
- startDetail: 'Before any changes',
119
- formatTime: defaultFormatTime
120
- };
@@ -22,8 +22,8 @@ import FileCopyIcon from '@material-ui/icons/FileCopy';
22
22
  import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
23
23
  import LockOpenIcon from '@material-ui/icons/LockOpen';
24
24
 
25
- <Layout itemSpacing={ 40 }>
26
- <Layout itemSpacing={ 10 }>
25
+ <Layout itemSpacing={ 32 }>
26
+ <Layout itemSpacing={ 8 }>
27
27
  <Title level={ 4 }>Display Flex</Title>
28
28
  <Layout display="flex">
29
29
  <Title level={ 3 }>Layers</Title>
@@ -32,7 +32,7 @@ import LockOpenIcon from '@material-ui/icons/LockOpen';
32
32
  </Button>
33
33
  </Layout>
34
34
  </Layout>
35
- <Layout itemSpacing={ 10 }>
35
+ <Layout itemSpacing={ 8 }>
36
36
  <Title level={ 4 }>Display Flex and Align Item</Title>
37
37
  <Layout display="flex" alignItems="center">
38
38
  <Title level={ 3 }>Layers</Title>
@@ -41,7 +41,7 @@ import LockOpenIcon from '@material-ui/icons/LockOpen';
41
41
  </Button>
42
42
  </Layout>
43
43
  </Layout>
44
- <Layout itemSpacing={ 10 }>
44
+ <Layout itemSpacing={ 8 }>
45
45
  <Title level={ 4 }>Display Flex and Align Item and Spaced Apart</Title>
46
46
  <Layout display="flex" alignItems="center" justifyContent="space-between">
47
47
  <Title level={ 3 }>Layers</Title>
@@ -1,67 +1,34 @@
1
1
  @import "../../styles/variables.scss";
2
2
 
3
+ // Spacing between children comes from the 4px grid (--space--N, see the
4
+ // Spacing page). Stacked layouts (block, or a flex column) space with
5
+ // margin-top; a flex row with margin-left.
6
+ $layout-steps: 0, 2, 4, 8, 12, 16, 24, 32, 48, 64;
7
+
3
8
  .#{$cls-prefix}.layout {
4
9
  &[data-display="block"] {
5
10
  display: block;
6
11
  }
7
12
 
8
- // Vertical Item Stacking
9
- &[data-display="block"],
10
- &[data-flex-direction="column"] {
11
- &[data-item-spacing="10"] {
12
- > * + * {
13
- margin-top: $spacing-10;
14
- }
15
- }
16
-
17
- &[data-item-spacing="13"] {
18
- > * + * {
19
- margin-top: 13px;
20
- }
21
- }
22
-
23
- &[data-item-spacing="20"] {
24
- > * + * {
25
- margin-top: $spacing-medium;
26
- }
27
- }
28
-
29
- &[data-item-spacing="30"] {
30
- > * + * {
31
- margin-top: $spacing-extra-medium;
32
- }
33
- }
34
-
35
- &[data-item-spacing="40"] {
36
- > * + * {
37
- margin-top: $spacing-40;
38
- }
39
- }
40
- }
41
-
42
13
  &[data-display="flex"] {
43
14
  display: flex;
15
+ }
44
16
 
45
- &[data-item-spacing="10"] {
46
- > * + * {
47
- margin-left: 10px;
48
- }
49
- }
50
-
51
- &[data-item-spacing="20"] {
52
- > * + * {
53
- margin-left: $spacing-medium;
17
+ @each $n in $layout-steps {
18
+ &[data-display="block"][data-item-spacing="#{$n}"],
19
+ &[data-flex-direction="column"][data-item-spacing="#{$n}"] {
20
+ > * + * {
21
+ margin-top: var(--space--#{$n});
54
22
  }
55
23
  }
56
24
 
57
- &[data-item-spacing="40"] {
58
- > * + * {
59
- margin-left: 40px;
25
+ &[data-display="flex"]:not([data-flex-direction="column"])[data-item-spacing="#{$n}"] {
26
+ > * + * {
27
+ margin-left: var(--space--#{$n});
60
28
  }
61
29
  }
62
30
  }
63
31
 
64
-
65
32
  // Align Items
66
33
  &[data-align-items="flex-start"] {
67
34
  align-items: flex-start;
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Layout.scss';
5
+
6
+ import { Spacing, LegacySpacing, toGrid } from '../../spacing';
7
+
8
+ export type { Spacing, LegacySpacing };
9
+
10
+ export interface LayoutProps extends React.HTMLAttributes<HTMLDivElement> {
11
+ /** `block` stacks the children top to bottom; `flex` puts them in a row. */
12
+ display?: 'block' | 'flex';
13
+ /** With `display="flex"`: `column` stacks the children instead of a row. */
14
+ flexDirection?: 'row' | 'column';
15
+ /** Space between the children, in px, from the 4px grid: 0, 2, 4, 8, 12, 16, 24, 32, 48 or 64. The old values (10, 13, 20, 30, 40) still work: they snap to the grid, with a console warning. */
16
+ itemSpacing?: Spacing | LegacySpacing;
17
+ /** With `display="flex"`: how the children line up across the row (CSS `align-items`). */
18
+ alignItems?: 'flex-start' | 'center' | 'flex-end';
19
+ /** With `display="flex"`: how the children spread along the row (CSS `justify-content`). */
20
+ justifyContent?: 'flex-start' | 'center' | 'flex-end' | 'space-between';
21
+ /** `block` makes every child `display: block` (e.g. links stacked one per line). */
22
+ itemDisplay?: 'block';
23
+ /** What to lay out. */
24
+ children?: React.ReactNode;
25
+ /** Custom class name. */
26
+ className?: string;
27
+ }
28
+
29
+ /**
30
+ * Stacks its children in a column (`block`) or a row (`flex`) with even
31
+ * space between them, from the 4px spacing grid. Any other prop goes on the
32
+ * wrapping `<div>`.
33
+ */
34
+ export default function Layout({
35
+ alignItems,
36
+ className,
37
+ display = 'block',
38
+ flexDirection,
39
+ justifyContent,
40
+ itemDisplay,
41
+ itemSpacing = 16,
42
+ ...restProps
43
+ }: LayoutProps) {
44
+ return (
45
+ <div
46
+ className={ classNames(className, 'layout', CONSTANT.CLASS_PREFIX) }
47
+ data-align-items={ alignItems }
48
+ data-display={ display }
49
+ data-flex-direction={ flexDirection }
50
+ data-item-display={ itemDisplay }
51
+ data-item-spacing={ toGrid(itemSpacing) }
52
+ data-justify-content={ justifyContent }
53
+ { ...restProps }
54
+ />
55
+ );
56
+ }
@@ -1,18 +1,18 @@
1
1
  @import "../../styles/variables.scss";
2
2
 
3
+ // The theme's accent, so links follow every theme (it was a fixed #47c3f3).
3
4
  .#{$cls-prefix}.link {
4
- color: #47c3f3;
5
+ color: var(--nv-accent);
5
6
  cursor: pointer;
7
+ text-underline-offset: 2px;
6
8
 
7
9
  &:hover {
8
- color: #0e9fd8;
10
+ color: color-mix(in srgb, var(--nv-accent) 80%, var(--nv-text));
9
11
  }
10
12
 
11
- &:active {
12
- color: #0a7199;
13
+ &:focus-visible {
14
+ outline: 2px solid var(--nv-accent);
15
+ outline-offset: 2px;
16
+ border-radius: 2px;
13
17
  }
14
-
15
- // &:disabled {
16
- // background: $green-1;
17
- // }
18
- }
18
+ }
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Link.scss';
5
+
6
+ export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
7
+ /** Content to render. */
8
+ children?: React.ReactNode;
9
+ /** Custom class name. */
10
+ className?: string;
11
+ }
12
+
13
+ /** A link in the theme's accent color. Any other prop (href, target…) goes on the `<a>`. */
14
+ export default function Link({ children, className, ...restProps }: LinkProps) {
15
+ return (
16
+ <a
17
+ className={ classNames(className, 'link', CONSTANT.CLASS_PREFIX) }
18
+ { ...restProps }
19
+ >
20
+ { children }
21
+ </a>
22
+ );
23
+ }
@@ -0,0 +1,90 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Menu.scss';
5
+
6
+ export interface MenuItem {
7
+ /** What the row shows (unless itemRenderer draws it). */
8
+ label?: React.ReactNode;
9
+ /** Child rows, shown indented under this one. */
10
+ items?: MenuItem[];
11
+ /** Custom class name for this row. */
12
+ className?: string;
13
+ /** Inline style for this row. */
14
+ style?: React.CSSProperties;
15
+ /** Anything else your itemRenderer needs. */
16
+ [key: string]: any;
17
+ }
18
+
19
+ export interface MenuProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick'> {
20
+ /** The rows to render; each can have child `items`. */
21
+ items?: MenuItem[];
22
+ /** The active row as a path of indexes, e.g. [2, 0] = the first child of the third row. */
23
+ activePath?: number[];
24
+ /** Draws a row's content instead of its label. */
25
+ itemRenderer?: (item: MenuItem) => React.ReactNode;
26
+ /** Called on a row click with the event and that row's path. */
27
+ onClick?: (event: React.MouseEvent<HTMLDivElement>, path: number[]) => void;
28
+ /**
29
+ * Deepest level that still indents. Deeper rows stay at that indent, so the
30
+ * label keeps its room in a narrow panel.
31
+ */
32
+ maxIndentDepth?: number;
33
+ /** Custom class name. */
34
+ className?: string;
35
+ }
36
+
37
+ /**
38
+ * A nested list of rows, like a layers panel. Rows indent by depth, the
39
+ * active one is highlighted, and a click reports the row's path.
40
+ */
41
+ export default function Menu({
42
+ activePath = [],
43
+ className,
44
+ itemRenderer,
45
+ items,
46
+ maxIndentDepth = 6,
47
+ onClick,
48
+ children: _children,
49
+ ...props
50
+ }: MenuProps) {
51
+ const handleClick = (event: React.MouseEvent<HTMLDivElement>, path: number[]) => {
52
+ event.stopPropagation();
53
+ if (onClick) onClick(event, path);
54
+ };
55
+
56
+ const renderItems = (list: MenuItem[] | undefined, active: number[], path: number[] = []): React.ReactNode => {
57
+ if (!list) return null;
58
+ return list.map((item, i) => {
59
+ const { className: itemClassName, label, style } = item;
60
+ const type = path.length > 1 ? 'group' : '';
61
+ const isActive = active.length === 1 && active[0] === i;
62
+ const [first, ...remainingPath] = active;
63
+ const nextPath = [...path, i];
64
+ // Clamped so a deep tree cannot indent the label out of a narrow panel.
65
+ // The px maths lives in Menu.scss against spacing tokens; JS only supplies depth.
66
+ const depth = Math.min(path.length, maxIndentDepth);
67
+
68
+ return (
69
+ <React.Fragment key={ i }>
70
+ <div
71
+ className={ classNames(itemClassName, 'menu-item', CONSTANT.CLASS_PREFIX) }
72
+ data-active={ isActive }
73
+ data-type={ type }
74
+ onClick={ (e) => handleClick(e, nextPath) }
75
+ style={ { '--nurvus-menu-depth': String(depth), ...style } as React.CSSProperties }
76
+ >
77
+ { itemRenderer ? itemRenderer(item) : label }
78
+ </div>
79
+ { renderItems(item.items, first === i ? remainingPath : [], nextPath) }
80
+ </React.Fragment>
81
+ );
82
+ });
83
+ };
84
+
85
+ return (
86
+ <div className={ classNames(className, 'menu', CONSTANT.CLASS_PREFIX) } { ...props }>
87
+ { renderItems(items, activePath) }
88
+ </div>
89
+ );
90
+ }
@@ -0,0 +1,39 @@
1
+ Sections open and close with the chevron (or the whole heading, when it isn't a link). The current page is marked with a bar beside it, and its section opens by itself.
2
+ ```jsx
3
+ import { NavList } from '@nurvus/ui';
4
+
5
+ <div style={ { maxWidth: 260 } }>
6
+ <NavList
7
+ current="#/settings/billing"
8
+ onNavigate={ (href, event) => event.preventDefault() }
9
+ sections={ [
10
+ { title: 'Account', href: '#/account', items: [
11
+ { label: 'Profile', href: '#/account/profile' },
12
+ { label: 'Security', href: '#/account/security' },
13
+ ] },
14
+ { title: 'Settings', items: [
15
+ { label: 'General', href: '#/settings/general' },
16
+ { label: 'Billing', href: '#/settings/billing' },
17
+ { label: 'Danger zone', href: '#/settings/danger', divider: true },
18
+ ] },
19
+ ] }
20
+ />
21
+ </div>
22
+ ```
23
+
24
+ Start with some sections closed: `defaultOpen` takes a map of section ids (the title as a slug, or the section's own `id`).
25
+ ```jsx
26
+ import { NavList } from '@nurvus/ui';
27
+
28
+ <div style={ { maxWidth: 260 } }>
29
+ <NavList
30
+ id="closed-example"
31
+ defaultOpen={ { reports: false } }
32
+ onNavigate={ (href, event) => event.preventDefault() }
33
+ sections={ [
34
+ { title: 'Projects', items: [{ label: 'Website', href: '#/p/web' }, { label: 'App', href: '#/p/app' }] },
35
+ { title: 'Reports', items: [{ label: 'Weekly', href: '#/r/week' }, { label: 'Monthly', href: '#/r/month' }] },
36
+ ] }
37
+ />
38
+ </div>
39
+ ```