@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,149 @@
1
+ @import "../../styles/variables.scss";
2
+
3
+ // Site navigation. Sections open and close by animating the list's row
4
+ // (grid-template-rows 1fr <-> 0fr): smooth, no height measuring, any length.
5
+ $nav-list-speed: 0.2s;
6
+
7
+ .#{$cls-prefix}.nav-list {
8
+ font-size: 14px;
9
+ line-height: 20px;
10
+
11
+ .nav-list-section + .nav-list-section { margin-top: var(--space--8); }
12
+
13
+ .nav-list-heading {
14
+ display: flex;
15
+ align-items: center;
16
+ gap: var(--space--4);
17
+ }
18
+
19
+ .nav-list-title {
20
+ flex: 1;
21
+ min-width: 0;
22
+ padding: var(--space--4) 10px;
23
+ border: 0;
24
+ border-radius: 6px;
25
+ background: none;
26
+ color: var(--nv-text);
27
+ font: inherit;
28
+ font-weight: 600;
29
+ text-align: left;
30
+ text-decoration: none;
31
+ cursor: pointer;
32
+
33
+ &:hover { background: var(--nv-surface-hover); }
34
+ &:focus-visible { outline: 2px solid var(--nv-accent); outline-offset: -2px; }
35
+ &[data-active="true"] { background: var(--nv-accent-soft); }
36
+ }
37
+
38
+ // The chevron: a turned corner, pointing down when open, right when closed.
39
+ .nav-list-toggle {
40
+ display: inline-flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+
44
+ &::after {
45
+ content: '';
46
+ width: 6px;
47
+ height: 6px;
48
+ margin: 0 var(--space--4);
49
+ border-right: 1.5px solid currentColor;
50
+ border-bottom: 1.5px solid currentColor;
51
+ transform: translateY(-2px) rotate(45deg);
52
+ transition: transform $nav-list-speed ease;
53
+ }
54
+ }
55
+
56
+ // The icon-only toggle beside a heading that is a link.
57
+ .nav-list-toggle:not(.nav-list-title) {
58
+ flex: none;
59
+ width: 24px;
60
+ height: 24px;
61
+ padding: 0;
62
+ border: 0;
63
+ border-radius: 6px;
64
+ background: none;
65
+ color: var(--nv-text-muted);
66
+ cursor: pointer;
67
+
68
+ &::after { margin: 0; }
69
+ &:hover { background: var(--nv-surface-hover); color: var(--nv-text); }
70
+ &:focus-visible { outline: 2px solid var(--nv-accent); outline-offset: -2px; }
71
+ }
72
+
73
+ // A heading with no page of its own: the whole row is the toggle.
74
+ .nav-list-title.nav-list-toggle { justify-content: space-between; }
75
+
76
+ .nav-list-section[data-open="false"] .nav-list-toggle::after { transform: rotate(-45deg); }
77
+
78
+ .nav-list-items {
79
+ display: grid;
80
+ grid-template-rows: 1fr;
81
+ transition: grid-template-rows $nav-list-speed ease;
82
+ }
83
+
84
+ .nav-list-section[data-open="false"] .nav-list-items { grid-template-rows: 0fr; }
85
+
86
+ ul {
87
+ min-height: 0;
88
+ overflow: hidden;
89
+ // Room on the left for the current-page bar, which sits outside the item.
90
+ margin: 0 0 0 -12px;
91
+ padding: 0 0 0 12px; // no vertical padding: it would stay when the row closes to 0
92
+ list-style: none;
93
+ }
94
+
95
+ li:first-child { margin-top: 2px; }
96
+ li:last-child { margin-bottom: var(--space--8); }
97
+
98
+ // Closed: out of sight and out of the tab order once the animation ends.
99
+ .nav-list-section[data-open="false"] ul {
100
+ visibility: hidden;
101
+ transition: visibility 0s $nav-list-speed;
102
+ }
103
+
104
+ li + li { margin-top: 2px; }
105
+
106
+ li[data-divider] {
107
+ margin-top: var(--space--8);
108
+ padding-top: var(--space--8);
109
+ border-top: 1px solid var(--nv-border);
110
+ }
111
+
112
+ .nav-list-item {
113
+ position: relative;
114
+ display: block;
115
+ padding: var(--space--4) 10px var(--space--4) 20px;
116
+ border-radius: 6px;
117
+ color: var(--nv-text-muted);
118
+ text-decoration: none;
119
+
120
+ &:hover { background: var(--nv-surface-hover); color: var(--nv-text); }
121
+ &:focus-visible { outline: 2px solid var(--nv-accent); outline-offset: -2px; }
122
+
123
+ &[data-active="true"] {
124
+ background: var(--nv-accent-soft);
125
+ color: var(--nv-text);
126
+ font-weight: 500;
127
+ }
128
+
129
+ // The current page's marker: its own small rounded bar beside the item
130
+ // (as GitHub Primer's NavList draws it), not a border on the rounded item.
131
+ &[data-active="true"]::before {
132
+ content: '';
133
+ position: absolute;
134
+ top: 50%;
135
+ left: -8px;
136
+ width: 4px;
137
+ height: 18px;
138
+ border-radius: 2px;
139
+ background: var(--nv-accent);
140
+ transform: translateY(-50%);
141
+ }
142
+ }
143
+
144
+ @media (prefers-reduced-motion: reduce) {
145
+ .nav-list-items,
146
+ .nav-list-toggle::after,
147
+ .nav-list-section[data-open="false"] ul { transition: none; }
148
+ }
149
+ }
@@ -0,0 +1,129 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import { sectionId, startsOpen } from '../../navList';
5
+ import './NavList.scss';
6
+
7
+ export interface NavListItem {
8
+ /** What the link says. */
9
+ label: React.ReactNode;
10
+ /** Where it goes. The item whose href equals `current` is marked as the current page. */
11
+ href: string;
12
+ /** Draws a hairline above this item, to split a section into groups. */
13
+ divider?: boolean;
14
+ }
15
+
16
+ export interface NavListSection {
17
+ /** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
18
+ id?: string;
19
+ /** The section heading. */
20
+ title: React.ReactNode;
21
+ /** Makes the heading a link too (e.g. to the section's overview page). */
22
+ href?: string;
23
+ /** The section's links. */
24
+ items: NavListItem[];
25
+ }
26
+
27
+ export interface NavListProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onToggle'> {
28
+ /** The sections, in order. */
29
+ sections: NavListSection[];
30
+ /** The href of the page being shown: its link is marked, and its section opens. */
31
+ current?: string;
32
+ /** Which sections start open: true (all), false (none) or a map of section id → open. Defaults to all. */
33
+ defaultOpen?: boolean | Record<string, boolean>;
34
+ /** Called when a section opens or closes (e.g. to remember it). */
35
+ onToggle?: (id: string, open: boolean) => void;
36
+ /** Called when any link is clicked, with its href (e.g. to close a drawer). */
37
+ onNavigate?: (href: string, event: React.MouseEvent<HTMLAnchorElement>) => void;
38
+ /** Accessible name of the navigation landmark. */
39
+ label?: string;
40
+ /** Prefix for the ids that link each toggle to its list. Defaults to "nav-list". */
41
+ id?: string;
42
+ /** Custom class name. */
43
+ className?: string;
44
+ }
45
+
46
+ /**
47
+ * Site navigation: sections of links that open and close (an accordion, with
48
+ * a smooth animation), and the current page marked by a bar beside it.
49
+ * A section opens by itself when the current page is in it.
50
+ */
51
+ export default function NavList({
52
+ sections,
53
+ current,
54
+ defaultOpen = true,
55
+ onToggle,
56
+ onNavigate,
57
+ label = 'Pages',
58
+ id = 'nav-list',
59
+ className,
60
+ ...restProps
61
+ }: NavListProps) {
62
+ // The current page's section starts open, whatever defaultOpen says.
63
+ const [open, setOpen] = React.useState<Record<string, boolean>>(() => {
64
+ const home = sections.find((s) => s.items.some((item) => item.href === current));
65
+ return Object.fromEntries(sections.map((s) => [sectionId(s), s === home || startsOpen(defaultOpen, sectionId(s))]));
66
+ });
67
+
68
+ // Navigating into a closed section opens it, so the current page is always visible.
69
+ React.useEffect(() => {
70
+ const home = sections.find((s) => s.items.some((item) => item.href === current));
71
+ if (home && open[sectionId(home)] === false) setOpen((was) => ({ ...was, [sectionId(home)]: true }));
72
+ }, [current]); // eslint-disable-line react-hooks/exhaustive-deps
73
+
74
+ const toggle = (sid: string) => {
75
+ const next = open[sid] === false;
76
+ setOpen((was) => ({ ...was, [sid]: next }));
77
+ if (onToggle) onToggle(sid, next);
78
+ };
79
+ const navigate = (href: string) => (event: React.MouseEvent<HTMLAnchorElement>) => { if (onNavigate) onNavigate(href, event); };
80
+
81
+ return (
82
+ <nav className={ classNames(className, 'nav-list', CONSTANT.CLASS_PREFIX) } aria-label={ label } { ...restProps }>
83
+ { sections.map((section) => {
84
+ const sid = sectionId(section);
85
+ const shown = open[sid] !== false;
86
+ const listId = `${id}-${sid}`;
87
+ const toggleProps = {
88
+ type: 'button' as const,
89
+ 'aria-expanded': shown,
90
+ 'aria-controls': listId,
91
+ onClick: () => toggle(sid),
92
+ };
93
+ return (
94
+ <div key={ sid } className="nav-list-section" data-section={ sid } data-open={ shown }>
95
+ <div className="nav-list-heading">
96
+ { section.href ? (
97
+ <>
98
+ <a className="nav-list-title" href={ section.href } data-active={ current === section.href } onClick={ navigate(section.href) }>
99
+ { section.title }
100
+ </a>
101
+ <button className="nav-list-toggle" aria-label={ `${shown ? 'Hide' : 'Show'} ${String(section.title)}` } { ...toggleProps } />
102
+ </>
103
+ ) : (
104
+ <button className="nav-list-title nav-list-toggle" { ...toggleProps }>{ section.title }</button>
105
+ ) }
106
+ </div>
107
+ <div className="nav-list-items" id={ listId }>
108
+ <ul>
109
+ { section.items.map((item) => (
110
+ <li key={ item.href } data-divider={ item.divider || undefined }>
111
+ <a
112
+ className="nav-list-item"
113
+ href={ item.href }
114
+ data-active={ current === item.href }
115
+ aria-current={ current === item.href ? 'page' : undefined }
116
+ onClick={ navigate(item.href) }
117
+ >
118
+ { item.label }
119
+ </a>
120
+ </li>
121
+ )) }
122
+ </ul>
123
+ </div>
124
+ </div>
125
+ );
126
+ }) }
127
+ </nav>
128
+ );
129
+ }
@@ -1,9 +1,23 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import classNames from 'classnames';
4
- import CONSTANT from '../../constants.js';
3
+ import CONSTANT from '../../constants';
5
4
  import './Panel.scss';
