@tangible/ui 0.2.23 → 0.2.25

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 (46) hide show
  1. package/components/Checkbox/Checkbox.js +1 -1
  2. package/components/DatePicker/DateRangePicker.js +1 -1
  3. package/components/Dropdown/Dropdown.js +1 -1
  4. package/components/GradientPicker/GradientPicker.js +3 -3
  5. package/components/NavMenu/NavMenu.d.ts +32 -0
  6. package/components/NavMenu/NavMenu.js +230 -0
  7. package/components/NavMenu/index.d.ts +3 -0
  8. package/components/NavMenu/index.js +2 -0
  9. package/components/NavMenu/types.d.ts +103 -0
  10. package/components/NavMenu/types.js +6 -0
  11. package/components/index.d.ts +2 -0
  12. package/components/index.js +1 -0
  13. package/figma-tokens.json +90 -1
  14. package/package.json +5 -1
  15. package/skills/building-with-tui/SKILL.md +10 -6
  16. package/styles/all.css +1 -1
  17. package/styles/all.expanded.css +546 -64
  18. package/styles/all.expanded.unlayered.css +546 -64
  19. package/styles/all.unlayered.css +1 -1
  20. package/styles/components/_bundle.scss +2 -0
  21. package/styles/components/checkbox.scss +13 -2
  22. package/styles/components/color-picker.scss +12 -4
  23. package/styles/components/combobox.scss +7 -6
  24. package/styles/components/date-picker.scss +8 -6
  25. package/styles/components/dropdown.scss +3 -5
  26. package/styles/components/gradient-picker.scss +3 -5
  27. package/styles/components/input/index.scss +16 -6
  28. package/styles/components/multi-combobox.scss +6 -6
  29. package/styles/components/multi-select.scss +10 -7
  30. package/styles/components/nav-menu.scss +385 -0
  31. package/styles/components/radio.scss +11 -3
  32. package/styles/components/search-select.scss +7 -7
  33. package/styles/components/select.scss +7 -6
  34. package/styles/components/slider.scss +1 -1
  35. package/styles/components/switch.scss +1 -1
  36. package/styles/components/text-input.scss +15 -1
  37. package/styles/core.css +1 -1
  38. package/styles/core.unlayered.css +1 -1
  39. package/styles/index.scss +18 -0
  40. package/styles/system/_constants.scss +0 -6
  41. package/styles/system/_palettes.scss +6 -0
  42. package/styles/system/_text-styles.scss +200 -0
  43. package/styles/system/_tokens.scss +7 -0
  44. package/styles/system/index.scss +3 -1
  45. package/tui-manifest.json +115 -3
  46. package/utils/listbox/group.js +3 -1
@@ -16,7 +16,7 @@ import { isDev } from '../../utils/is-dev.js';
16
16
  //
17
17
  // CSS token API (component layer, read via fallback):
18
18
  // --tui-checkbox-accent Accent color → --tui-input-accent → --tui-theme-primary-base
19
- // --tui-checkbox-border Border color → --tui-color-border
19
+ // --tui-checkbox-border Border color → --tui-input-border → --tui-color-border-control
20
20
  // --tui-checkbox-border-invalid Invalid border → --tui-theme-danger-base
21
21
  // --tui-checkbox-radius Border radius → --tui-radius-sm
22
22
  // --tui-checkbox-bg Background → --tui-color-bg
@@ -167,7 +167,7 @@ function RangeField({ label, value, locale, onCommit, }) {
167
167
  if (parsed)
168
168
  onCommit(parsed);
169
169
  };
