@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.
@@ -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,
@@ -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';