6
5
 
6
+ export type PanelPadding = 'none' | 'small' | 'medium';
7
+
8
+ export interface PanelProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
9
+ /** Heading at the top of the panel. */
10
+ title?: React.ReactNode;
11
+ /** Footer line under a hairline, in caption type. */
12
+ caption?: React.ReactNode;
13
+ /** Inner spacing: none (e.g. a full-bleed image), small (12px) or medium (16px). */
14
+ padding?: PanelPadding;
15
+ /** The panel's content. */
16
+ children?: React.ReactNode;
17
+ /** Custom class name. */
18
+ className?: string;
19
+ }
20
+
7
21
  /**
8
22
  * A card: the theme's surface, a hairline border and 12px corners, with an
9
23
  * optional title and a caption footer. Use it to group related content.
@@ -15,7 +29,7 @@ export default function Panel({
15
29
  children,
16
30
  className,
17
31
  ...restProps
18
- }) {
32
+ }: PanelProps) {
19
33
  return (
20
34
  <section
21
35
  className={ classNames(className, 'panel', CONSTANT.CLASS_PREFIX) }
@@ -32,26 +46,3 @@ export default function Panel({
32
46
  </section>
33
47
  );
34
48
  }
35
-
36
- Panel.propTypes = {
37
- /**
38
- * Heading at the top of the panel.
39
- */
40
- title: PropTypes.node,
41
- /**
42
- * Footer line under a hairline, in caption type.
43
- */
44
- caption: PropTypes.node,
45
- /**
46
- * Inner spacing: none (e.g. a full-bleed image), small (12px) or medium (16px).
47
- */
48
- padding: PropTypes.oneOf(['none', 'small', 'medium']),
49
- /**
50
- * Custom class name.
51
- */
52
- className: PropTypes.string,
53
- /**
54
- * The panel's content.
55
- */
56
- children: PropTypes.node
57
- };
@@ -2,18 +2,18 @@ Basic Example
2
2
  ```jsx
3
3
  import Layout from '../Layout/Layout.jsx';
4
4
 
5
- <Layout itemSpacing={ 40 }>
6
- <Layout itemSpacing={ 13 } style={ { maxWidth: 90 } }>
5
+ <Layout itemSpacing={ 32 }>
6
+ <Layout itemSpacing={ 12 } style={ { maxWidth: 90 } }>
7
7
  <Progress size="small" />
8
8
  <Progress size="small" percent={ 50 } />
9
9
  <Progress size="small" percent={ 100 } />
10
10
  </Layout>
11
- <Layout itemSpacing={ 13 } style={ { maxWidth: 105 } }>
11
+ <Layout itemSpacing={ 12 } style={ { maxWidth: 105 } }>
12
12
  <Progress size="medium" />
13
13
  <Progress size="medium" percent={ 50 } />
14
14
  <Progress size="medium" percent={ 100 } />
15
15
  </Layout>
16
- <Layout itemSpacing={ 13 } style={ { maxWidth: 226 } }>
16
+ <Layout itemSpacing={ 12 } style={ { maxWidth: 226 } }>
17
17
  <Progress size="large" />
18
18
  <Progress size="large" percent={ 50 } />
19
19
  <Progress size="large" percent={ 100 } />
@@ -24,7 +24,7 @@ import Layout from '../Layout/Layout.jsx';
24
24
  Status Example
25
25
  ```jsx