170
- return (_jsxs("label", { className: "tui-date-range-picker__field", children: [_jsx("span", { className: "tui-date-range-picker__field-label", children: label }), _jsx(TextInput, { value: text ?? value, onChange: (e) => setText(e.target.value), onBlur: (e) => commit(e.target.value), onKeyDown: (e) => {
170
+ return (_jsxs("label", { className: "tui-date-range-picker__field", children: [_jsx("span", { className: "tui-date-range-picker__field-label tui-text-style-overline", children: label }), _jsx(TextInput, { value: text ?? value, onChange: (e) => setText(e.target.value), onBlur: (e) => commit(e.target.value), onKeyDown: (e) => {
171
171
  if (e.key === 'Enter')
172
172
  commit(e.currentTarget.value);
173
173
  } })] }));
@@ -277,7 +277,7 @@ DropdownSeparatorComponent.displayName = 'Dropdown.Separator';
277
277
  * Non-interactive section label for grouping menu items.
278
278
  */
279
279
  function DropdownHeaderComponent({ className, children }) {
280
- return (_jsx("div", { role: "presentation", className: cx('tui-dropdown__header', className), children: children }));
280
+ return (_jsx("div", { role: "presentation", className: cx('tui-dropdown__header', 'tui-text-style-overline', className), children: children }));
281
281
  }
282
282
  DropdownHeaderComponent.displayName = 'Dropdown.Header';
283
283
  export const Dropdown = DropdownRoot;
@@ -33,7 +33,7 @@ function NumberField({ label, hideLabel, value, min, max, suffix, disabled, onCo
33
33
  if (raw >= min && raw <= max)
34
34
  onCommit(raw);
35
35
  };
36
- return (_jsxs("span", { className: cx('tui-gradient-picker__field', className), children: [!hideLabel && (_jsx("label", { className: "tui-gradient-picker__label", htmlFor: id, children: label })), _jsx(TextInput, { id: id, size: "sm", inputMode: "decimal", autoComplete: "off", spellCheck: false, value: display, suffix: suffix, disabled: disabled, role: "spinbutton", "aria-label": hideLabel ? label : undefined, "aria-valuenow": round1(value), "aria-valuetext": `${round1(value)}${suffix ?? ''}`, "aria-valuemin": min, "aria-valuemax": max, onChange: (e) => {
36
+ return (_jsxs("span", { className: cx('tui-gradient-picker__field', className), children: [!hideLabel && (_jsx("label", { className: "tui-gradient-picker__label tui-text-style-overline", htmlFor: id, children: label })), _jsx(TextInput, { id: id, size: "sm", inputMode: "decimal", autoComplete: "off", spellCheck: false, value: display, suffix: suffix, disabled: disabled, role: "spinbutton", "aria-label": hideLabel ? label : undefined, "aria-valuenow": round1(value), "aria-valuetext": `${round1(value)}${suffix ?? ''}`, "aria-valuemin": min, "aria-valuemax": max, onChange: (e) => {
37
37
  const text = e.target.value;
38
38
  setDraft(text);
39
39
  const num = parseFloat(text);
@@ -181,11 +181,11 @@ export function GradientPicker({ value: controlledValue, defaultValue = formatGr
181
181
  // stop after the reorder — close it instead.
182
182
  setOpenStop(null);
183
183
  patch({ stops: reverseStops(stops) });
184
- } }) }), _jsx(Tooltip.Content, { children: L.reverse })] }), _jsxs(Tooltip, { children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: "system/copy", label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsxs("div", { className: "tui-gradient-picker__stops", children: [_jsx("span", { className: "tui-gradient-picker__label", children: L.stopsHeading }), stops.map((stop, i) => (_jsxs("div", { className: "tui-gradient-picker__stop", children: [_jsxs(Popover, { open: openStop === i, onOpenChange: (open) => setOpenStop(open ? i : null), children: [_jsx(Popover.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "tui-gradient-picker__swatch", "aria-label": L.editStop(i + 1), disabled: disabled, children: _jsx("span", { className: "tui-gradient-picker__swatch-fill", "aria-hidden": "true", style: { '--_swatch': stop.color } }) }) }), _jsx(Popover.Content, { side: "bottom", align: "start", modal: true, "aria-label": L.editStop(i + 1), className: "tui-gradient-picker__stop-popover", children: _jsx(ColorPicker, { value: stop.color, onValueChange: (color) => updateStop(i, { color }), alpha: alpha, formats: formats }) })] }), _jsx(NumberField, { label: L.stopPosition(i + 1), hideLabel: true, value: stop.position, min: stops[i - 1]?.position ?? 0, max: stops[i + 1]?.position ?? 100, suffix: "%", disabled: disabled, onCommit: (position) => updateStop(i, { position: round1(position) }), className: "tui-gradient-picker__stop-position" }), _jsx(IconButton, { ref: (el) => {
184
+ } }) }), _jsx(Tooltip.Content, { children: L.reverse })] }), _jsxs(Tooltip, { children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: "system/copy", label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsxs("div", { className: "tui-gradient-picker__stops", children: [_jsx("span", { className: "tui-gradient-picker__label tui-text-style-overline", children: L.stopsHeading }), stops.map((stop, i) => (_jsxs("div", { className: "tui-gradient-picker__stop", children: [_jsxs(Popover, { open: openStop === i, onOpenChange: (open) => setOpenStop(open ? i : null), children: [_jsx(Popover.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "tui-gradient-picker__swatch", "aria-label": L.editStop(i + 1), disabled: disabled, children: _jsx("span", { className: "tui-gradient-picker__swatch-fill", "aria-hidden": "true", style: { '--_swatch': stop.color } }) }) }), _jsx(Popover.Content, { side: "bottom", align: "start", modal: true, "aria-label": L.editStop(i + 1), className: "tui-gradient-picker__stop-popover", children: _jsx(ColorPicker, { value: stop.color, onValueChange: (color) => updateStop(i, { color }), alpha: alpha, formats: formats }) })] }), _jsx(NumberField, { label: L.stopPosition(i + 1), hideLabel: true, value: stop.position, min: stops[i - 1]?.position ?? 0, max: stops[i + 1]?.position ?? 100, suffix: "%", disabled: disabled, onCommit: (position) => updateStop(i, { position: round1(position) }), className: "tui-gradient-picker__stop-position" }), _jsx(IconButton, { ref: (el) => {
185
185
  removeRefs.current[i] = el;
186
186
  }, icon: "system/trash", label: L.removeStop(i + 1), variant: "ghost", theme: "danger", size: "sm", disabled: disabled || stops.length <= 2, onClick: () => removeStop(i, true) })] }, i))), _jsx(Button, { ref: (el) => {
187
187
  addRef.current = el;
188
- }, variant: "outline", size: "sm", disabled: disabled, onClick: () => addStop(), className: "tui-gradient-picker__add", children: L.addStop })] }), _jsxs("div", { className: cx('tui-gradient-picker__geometry', gradient.type === 'linear' && 'is-linear'), children: [_jsxs("span", { className: "tui-gradient-picker__field tui-gradient-picker__type-field", children: [_jsx("span", { className: "tui-gradient-picker__label", id: typeLabelId, children: L.type }), _jsxs(Select, { value: gradient.type, onValueChange: (t) => patch({ type: t }), disabled: disabled, size: "sm", "aria-labelledby": typeLabelId, children: [_jsx(Select.Trigger, { className: "tui-gradient-picker__type" }), _jsx(Select.Content, { children: GRADIENT_TYPES.map((t) => (_jsx(Select.Option, { value: t, children: L.types[t] }, t))) })] })] }), gradient.type === 'linear' && (_jsxs("span", { className: "tui-gradient-picker__angle", children: [_jsx(NumberField, { label: L.angle, value: gradient.angle, min: 0, max: 360, suffix: "\u00B0", disabled: disabled,
188
+ }, variant: "outline", size: "sm", disabled: disabled, onClick: () => addStop(), className: "tui-gradient-picker__add", children: L.addStop })] }), _jsxs("div", { className: cx('tui-gradient-picker__geometry', gradient.type === 'linear' && 'is-linear'), children: [_jsxs("span", { className: "tui-gradient-picker__field tui-gradient-picker__type-field", children: [_jsx("span", { className: "tui-gradient-picker__label tui-text-style-overline", id: typeLabelId, children: L.type }), _jsxs(Select, { value: gradient.type, onValueChange: (t) => patch({ type: t }), disabled: disabled, size: "sm", "aria-labelledby": typeLabelId, children: [_jsx(Select.Trigger, { className: "tui-gradient-picker__type" }), _jsx(Select.Content, { children: GRADIENT_TYPES.map((t) => (_jsx(Select.Option, { value: t, children: L.types[t] }, t))) })] })] }), gradient.type === 'linear' && (_jsxs("span", { className: "tui-gradient-picker__angle", children: [_jsx(NumberField, { label: L.angle, value: gradient.angle, min: 0, max: 360, suffix: "\u00B0", disabled: disabled,
189
189
  // mod 360 so a committed 360 doesn't flip to 0 on blur.
190
190
  onCommit: (angle) => patch({ angle: round1(angle) % 360 }) }), _jsx(AngleDial, { angle: gradient.angle, onAngleChange: (angle) => patch({ angle }), disabled: disabled })] })), gradient.type === 'radial' && (_jsxs(_Fragment, { children: [_jsx(NumberField, { label: L.sizeX, value: gradient.sizeX, min: 0, max: 1000, suffix: "%", disabled: disabled, onCommit: (sizeX) => patch({ sizeX: round1(sizeX) }) }), _jsx(NumberField, { label: L.sizeY, value: gradient.sizeY, min: 0, max: 1000, suffix: "%", disabled: disabled, onCommit: (sizeY) => patch({ sizeY: round1(sizeY) }) })] })), (gradient.type === 'radial' || gradient.type === 'conic') && (_jsxs(_Fragment, { children: [_jsx(NumberField, { label: L.posX, value: gradient.posX, min: 0, max: 100, suffix: "%", disabled: disabled, onCommit: (posX) => patch({ posX: round1(posX) }) }), _jsx(NumberField, { label: L.posY, value: gradient.posY, min: 0, max: 100, suffix: "%", disabled: disabled, onCommit: (posY) => patch({ posY: round1(posY) }) })] }))] }), _jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", children: copied ? L.copied : '' })] }));
191
191
  }
@@ -0,0 +1,32 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { NavMenuItemProps, NavMenuLabels, NavMenuOrientation, NavMenuSubProps } from './types';
3
+ /**
4
+ * Navigation menu rows: groups with headings, the current item, nested items.
5
+ * Vertical by default (sidebars). `orientation="horizontal"` makes a bar whose
6
+ * items with a `NavMenu.Sub` open as flyouts, following the APG disclosure
7
+ * navigation pattern: buttons with aria-expanded, never role="menu", never
8
+ * hover-to-open. Not a landmark: put it inside `Sidebar.Nav` or a labelled
9
+ * `<nav>`.
10
+ */
11
+ declare const NavMenuRoot: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
12
+ orientation?: NavMenuOrientation;
13
+ labels?: NavMenuLabels;
14
+ children: ReactNode;
15
+ } & import("react").RefAttributes<HTMLDivElement>>;
16
+ declare const NavMenuGroup: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "children"> & {
17
+ label?: ReactNode;
18
+ labelAs?: import("./types").NavMenuGroupLabelElement;
19
+ children: ReactNode;
20
+ } & import("react").RefAttributes<HTMLDivElement>>;
21
+ declare function NavMenuSub({ className, children, ...rest }: NavMenuSubProps): import("react/jsx-runtime").JSX.Element;
22
+ declare namespace NavMenuSub {
23
+ var displayName: string;
24
+ }
25
+ declare const NavMenuItem: import("react").ForwardRefExoticComponent<NavMenuItemProps & import("react").RefAttributes<HTMLElement>>;
26
+ type NavMenuComponent = typeof NavMenuRoot & {
27
+ Group: typeof NavMenuGroup;
28
+ Item: typeof NavMenuItem;
29
+ Sub: typeof NavMenuSub;
30
+ };
31
+ export declare const NavMenu: NavMenuComponent;
32
+ export {};
@@ -0,0 +1,230 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Children, cloneElement, createContext, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, } from 'react';
3
+ import { useFloating, autoUpdate, offset, flip, shift } from '@floating-ui/react';
4
+ import { cx } from '../../utils/cx.js';
5
+ import { isDev } from '../../utils/is-dev.js';
6
+ import { mergeProps } from '../../utils/merge-props.js';
7
+ import { composeRefs, getElementRef } from '../../utils/compose-refs.js';
8
+ import { Icon } from '../Icon/index.js';
9
+ import { defaultNavMenuLabels } from './types.js';
10
+ // Items render <li>, so they're only valid inside a Group or Sub list. The
11
+ // context exists to warn when one isn't.
12
+ const ListContext = createContext(false);
13
+ const RootContext = createContext({
14
+ orientation: 'vertical',
15
+ labels: defaultNavMenuLabels,
16
+ openId: null,
17
+ setOpenId: () => { },
18
+ });
19
+ // True inside a flyout panel: everything there lays out vertically, and an
20
+ // item with its own Sub nests inline instead of opening another flyout.
21
+ const FlyoutContext = createContext(false);
22
+ // =============================================================================
23
+ // NavMenu (root)
24
+ // =============================================================================
25
+ /**
26
+ * Navigation menu rows: groups with headings, the current item, nested items.
27
+ * Vertical by default (sidebars). `orientation="horizontal"` makes a bar whose
28
+ * items with a `NavMenu.Sub` open as flyouts, following the APG disclosure
29
+ * navigation pattern: buttons with aria-expanded, never role="menu", never
30
+ * hover-to-open. Not a landmark: put it inside `Sidebar.Nav` or a labelled
31
+ * `<nav>`.
32
+ */
33
+ const NavMenuRoot = forwardRef(function NavMenu({ orientation = 'vertical', labels, className, children, ...rest }, ref) {
34
+ const [openId, setOpenId] = useState(null);
35
+ const value = useMemo(() => ({ orientation, labels: { ...defaultNavMenuLabels, ...labels }, openId, setOpenId }), [orientation, labels, openId]);
36
+ return (_jsx("div", { ref: ref, ...rest, "data-orientation": orientation, className: cx('tui-nav-menu', orientation === 'horizontal' && 'is-horizontal', className), children: _jsx(RootContext.Provider, { value: value, children: children }) }));
37
+ });
38
+ // =============================================================================
39
+ // NavMenu.Group
40
+ // =============================================================================
41
+ const NavMenuGroup = forwardRef(function NavMenuGroup({ label, labelAs: Label = 'h2', className, children, ...rest }, ref) {
42
+ const labelId = useId();
43
+ const { orientation } = useContext(RootContext);
44
+ const inFlyout = useContext(FlyoutContext);
45
+ const hasLabel = label !== undefined && label !== null && label !== false;
46
+ // In a bar, a group is an inline cluster: its heading stays (it still names
47
+ // the list for AT) but is visually hidden. Inside a flyout it shows.
48
+ const headingHidden = orientation === 'horizontal' && !inFlyout;
49
+ return (_jsxs("div", { ref: ref, ...rest, className: cx('tui-nav-menu__group', className), children: [hasLabel &&
50
+ (headingHidden ? (
51
+ // In a bar the label only names the list. A visually hidden heading
52
+ // would show up in heading navigation with nothing under it, so it
53
+ // renders as a plain span instead.
54
+ _jsx("span", { id: labelId, className: "tui-visually-hidden", children: label })) : (
55
+ // The class is the override hook for the overline style; the
56
+ // stylesheet also applies it, so static markup stays styled.
57
+ _jsx(Label, { id: labelId, className: "tui-nav-menu__group-label tui-text-style-overline", children: label }))), _jsx("ul", { className: "tui-nav-menu__list", "aria-labelledby": hasLabel ? labelId : undefined, children: _jsx(ListContext.Provider, { value: true, children: children }) })] }));
58
+ });
59
+ // =============================================================================
60
+ // NavMenu.Sub
61
+ // =============================================================================
62
+ const isGroup = (node) => isValidElement(node) && node.type === NavMenuGroup;
63
+ function NavMenuSub({ className, children, ...rest }) {
64
+ // Groups bring their own headed lists, so a Sub of groups is a plain
65
+ // container; a Sub of items is the list itself.
66
+ if (Children.toArray(children).some(isGroup)) {
67
+ return (_jsx("div", { ...rest, className: cx('tui-nav-menu__sub', 'has-groups', className), children: children }));
68
+ }
69
+ return (_jsx("ul", { ...rest, className: cx('tui-nav-menu__sub', className), children: _jsx(ListContext.Provider, { value: true, children: children }) }));
70
+ }
71
+ NavMenuSub.displayName = 'NavMenu.Sub';
72
+ // =============================================================================
73
+ // NavMenu.Item
74
+ // =============================================================================
75
+ function toAriaCurrent(current) {
76
+ if (current === undefined || current === false)
77
+ return undefined;
78
+ return current === true ? 'page' : current;
79
+ }
80
+ const isSub = (node) => isValidElement(node) && node.type === NavMenuSub;
81
+ const NavMenuItem = forwardRef(function NavMenuItem(props, ref) {
82
+ const { current, icon, disabled, asChild, className, children, ...rest } = props;
83
+ const inList = useContext(ListContext);
84
+ const { orientation, labels, openId, setOpenId } = useContext(RootContext);
85
+ const inFlyout = useContext(FlyoutContext);
86
+ const warned = useRef(false);
87
+ useEffect(() => {
88
+ if (isDev() && !inList && !warned.current) {
89
+ warned.current = true;
90
+ console.warn('NavMenu.Item renders an <li>: place it inside NavMenu.Group or NavMenu.Sub.');
91
+ }
92
+ }, [inList]);
93
+ // Sub lists render after the link, inside the same <li>.
94
+ const all = Children.toArray(children);
95
+ const subs = all.filter(isSub);
96
+ const label = all.filter((c) => !isSub(c));
97
+ // -- Flyout (horizontal bar, item with a Sub) -------------------------------
98
+ const id = useId();
99
+ const panelId = `${id}-panel`;
100
+ const labelId = `${id}-label`;
101
+ const toggleTextId = `${id}-toggle`;
102
+ const flyout = orientation === 'horizontal' && !inFlyout && subs.length > 0 && !disabled;
103
+ const open = flyout && openId === id;
104
+ const setOpen = useCallback((next) => {
105
+ if (next)
106
+ setOpenId(id);
107
+ else if (openId === id)
108
+ setOpenId(null);
109
+ }, [id, openId, setOpenId]);
110
+ const entryRef = useRef(null);
111
+ const toggleRef = useRef(null);
112
+ const { refs, floatingStyles } = useFloating({
113
+ open,
114
+ placement: 'bottom-start',
115
+ strategy: 'absolute',
116
+ middleware: [offset(4), flip(), shift({ padding: 8 })],
117
+ whileElementsMounted: autoUpdate,
118
+ });
119
+ // Click or tap outside closes it. Focus leaving is handled by onBlur below.
120
+ useEffect(() => {
121
+ if (!open)
122
+ return;
123
+ const onPointerDown = (e) => {
124
+ if (!entryRef.current?.contains(e.target))
125
+ setOpen(false);
126
+ };
127
+ document.addEventListener('pointerdown', onPointerDown);
128
+ return () => document.removeEventListener('pointerdown', onPointerDown);
129
+ }, [open, setOpen]);
130
+ const onEntryKeyDown = (e) => {
131
+ if (open && e.key === 'Escape') {
132
+ e.preventDefault();
133
+ setOpen(false);
134
+ toggleRef.current?.focus();
135
+ }
136
+ };
137
+ const onEntryBlur = (e) => {
138
+ if (open && !entryRef.current?.contains(e.relatedTarget))
139
+ setOpen(false);
140
+ };
141
+ // Safari and Firefox on macOS don't focus a button on click. Without this,
142
+ // clicking the toggle to close an open flyout blurs the panel first (closing
143
+ // it), and the click then re-opens it. Only while open: Chromium treats a
144
+ // programmatic focus inside a pointer event as focus-visible, so doing it on
145
+ // every click would ring the toggle for mouse users.
146
+ const focusOnPointerDown = (e) => {
147
+ if (open)
148
+ e.currentTarget.focus();
149
+ };
150
+ // -- Row --------------------------------------------------------------------
151
+ const ariaCurrent = toAriaCurrent(current);
152
+ // Top-level rows of a bar. Rows inside a flyout panel keep the vertical look.
153
+ const bar = orientation === 'horizontal' && !inFlyout;
154
+ const itemClass = cx('tui-nav-menu__item', bar && 'is-bar', className);
155
+ const iconNode = icon ? (_jsx("span", { className: "tui-nav-menu__icon", "aria-hidden": "true", children: _jsx(Icon, { name: icon }) })) : null;
156
+ const content = (inner) => (_jsxs(_Fragment, { children: [iconNode, _jsx("span", { className: "tui-nav-menu__label", id: flyout ? labelId : undefined, children: inner })] }));
157
+ const chevron = (_jsx("span", { className: "tui-nav-menu__chevron", "aria-hidden": "true", children: _jsx(Icon, { name: "system/chevron-down-small" }) }));
158
+ let row;
159
+ // A flyout parent with no destination of its own: the row IS the toggle.
160
+ const rowIsToggle = flyout && !asChild && props.href === undefined;
161
+ if (disabled) {
162
+ // Inert: the APG disabled-link pattern. An <a> with no href is out of the
163
+ // tab order; role="link" keeps it announced as a link, and aria-disabled
164
+ // is valid on that role (it isn't on a role-less span). Rest still lands
165
+ // (data-testid), minus the href that would make it live again.
166
+ const inertRest = { ...rest };
167
+ delete inertRest.href;
168
+ row = (_jsx("a", { ref: ref, ...inertRest, role: "link", className: itemClass, "aria-disabled": "true", "aria-current": ariaCurrent, children: content(asChild && isValidElement(label[0]) ? label[0].props.children : label) }));
169
+ }
170
+ else if (rowIsToggle) {
171
+ const restProps = rest;
172
+ row = (_jsxs("button", { ref: composeRefs(ref, toggleRef), type: "button", ...rest, className: cx(itemClass, 'is-toggle'), "aria-current": ariaCurrent, "aria-expanded": open, "aria-controls": panelId, onPointerDown: focusOnPointerDown, onClick: (e) => {
173
+ restProps.onClick?.(e);
174
+ if (!e.defaultPrevented)
175
+ setOpen(!open);
176
+ }, children: [content(label), chevron] }));
177
+ }
178
+ else if (asChild) {
179
+ const child = label[0];
180
+ if (!isValidElement(child)) {
181
+ if (isDev())
182
+ console.warn('NavMenu.Item asChild needs a single element child (a router <Link>).');
183
+ row = null;
184
+ }
185
+ else {
186
+ const childProps = child.props;
187
+ const merged = mergeProps(childProps, {
188
+ // Rest (data-testid, handlers) lands on the link like the other branches.
189
+ ...rest,
190
+ className: itemClass,
191
+ // When `current` is set it wins over the router's own active props.
192
+ // When it's unset, mergeProps skips the undefined value, so a router
193
+ // that sets aria-current itself keeps it.
194
+ 'aria-current': ariaCurrent,
195
+ });
196
+ merged.ref = composeRefs(ref, getElementRef(child));
197
+ row = cloneElement(child, merged, content(childProps.children));
198
+ }
199
+ }
200
+ else if (props.href !== undefined) {
201
+ row = (_jsx("a", { ref: ref, ...rest, className: itemClass, "aria-current": ariaCurrent, children: content(label) }));
202
+ }
203
+ else {
204
+ row = (_jsx("button", { ref: ref, type: "button", ...rest, className: itemClass, "aria-current": ariaCurrent, children: content(label) }));
205
+ }
206
+ if (!flyout) {
207
+ return (_jsxs("li", { className: "tui-nav-menu__entry", children: [row, !(disabled && bar) && subs] }));
208
+ }
209
+ return (_jsxs("li", { ref: composeRefs(entryRef, refs.setReference), className: cx('tui-nav-menu__entry', 'has-flyout', !rowIsToggle && 'is-split'), onKeyDown: onEntryKeyDown, onBlur: onEntryBlur, children: [row, !rowIsToggle && (
210
+ // A link can't also toggle, so a parent with a destination gets its own
211
+ // toggle. It's named "<label> <submenu>", so the bar never has a row
212
+ // of identical "toggle" buttons.
213
+ _jsxs("button", { ref: toggleRef, type: "button", className: cx('tui-nav-menu__toggle', 'is-bar'), "aria-expanded": open, "aria-controls": panelId, "aria-labelledby": `${labelId} ${toggleTextId}`, onPointerDown: focusOnPointerDown, onClick: () => setOpen(!open), children: [chevron, _jsx("span", { id: toggleTextId, hidden: true, children: labels.submenu })] })), _jsx("div", { id: panelId, ref: refs.setFloating, style: floatingStyles, className: "tui-nav-menu__flyout", hidden: !open,
214
+ // Following a link inside closes the panel (APG): in a single-page
215
+ // app nothing else would, and it would sit over the new page. Enter
216
+ // on a link fires click too. Router onClicks compose: this runs after
217
+ // the link's own handler, on the bubble.
218
+ onClick: (e) => {
219
+ if (e.target.closest('a[href]'))
220
+ setOpen(false);
221
+ }, children: _jsx(FlyoutContext.Provider, { value: true, children: subs }) })] }));
222
+ });
223
+ export const NavMenu = Object.assign(NavMenuRoot, {
224
+ Group: NavMenuGroup,
225
+ Item: NavMenuItem,
226
+ Sub: NavMenuSub,
227
+ });
228
+ NavMenuRoot.displayName = 'NavMenu';
229
+ NavMenuGroup.displayName = 'NavMenu.Group';
230
+ NavMenuItem.displayName = 'NavMenu.Item';
@@ -0,0 +1,3 @@
1
+ export { NavMenu } from './NavMenu';
2
+ export { defaultNavMenuLabels } from './types';
3
+ export type { NavMenuProps, NavMenuOrientation, NavMenuLabels, NavMenuGroupProps, NavMenuGroupLabelElement, NavMenuItemProps, NavMenuItemAsLink, NavMenuItemAsButton, NavMenuItemAsChild, NavMenuCurrent, NavMenuSubProps, } from './types';
@@ -0,0 +1,2 @@
1
+ export { NavMenu } from './NavMenu.js';
2
+ export { defaultNavMenuLabels } from './types.js';
@@ -0,0 +1,103 @@
1
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2
+ import type { IconName } from '../../icons/registry';
3
+ export type NavMenuOrientation = 'vertical' | 'horizontal';
4
+ /** Visually hidden strings, for localisation. */
5
+ export type NavMenuLabels = {
6
+ /**
7
+ * Word appended to a flyout parent's label to name its separate toggle
8
+ * button (a parent that is also a link): "Catalog submenu".
9
+ * @default 'submenu'
10
+ */
11
+ submenu?: string;
12
+ };
13
+ export declare const defaultNavMenuLabels: Required<NavMenuLabels>;
14
+ /**
15
+ * Root. Not a landmark: put it inside `Sidebar.Nav` or your own `<nav>`,
16
+ * which owns the label.
17
+ */
18
+ export type NavMenuProps = ComponentPropsWithoutRef<'div'> & {
19
+ /**
20
+ * `vertical` (sidebars) stacks groups and nests a `NavMenu.Sub` inline.
21
+ * `horizontal` makes a bar: groups become inline clusters (headings visually
22
+ * hidden, lists still labelled), and an item with a `NavMenu.Sub` opens it
23
+ * as a flyout. A flyout follows the APG disclosure pattern: a button with
24
+ * `aria-expanded`, opened by click or Enter/Space (never hover), closed by
25
+ * Escape (focus returns to the button), Tab-ing out or clicking elsewhere.
26
+ * One flyout is open at a time. Groups inside a flyout show their headings.
27
+ * @default 'vertical'
28
+ */
29
+ orientation?: NavMenuOrientation;
30
+ /** Visually hidden strings. */
31
+ labels?: NavMenuLabels;
32
+ children: ReactNode;
33
+ };
34
+ export type NavMenuGroupLabelElement = 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span';
35
+ export type NavMenuGroupProps = Omit<ComponentPropsWithoutRef<'div'>, 'children'> & {
36
+ /**
37
+ * Visible group heading, styled with the overline text style. It names the
38
+ * group's list via `aria-labelledby`. Omit it for an unlabelled group.
39
+ */
40
+ label?: ReactNode;
41
+ /**
42
+ * Element for the heading. Pick the level that fits the page outline; use
43
+ * `'span'` when headings would be noise (the list stays labelled either way).
44
+ * @default 'h2'
45
+ */
46
+ labelAs?: NavMenuGroupLabelElement;
47
+ children: ReactNode;
48
+ };
49
+ /**
50
+ * `aria-current` values for a nav item. `true` means `'page'`, the item for
51
+ * the page being shown. `'true'` marks an ancestor of that page, such as an
52
+ * open parent whose child is current, and gives it ancestor styling
53
+ * (emphasis, no fill). Screen readers announce both as "current", so a nested
54
+ * page reads as two current items; that's valid ARIA and matches what the
55
+ * route actually is.
56
+ */
57
+ export type NavMenuCurrent = boolean | 'page' | 'step' | 'location' | 'date' | 'time' | 'true';
58
+ type NavMenuItemBaseProps = {
59
+ /** Marks the current item; see {@link NavMenuCurrent}. */
60
+ current?: NavMenuCurrent;
61
+ /** Leading icon, from the registry. Sized by `--tui-nav-menu-icon-size`. */
62
+ icon?: IconName;
63
+ /**
64
+ * Inert item: rendered as a disabled link (`role="link"`, `aria-disabled`,
65
+ * no href), out of the tab order. For destinations that exist but aren't
66
+ * available yet.
67
+ */
68
+ disabled?: boolean;
69
+ /**
70
+ * The label, plus an optional `NavMenu.Sub` of nested items.
71
+ *
72
+ * Vertical: the Sub renders after the link, inside the same list item, and
73
+ * whether it renders at all is up to you (e.g. only while its parent is
74
+ * current). Horizontal: the Sub is a flyout. With no `href`, the row itself
75
+ * toggles it; with an `href` (or `asChild` link), the row navigates and a
76
+ * separate toggle button opens it.
77
+ */
78
+ children: ReactNode;
79
+ };
80
+ /** Link item: renders an `<a>`. */
81
+ export type NavMenuItemAsLink = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'a'>, 'children' | 'aria-current'> & {
82
+ href: string;
83
+ asChild?: never;
84
+ };
85
+ /** Action item: renders a `<button type="button">`. */
86
+ export type NavMenuItemAsButton = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'button'>, 'children' | 'aria-current' | 'disabled'> & {
87
+ href?: never;
88
+ asChild?: never;
89
+ };
90
+ /**
91
+ * Router item: the first non-`NavMenu.Sub` child is the element (a router
92
+ * `<Link>`, say). It receives the item's class, `aria-current`, the icon and
93
+ * a label wrapper. It must render a real `<a href>`.
94
+ */
95
+ export type NavMenuItemAsChild = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'a'>, 'children' | 'aria-current' | 'href'> & {
96
+ asChild: true;
97
+ href?: never;
98
+ };
99
+ export type NavMenuItemProps = NavMenuItemAsLink | NavMenuItemAsButton | NavMenuItemAsChild;
100
+ export type NavMenuSubProps = Omit<ComponentPropsWithoutRef<'ul'>, 'children'> & {
101
+ children: ReactNode;
102
+ };
103
+ export {};
@@ -0,0 +1,6 @@
1
+ // =============================================================================
2
+ // NavMenu Types
3
+ // =============================================================================
4
+ export const defaultNavMenuLabels = {
5
+ submenu: 'submenu',
6
+ };
@@ -33,6 +33,7 @@ export { Rating } from './Rating';
33
33
  export { SegmentedControl } from './SegmentedControl';
34
34
  export { Slider } from './Slider';
35
35
  export { Sidebar, defaultSidebarToggleLabels } from './Sidebar';
36
+ export { NavMenu, defaultNavMenuLabels } from './NavMenu';
36
37
  export { StepIndicator } from './StepIndicator';
37
38
  export { StepList } from './StepList';
38
39
  export { DataTable } from './Table';
@@ -77,6 +78,7 @@ export type { RadioGroupProps, RadioProps } from './Radio';
77
78
  export type { RatingProps } from './Rating';
78
79
  export type { SegmentedControlProps, SegmentedControlItemProps, SegmentedControlValue, SegmentedControlVariant, SegmentedControlSize, SegmentedControlOrientation, } from './SegmentedControl';
79
80
  export type { SidebarProps, SidebarHeaderProps, SidebarFooterProps, SidebarNavProps, SidebarToggleProps, SidebarToggleLabels, } from './Sidebar';
81
+ export type { NavMenuProps, NavMenuOrientation, NavMenuLabels, NavMenuGroupProps, NavMenuGroupLabelElement, NavMenuItemProps, NavMenuItemAsLink, NavMenuItemAsButton, NavMenuItemAsChild, NavMenuCurrent, NavMenuSubProps, } from './NavMenu';
80
82
  export type { StepIndicatorProps, StepStatus } from './StepIndicator';
81
83
  export type { StepListProps, StepListItemProps } from './StepList';
82
84
  export type { DataTableProps } from './Table';
@@ -31,6 +31,7 @@ export { Rating } from './Rating/index.js';
31
31
  export { SegmentedControl } from './SegmentedControl/index.js';
32
32
  export { Slider } from './Slider/index.js';
33
33
  export { Sidebar, defaultSidebarToggleLabels } from './Sidebar/index.js';
34
+ export { NavMenu, defaultNavMenuLabels } from './NavMenu/index.js';
34
35
  export { StepIndicator } from './StepIndicator/index.js';
35
36
  export { StepList } from './StepList/index.js';
36
37
  export { DataTable } from './Table/index.js';
package/figma-tokens.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.23",
2
+ "version": "0.2.25",
3
3
  "source": "publish/styles/all.expanded.css",
4
4
  "prefix": "tui-",
5
5
  "note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation. CONTRACT: consumers read TUI defaults from this file at build time (variables[].cssVar, the \"Light\"/\"Dark\" mode names, and alias chains into TUI/Primitives). Renaming a cssVar or a mode is a breaking change to those consumers even when the CSS value is unchanged — a rename silently becomes an undefined default downstream — so treat it as at least a minor bump and call it out in the CHANGELOG.",
@@ -98,6 +98,18 @@
98
98
  }
99
99
  }
100
100
  },
101
+ {
102
+ "name": "palette/blue/450",
103
+ "type": "COLOR",
104
+ "values": {
105
+ "Default": {
106
+ "r": 0.18823529411764706,
107
+ "g": 0.30196078431372547,
108
+ "b": 0.8666666666666667,
109
+ "a": 1
110
+ }
111
+ }
112
+ },
101
113
  {
102
114
  "name": "palette/blue/50",
103
115
  "type": "COLOR",
@@ -266,6 +278,18 @@
266
278
  }
267
279
  }
268
280
  },
281
+ {
282
+ "name": "palette/gray/450",
283
+ "type": "COLOR",
284
+ "values": {
285
+ "Default": {
286
+ "r": 0.5137254901960784,
287
+ "g": 0.5411764705882353,
288
+ "b": 0.592156862745098,
289
+ "a": 1
290
+ }
291
+ }
292
+ },
269
293
  {
270
294
  "name": "palette/gray/50",
271
295
  "type": "COLOR",
@@ -434,6 +458,18 @@
434
458
  }
435
459
  }
436
460
  },
461
+ {
462
+ "name": "palette/green/450",
463
+ "type": "COLOR",
464
+ "values": {
465
+ "Default": {
466
+ "r": 0,
467
+ "g": 0.5882352941176471,
468
+ "b": 0.1450980392156863,
469
+ "a": 1
470
+ }
471
+ }
472
+ },
437
473
  {
438
474
  "name": "palette/green/50",
439
475
  "type": "COLOR",
@@ -602,6 +638,18 @@
602
638
  }
603
639
  }
604
640
  },
641
+ {
642
+ "name": "palette/purple/450",
643
+ "type": "COLOR",
644
+ "values": {
645
+ "Default": {
646
+ "r": 0.611764705882353,
647
+ "g": 0.3176470588235294,
648
+ "b": 0.6745098039215687,
649
+ "a": 1
650
+ }
651
+ }
652
+ },
605
653
  {
606
654
  "name": "palette/purple/50",
607
655
  "type": "COLOR",
@@ -770,6 +818,18 @@
770
818
  }
771
819
  }
772
820
  },
821
+ {
822
+ "name": "palette/red/450",
823
+ "type": "COLOR",
824
+ "values": {
825
+ "Default": {
826
+ "r": 0.8705882352941177,
827
+ "g": 0.26666666666666666,
828
+ "b": 0.27450980392156865,
829
+ "a": 1
830
+ }
831
+ }
832
+ },
773
833
  {
774
834
  "name": "palette/red/50",
775
835
  "type": "COLOR",
@@ -938,6 +998,18 @@
938
998
  }
939
999
  }
940
1000
  },
1001
+ {
1002
+ "name": "palette/yellow/450",
1003
+ "type": "COLOR",
1004
+ "values": {
1005
+ "Default": {
1006
+ "r": 0.6705882352941176,
1007
+ "g": 0.4666666666666667,
1008
+ "b": 0,
1009
+ "a": 1
1010
+ }
1011
+ }
1012
+ },
941
1013
  {
942
1014
  "name": "palette/yellow/50",
943
1015
  "type": "COLOR",
@@ -1285,6 +1357,23 @@
1285
1357
  }
1286
1358
  }
1287
1359
  },
1360
+ {
1361
+ "name": "color/border/control",
1362
+ "cssVar": "--tui-color-border-control",
1363
+ "type": "COLOR",
1364
+ "values": {
1365
+ "Light": {
1366
+ "alias": "palette/gray/450",
1367
+ "collection": "TUI/Primitives",
1368
+ "hex": "#838a97"
1369
+ },
1370
+ "Dark": {
1371
+ "alias": "palette/gray/500",
1372
+ "collection": "TUI/Primitives",
1373
+ "hex": "#6b7280"
1374
+ }
1375
+ }
1376
+ },
1288
1377
  {
1289
1378
  "name": "color/border/default",
1290
1379
  "cssVar": "--tui-color-border",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "description": "Tangible Design System",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",
@@ -142,6 +142,10 @@
142
142
  "import": "./components/MultiSelect/index.js",
143
143
  "types": "./components/MultiSelect/index.d.ts"
144
144
  },
145
+ "./components/NavMenu": {
146
+ "import": "./components/NavMenu/index.js",
147
+ "types": "./components/NavMenu/index.d.ts"
148
+ },
145
149
  "./components/Notice": {
146
150
  "import": "./components/Notice/index.js",
147
151
  "types": "./components/Notice/index.d.ts"