@helixds/react 0.1.0 → 0.2.0
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/AGENTS.md +4 -1
- package/dist/archetypes/actions-navigation.md +62 -0
- package/dist/archetypes/data-display.md +68 -0
- package/dist/archetypes/feedback-status.md +54 -0
- package/dist/archetypes/form-selection.md +61 -0
- package/dist/archetypes/foundation.md +56 -0
- package/dist/archetypes/layout.md +53 -0
- package/dist/archetypes/overlays.md +54 -0
- package/dist/archetypes/text-input.md +58 -0
- package/dist/components/Badge/Badge.types.d.ts +1 -1
- package/dist/components/Combobox/Combobox.d.ts +17 -0
- package/dist/components/Combobox/Combobox.doc.d.ts +4 -0
- package/dist/components/Combobox/Combobox.doc.js +41 -0
- package/dist/components/Combobox/Combobox.js +141 -0
- package/dist/components/Combobox/Combobox.types.d.ts +31 -0
- package/dist/components/Combobox/Combobox.types.js +2 -0
- package/dist/components/Combobox/index.d.ts +9 -0
- package/dist/components/Combobox/index.js +2 -0
- package/dist/components/Icon/Icon.doc.js +2 -2
- package/dist/components/Icon/Icon.js +1 -1
- package/dist/components/Icon/Icon.types.d.ts +1 -1
- package/dist/components/Icon/iconStroke.d.ts +1 -1
- package/dist/components/Icon/iconStroke.js +1 -1
- package/dist/components/Menu/Menu.doc.js +4 -4
- package/dist/components/Menu/Menu.js +3 -3
- package/dist/components/Menu/Menu.types.d.ts +1 -1
- package/dist/components/Modal/Modal.doc.js +1 -1
- package/dist/components/Modal/Modal.types.d.ts +1 -1
- package/dist/components/MultiSelect/MultiSelect.d.ts +2 -2
- package/dist/components/MultiSelect/MultiSelect.doc.js +1 -1
- package/dist/components/MultiSelect/MultiSelect.js +4 -4
- package/dist/components/Popover/Popover.d.ts +14 -0
- package/dist/components/Popover/Popover.doc.d.ts +4 -0
- package/dist/components/Popover/Popover.doc.js +47 -0
- package/dist/components/Popover/Popover.js +157 -0
- package/dist/components/Popover/Popover.types.d.ts +27 -0
- package/dist/components/Popover/Popover.types.js +2 -0
- package/dist/components/Popover/index.d.ts +9 -0
- package/dist/components/Popover/index.js +2 -0
- package/dist/components/SegmentedControl/SegmentedControl.doc.js +2 -2
- package/dist/components/SegmentedControl/SegmentedControl.js +1 -1
- package/dist/components/Select/Select.doc.js +2 -2
- package/dist/components/Select/Select.js +1 -1
- package/dist/components/SidePanel/SidePanel.doc.js +1 -1
- package/dist/components/SidePanel/SidePanel.types.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +13 -0
- package/dist/components/Tabs/Tabs.doc.d.ts +4 -0
- package/dist/components/Tabs/Tabs.doc.js +47 -0
- package/dist/components/Tabs/Tabs.js +61 -0
- package/dist/components/Tabs/Tabs.types.d.ts +33 -0
- package/dist/components/Tabs/Tabs.types.js +2 -0
- package/dist/components/Tabs/index.d.ts +9 -0
- package/dist/components/Tabs/index.js +2 -0
- package/dist/components/Toast/Toast.doc.js +1 -1
- package/dist/components/Toast/Toast.js +2 -2
- package/dist/components/Toast/toastStore.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.doc.js +1 -1
- package/dist/components/Tooltip/Tooltip.js +5 -5
- package/dist/components/Tooltip/Tooltip.types.d.ts +1 -1
- package/dist/contracts/Accordion.json +5 -4
- package/dist/contracts/AppShell.json +111 -28
- package/dist/contracts/Avatar.json +3 -2
- package/dist/contracts/AvatarGroup.json +1 -0
- package/dist/contracts/Badge.json +2 -1
- package/dist/contracts/Button.json +2 -1
- package/dist/contracts/Card.json +3 -2
- package/dist/contracts/Chart.json +2 -1
- package/dist/contracts/Checkbox.json +1 -0
- package/dist/contracts/CheckboxGroup.json +1 -0
- package/dist/contracts/Chip.json +3 -2
- package/dist/contracts/ChipGroup.json +1 -0
- package/dist/contracts/Combobox.json +431 -0
- package/dist/contracts/FAB.json +3 -2
- package/dist/contracts/Icon.json +10 -9
- package/dist/contracts/IconButton.json +2 -1
- package/dist/contracts/Input.json +2 -1
- package/dist/contracts/Menu.json +7 -6
- package/dist/contracts/Modal.json +5 -4
- package/dist/contracts/MultiSelect.json +6 -5
- package/dist/contracts/NavItem.json +2 -1
- package/dist/contracts/PageHeader.json +1 -0
- package/dist/contracts/Popover.json +322 -0
- package/dist/contracts/RadioButton.json +1 -0
- package/dist/contracts/RadioGroup.json +1 -0
- package/dist/contracts/SegmentedControl.json +4 -3
- package/dist/contracts/Select.json +9 -9
- package/dist/contracts/SideNav.json +2 -1
- package/dist/contracts/SidePanel.json +5 -4
- package/dist/contracts/Switch.json +1 -0
- package/dist/contracts/Table.json +1 -0
- package/dist/contracts/Tabs.json +353 -0
- package/dist/contracts/Textarea.json +2 -1
- package/dist/contracts/Toast.json +6 -5
- package/dist/contracts/Tooltip.json +4 -3
- package/dist/contracts/TopBar.json +2 -0
- package/dist/contracts/manifest.json +1539 -44
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6 -0
- package/dist/layout/AppShell/AppShell.d.ts +1 -1
- package/dist/layout/AppShell/AppShell.doc.js +5 -0
- package/dist/layout/AppShell/AppShell.js +109 -2
- package/dist/layout/AppShell/AppShell.types.d.ts +6 -0
- package/dist/layout/AppShell/AppShellContext.d.ts +17 -0
- package/dist/layout/AppShell/AppShellContext.js +4 -0
- package/dist/layout/SideNav/SideNav.doc.js +1 -0
- package/dist/layout/TopBar/TopBar.js +7 -1
- package/dist/lib/useDialogTransition.d.ts +1 -1
- package/dist/lib/useDialogTransition.js +1 -1
- package/dist/lib/useDisclosureTransition.d.ts +1 -1
- package/dist/lib/useDisclosureTransition.js +1 -1
- package/dist/patterns/expand-collapse-chevron.md +1 -1
- package/dist/patterns/motion-effects.md +2 -4
- package/package.json +26 -4
- package/src/globals.css +338 -22
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { IconChevronDown, IconSearch } from '@tabler/icons-react';
|
|
4
|
+
import { cn } from '../../lib/utils.js';
|
|
5
|
+
import { Icon } from '../Icon/index.js';
|
|
6
|
+
import { Menu, optionId } from '../Menu/index.js';
|
|
7
|
+
let idCounter = 0;
|
|
8
|
+
/** The one row Menu shows when nothing matches — disabled, so it can't be picked (the Combobox contract). */
|
|
9
|
+
const NO_RESULTS = '__helix-combobox-no-results__';
|
|
10
|
+
const matches = (label, query) => label.toLowerCase().includes(query.trim().toLowerCase());
|
|
11
|
+
/**
|
|
12
|
+
* Select's field with a real <input> as the trigger: typing filters Menu's listbox (see Combobox's and the Menu contracts).
|
|
13
|
+
* Real DOM focus stays on the input; aria-activedescendant points at the highlighted option.
|
|
14
|
+
*/
|
|
15
|
+
export function Combobox({ label, options, value, defaultValue, onChange, placeholder, description, errorMessage, invalid = false, disabled = false, required = false, fullWidth = false, hideLabel = false, id: idProp, name, className, }) {
|
|
16
|
+
const uid = React.useRef(`helix-combobox-${++idCounter}`).current;
|
|
17
|
+
const id = idProp ?? uid;
|
|
18
|
+
const menuId = `${id}-menu`;
|
|
19
|
+
const descId = description && !invalid ? `${id}-desc` : undefined;
|
|
20
|
+
const errId = invalid && errorMessage ? `${id}-err` : undefined;
|
|
21
|
+
const describedby = [descId, errId].filter(Boolean).join(' ') || undefined;
|
|
22
|
+
const isControlled = value !== undefined;
|
|
23
|
+
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
24
|
+
const current = isControlled ? value : internalValue;
|
|
25
|
+
const labelOf = React.useCallback((v) => options.find(o => o.value === v)?.label ?? '', [options]);
|
|
26
|
+
const [query, setQuery] = React.useState(() => labelOf(current));
|
|
27
|
+
// The filter applies only once the user types — opening from a chosen value shows every option.
|
|
28
|
+
const [typed, setTyped] = React.useState(false);
|
|
29
|
+
const [open, setOpen] = React.useState(false);
|
|
30
|
+
const [activeValue, setActiveValue] = React.useState();
|
|
31
|
+
const inputRef = React.useRef(null);
|
|
32
|
+
// Set while a pointer presses inside the list: Safari doesn't focus a pressed button, so the field's blur has no
|
|
33
|
+
// relatedTarget to tell it the press is on an option — this does.
|
|
34
|
+
const pressingMenu = React.useRef(false);
|
|
35
|
+
// A controlled value changed from outside — show its label (unless the user is mid-typing).
|
|
36
|
+
React.useEffect(() => { if (!typed)
|
|
37
|
+
setQuery(labelOf(current)); }, [current, labelOf, typed]);
|
|
38
|
+
const filtered = React.useMemo(() => (typed && query.trim() ? options.filter(o => matches(o.label, query)) : options), [options, query, typed]);
|
|
39
|
+
const enabled = filtered.filter(o => !o.disabled);
|
|
40
|
+
const menuOptions = filtered.length ? filtered : [{ value: NO_RESULTS, label: 'No results', disabled: true }];
|
|
41
|
+
const restore = () => { setQuery(labelOf(current)); setTyped(false); };
|
|
42
|
+
const openMenu = () => {
|
|
43
|
+
if (disabled)
|
|
44
|
+
return;
|
|
45
|
+
const selected = options.find(o => o.value === current && !o.disabled)?.value;
|
|
46
|
+
setActiveValue(selected ?? enabled[0]?.value);
|
|
47
|
+
setOpen(true);
|
|
48
|
+
};
|
|
49
|
+
const closeMenu = () => { setOpen(false); restore(); };
|
|
50
|
+
const commit = (next) => {
|
|
51
|
+
pressingMenu.current = false;
|
|
52
|
+
if (next === NO_RESULTS)
|
|
53
|
+
return;
|
|
54
|
+
if (!isControlled)
|
|
55
|
+
setInternalValue(next);
|
|
56
|
+
onChange?.(next);
|
|
57
|
+
setQuery(labelOf(next));
|
|
58
|
+
setTyped(false);
|
|
59
|
+
setOpen(false);
|
|
60
|
+
inputRef.current?.focus();
|
|
61
|
+
};
|
|
62
|
+
const moveActive = (dir) => {
|
|
63
|
+
if (!enabled.length)
|
|
64
|
+
return;
|
|
65
|
+
const i = enabled.findIndex(o => o.value === activeValue);
|
|
66
|
+
const next = i === -1 ? (dir === 1 ? 0 : enabled.length - 1) : (i + dir + enabled.length) % enabled.length;
|
|
67
|
+
setActiveValue(enabled[next].value);
|
|
68
|
+
};
|
|
69
|
+
const handleKeyDown = (e) => {
|
|
70
|
+
if (disabled)
|
|
71
|
+
return;
|
|
72
|
+
switch (e.key) {
|
|
73
|
+
case 'ArrowDown':
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
open ? moveActive(1) : openMenu();
|
|
76
|
+
break;
|
|
77
|
+
case 'ArrowUp':
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
open ? moveActive(-1) : openMenu();
|
|
80
|
+
break;
|
|
81
|
+
case 'Enter':
|
|
82
|
+
if (open && activeValue) {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
commit(activeValue);
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case 'Escape':
|
|
88
|
+
if (open) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
closeMenu();
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case 'Tab':
|
|
94
|
+
// Close first, then let focus move on as usual (no preventDefault).
|
|
95
|
+
if (open)
|
|
96
|
+
closeMenu();
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const handleChange = (e) => {
|
|
103
|
+
const q = e.target.value;
|
|
104
|
+
setQuery(q);
|
|
105
|
+
setTyped(true);
|
|
106
|
+
setActiveValue(options.find(o => !o.disabled && matches(o.label, q))?.value);
|
|
107
|
+
setOpen(true);
|
|
108
|
+
};
|
|
109
|
+
// Click-outside — closes when a pointer lands outside both the field and the portaled menu.
|
|
110
|
+
React.useEffect(() => {
|
|
111
|
+
if (!open)
|
|
112
|
+
return;
|
|
113
|
+
const handlePointerDown = (e) => {
|
|
114
|
+
const target = e.target;
|
|
115
|
+
if (inputRef.current?.parentElement?.contains(target))
|
|
116
|
+
return;
|
|
117
|
+
if (document.getElementById(menuId)?.contains(target)) {
|
|
118
|
+
pressingMenu.current = true;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
setOpen(false);
|
|
122
|
+
setQuery(labelOf(current));
|
|
123
|
+
setTyped(false);
|
|
124
|
+
};
|
|
125
|
+
document.addEventListener('pointerdown', handlePointerDown);
|
|
126
|
+
return () => document.removeEventListener('pointerdown', handlePointerDown);
|
|
127
|
+
}, [open, menuId, labelOf, current]);
|
|
128
|
+
return (_jsxs("div", { "data-helix-part": "combobox-root", ...(fullWidth ? { 'data-full-width': '' } : {}), ...(disabled ? { 'data-disabled': '' } : {}), ...(invalid ? { 'data-invalid': '' } : {}), className: cn(className), children: [_jsxs("label", { "data-helix-part": "combobox-label", htmlFor: id, style: hideLabel ? { position: 'absolute', width: 1, height: 1, overflow: 'hidden', clip: 'rect(0,0,0,0)' } : undefined, children: [label, required && _jsx("span", { "data-helix-part": "combobox-required", "aria-hidden": "true", children: " *" })] }), _jsxs("div", { "data-helix-part": "combobox-wrapper", ...(disabled ? { 'data-disabled': '' } : {}), ...(invalid ? { 'data-invalid': '' } : {}), children: [_jsx("span", { "data-helix-part": "combobox-icon", "aria-hidden": "true", children: _jsx(Icon, { icon: IconSearch, size: 16 }) }), _jsx("input", { ref: inputRef, id: id, type: "text", "data-helix-part": "combobox-input", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": open ? menuId : undefined, "aria-activedescendant": open && activeValue ? optionId(menuId, activeValue) : undefined, "aria-invalid": invalid || undefined, "aria-describedby": describedby, "aria-required": required || undefined, autoComplete: "off", spellCheck: false, disabled: disabled, placeholder: placeholder, value: query, onFocus: e => e.currentTarget.select(),
|
|
129
|
+
// Focus leaving the field closes the list and puts the chosen label back — unless it went into the list
|
|
130
|
+
// itself (a pointer pressing an option), which picks it.
|
|
131
|
+
onBlur: e => {
|
|
132
|
+
if (pressingMenu.current) {
|
|
133
|
+
pressingMenu.current = false;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (open && !document.getElementById(menuId)?.contains(e.relatedTarget))
|
|
137
|
+
closeMenu();
|
|
138
|
+
}, onClick: () => (open ? closeMenu() : openMenu()), onChange: handleChange, onKeyDown: handleKeyDown }), _jsx("span", { "data-helix-part": "combobox-chevron", "aria-hidden": "true", children: _jsx(Icon, { icon: IconChevronDown, size: 16 }) }), _jsx(Menu, { id: menuId, expanded: open, anchorRef: inputRef, options: menuOptions, onSelect: commit, ...(current !== undefined ? { value: current } : {}), ...(activeValue !== undefined ? { activeValue } : {}) }), (name || required) && (_jsx("input", { "data-helix-part": "combobox-native", type: "text", tabIndex: -1, "aria-hidden": "true", name: name, value: current ?? '', required: required, disabled: disabled, onChange: () => { }, onFocus: () => inputRef.current?.focus() }))] }), description && !invalid && (_jsx("span", { id: descId, "data-helix-part": "combobox-description", children: description })), invalid && errorMessage && (_jsx("span", { id: errId, "data-helix-part": "combobox-error", role: "alert", children: errorMessage }))] }));
|
|
139
|
+
}
|
|
140
|
+
Combobox.displayName = 'Combobox';
|
|
141
|
+
//# sourceMappingURL=Combobox.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @helixds/react — agent note
|
|
3
|
+
* Before using Combobox, read its contract: node_modules/@helixds/react/dist/contracts/Combobox.json
|
|
4
|
+
* (every prop, which are required, when not to use it, the import line). Do not guess Helix props.
|
|
5
|
+
* Guide: node_modules/@helixds/react/AGENTS.md
|
|
6
|
+
*/
|
|
7
|
+
export interface ComboboxOption {
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ComboboxProps {
|
|
13
|
+
label: string;
|
|
14
|
+
/** The options to search and pick from. Typing filters them by label (case-insensitive, contains). */
|
|
15
|
+
options: ComboboxOption[];
|
|
16
|
+
value?: string;
|
|
17
|
+
defaultValue?: string;
|
|
18
|
+
onChange?: (value: string) => void;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
errorMessage?: string;
|
|
22
|
+
invalid?: boolean;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
fullWidth?: boolean;
|
|
26
|
+
hideLabel?: boolean;
|
|
27
|
+
id?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=Combobox.types.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @helixds/react — agent note
|
|
3
|
+
* Before using Combobox, read its contract: node_modules/@helixds/react/dist/contracts/Combobox.json
|
|
4
|
+
* (every prop, which are required, when not to use it, the import line). Do not guess Helix props.
|
|
5
|
+
* Guide: node_modules/@helixds/react/AGENTS.md
|
|
6
|
+
*/
|
|
7
|
+
export { Combobox } from './Combobox.js';
|
|
8
|
+
export type { ComboboxProps, ComboboxOption } from './Combobox.types.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -19,13 +19,13 @@ export const doc = {
|
|
|
19
19
|
{ part: 'icon-root', label: 'color.success', token: '--helix-color-icon-success', kind: 'color' },
|
|
20
20
|
{ part: 'icon-root', label: 'color.warning', token: '--helix-color-icon-warning', kind: 'color' },
|
|
21
21
|
{ part: 'icon-root', label: 'color.info', token: '--helix-color-icon-info', kind: 'color' },
|
|
22
|
-
{ part: 'icon-root', label: 'stroke-width', value: '1.3px → 2.8px real', kind: 'other', meta: 'ADR-
|
|
22
|
+
{ part: 'icon-root', label: 'stroke-width', value: '1.3px → 2.8px real', kind: 'other', meta: 'ADR-014 stroke rule — real on-screen width per size (12: 1.3, 14: 1.4, 16: 1.5, 18: 1.5, 20: 1.7, 24: 1.8, 28: 2.0, 32: 2.2, 36: 2.4, 40: 2.8px), applied automatically by Icon' },
|
|
23
23
|
{ part: 'icon-root', label: 'viewBox', value: '0 0 24 24', kind: 'other' },
|
|
24
24
|
],
|
|
25
25
|
features: [
|
|
26
26
|
'icon — any HelixIconComponent-shaped icon (e.g. IconPlus), passed by reference not by name string — Tabler is the default set, not a requirement',
|
|
27
27
|
'size — fixed pixel size, one of 12 | 14 | 16 | 18 | 20 | 24 | 28 | 32 | 36 | 40 — never scales with font-size',
|
|
28
|
-
'stroke — derived automatically from size (ADR-
|
|
28
|
+
'stroke — derived automatically from size (ADR-014 stroke rule); pass only for a deliberate one-off',
|
|
29
29
|
'decorative/label — controls aria-hidden vs role="img" + aria-label',
|
|
30
30
|
],
|
|
31
31
|
examples: [
|
|
@@ -4,7 +4,7 @@ import { cn } from '../../lib/utils.js';
|
|
|
4
4
|
import { iconStrokeForSize } from './iconStroke.js';
|
|
5
5
|
const Icon = ({ icon: IconComponent, size = 16, stroke, color = 'currentColor', label, decorative = true, className, }) => {
|
|
6
6
|
const isMeaningful = !decorative && !!label;
|
|
7
|
-
// Stroke rule (ADR-
|
|
7
|
+
// Stroke rule (ADR-014): derived from the real on-screen line width for this size.
|
|
8
8
|
const resolvedStroke = stroke ?? iconStrokeForSize(size);
|
|
9
9
|
// icon-vector (the inner <path>) is generated inside the Tabler component and isn't
|
|
10
10
|
// reachable as a prop target — only icon-root carries a data-helix-part.
|
|
@@ -28,7 +28,7 @@ export interface IconProps {
|
|
|
28
28
|
size?: IconSize;
|
|
29
29
|
/**
|
|
30
30
|
* Stroke width applied to the icon path (24×24 viewBox units). Default: derived automatically
|
|
31
|
-
* from `size` by the icon stroke rule (ADR-
|
|
31
|
+
* from `size` by the icon stroke rule (ADR-014, `ICON_STROKE_PX_BY_SIZE` in iconStroke.ts) —
|
|
32
32
|
* a real on-screen line of 1.3px at 12 rising to 2.8px at 40. Tabler's viewBox stays fixed at
|
|
33
33
|
* 24×24, so a flat stroke value would get thinner on screen as `size` drops. Don't pass it to
|
|
34
34
|
* fix a "too thin" icon — change the rule instead. Pass explicitly only for a deliberate
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IconSize } from './Icon.types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Icon stroke rule (ADR-
|
|
3
|
+
* Icon stroke rule (ADR-014) — the single source of truth for how thick an icon's line reads on
|
|
4
4
|
* screen. Values are the **real rendered line width in CSS px**, not the SVG `stroke` attribute:
|
|
5
5
|
* Tabler's viewBox stays fixed at 24×24 whatever `size` renders at, so the same `stroke` value
|
|
6
6
|
* gets thinner on screen as the icon shrinks (rendered px = stroke × size / 24). Designing in real
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Icon stroke rule (ADR-
|
|
2
|
+
* Icon stroke rule (ADR-014) — the single source of truth for how thick an icon's line reads on
|
|
3
3
|
* screen. Values are the **real rendered line width in CSS px**, not the SVG `stroke` attribute:
|
|
4
4
|
* Tabler's viewBox stays fixed at 24×24 whatever `size` renders at, so the same `stroke` value
|
|
5
5
|
* gets thinner on screen as the icon shrinks (rendered px = stroke × size / 24). Designing in real
|
|
@@ -3,9 +3,9 @@ export const doc = {
|
|
|
3
3
|
purpose: 'A Helix-styled, portaled popup listbox anchored to a trigger — the internal primitive Select uses instead of a native <select> dropdown.',
|
|
4
4
|
contract: 'contracts/components/Menu.json',
|
|
5
5
|
a11y: [
|
|
6
|
-
'`role="listbox"` on the root, `role="option"` + `aria-selected` on each item — hand-rolled, see
|
|
6
|
+
'`role="listbox"` on the root, `role="option"` + `aria-selected` on each item — hand-rolled, see the Menu contract.',
|
|
7
7
|
'Menu is deliberately non-focusable — the consumer\'s trigger owns real keyboard focus and drives selection via `aria-activedescendant`, matching how Select\'s own button trigger works.',
|
|
8
|
-
'Portaled to `document.body` so it always renders above ancestor `overflow`/`z-index` — same reasoning Toast already established (
|
|
8
|
+
'Portaled to `document.body` so it always renders above ancestor `overflow`/`z-index` — same reasoning Toast already established (the Toast contract).',
|
|
9
9
|
],
|
|
10
10
|
variants: [],
|
|
11
11
|
sizes: [],
|
|
@@ -33,8 +33,8 @@ export const doc = {
|
|
|
33
33
|
'labelEnd — optional per-option secondary text on the end edge (menu-item-label-end), muted, tabular figures',
|
|
34
34
|
'value — selected value, drives aria-selected + the blue highlight',
|
|
35
35
|
'activeValue — keyboard-highlighted value, drives the gray highlight (consumer owns the keyboard handling, e.g. Select)',
|
|
36
|
-
'Positioning: always opens below the anchor, never flips above — horizontal clamp only, adapted from Tooltip\'s clamp (
|
|
37
|
-
'Not exported as a top-level app-facing pattern yet — currently consumed only by Select internally, per
|
|
36
|
+
'Positioning: always opens below the anchor, never flips above — horizontal clamp only, adapted from Tooltip\'s clamp (the Tooltip contract).',
|
|
37
|
+
'Not exported as a top-level app-facing pattern yet — currently consumed only by Select internally, per the Menu contract.',
|
|
38
38
|
],
|
|
39
39
|
examples: [
|
|
40
40
|
{
|
|
@@ -10,9 +10,9 @@ export function optionId(menuId, value) {
|
|
|
10
10
|
return `${menuId}-option-${value}`;
|
|
11
11
|
}
|
|
12
12
|
// Keeps the menu this many px clear of the viewport edge — same principle as Tooltip's own
|
|
13
|
-
// EDGE_GUTTER (
|
|
13
|
+
// EDGE_GUTTER (the Tooltip contract), horizontal clamp only: always opens below the anchor — never flips above,
|
|
14
14
|
// even when there isn't room below (the page scrolls instead) — and is clamped so it never overflows
|
|
15
|
-
// the left/right edge for an anchor sitting near either side of the viewport. See
|
|
15
|
+
// the left/right edge for an anchor sitting near either side of the viewport. See the Menu contract.
|
|
16
16
|
const EDGE_GUTTER = 8;
|
|
17
17
|
function usePosition(expanded, anchorRef, menuRef) {
|
|
18
18
|
const [style, setStyle] = React.useState({ visibility: 'hidden' });
|
|
@@ -95,7 +95,7 @@ export function Menu({ id, expanded, anchorRef, options, value, multiple = false
|
|
|
95
95
|
const flat = options.flatMap(o => ('options' in o ? o.options : [o]));
|
|
96
96
|
const numericOnly = flat.length > 0 && flat.every(o => /^[\d\s.,%+-]+$/.test(o.label.trim()));
|
|
97
97
|
const renderOption = (opt) => (_jsx("button", { type: "button", id: optionId(id, opt.value), "data-helix-part": "menu-item", role: "option", "aria-selected": multiple ? (values ?? []).includes(opt.value) : opt.value === value, "data-active": opt.value === activeValue ? '' : undefined, disabled: opt.disabled, onClick: () => !opt.disabled && onSelect(opt.value),
|
|
98
|
-
// Keeps focus on the trigger — Menu is deliberately non-focusable (see
|
|
98
|
+
// Keeps focus on the trigger — Menu is deliberately non-focusable (see the Menu contract: the consumer's
|
|
99
99
|
// trigger button owns real keyboard focus and drives aria-activedescendant; mousedown here would
|
|
100
100
|
// otherwise steal it).
|
|
101
101
|
onMouseDown: e => e.preventDefault(), children: opt.labelEnd === undefined ? opt.label : (_jsxs(_Fragment, { children: [_jsx("span", { "data-helix-part": "menu-item-label", children: opt.label }), _jsx("span", { "data-helix-part": "menu-item-label-end", children: opt.labelEnd })] })) }, opt.value));
|
|
@@ -22,7 +22,7 @@ export interface MenuProps {
|
|
|
22
22
|
anchorRef: React.RefObject<HTMLElement | null>;
|
|
23
23
|
options: (MenuOption | MenuOptionGroup)[];
|
|
24
24
|
value?: string;
|
|
25
|
-
/** Multi-selection (
|
|
25
|
+
/** Multi-selection (the MultiSelect contract): the listbox gets aria-multiselectable and every value in `values` is
|
|
26
26
|
* marked selected. `value` is ignored when this is set. */
|
|
27
27
|
multiple?: boolean;
|
|
28
28
|
/** Selected values when `multiple` is set. */
|
|
@@ -3,7 +3,7 @@ export const doc = {
|
|
|
3
3
|
purpose: 'A centered modal overlay that interrupts the page for a focused task or decision.',
|
|
4
4
|
contract: 'contracts/components/Modal.json',
|
|
5
5
|
a11y: [
|
|
6
|
-
'Built on native <dialog> opened via showModal() — backdrop, focus trap, Escape-to-close, and top-layer stacking all come from the browser (see
|
|
6
|
+
'Built on native <dialog> opened via showModal() — backdrop, focus trap, Escape-to-close, and top-layer stacking all come from the browser (see the Modal contract).',
|
|
7
7
|
'The title is referenced via aria-labelledby, giving the modal its accessible name.',
|
|
8
8
|
'Modal never closes itself — it always calls onDismiss and expects the consumer to set expanded to false.',
|
|
9
9
|
],
|
|
@@ -10,7 +10,7 @@ export interface ModalProps {
|
|
|
10
10
|
label: string;
|
|
11
11
|
/** The modal's body content. */
|
|
12
12
|
children: React.ReactNode;
|
|
13
|
-
/** Whether the modal is open. Always controlled — see
|
|
13
|
+
/** Whether the modal is open. Always controlled — see the Modal contract. */
|
|
14
14
|
expanded: boolean;
|
|
15
15
|
/** Called when the modal should close (close button, Escape, or a backdrop click). Modal never closes itself — set `expanded` to false in response. */
|
|
16
16
|
onDismiss: () => void;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import type { MultiSelectProps } from './MultiSelect.types.js';
|
|
9
9
|
/**
|
|
10
|
-
* Select's field and interaction model (
|
|
11
|
-
* see
|
|
10
|
+
* Select's field and interaction model (the Menu contract) with the selected values as Chips inside the field —
|
|
11
|
+
* see the MultiSelect contract. The combobox button owns real DOM focus; the chips' × buttons are the only other stops.
|
|
12
12
|
*/
|
|
13
13
|
export declare function MultiSelect({ label, options, value, defaultValue, onChange, placeholder, description, errorMessage, invalid, disabled, required, fullWidth, hideLabel, id: idProp, name, className, }: MultiSelectProps): React.JSX.Element;
|
|
14
14
|
export declare namespace MultiSelect {
|
|
@@ -4,7 +4,7 @@ export const doc = {
|
|
|
4
4
|
contract: 'contracts/components/MultiSelect.json',
|
|
5
5
|
a11y: [
|
|
6
6
|
'The `label` prop is required. The combobox button owns focus and announces the selection ("2 selected: …").',
|
|
7
|
-
'Same select-only combobox model as Select (
|
|
7
|
+
'Same select-only combobox model as Select (the Menu contract), with the Menu listbox in `multiple` mode (`aria-multiselectable`) — the MultiSelect contract.',
|
|
8
8
|
'Enter/Space toggle the highlighted option and keep the menu open; Backspace (menu closed) removes the last chip; each chip\'s × is focusable and removes that value.',
|
|
9
9
|
],
|
|
10
10
|
variants: [],
|
|
@@ -16,8 +16,8 @@ const VISUALLY_HIDDEN = {
|
|
|
16
16
|
position: 'absolute', width: 1, height: 1, overflow: 'hidden', clip: 'rect(0,0,0,0)', whiteSpace: 'nowrap',
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* Select's field and interaction model (
|
|
20
|
-
* see
|
|
19
|
+
* Select's field and interaction model (the Menu contract) with the selected values as Chips inside the field —
|
|
20
|
+
* see the MultiSelect contract. The combobox button owns real DOM focus; the chips' × buttons are the only other stops.
|
|
21
21
|
*/
|
|
22
22
|
export function MultiSelect({ label, options, value, defaultValue, onChange, placeholder, description, errorMessage, invalid = false, disabled = false, required = false, fullWidth = false, hideLabel = false, id: idProp, name, className, }) {
|
|
23
23
|
const uid = React.useRef(`helix-multi-select-${++idCounter}`).current;
|
|
@@ -43,7 +43,7 @@ export function MultiSelect({ label, options, value, defaultValue, onChange, pla
|
|
|
43
43
|
setInternalValue(next);
|
|
44
44
|
onChange?.(next);
|
|
45
45
|
};
|
|
46
|
-
// Toggle, don't close — several values can be picked in one go (
|
|
46
|
+
// Toggle, don't close — several values can be picked in one go (the MultiSelect contract).
|
|
47
47
|
const toggle = (optionValue) => {
|
|
48
48
|
setValues(current.includes(optionValue) ? current.filter(v => v !== optionValue) : [...current, optionValue]);
|
|
49
49
|
triggerRef.current?.focus();
|
|
@@ -71,7 +71,7 @@ export function MultiSelect({ label, options, value, defaultValue, onChange, pla
|
|
|
71
71
|
: (currentIndex + dir + enabled.length) % enabled.length;
|
|
72
72
|
setActiveValue(enabled[nextIndex].value);
|
|
73
73
|
};
|
|
74
|
-
// Same hand-rolled roving model as Select's trigger (
|
|
74
|
+
// Same hand-rolled roving model as Select's trigger (the Menu contract); differences are Enter/Space toggling
|
|
75
75
|
// without closing, and Backspace removing the last chip.
|
|
76
76
|
const handleTriggerKeyDown = (e) => {
|
|
77
77
|
if (disabled)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @helixds/react — agent note
|
|
3
|
+
* Before using Popover, read its contract: node_modules/@helixds/react/dist/contracts/Popover.json
|
|
4
|
+
* (every prop, which are required, when not to use it, the import line). Do not guess Helix props.
|
|
5
|
+
* Guide: node_modules/@helixds/react/AGENTS.md
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import type { PopoverProps } from './Popover.types.js';
|
|
9
|
+
declare const Popover: {
|
|
10
|
+
({ label, children, trigger, placement, expanded, defaultExpanded, onExpandedChange, className, }: PopoverProps): React.JSX.Element;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
|
13
|
+
export { Popover };
|
|
14
|
+
//# sourceMappingURL=Popover.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const doc = {
|
|
2
|
+
name: 'Popover',
|
|
3
|
+
purpose: 'Shows a small, non-modal panel of rich content — a title, text and actions — anchored to the control that opened it, without blocking the rest of the page.',
|
|
4
|
+
contract: 'contracts/components/Popover.json',
|
|
5
|
+
a11y: [
|
|
6
|
+
'The panel is a non-modal `role="dialog"` named by its visible title (`aria-labelledby`). The trigger gets `aria-expanded`, `aria-controls` and `aria-haspopup="dialog"` (the Popover contract).',
|
|
7
|
+
'Opening it from the trigger moves focus to its first focusable element; Escape closes it and returns focus to the trigger. Focus is never trapped — Tab moves on to the rest of the page.',
|
|
8
|
+
'A pointerdown outside closes it without moving focus.',
|
|
9
|
+
'Native `popover="manual"`: the panel renders in the top layer, so no z-index or portal is needed.',
|
|
10
|
+
],
|
|
11
|
+
variants: [],
|
|
12
|
+
sizes: [],
|
|
13
|
+
tokens: [
|
|
14
|
+
{ part: 'popover-content', label: 'Background', token: '--helix-popover-fill', kind: 'color', colorRole: 'background' },
|
|
15
|
+
{ part: 'popover-content', label: 'Text', token: '--helix-popover-text', kind: 'color', colorRole: 'text' },
|
|
16
|
+
{ part: 'popover-content', label: 'Border', token: '--helix-popover-border', kind: 'color', colorRole: 'border' },
|
|
17
|
+
{ part: 'popover-content', label: 'border width', token: '--helix-popover-borderWidth', kind: 'space' },
|
|
18
|
+
{ part: 'popover-content', label: 'radius', token: '--helix-popover-radius', kind: 'radius' },
|
|
19
|
+
{ part: 'popover-content', label: 'shadow', token: '--helix-popover-shadow', kind: 'shadow' },
|
|
20
|
+
{ part: 'popover-content', label: 'padding', token: '--helix-popover-padding', kind: 'space', padding: 'all' },
|
|
21
|
+
{ part: 'popover-content', label: 'gap (title → body)', token: '--helix-popover-gap', kind: 'space' },
|
|
22
|
+
{ part: 'popover-content', label: 'distance from the trigger', token: '--helix-popover-offset', kind: 'space' },
|
|
23
|
+
{ part: 'popover-title', label: 'title fontSize', token: '--helix-popover-titleFontSize', kind: 'typography' },
|
|
24
|
+
{ part: 'popover-title', label: 'title fontWeight', token: '--helix-popover-titleFontWeight', kind: 'typography' },
|
|
25
|
+
{ part: 'popover-body', label: 'body fontSize', token: '--helix-popover-fontSize', kind: 'typography' },
|
|
26
|
+
{ part: 'popover-body', label: 'body fontWeight', token: '--helix-popover-fontWeight', kind: 'typography' },
|
|
27
|
+
{ part: 'popover-content', label: 'max-width', value: '320px' },
|
|
28
|
+
],
|
|
29
|
+
features: [
|
|
30
|
+
'label — required, the visible title and the dialog\'s accessible name',
|
|
31
|
+
'children — the content: text and any actions',
|
|
32
|
+
'trigger — the Button/IconButton that toggles it',
|
|
33
|
+
'placement — top/bottom/left/right, flips and clamps to the viewport (the Tooltip contract)',
|
|
34
|
+
'expanded / defaultExpanded / onExpandedChange — controlled or uncontrolled',
|
|
35
|
+
],
|
|
36
|
+
examples: [
|
|
37
|
+
{
|
|
38
|
+
label: 'Default',
|
|
39
|
+
code: `<Popover label="Share link" trigger={<Button variant="secondary">Share</Button>}>Anyone with the link can view this report.</Popover>`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
label: 'Controlled',
|
|
43
|
+
code: `<Popover label="Share link" trigger={<Button>Share</Button>} expanded={open} onExpandedChange={setOpen}>…</Popover>`,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=Popover.doc.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cn } from '../../lib/utils.js';
|
|
4
|
+
// Same gutter as Tooltip: "doesn't fit" means "would land inside this margin of the viewport" (the Tooltip contract).
|
|
5
|
+
const EDGE_GUTTER = 8;
|
|
6
|
+
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
7
|
+
function readOffset(el) {
|
|
8
|
+
const value = parseFloat(getComputedStyle(el).getPropertyValue('--helix-popover-offset'));
|
|
9
|
+
return Number.isFinite(value) ? value : 4;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Flip + clamp, as Tooltip does (the Tooltip contract), but for a position: fixed panel in the top layer: the panel's
|
|
13
|
+
* top/left are computed from the trigger's viewport rect. Recomputed on open, on resize and on any
|
|
14
|
+
* ancestor scroll (capture phase) while open.
|
|
15
|
+
*/
|
|
16
|
+
function usePlacement(triggerRef, contentRef, requested, expanded) {
|
|
17
|
+
const [state, setState] = React.useState({
|
|
18
|
+
placement: requested,
|
|
19
|
+
top: 0,
|
|
20
|
+
left: 0,
|
|
21
|
+
});
|
|
22
|
+
const recalculate = React.useCallback(() => {
|
|
23
|
+
const trigger = triggerRef.current;
|
|
24
|
+
const content = contentRef.current;
|
|
25
|
+
if (!trigger || !content)
|
|
26
|
+
return;
|
|
27
|
+
const t = trigger.getBoundingClientRect();
|
|
28
|
+
const c = content.getBoundingClientRect();
|
|
29
|
+
const vw = window.innerWidth;
|
|
30
|
+
const vh = window.innerHeight;
|
|
31
|
+
const offset = readOffset(content);
|
|
32
|
+
let placement = requested;
|
|
33
|
+
if (requested === 'top' || requested === 'bottom') {
|
|
34
|
+
const fitsTop = t.top - c.height - offset - EDGE_GUTTER >= 0;
|
|
35
|
+
const fitsBottom = t.bottom + c.height + offset + EDGE_GUTTER <= vh;
|
|
36
|
+
if (requested === 'top' && !fitsTop && fitsBottom)
|
|
37
|
+
placement = 'bottom';
|
|
38
|
+
if (requested === 'bottom' && !fitsBottom && fitsTop)
|
|
39
|
+
placement = 'top';
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const fitsLeft = t.left - c.width - offset - EDGE_GUTTER >= 0;
|
|
43
|
+
const fitsRight = t.right + c.width + offset + EDGE_GUTTER <= vw;
|
|
44
|
+
if (requested === 'left' && !fitsLeft && fitsRight)
|
|
45
|
+
placement = 'right';
|
|
46
|
+
if (requested === 'right' && !fitsRight && fitsLeft)
|
|
47
|
+
placement = 'left';
|
|
48
|
+
}
|
|
49
|
+
const clamp = (value, size, max) => Math.min(Math.max(value, EDGE_GUTTER), Math.max(EDGE_GUTTER, max - size - EDGE_GUTTER));
|
|
50
|
+
let top;
|
|
51
|
+
let left;
|
|
52
|
+
if (placement === 'top' || placement === 'bottom') {
|
|
53
|
+
// Start-aligned with the trigger, clamped on the cross axis.
|
|
54
|
+
left = clamp(t.left, c.width, vw);
|
|
55
|
+
top = placement === 'bottom' ? t.bottom + offset : t.top - c.height - offset;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
top = clamp(t.top, c.height, vh);
|
|
59
|
+
left = placement === 'right' ? t.right + offset : t.left - c.width - offset;
|
|
60
|
+
}
|
|
61
|
+
setState({ placement, top, left });
|
|
62
|
+
}, [requested, triggerRef, contentRef]);
|
|
63
|
+
React.useLayoutEffect(() => {
|
|
64
|
+
if (!expanded)
|
|
65
|
+
return;
|
|
66
|
+
recalculate();
|
|
67
|
+
window.addEventListener('resize', recalculate);
|
|
68
|
+
window.addEventListener('scroll', recalculate, true);
|
|
69
|
+
return () => {
|
|
70
|
+
window.removeEventListener('resize', recalculate);
|
|
71
|
+
window.removeEventListener('scroll', recalculate, true);
|
|
72
|
+
};
|
|
73
|
+
}, [expanded, recalculate]);
|
|
74
|
+
// Closed, the panel shows the requested side: flip only applies once it's measured open.
|
|
75
|
+
return expanded ? state : { ...state, placement: requested };
|
|
76
|
+
}
|
|
77
|
+
const Popover = ({ label, children, trigger, placement = 'bottom', expanded, defaultExpanded = false, onExpandedChange, className, }) => {
|
|
78
|
+
const uid = React.useId();
|
|
79
|
+
const contentId = `helix-popover-${uid}`;
|
|
80
|
+
const titleId = `${contentId}-title`;
|
|
81
|
+
const rootRef = React.useRef(null);
|
|
82
|
+
const triggerRef = React.useRef(null);
|
|
83
|
+
const contentRef = React.useRef(null);
|
|
84
|
+
// Focus moves into the panel only when the user opened it — never for a panel open on mount.
|
|
85
|
+
const focusOnOpen = React.useRef(false);
|
|
86
|
+
const isControlled = expanded !== undefined;
|
|
87
|
+
const [internal, setInternal] = React.useState(defaultExpanded);
|
|
88
|
+
const open = isControlled ? expanded : internal;
|
|
89
|
+
const setOpen = React.useCallback((next) => {
|
|
90
|
+
if (!isControlled)
|
|
91
|
+
setInternal(next);
|
|
92
|
+
onExpandedChange?.(next);
|
|
93
|
+
}, [isControlled, onExpandedChange]);
|
|
94
|
+
const position = usePlacement(triggerRef, contentRef, placement, open);
|
|
95
|
+
// Native popover="manual": the browser puts it in the top layer (no z-index, no portal) — the Popover contract.
|
|
96
|
+
// Light dismiss is "manual" on purpose: Escape has to return focus to the trigger, and an outside
|
|
97
|
+
// click must not, so both are handled below rather than by popover="auto".
|
|
98
|
+
React.useLayoutEffect(() => {
|
|
99
|
+
const el = contentRef.current;
|
|
100
|
+
if (!el || typeof el.showPopover !== 'function')
|
|
101
|
+
return;
|
|
102
|
+
const isOpen = el.matches(':popover-open');
|
|
103
|
+
if (open && !isOpen)
|
|
104
|
+
el.showPopover();
|
|
105
|
+
if (!open && isOpen)
|
|
106
|
+
el.hidePopover();
|
|
107
|
+
}, [open]);
|
|
108
|
+
React.useEffect(() => {
|
|
109
|
+
if (!open || !focusOnOpen.current)
|
|
110
|
+
return;
|
|
111
|
+
focusOnOpen.current = false;
|
|
112
|
+
const first = contentRef.current?.querySelector(FOCUSABLE);
|
|
113
|
+
(first ?? contentRef.current)?.focus();
|
|
114
|
+
}, [open]);
|
|
115
|
+
// Outside pointerdown closes without moving focus — the user is already putting it somewhere else.
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
if (!open)
|
|
118
|
+
return;
|
|
119
|
+
const onPointerDown = (event) => {
|
|
120
|
+
if (rootRef.current?.contains(event.target))
|
|
121
|
+
return;
|
|
122
|
+
setOpen(false);
|
|
123
|
+
};
|
|
124
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
125
|
+
return () => document.removeEventListener('pointerdown', onPointerDown);
|
|
126
|
+
}, [open, setOpen]);
|
|
127
|
+
const handleKeyDown = (event) => {
|
|
128
|
+
if (event.key !== 'Escape' || !open)
|
|
129
|
+
return;
|
|
130
|
+
event.stopPropagation();
|
|
131
|
+
setOpen(false);
|
|
132
|
+
triggerRef.current?.focus();
|
|
133
|
+
};
|
|
134
|
+
const triggerProps = trigger.props;
|
|
135
|
+
const triggerElement = React.cloneElement(trigger, {
|
|
136
|
+
ref: (node) => {
|
|
137
|
+
triggerRef.current = node;
|
|
138
|
+
},
|
|
139
|
+
'aria-expanded': open,
|
|
140
|
+
'aria-controls': contentId,
|
|
141
|
+
'aria-haspopup': 'dialog',
|
|
142
|
+
onClick: (event) => {
|
|
143
|
+
triggerProps.onClick?.(event);
|
|
144
|
+
if (event.defaultPrevented)
|
|
145
|
+
return;
|
|
146
|
+
if (!open)
|
|
147
|
+
focusOnOpen.current = true;
|
|
148
|
+
setOpen(!open);
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
return (_jsxs("span", { ref: rootRef, "data-helix-part": "popover-root", onKeyDown: handleKeyDown, className: cn(className), children: [triggerElement, _jsxs("div", { ref: contentRef, id: contentId, popover: "manual", role: "dialog", "aria-labelledby": titleId, tabIndex: -1, "data-helix-part": "popover-content", "data-placement": position.placement, "data-expanded": open ? 'true' : 'false',
|
|
152
|
+
// Only the computed geometry is inline; every visual property stays in CSS.
|
|
153
|
+
style: { top: `${position.top}px`, left: `${position.left}px` }, children: [_jsx("p", { id: titleId, "data-helix-part": "popover-title", children: label }), _jsx("div", { "data-helix-part": "popover-body", children: children })] })] }));
|
|
154
|
+
};
|
|
155
|
+
Popover.displayName = 'Popover';
|
|
156
|
+
export { Popover };
|
|
157
|
+
//# sourceMappingURL=Popover.js.map
|