@nurvus/ui 0.1.0-alpha.13 → 0.1.0-alpha.14
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.
- package/README.md +5 -0
- package/dist/index.js +1 -1
- package/dist/nurvus.css +6 -5
- package/dist/respawn.js +1 -1
- package/dist/types/components/Menu/Menu.d.ts +35 -27
- package/dist/types/components/Select/Select.d.ts +55 -0
- package/dist/types/components/Tree/Tree.d.ts +39 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/menu.d.ts +24 -0
- package/dist/types/respawn/Menu.d.ts +36 -26
- package/dist/types/respawn/Select.d.ts +54 -0
- package/dist/types/respawn/Tree.d.ts +36 -0
- package/dist/types/respawn/index.d.ts +5 -3
- package/dist/types/select.d.ts +70 -0
- package/dist/types/tree.d.ts +9 -0
- package/package.json +2 -2
- package/src/components/Button/Button.scss +8 -2
- package/src/components/Link/Link.md +11 -2
- package/src/components/Menu/Menu.md +32 -126
- package/src/components/Menu/Menu.scss +133 -51
- package/src/components/Menu/Menu.tsx +118 -67
- package/src/components/Select/Select.md +72 -0
- package/src/components/Select/Select.scss +170 -0
- package/src/components/Select/Select.tsx +196 -0
- package/src/components/Table/Table.md +3 -2
- package/src/components/Tag/Tag.scss +3 -1
- package/src/components/Text/Text.md +1 -1
- package/src/components/Tree/Tree.md +62 -0
- package/src/components/Tree/Tree.scss +73 -0
- package/src/components/Tree/Tree.tsx +125 -0
- package/src/css.ts +2 -1
- package/src/index.ts +5 -3
- package/src/menu.ts +66 -0
- package/src/respawn/Menu.ts +113 -62
- package/src/respawn/Select.ts +212 -0
- package/src/respawn/Tree.ts +116 -0
- package/src/respawn/index.ts +5 -3
- package/src/select.ts +140 -0
- package/src/styles/theme.scss +1 -1
- package/src/styles/type.json +1 -1
- package/src/tree.ts +46 -0
- package/dist/types/components/NavList/NavList.d.ts +0 -43
- package/dist/types/navList.d.ts +0 -7
- package/dist/types/respawn/NavList.d.ts +0 -43
- package/src/components/NavList/NavList.md +0 -39
- package/src/components/NavList/NavList.scss +0 -149
- package/src/components/NavList/NavList.tsx +0 -129
- package/src/navList.ts +0 -9
- package/src/respawn/NavList.ts +0 -126
package/src/respawn/NavList.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import CONSTANT from '../constants';
|
|
3
|
-
import { sectionId, startsOpen } from '../navList';
|
|
4
|
-
import { spawn, Child, ElementProps } from './spawn';
|
|
5
|
-
import { updatable, NurvusElement } from './update';
|
|
6
|
-
import '../components/NavList/NavList.scss';
|
|
7
|
-
|
|
8
|
-
export interface NavListItem {
|
|
9
|
-
/** What the link says. */
|
|
10
|
-
label: Child;
|
|
11
|
-
/** Where it goes. The item whose href equals `current` is marked as the current page. */
|
|
12
|
-
href: string;
|
|
13
|
-
/** Draws a hairline above this item, to split a section into groups. */
|
|
14
|
-
divider?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface NavListSection {
|
|
18
|
-
/** Stable id: names the section's open state and links its toggle to its list. Defaults to the title. */
|
|
19
|
-
id?: string;
|
|
20
|
-
/** The section heading. */
|
|
21
|
-
title: string;
|
|
22
|
-
/** Makes the heading a link too (e.g. to the section's overview page). */
|
|
23
|
-
href?: string;
|
|
24
|
-
/** The section's links. */
|
|
25
|
-
items: NavListItem[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface NavListProps extends ElementProps {
|
|
29
|
-
/** The sections, in order. */
|
|
30
|
-
sections: NavListSection[];
|
|
31
|
-
/** The href of the page being shown: its link is marked, and its section opens. */
|
|
32
|
-
current?: string;
|
|
33
|
-
/** Which sections start open: true (all), false (none) or a map of section id -> open. Defaults to all. */
|
|
34
|
-
defaultOpen?: boolean | Record<string, boolean>;
|
|
35
|
-
/** Called when a section opens or closes (e.g. to remember it). */
|
|
36
|
-
onToggle?: (id: string, open: boolean) => void;
|
|
37
|
-
/** Called when any link is clicked, with its href (e.g. to close a drawer). */
|
|
38
|
-
onNavigate?: (href: string, event: MouseEvent) => void;
|
|
39
|
-
/** Accessible name of the navigation landmark. */
|
|
40
|
-
label?: string;
|
|
41
|
-
/** Prefix for the ids that link each toggle to its list. Defaults to "nav-list". */
|
|
42
|
-
id?: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Site navigation: sections of links that open and close (an accordion, with
|
|
47
|
-
* a smooth animation), and the current page marked by a bar beside it. A
|
|
48
|
-
* click on a toggle opens or closes its section in place (the element stays
|
|
49
|
-
* the same); update({ current }) marks another page and opens its section.
|
|
50
|
-
*/
|
|
51
|
-
export default function NavList(props: NavListProps): NurvusElement<HTMLElement, NavListProps> {
|
|
52
|
-
return updatable(({
|
|
53
|
-
sections, current, defaultOpen = true, onToggle, onNavigate, label = 'Pages', id = 'nav-list', className, ...rest
|
|
54
|
-
}: NavListProps, keep) => {
|
|
55
|
-
const open: Record<string, boolean> = Object.fromEntries(sections.map((s) => [sectionId(s), startsOpen(defaultOpen, sectionId(s))]));
|
|
56
|
-
// The current page's section always starts open, as in React.
|
|
57
|
-
const home = sections.find((s) => s.items.some((item) => item.href === current));
|
|
58
|
-
if (home) open[sectionId(home)] = true;
|
|
59
|
-
|
|
60
|
-
const navigate = (href: string) => ({ click: (event: MouseEvent) => { if (onNavigate) onNavigate(href, event); } });
|
|
61
|
-
|
|
62
|
-
const renderSection = (section: NavListSection): HTMLElement => {
|
|
63
|
-
const sid = sectionId(section);
|
|
64
|
-
const listId = `${id}-${sid}`;
|
|
65
|
-
const toggles: HTMLElement[] = [];
|
|
66
|
-
const toggle = () => {
|
|
67
|
-
open[sid] = !open[sid];
|
|
68
|
-
keep({ defaultOpen: { ...open } });
|
|
69
|
-
el.setAttribute('data-open', String(open[sid]));
|
|
70
|
-
toggles.forEach((t) => {
|
|
71
|
-
t.setAttribute('aria-expanded', String(open[sid]));
|
|
72
|
-
if (t.hasAttribute('aria-label')) t.setAttribute('aria-label', `${open[sid] ? 'Hide' : 'Show'} ${section.title}`);
|
|
73
|
-
});
|
|
74
|
-
if (onToggle) onToggle(sid, open[sid]);
|
|
75
|
-
};
|
|
76
|
-
const toggleProps = (extra: Record<string, unknown>) => ({
|
|
77
|
-
tag: 'button', type: 'button', 'aria-expanded': open[sid], 'aria-controls': listId, events: { click: toggle }, ...extra,
|
|
78
|
-
});
|
|
79
|
-
const heading = section.href
|
|
80
|
-
? [
|
|
81
|
-
spawn({ tag: 'a', className: 'nav-list-title', href: section.href, 'data-active': current === section.href, events: navigate(section.href), children: section.title }),
|
|
82
|
-
spawn(toggleProps({ className: 'nav-list-toggle', 'aria-label': `${open[sid] ? 'Hide' : 'Show'} ${section.title}` })),
|
|
83
|
-
]
|
|
84
|
-
: [spawn(toggleProps({ className: 'nav-list-title nav-list-toggle', children: section.title }))];
|
|
85
|
-
heading.forEach((h) => { if (h.tagName === 'BUTTON') toggles.push(h); });
|
|
86
|
-
|
|
87
|
-
const el: HTMLElement = spawn({
|
|
88
|
-
className: 'nav-list-section',
|
|
89
|
-
'data-section': sid,
|
|
90
|
-
'data-open': open[sid],
|
|
91
|
-
children: [
|
|
92
|
-
spawn({ className: 'nav-list-heading', children: heading }),
|
|
93
|
-
spawn({
|
|
94
|
-
className: 'nav-list-items',
|
|
95
|
-
id: listId,
|
|
96
|
-
children: spawn({
|
|
97
|
-
tag: 'ul',
|
|
98
|
-
children: section.items.map((item) => spawn({
|
|
99
|
-
tag: 'li',
|
|
100
|
-
'data-divider': item.divider || undefined,
|
|
101
|
-
children: spawn({
|
|
102
|
-
tag: 'a',
|
|
103
|
-
className: 'nav-list-item',
|
|
104
|
-
href: item.href,
|
|
105
|
-
'data-active': current === item.href,
|
|
106
|
-
'aria-current': current === item.href ? 'page' : undefined,
|
|
107
|
-
events: navigate(item.href),
|
|
108
|
-
children: item.label,
|
|
109
|
-
}),
|
|
110
|
-
})),
|
|
111
|
-
}),
|
|
112
|
-
}),
|
|
113
|
-
],
|
|
114
|
-
});
|
|
115
|
-
return el;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
return spawn<HTMLElement>({
|
|
119
|
-
tag: 'nav',
|
|
120
|
-
className: classNames(className, 'nav-list', CONSTANT.CLASS_PREFIX),
|
|
121
|
-
'aria-label': label,
|
|
122
|
-
...rest,
|
|
123
|
-
children: sections.map(renderSection),
|
|
124
|
-
});
|
|
125
|
-
}, props);
|
|
126
|
-
}
|