26
26
  import Layout from '../Layout/Layout.jsx';
27
- <Layout itemSpacing={ 13 } style={ { maxWidth: 90 } }>
27
+ <Layout itemSpacing={ 12 } style={ { maxWidth: 90 } }>
28
28
  <Progress status="critical" percent={ 10 } />
29
29
  <Progress status="warning" percent={ 50 } />
30
30
  <Progress status="success" percent={ 100 } />
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Progress.scss';
5
+
6
+ export type ProgressSize = 'small' | 'medium' | 'large';
7
+ export type ProgressStatus = 'active' | 'success' | 'warning' | 'critical';
8
+
9
+ export interface ProgressProps {
10
+ /** How far along, 0 to 100. */
11
+ percent?: number;
12
+ /** Bar height. */
13
+ size?: ProgressSize;
14
+ /** The bar color: active (accent), success, warning or critical (danger). */
15
+ status?: ProgressStatus;
16
+ /** Custom class name. */
17
+ className?: string;
18
+ }
19
+
20
+ /** A progress bar. Use it to track progress! */
21
+ export default function Progress({
22
+ className,
23
+ percent = 0,
24
+ size = 'medium',
25
+ status = 'active'
26
+ }: ProgressProps) {
27
+ return (
28
+ <div
29
+ className={ classNames(className, 'progress', CONSTANT.CLASS_PREFIX) }
30
+ data-size={ size }
31
+ data-status={ status }
32
+ >
33
+ <div className="bar" style={ { width: `${percent}%` } } />
34
+ </div>
35
+ );
36
+ }
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Table.scss';
5
+
6
+ /** A row of data: any object. Its `key` (if any) keys the row. */
7
+ export type TableRow = Record<string, any>;
8
+
9
+ export interface TableColumn<Row extends TableRow = TableRow>
10
+ extends Omit<React.TdHTMLAttributes<HTMLTableCellElement>, 'title'> {
11
+ /** Which field of each row this column shows. */
12
+ dataKey: string;
13
+ /** Header text. Defaults to the dataKey. */
14
+ title?: React.ReactNode;
15
+ /** Formats a cell: gets the value, the dataKey and the whole row. */
16
+ render?: (value: any, dataKey: string, row: Row) => React.ReactNode;
17
+ }
18
+
19
+ export interface TableProps<Row extends TableRow = TableRow> {
20
+ /** The columns, in order. Any other column prop (e.g. style) goes on its `<th>` and `<td>`s. */
21
+ columns: TableColumn<Row>[];
22
+ /** The rows, in order. */
23
+ data: Row[];
24
+ /** Custom class name. */
25
+ className?: string;
26
+ }
27
+
28
+ /**
29
+ * A data table: one rounded frame, a tinted header row with sentence-case
30
+ * labels, hairlines between rows. Columns describe the fields; each can
31
+ * format its cells with `render`.
32
+ */
33
+ export default function Table<Row extends TableRow = TableRow>({ className, columns = [], data = [] }: TableProps<Row>) {
34
+ return (
35
+ <table className={ classNames(className, 'table', CONSTANT.CLASS_PREFIX) }>
36
+ <thead>
37
+ <tr>
38
+ { columns.map((column, i) => {
39
+ // render formats cells; passing it on to <th> made React warn.
40
+ const { dataKey, title, render, ...props } = column;
41
+ return <th key={ dataKey || i } { ...props }>{ title || dataKey }</th>;
42
+ }) }
43
+ </tr>
44
+ </thead>
45
+ <tbody>
46
+ { data.map((row, i) => (
47
+ <tr key={ row.key || i } data-even={ i % 2 === 0 }>
48
+ { columns.map((column, j) => {
49
+ // title and render describe the column; they are not <td> attributes.
50
+ const { dataKey, render, title, ...props } = column;
51
+ const value = row[dataKey];
52
+ return <td key={ dataKey || j } { ...props }>{ render ? render(value, dataKey, row) : value }</td>;
53
+ }) }
54
+ </tr>
55
+ )) }
56
+ </tbody>
57
+ </table>
58
+ );
59
+ }
@@ -1,9 +1,19 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import classNames from 'classnames';
4
- import CONSTANT from '../../constants.js';
3
+ import CONSTANT from '../../constants';
5
4
  import './Tag.scss';
