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

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 (55) hide show
  1. package/README.md +13 -0
  2. package/dist/icons.svg +2 -0
  3. package/dist/index.js +1 -1
  4. package/dist/nurvus.css +6 -1
  5. package/dist/respawn.js +1 -1
  6. package/dist/types/anchor.d.ts +45 -0
  7. package/dist/types/components/Anchor/Anchor.d.ts +33 -0
  8. package/dist/types/components/Dropdown/Dropdown.d.ts +31 -0
  9. package/dist/types/components/Kbd/Kbd.d.ts +16 -0
  10. package/dist/types/components/Menu/Menu.d.ts +8 -1
  11. package/dist/types/components/NavToggle/NavToggle.d.ts +27 -0
  12. package/dist/types/components/Tooltip/Tooltip.d.ts +27 -0
  13. package/dist/types/dropdown.d.ts +9 -0
  14. package/dist/types/icons.d.ts +2 -0
  15. package/dist/types/index.d.ts +11 -0
  16. package/dist/types/respawn/Anchor.d.ts +30 -0
  17. package/dist/types/respawn/Dropdown.d.ts +27 -0
  18. package/dist/types/respawn/Kbd.d.ts +10 -0
  19. package/dist/types/respawn/Menu.d.ts +2 -0
  20. package/dist/types/respawn/NavToggle.d.ts +22 -0
  21. package/dist/types/respawn/Tooltip.d.ts +20 -0
  22. package/dist/types/respawn/index.d.ts +11 -0
  23. package/dist/types/tooltip.d.ts +4 -0
  24. package/package.json +1 -1
  25. package/src/anchor.ts +150 -0
  26. package/src/components/Anchor/Anchor.md +59 -0
  27. package/src/components/Anchor/Anchor.scss +88 -0
  28. package/src/components/Anchor/Anchor.tsx +114 -0
  29. package/src/components/Dropdown/Dropdown.md +48 -0
  30. package/src/components/Dropdown/Dropdown.scss +67 -0
  31. package/src/components/Dropdown/Dropdown.tsx +110 -0
  32. package/src/components/Kbd/Kbd.md +14 -0
  33. package/src/components/Kbd/Kbd.scss +30 -0
  34. package/src/components/Kbd/Kbd.tsx +28 -0
  35. package/src/components/Menu/Menu.md +1 -1
  36. package/src/components/Menu/Menu.scss +78 -0
  37. package/src/components/Menu/Menu.tsx +15 -3
  38. package/src/components/NavToggle/NavToggle.md +51 -0
  39. package/src/components/NavToggle/NavToggle.scss +162 -0
  40. package/src/components/NavToggle/NavToggle.tsx +68 -0
  41. package/src/components/Tooltip/Tooltip.md +19 -0
  42. package/src/components/Tooltip/Tooltip.scss +75 -0
  43. package/src/components/Tooltip/Tooltip.tsx +69 -0
  44. package/src/css.ts +5 -0
  45. package/src/dropdown.ts +24 -0
  46. package/src/icons.ts +3 -0
  47. package/src/index.ts +11 -0
  48. package/src/respawn/Anchor.ts +135 -0
  49. package/src/respawn/Dropdown.ts +90 -0
  50. package/src/respawn/Kbd.ts +22 -0
  51. package/src/respawn/Menu.ts +10 -7
  52. package/src/respawn/NavToggle.ts +78 -0
  53. package/src/respawn/Tooltip.ts +63 -0
  54. package/src/respawn/index.ts +11 -0
  55. package/src/tooltip.ts +14 -0
