@nurvus/ui 0.1.0-alpha.16 → 0.1.0-alpha.17
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 +6 -0
- package/dist/icons.svg +1 -0
- package/dist/index.js +1 -1
- package/dist/nurvus.css +3 -1
- package/dist/respawn.js +1 -1
- package/dist/types/anchor.d.ts +37 -0
- package/dist/types/components/Anchor/Anchor.d.ts +30 -0
- package/dist/types/components/Dropdown/Dropdown.d.ts +31 -0
- package/dist/types/components/Menu/Menu.d.ts +8 -1
- package/dist/types/dropdown.d.ts +9 -0
- package/dist/types/icons.d.ts +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/respawn/Anchor.d.ts +28 -0
- package/dist/types/respawn/Dropdown.d.ts +27 -0
- package/dist/types/respawn/Menu.d.ts +2 -0
- package/dist/types/respawn/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/anchor.ts +127 -0
- package/src/components/Anchor/Anchor.md +59 -0
- package/src/components/Anchor/Anchor.scss +65 -0
- package/src/components/Anchor/Anchor.tsx +105 -0
- package/src/components/Dropdown/Dropdown.md +48 -0
- package/src/components/Dropdown/Dropdown.scss +67 -0
- package/src/components/Dropdown/Dropdown.tsx +110 -0
- package/src/components/Menu/Menu.md +1 -1
- package/src/components/Menu/Menu.scss +78 -0
- package/src/components/Menu/Menu.tsx +15 -3
- package/src/css.ts +2 -0
- package/src/dropdown.ts +24 -0
- package/src/icons.ts +2 -0
- package/src/index.ts +4 -0
- package/src/respawn/Anchor.ts +126 -0
- package/src/respawn/Dropdown.ts +90 -0
- package/src/respawn/Menu.ts +10 -7
- package/src/respawn/index.ts +4 -0
package/src/respawn/Menu.ts
CHANGED
|
@@ -48,6 +48,8 @@ interface MenuBaseProps extends ElementProps {
|
|
|
48
48
|
label?: string;
|
|
49
49
|
/** Prefix for the ids inside (each toggle names its list). Defaults to "menu". */
|
|
50
50
|
id?: string;
|
|
51
|
+
/** Navigation: the chevron before the title ('start', the default: right when closed, down when open, a guide line down the items) or after it ('end'). */
|
|
52
|
+
chevron?: 'start' | 'end';
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export interface MenuProps extends MenuBaseProps {
|
|
@@ -81,12 +83,12 @@ export type MenuTreeProps = TreeProps & { kind: 'tree' };
|
|
|
81
83
|
export default function Menu(props: MenuProps = { sections: [] }): NurvusElement<HTMLElement, MenuProps> {
|
|
82
84
|
const kind = menuKind(props || {});
|
|
83
85
|
if (kind === 'tree') {
|
|
84
|
-
const { kind: _kind, sections: _s, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, ...tree } = props;
|
|
86
|
+
const { kind: _kind, sections: _s, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, chevron: _ch, ...tree } = props;
|
|
85
87
|
return Tree(tree as TreeProps) as any;
|
|
86
88
|
}
|
|
87
89
|
if (kind === 'actions') return MenuActions(props as MenuListProps) as any;
|
|
88
90
|
return updatable<HTMLElement, MenuListProps>(({
|
|
89
|
-
kind: _kind, sections = [], current, defaultOpen = true, onToggle, onNavigate, label = 'Pages', id = 'menu', className, ...rest
|
|
91
|
+
kind: _kind, sections = [], current, defaultOpen = true, onToggle, onNavigate, chevron = 'start', label = 'Pages', id = 'menu', className, ...rest
|
|
90
92
|
}: MenuListProps, keep) => {
|
|
91
93
|
const open: Record<string, boolean> = Object.fromEntries(sections.map((s) => [sectionId(s), startsOpen(defaultOpen, sectionId(s))]));
|
|
92
94
|
// The current page's section always starts open, as in React.
|
|
@@ -112,11 +114,10 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
112
114
|
const toggleProps = (extra: Record<string, unknown>) => ({
|
|
113
115
|
tag: 'button', type: 'button', 'aria-expanded': open[sid], 'aria-controls': listId, events: { click: toggle }, ...extra,
|
|
114
116
|
});
|
|
117
|
+
const link = () => spawn({ tag: 'a', className: 'menu-title', href: section.href, 'data-active': current === section.href, events: navigate(section.href as string), children: section.title });
|
|
118
|
+
const chev = () => spawn(toggleProps({ className: 'menu-toggle', 'aria-label': `${open[sid] ? 'Hide' : 'Show'} ${String(section.title)}` }));
|
|
115
119
|
const heading = section.href
|
|
116
|
-
? [
|
|
117
|
-
spawn({ tag: 'a', className: 'menu-title', href: section.href, 'data-active': current === section.href, events: navigate(section.href), children: section.title }),
|
|
118
|
-
spawn(toggleProps({ className: 'menu-toggle', 'aria-label': `${open[sid] ? 'Hide' : 'Show'} ${String(section.title)}` })),
|
|
119
|
-
]
|
|
120
|
+
? (chevron === 'start' ? [chev(), link()] : [link(), chev()])
|
|
120
121
|
: [spawn(toggleProps({ className: 'menu-title menu-toggle', children: section.title }))];
|
|
121
122
|
heading.forEach((h) => { if (h.tagName === 'BUTTON') toggles.push(h); });
|
|
122
123
|
|
|
@@ -166,6 +167,7 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
166
167
|
className: classNames(className, 'menu', CONSTANT.CLASS_PREFIX),
|
|
167
168
|
'aria-label': label,
|
|
168
169
|
'data-kind': 'nav',
|
|
170
|
+
'data-chevron': chevron,
|
|
169
171
|
...others,
|
|
170
172
|
events: {
|
|
171
173
|
...events,
|
|
@@ -182,13 +184,14 @@ export default function Menu(props: MenuProps = { sections: [] }): NurvusElement
|
|
|
182
184
|
/** A menu of actions (role="menu"): one Tab stop that follows the focus, arrow keys, type to find. */
|
|
183
185
|
function MenuActions(props: MenuListProps): NurvusElement<HTMLElement, MenuListProps> {
|
|
184
186
|
return updatable(({
|
|
185
|
-
kind: _kind, sections = [], label = 'Actions', id = 'menu', className, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, ...rest
|
|
187
|
+
kind: _kind, sections = [], label = 'Actions', id = 'menu', className, current: _c, defaultOpen: _d, onToggle: _t, onNavigate: _n, chevron: _ch, ...rest
|
|
186
188
|
}: MenuListProps) => {
|
|
187
189
|
let first = true;
|
|
188
190
|
const { events, ...others } = rest;
|
|
189
191
|
return spawn<HTMLElement>({
|
|
190
192
|
className: classNames(className, 'menu', CONSTANT.CLASS_PREFIX),
|
|
191
193
|
role: 'menu',
|
|
194
|
+
id,
|
|
192
195
|
'aria-label': label,
|
|
193
196
|
'data-kind': 'actions',
|
|
194
197
|
...others,
|
package/src/respawn/index.ts
CHANGED
|
@@ -53,6 +53,10 @@ export { BREAKPOINTS, isAtLeast } from '../breakpoints';
|
|
|
53
53
|
export type { Breakpoint, Responsive } from '../breakpoints';
|
|
54
54
|
export { default as Loader } from './Loader';
|
|
55
55
|
export type { LoaderProps } from './Loader';
|
|
56
|
+
export { default as Anchor } from './Anchor';
|
|
57
|
+
export type { AnchorProps, AnchorItem } from './Anchor';
|
|
58
|
+
export { default as Dropdown } from './Dropdown';
|
|
59
|
+
export type { DropdownProps } from './Dropdown';
|
|
56
60
|
export { default as Menu } from './Menu';
|
|
57
61
|
export type { MenuProps, MenuListProps, MenuTreeProps, MenuItem, MenuSection, MenuKind } from './Menu';
|
|
58
62
|
export { default as Select } from './Select';
|