6
5
 
6
+ export type TagTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger' | 'info';
7
+
8
+ export interface TagProps extends React.HTMLAttributes<HTMLSpanElement> {
9
+ /** Color: neutral (muted text) or one of the theme's accent / status colors. */
10
+ tone?: TagTone;
11
+ /** The label. */
12
+ children?: React.ReactNode;
13
+ /** Custom class name. */
14
+ className?: string;
15
+ }
16
+
7
17
  /**
8
18
  * A small pill for a status or label ("new", "preview", "demo"). The text and
9
19
  * the border take the tone's theme color; the fill is a faint tint of it.
@@ -13,7 +23,7 @@ export default function Tag({
13
23
  children,
14
24
  className,
15
25
  ...restProps
16
- }) {
26
+ }: TagProps) {
17
27
  return (
18
28
  <span
19
29
  className={ classNames(className, 'tag', CONSTANT.CLASS_PREFIX) }
@@ -24,18 +34,3 @@ export default function Tag({
24
34
  </span>
25
35
  );
26
36
  }
27
-
28
- Tag.propTypes = {
29
- /**
30
- * Color: neutral (muted text) or one of the theme's accent / status colors.
31
- */
32
- tone: PropTypes.oneOf(['neutral', 'accent', 'success', 'warning', 'danger', 'info']),
33
- /**
34
- * Custom class name.
35
- */
36
- className: PropTypes.string,
37
- /**
38
- * The label.
39
- */
40
- children: PropTypes.node
41
- };
@@ -16,6 +16,19 @@ Basic Usage
16
16
  <Text>Hi</Text>