@@ -0,0 +1,88 @@
1
+ // Styles for Anchor (React and Respawn: same markup). Rows are exactly 1.75rem
2
+ // tall so the rail (drawn from the items, src/anchor.ts) lines up with them.
3
+ @import "../../styles/variables.scss";
4
+
5
+ .#{$cls-prefix}.anchor {
6
+ font-size: 0.8125rem;
7
+ line-height: 1.25rem;
8
+
9
+ .anchor-title {
10
+ display: flex;
11
+ align-items: center;
12
+ gap: var(--space--8);
13
+ margin: 0 0 var(--space--8);
14
+ color: var(--nv-text-muted);
15
+ font-size: 0.8125rem;
16
+ font-weight: 500;
17
+ }
18
+
19
+ .anchor-body { position: relative; }
20
+
21
+ .anchor-rail {
22
+ position: absolute;
23
+ top: 0;
24
+ left: 0;
25
+ overflow: visible;
26
+ fill: none;
27
+ stroke-linecap: round;
28
+ }
29
+
30
+ .anchor-track { stroke: var(--nv-border-strong); stroke-width: 1; }
31
+
32
+ // A dot where the line starts and one where it ends; lit while the first or
33
+ // last section is in view.
34
+ .anchor-cap {
35
+ fill: var(--nv-border-strong);
36
+ transition: fill 0.35s ease;
37
+
38
+ &[data-lit="true"] { fill: var(--nv-accent); }
39
+ }
40
+
41
+ // The highlight: the same path, a dash over the section in view, sliding.
42
+ .anchor-thumb {
43
+ stroke: var(--nv-accent);
44
+ stroke-width: 2;
45
+ transition: stroke-dasharray 0.35s cubic-bezier(0.4, 0, 0.2, 1), stroke-dashoffset 0.35s cubic-bezier(0.4, 0, 0.2, 1);
46
+ }
47
+
48
+ .anchor-list {
49
+ margin: 0;
50
+ padding: 0;
51
+ list-style: none;
52
+ }
53
+
54
+ li { padding-left: calc(var(--anchor-level, 0) * 0.75rem + 1rem); }
55
+
56
+ .anchor-link {
57
+ display: block;
58
+ height: 1.75rem;
59
+ overflow: hidden;
60
+ border-radius: 0.25rem;
61
+ color: var(--nv-text-muted);
62
+ line-height: 1.75rem;
63
+ text-decoration: none;
64
+ text-overflow: ellipsis;
65
+ white-space: nowrap;
66
+ transition: color 0.2s ease;
67
+
68
+ &:hover { color: var(--nv-text); }
69
+ &:focus-visible { outline: 2px solid var(--nv-accent); outline-offset: -2px; }
70
+ &[data-inview="true"] { color: var(--nv-text); }
71
+ &[data-active="true"] { font-weight: 500; }
72
+ }
73
+
74
+ // fade: a soft wash behind the row being read, fading to the right.
75
+ &[data-fade="true"] .anchor-link {
76
+ margin-left: calc(-1 * var(--space--8));
77
+ padding-left: var(--space--8);
78
+ background: linear-gradient(90deg, color-mix(in srgb, var(--nv-accent) 16%, transparent), transparent 85%) 0 0 / 0% 100% no-repeat;
79
+ transition: color 0.2s ease, background-size 0.35s cubic-bezier(0.4, 0, 0.2, 1);
80
+
81
+ &[data-active="true"] { background-size: 100% 100%; }
82
+ }
83
+ }
84
+
85
+ @media (prefers-reduced-motion: reduce) {
86
+ .#{$cls-prefix}.anchor .anchor-thumb,
87
+ .#{$cls-prefix}.anchor .anchor-link { transition: none; }
88
+ }
@@ -0,0 +1,114 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import Icon from '../Icon/Icon';
5
+ import { AnchorItem, anchorRail, anchorDash, anchorRange, anchorGo } from '../../anchor';
6
+ import './Anchor.scss';
7
+
8
+ export type { AnchorItem };
9
+
10
+ export interface AnchorProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
11
+ /** The sections, in page order: each an "#id" href, a label and a level (1, 2…). */
12
+ items: AnchorItem[];
13
+ /** The heading above the list. */
14
+ title?: string;
15
+ /** Prefix for the ids inside (the title is "<id>-title"). Defaults to "anchor". */
16
+ id?: string;
17
+ /** How far below the top a section's heading must be scrolled to count as "in view", in pixels (room for a sticky header). */
18
+ offset?: number;
19
+ /** The section in view, set by you (its href). Left out, the Anchor follows the scrolling itself. */
20
+ current?: string;
21
+ /** Scroll-spy inside this element instead of the page: an element or a CSS selector. */
22
+ scrollRoot?: Element | string;
23
+ /** Writes the section's #id in the address bar when one is picked. Turn off for hash routers. */
24
+ updateHash?: boolean;
25
+ /** Called when a row is picked, with its href. Call event.preventDefault() to handle it yourself. */
26
+ onNavigate?: (href: string, event: React.MouseEvent<HTMLAnchorElement>) => void;
27
+ /** A soft wash behind the row being read, fading to the right. */
28
+ fade?: boolean;
29
+ /** Custom class name. */
30
+ className?: string;
31
+ }
32
+
33
+ const rootOf = (scrollRoot?: Element | string): Element | null => (typeof scrollRoot === 'string' ? document.querySelector(scrollRoot) : scrollRoot || null);
34
+
35
+ /**
36
+ * "On this page": the sections of a long page, the ones in view marked as you
37
+ * scroll. A rail runs down beside the rows from a dot to a dot, bending in and
38
+ * out with the nesting, and a highlight slides along it over the sections in
39
+ * view (their names brighten; the first is the one being read). Picking a row
40
+ * scrolls to the section and moves focus there.
41
+ */
42
+ export default function Anchor({
43
+ items,
44
+ title = 'On this page',
45
+ id = 'anchor',
46
+ offset = 96,
47
+ current,
48
+ scrollRoot,
49
+ updateHash = true,
50
+ onNavigate,
51
+ fade = false,
52
+ className,
53
+ ...restProps
54
+ }: AnchorProps) {
55
+ const [spied, setSpied] = React.useState<[number, number]>([0, 0]);
56
+ const controlled = current !== undefined;
57
+ const fixed = Math.max(0, items.findIndex((item) => item.href === current));
58
+ const [from, to] = controlled ? [fixed, fixed] : spied;
59
+ const rail = anchorRail(items.map((item) => item.level || 1));
60
+ const dash = anchorDash(rail, from, to);
61
+
62
+ // Follow the scrolling (unless the section in view is set from outside).
63
+ const list = React.useRef(items);
64
+ list.current = items;
65
+ const hrefs = items.map((item) => item.href).join(' ');
66
+ React.useEffect(() => {
67
+ if (controlled || typeof window === 'undefined') return undefined;
68
+ const root = rootOf(scrollRoot);
69
+ let frame = 0;
70
+ const update = () => { cancelAnimationFrame(frame); frame = requestAnimationFrame(() => setSpied((was) => { const next = anchorRange(list.current, offset, root); return was[0] === next[0] && was[1] === next[1] ? was : next; })); };
71
+ update();
72
+ const target: EventTarget = root || window;
73
+ target.addEventListener('scroll', update, { passive: true });
74
+ window.addEventListener('resize', update);
75
+ return () => { cancelAnimationFrame(frame); target.removeEventListener('scroll', update); window.removeEventListener('resize', update); };
76
+ }, [controlled, hrefs, offset, scrollRoot]);
77
+
78
+ const go = (href: string, i: number) => (event: React.MouseEvent<HTMLAnchorElement>) => {
79
+ if (onNavigate) onNavigate(href, event);
80
+ if (event.defaultPrevented) return;
81
+ if (anchorGo(href, updateHash)) { event.preventDefault(); if (!controlled) setSpied([i, i]); }
82
+ };
83
+
84
+ return (
85
+ <nav className={ classNames(className, 'anchor', CONSTANT.CLASS_PREFIX) } aria-labelledby={ `${id}-title` } data-fade={ fade || undefined } { ...restProps }>
86
+ <p className="anchor-title"><Icon name="align-left" size="1.125em" /><span id={ `${id}-title` }>{ title }</span></p>
87
+ <div className="anchor-body">
88
+ <svg className="anchor-rail" viewBox={ `0 0 ${rail.width} ${rail.height}` } style={ { width: `${rail.width / 16}rem`, height: `${rail.height / 16}rem` } } aria-hidden="true" focusable="false">
89
+ <path className="anchor-track" d={ rail.d } />
90
+ <path className="anchor-thumb" d={ rail.d } style={ { strokeDasharray: dash.dasharray, strokeDashoffset: dash.dashoffset } } />
91
+ { items.length > 0 && <circle className="anchor-cap" cx={ rail.caps[0][0] } cy={ rail.caps[0][1] } r="2.25" data-lit={ from === 0 } /> }
92
+ { items.length > 0 && <circle className="anchor-cap" cx={ rail.caps[1][0] } cy={ rail.caps[1][1] } r="2.25" data-lit={ to === items.length - 1 } /> }
93
+ </svg>
94
+ <ul className="anchor-list">
95
+ { items.map((item, i) => (
96
+ <li key={ item.href } style={ { '--anchor-level': String((item.level || 1) - 1) } as React.CSSProperties }>
97
+ <a
98
+ className="anchor-link"
99
+ href={ item.href }
100
+ title={ item.label }
101
+ data-active={ i === from }
102
+ data-inview={ i >= from && i <= to }
103
+ aria-current={ i === from ? 'location' : undefined }
104
+ onClick={ go(item.href, i) }
105
+ >
106
+ { item.label }
107
+ </a>
108
+ </li>
109
+ )) }
110
+ </ul>
111
+ </div>
112
+ </nav>
113
+ );
114
+ }
@@ -0,0 +1,48 @@
1
+ Screen readers hear "Actions, menu button, collapsed"; once it opens, the menu and its items ("Duplicate, menu item"). A disabled action stays in the list, so people still find it, but does nothing.
2
+
3
+ ```jsx
4
+ import { Dropdown, Text } from '@nurvus/ui';
5
+
6
+ const Demo = () => {
7
+ const [done, setDone] = React.useState('Nothing yet');
8
+ const run = (what) => () => setDone(what);
9
+ return (
10
+ <div style={ { display: 'flex', alignItems: 'center', gap: 16 } }>
11
+ <Dropdown
12
+ id="file-actions"
13
+ label="Actions"
14
+ sections={ [
15
+ { title: 'File', items: [
16
+ { label: 'Duplicate', onSelect: run('Duplicated') },
17
+ { label: 'Rename', onSelect: run('Renamed') },
18
+ { label: 'Move to…', onSelect: run('Moved'), disabled: true },
19
+ ] },
20
+ { items: [{ label: 'Delete', onSelect: run('Deleted') }] },
21
+ ] }
22
+ />
23
+ <Text tone="muted">{ done }</Text>
24
+ </div>
25
+ );
26
+ };
27
+ <Demo />
28
+ ```
29
+
30
+ A flat list with `items`, lined up with the button's right edge (`align="end"`), and an icon-only button: give the icon a `label` so the button has a name.
31
+ ```jsx
32
+ import { Dropdown, Icon } from '@nurvus/ui';
33
+
34
+ <div style={ { display: 'flex', justifyContent: 'flex-end' } }>
35
+ <Dropdown
36
+ id="row-actions"
37
+ label={ <Icon name="more-horizontal" label="More actions" size="1.25em" /> }
38
+ align="end"
39
+ type="secondary"
40
+ size="small"
41
+ items={ [
42
+ { label: 'Share', onSelect: () => {} },
43
+ { label: 'Download', onSelect: () => {} },
44
+ { label: 'Archive', onSelect: () => {} },
45
+ ] }
46
+ />
47
+ </div>
48
+ ```
@@ -0,0 +1,67 @@
1
+ // Styles for Dropdown (React and Respawn: same markup). The popup opens
2
+ // under the button like Select's list.
3
+ @import "../../styles/variables.scss";
4
+
5
+ $dropdown-speed: 0.15s;
6
+
7
+ .#{$cls-prefix}.dropdown {
8
+ position: relative;
9
+ display: inline-block;
10
+
11
+ .dropdown-trigger {
12
+ display: inline-flex;
13
+ align-items: center;
14
+ gap: var(--space--8);
15
+ }
16
+
17
+ // A turned corner: down while closed, up while open.
18
+ .dropdown-chevron {
19
+ width: 0.375rem;
20
+ height: 0.375rem;
21
+ margin-left: var(--space--2);
22
+ border-right: 1.5px solid currentColor;
23
+ border-bottom: 1.5px solid currentColor;
24
+ transform: translateY(-2px) rotate(45deg);
25
+ transition: transform $dropdown-speed ease;
26
+ }
27
+
28
+ &[data-open="true"] .dropdown-chevron { transform: translateY(2px) rotate(225deg); }
29
+
30
+ .dropdown-popup {
31
+ position: absolute;
32
+ z-index: 1000;
33
+ top: calc(100% + var(--space--4));
34
+ left: 0;
35
+ min-width: max(100%, 12rem);
36
+ max-width: 20rem;
37
+ padding: var(--space--4);
38
+ border: 1px solid var(--nv-border);
39
+ border-radius: 0.625rem;
40
+ background: var(--nv-surface);
41
+ box-shadow: 0 12px 32px rgb(0 0 0 / 0.24);
42
+ opacity: 0;
43
+ visibility: hidden;
44
+ transform: translateY(-0.25rem) scale(0.98);
45
+ transform-origin: top left;
46
+ transition: opacity $dropdown-speed ease, transform $dropdown-speed ease, visibility 0s $dropdown-speed;
47
+ }
48
+
49
+ &[data-align="end"] .dropdown-popup { left: auto; right: 0; transform-origin: top right; }
50
+
51
+ &[data-open="true"] .dropdown-popup {
52
+ opacity: 1;
53
+ visibility: visible;
54
+ transform: none;
55
+ transition: opacity $dropdown-speed ease, transform $dropdown-speed ease, visibility 0s 0s;
56
+ }
57
+
58
+ .menu-section + .menu-section { margin-top: var(--space--4); padding-top: var(--space--4); border-top: 1px solid var(--nv-border); }
59
+ .menu-heading { padding: var(--space--4) 0 0; }
60
+ .menu-title { padding: var(--space--2) var(--space--8); }
61
+ .menu-item { min-height: 1.75rem; padding-left: var(--space--8); }
62
+ }
63
+
64
+ @media (prefers-reduced-motion: reduce) {
65
+ .#{$cls-prefix}.dropdown .dropdown-popup,
66
+ .#{$cls-prefix}.dropdown .dropdown-chevron { transition: none; }
67
+ }
@@ -0,0 +1,110 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import Button, { ButtonSize, ButtonType } from '../Button/Button';
5
+ import Menu, { MenuItem, MenuSection } from '../Menu/Menu';
6
+ import { focusItem, triggerKey } from '../../dropdown';
7
+ import './Dropdown.scss';
8
+
9
+ export interface DropdownProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect'> {
10
+ /** What the button says (text, or an Icon with a label for an icon-only button). */
11
+ label: React.ReactNode;
12
+ /** The actions, in groups (each may have a title). */
13
+ sections?: MenuSection[];
14
+ /** Or the actions as one flat list. */
15
+ items?: MenuItem[];
16
+ /** Which edge of the button the menu lines up with. */
17
+ align?: 'start' | 'end';
18
+ /** The button's look. Defaults to secondary. */
19
+ type?: ButtonType;
20
+ /** The button's size. */
21
+ size?: ButtonSize;
22
+ /** Stops the button working. */
23
+ disabled?: boolean;
24
+ /** Names the button and the menu ("<id>-button", "<id>-menu"). */
25
+ id: string;
26
+ /** Custom class name. */
27
+ className?: string;
28
+ }
29
+
30
+ /**
31
+ * A button that opens a menu of actions (the WAI-ARIA menu button pattern).
32
+ * A click, Enter, Space or ↓ opens it on its first item, ↑ on its last; inside,
33
+ * the Menu's keys work (↑ ↓ Home End, type a letter); choosing an action runs
34
+ * it, closes the menu and puts focus back on the button; Esc does the same
35
+ * without choosing; Tab or a click outside closes it.
36
+ */
37
+ export default function Dropdown({
38
+ label,
39
+ sections,
40
+ items,
41
+ align = 'start',
42
+ type = 'secondary',
43
+ size = 'medium',
44
+ disabled = false,
45
+ id,
46
+ className,
47
+ ...restProps
48
+ }: DropdownProps) {
49
+ const [open, setOpen] = React.useState(false);
50
+ const root = React.useRef<HTMLDivElement>(null);
51
+ const button = React.useRef<HTMLButtonElement>(null);
52
+ const pending = React.useRef<'first' | 'last' | null>(null);
53
+
54
+ // Focus goes into the menu once it shows.
55
+ React.useEffect(() => {
56
+ if (open && pending.current && root.current) { focusItem(root.current, pending.current); pending.current = null; }
57
+ }, [open]);
58
+
59
+ // A press anywhere outside closes it.
60
+ React.useEffect(() => {
61
+ if (!open) return undefined;
62
+ const away = (event: MouseEvent) => { if (root.current && !root.current.contains(event.target as Node)) setOpen(false); };
63
+ document.addEventListener('mousedown', away);
64
+ return () => document.removeEventListener('mousedown', away);
65
+ }, [open]);
66
+
67
+ const show = (which: 'first' | 'last') => { pending.current = which; setOpen(true); };
68
+ const close = (refocus: boolean) => { setOpen(false); if (refocus && button.current) button.current.focus(); };
69
+
70
+ // Choosing an action runs it, then closes the menu with focus on the button.
71
+ const wrap = (list: MenuItem[]): MenuItem[] => list.map((item) => ({
72
+ ...item,
73
+ onSelect: (event) => { if (item.onSelect) item.onSelect(event); close(true); },
74
+ }));
75
+ const groups: MenuSection[] = (sections || [{ items: items || [] }]).map((s) => ({ ...s, items: wrap(s.items) }));
76
+
77
+ return (
78
+ <div
79
+ ref={ root }
80
+ className={ classNames(className, 'dropdown', CONSTANT.CLASS_PREFIX) }
81
+ data-open={ open }
82
+ data-align={ align }
83
+ { ...restProps }
84
+ onKeyDown={ (event) => {
85
+ if (event.key === 'Escape' && open) { event.preventDefault(); close(true); }
86
+ } }
87
+ onBlur={ (event) => { if (open && root.current && !root.current.contains(event.relatedTarget as Node)) setOpen(false); } }
88
+ >
89
+ <Button
90
+ ref={ button }
91
+ id={ `${id}-button` }
92
+ className="dropdown-trigger"
93
+ type={ type }
94
+ size={ size }
95
+ disabled={ disabled }
96
+ aria-haspopup="menu"
97
+ aria-expanded={ open }
98
+ aria-controls={ `${id}-menu` }
99
+ onClick={ () => (open ? close(false) : show('first')) }
100
+ onKeyDown={ (event) => { const which = triggerKey(event.nativeEvent); if (which) { event.preventDefault(); show(which); } } }
101
+ >
102
+ { label }
103
+ <span className="dropdown-chevron" aria-hidden="true" />
104
+ </Button>
105
+ <div className="dropdown-popup">
106
+ <Menu kind="actions" id={ `${id}-menu` } aria-labelledby={ `${id}-button` } sections={ groups } />
107
+ </div>
108
+ </div>
109
+ );
110
+ }
@@ -0,0 +1,14 @@
1
+ Key caps for keyboard shortcuts: in tooltips, menus and guides, so people can see the keys to press. `keys` draws a shortcut; one key can be the child.
2
+
3
+ ```jsx
4
+ import { Kbd, Layout, Text } from '@nurvus/ui';
5
+
6
+ <Layout itemSpacing={ 12 }>
7
+ <Text>Search: <Kbd keys={ ['⌘', 'K'] } /> (Mac) or <Kbd keys={ ['Ctrl', 'K'] } /> (Windows, Linux)</Text>
8
+ <Text>Show or hide the sidebar: <Kbd keys={ ['⌘', 'B'] } /></Text>
9
+ <Text>Close: <Kbd>Esc</Kbd> · Move: <Kbd>↑</Kbd> <Kbd>↓</Kbd> · Pick: <Kbd>Enter</Kbd></Text>
10
+ <Text variant="caption" tone="muted">Sized in em: <Kbd keys={ ['Shift', '?'] } /> follows the text it sits in.</Text>
11
+ </Layout>
12
+ ```
13
+
14
+ A control with a shortcut should also say so to assistive technology: put `aria-keyshortcuts` on it (`aria-keyshortcuts="Meta+B"`), as the docs header's sidebar button does.
@@ -0,0 +1,30 @@
1
+ // Styles for Kbd (React and Respawn: same markup). Key caps in em: they size with the text.
2
+ @import "../../styles/variables.scss";
3
+
4
+ .#{$cls-prefix}.kbd {
5
+ display: inline-flex;
6
+ align-items: center;
7
+ gap: 0.2em;
8
+ font: inherit;
9
+ vertical-align: baseline;
10
+
11
+ .kbd-key {
12
+ display: inline-flex;
13
+ align-items: center;
14
+ justify-content: center;
15
+ box-sizing: border-box;
16
+ min-width: 1.6em;
17
+ height: 1.6em;
18
+ padding: 0 0.4em;
19
+ border: 1px solid var(--nv-border-strong);
20
+ border-bottom-width: 2px;
21
+ border-radius: 0.3em;
22
+ background: var(--nv-surface);
23
+ color: var(--nv-text);
24
+ font-family: var(--nv-font-sans);
25
+ font-size: 0.8em;
26
+ font-weight: 500;
27
+ line-height: 1;
28
+ white-space: nowrap;
29
+ }
30
+ }
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import CONSTANT from '../../constants';
4
+ import './Kbd.scss';
5
+
6
+ export interface KbdProps extends React.HTMLAttributes<HTMLElement> {
7
+ /** The keys of a shortcut, in order: ['⌘', 'B']. Each is drawn as a key cap. */
8
+ keys?: string[];
9
+ /** One key, when there is only one (instead of keys). */
10
+ children?: React.ReactNode;
11
+ /** Custom class name. */
12
+ className?: string;
13
+ }
14
+
15
+ /**
16
+ * A keyboard key, or a shortcut of several (⌘ B), drawn as key caps. The HTML
17
+ * way: a <kbd> for the shortcut holding a <kbd> per key, so screen readers and
18
+ * search engines know it is keyboard input. Sized in em, so it matches the
19
+ * text around it.
20
+ */
21
+ export default function Kbd({ keys, children, className, ...restProps }: KbdProps) {
22
+ const caps = keys && keys.length ? keys : [children];
23
+ return (
24
+ <kbd className={ classNames(className, 'kbd', CONSTANT.CLASS_PREFIX) } { ...restProps }>
25
+ { caps.map((key, i) => <kbd key={ i } className="kbd-key">{ key }</kbd>) }
26
+ </kbd>
27
+ );
28
+ }
@@ -8,7 +8,7 @@
8
8
 