17
17
  ```
18
18
 
19
+ Weight: `weight` overrides the role's own. For words that matter inside a sentence, use `<strong>` instead (screen readers know it). More on the **Typography** page.
20
+ ```jsx
21
+ import { Text } from '@nurvus/ui';
22
+
23
+ <div style={ { display: 'grid', gap: 4 } }>
24
+ <Text as="p" variant="body" weight="regular">Regular, 400</Text>
25
+ <Text as="p" variant="body" weight="medium">Medium, 500</Text>
26
+ <Text as="p" variant="body" weight="semibold">Semibold, 600</Text>
27
+ <Text as="p" variant="body" weight="bold">Bold, 700</Text>
28
+ <Text as="p" variant="body">A paragraph with <strong>one strong phrase</strong> and an <em>emphasised</em> one.</Text>
29
+ </div>
30
+ ```
31
+
19
32
  Using Text Overflow
20
33
  ```jsx
21
34
  import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
@@ -19,4 +19,10 @@
19
19
  &[data-tone="default"] { color: var(--nv-text); }
20
20
  &[data-tone="muted"] { color: var(--nv-text-muted); }
21
21
  &[data-tone="subtle"] { color: var(--nv-text-subtle); }
22
+
23
+ // Weight overrides the role's own (after the variants, so it wins).
24
+ &[data-weight="regular"] { font-weight: 400; }
25
+ &[data-weight="medium"] { font-weight: 500; }
26
+ &[data-weight="semibold"] { font-weight: 600; }
27
+ &[data-weight="bold"] { font-weight: 700; }
22
28
  }
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Text.scss';
5
+
6
+ export type TextVariant = 'display' | 'title' | 'body' | 'caption' | 'mono';
7
+ export type TextTone = 'default' | 'muted' | 'subtle';
8
+ export type TextWeight = 'regular' | 'medium' | 'semibold' | 'bold';
9
+
10
+ export interface TextProps extends React.HTMLAttributes<HTMLElement> {
11
+ /** The element to render: 'p' for a paragraph, 'span' inside a line, 'h1'…, 'label'. */
12
+ as?: React.ElementType;
13
+ /**
14
+ * Type role: display (the one big headline), title (section headings),
15
+ * body (running text), caption (labels and notes), mono (values and code).
16
+ */
17
+ variant?: TextVariant;
18
+ /** Text color from the theme: default (text), muted or subtle. */
19
+ tone?: TextTone;
20
+ /** Font weight, overriding the role's own: regular 400, medium 500, semibold 600, bold 700. */
21
+ weight?: TextWeight;
22
+ /** The text. */
23
+ children?: React.ReactNode;
24
+ /** Custom class name. */
25
+ className?: string;
26
+ }
27
+
28
+ /**
29
+ * Text in one of the type roles (display, title, body, caption, mono). The
30
+ * sizes come from the `--nv-type-*` tokens, so every NURVUS page uses the same
31
+ * scale. Without a `variant` it inherits its parent's type. A paragraph is
32
+ * `<Text as="p" variant="body">`.
33
+ */
34
+ export default function Text({
35
+ as: Element = 'span',
36
+ variant,
37
+ tone,
38
+ weight,
39
+ children,
40
+ className,
41
+ ...restProps
42
+ }: TextProps) {
43
+ return (
44
+ <Element
45
+ className={ classNames(className, 'text', CONSTANT.CLASS_PREFIX) }
46
+ data-variant={ variant }
47
+ data-tone={ tone }
48
+ data-weight={ weight }
49
+ { ...restProps }
50
+ >
51
+ { children }
52
+ </Element>
53
+ );
54
+ }
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Title.scss';
5
+
6
+ export type TitleLevel = 1 | 2 | 3 | 4 | 5 | 6;
7
+ export type TitleType = 'primary' | 'secondary';
8
+
9
+ export interface TitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
10
+ /** Heading level: 1 renders `<h1>` (24px) down to 6 (`<h6>`). */
11
+ level?: TitleLevel;
12
+ /** `primary` uses the theme's text color; `secondary` the muted one. */
13
+ type?: TitleType;
14
+ /** The heading text. */
15
+ children?: React.ReactNode;
16
+ /** Custom class name. */
17
+ className?: string;
18
+ }
19
+
20
+ const TAGS = { 1: 'h1', 2: 'h2', 3: 'h3', 4: 'h4', 5: 'h5', 6: 'h6' } as const;
21
+
22
+ /**
23
+ * A heading, `<h1>` to `<h6>`, in the theme's text color. For the larger
24
+ * type roles (display, title, caption) use `Text` with a `variant`.
25
+ */
26
+ export default function Title({
27
+ children,
28
+ className,
29
+ level = 1,
30
+ type = 'primary',
31
+ ...restProps
32
+ }: TitleProps) {
33
+ return React.createElement(
34
+ TAGS[level] || 'h6',
35
+ {
36
+ className: classNames(className, 'title', CONSTANT.CLASS_PREFIX),
37
+ 'data-type': type,
38
+ ...restProps
39
+ },
40
+ children
41
+ );
42
+ }
@@ -0,0 +1,6 @@
1
+ /** Every component's class list ends with this: class="my-class tag nurvus". */
2
+ const CONSTANT = {
3
+ CLASS_PREFIX: 'nurvus',
4
+ } as const;
5
+
6
+ export default CONSTANT;
package/src/css.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Build-only entry for dist/nurvus.css: the core CSS as one file (the
2
+ // primitives, the type roles, Apollo White and every component's styles).
3
+ import './styles/theme.scss';
4
+ import './components/Button/Button.scss';
5
+ import './components/ButtonGroup/ButtonGroup.scss';
6
+ import './components/FullPageModal/FullPageModal.scss';
7
+ import './components/HistoryList/HistoryList.scss';
8
+ import './components/Layout/Layout.scss';
9
+ import './components/Link/Link.scss';
10
+ import './components/Menu/Menu.scss';
11
+ import './components/NavList/NavList.scss';
12
+ import './components/Panel/Panel.scss';
13
+ import './components/Progress/Progress.scss';
14
+ import './components/Table/Table.scss';
15
+ import './components/Tag/Tag.scss';
16
+ import './components/Text/Text.scss';
17
+ import './components/Title/Title.scss';
@@ -0,0 +1,3 @@
1
+ // Style imports are side effects: the build injects or extracts the CSS.
2
+ declare module '*.scss';
3
+ declare module '*.css';