9
9
  Left out, `kind` follows the items: navigation when any item has an `href`, actions when none has. An item without an `href` inside navigation is a button there ("Sign out"). Links take Enter only, as everywhere on the web (Space scrolls the page); buttons, chevrons and tree rows take Enter and Space.
10
10
 
11
- **Navigation.** 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.
11
+ **Navigation.** Sections open and close with the chevron (or the whole heading, when it isn't a link). The chevron sits before the title, as Material UI draws it: › while a section is closed, ⌄ while it is open, so it stays next to the words it belongs to (easier to find for people who zoom in) and every title lines up. An open section has a hairline guide down its items, and the current page's bar sits on it; the page also opens its section by itself. `chevron="end"` puts the chevron after the title instead (⌄ closed, ⌃ open), with no guide line.
12
12
 
13
13
  ```jsx
14
14
  import { Menu } from '@nurvus/ui';
@@ -155,6 +155,82 @@ $menu-speed: 0.2s;
155
155
  }
156
156
  }
157
157
 
158
+ // Chevron at the start (data-chevron="start", the default since 0.1.0-alpha.17;
159
+ // as Material UI draws it): before the title, › while the section is closed
160
+ // and ⌄ while it is open, a quarter turn between. Every chevron is centered
161
+ // 12px from the left, both title kinds start their text at 30px, and a
162
+ // hairline guide runs down an open section's items under the chevron; the
163
+ // current page's bar is drawn on that line.
164
+ &[data-chevron="start"] {
165
+ .menu-heading { gap: var(--space--4); }
166
+
167
+ .menu-toggle::after { transform: translateY(-1px) rotate(45deg); }
168
+ .menu-section[data-open="false"] .menu-toggle::after { transform: translateX(-1px) rotate(-45deg); }
169
+
170
+ // A linked title: the chevron button first, then the link.
171
+ .menu-toggle:not(.menu-title) + .menu-title { padding-left: 0.125rem; }
172
+
173
+ // A title that is the toggle: the chevron drawn before the words.
174
+ .menu-title.menu-toggle {
175
+ justify-content: flex-start;
176
+ padding-left: var(--space--4);
177
+
178
+ &::after { content: none; }
179
+
180
+ &::before {
181
+ content: "";
182
+ flex: none;
183
+ width: 0.375rem;
184
+ height: 0.375rem;
185
+ margin: 0 0.9375rem 0 0.3125rem;
186
+ border-right: 1.5px solid currentColor;
187
+ border-bottom: 1.5px solid currentColor;
188
+ transform: translateY(-1px) rotate(45deg);
189
+ transition: transform $menu-speed ease;
190
+ }
191
+ }
192
+
193
+ .menu-section[data-open="false"] .menu-title.menu-toggle::before { transform: translateX(-1px) rotate(-45deg); }
194
+
195
+ ul {
196
+ position: relative;
197
+ margin: 0;
198
+ padding: 0;
199
+ }
200
+
201
+ // The guide line, under the chevrons.
202
+ ul::before {
203
+ content: "";
204
+ position: absolute;
205
+ top: 2px;
206
+ bottom: var(--space--8);
207
+ left: calc(0.75rem - 0.5px);
208
+ width: 1px;
209
+ background: var(--nv-border);
210
+ }
211
+
212
+ // A divider starts where the items do, right of the guide line.
213
+ li[data-divider] { margin-left: 1.25rem; }
214
+ li[data-divider] .menu-item { width: 100%; margin-left: 0; }
215
+
216
+ .menu-item {
217
+ width: calc(100% - 1.25rem);
218
+ margin-left: 1.25rem;
219
+ padding-left: var(--space--16);
220
+ }
221
+
222
+ // The current page: a bar on the guide line, the item's full height.
223
+ .menu-item[data-active="true"]::before {
224
+ top: 2px;
225
+ bottom: 2px;
226
+ left: calc(-0.5rem - 1px);
227
+ width: 2px;
228
+ height: auto;
229
+ border-radius: 1px;
230
+ transform: none;
231
+ }
232
+ }
233
+
158
234
  // Actions: always open; section titles are labels, not buttons; items in the text color.
159
235
  &[data-kind="actions"] {
160
236
  .menu-title {
@@ -169,12 +245,14 @@ $menu-speed: 0.2s;
169
245
  }
170
246
 
171
247
  .menu-item { padding-left: 0.625rem; color: var(--nv-text); }
248
+ .menu-item[aria-disabled="true"] { color: var(--nv-text-subtle); }
172
249
  li:last-child { margin-bottom: 0; }
173
250
  }
174
251
 
175
252
  @media (prefers-reduced-motion: reduce) {
176
253
  .menu-items,
177
254
  .menu-toggle::after,
255
+ .menu-toggle::before,
178
256
  .menu-section[data-open="false"] ul { transition: none; }
179
257
  }
180
258
  }