@efolusi/meridian 1.19.1 → 1.21.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/README.md +1 -1
- package/ai/Bubble.d.ts +16 -0
- package/ai/Bubble.js +71 -0
- package/ai/ChatMessage.js +2 -5
- package/ai/Confirmation.d.ts +0 -7
- package/ai/Confirmation.js +3 -6
- package/ai/GeneratedImage.d.ts +0 -2
- package/ai/GeneratedImage.js +2 -4
- package/ai/Marker.d.ts +26 -0
- package/ai/Marker.js +67 -0
- package/ai/Message.d.ts +13 -0
- package/ai/Message.js +68 -0
- package/ai/MessageScroller.d.ts +21 -0
- package/ai/MessageScroller.js +283 -0
- package/ai/ModelSelector.d.ts +2 -2
- package/ai/ModelSelector.js +1 -2
- package/ai/Player.js +1 -1
- package/ai/PromptSteps.js +4 -2
- package/ai/Sandbox.d.ts +0 -2
- package/ai/Sandbox.js +2 -4
- package/ai/Suggestions.d.ts +0 -2
- package/ai/Suggestions.js +1 -4
- package/ai/WebPreview.d.ts +0 -2
- package/ai/WebPreview.js +2 -4
- package/code/Console.js +1 -1
- package/code/EnvList.d.ts +0 -2
- package/code/EnvList.js +2 -3
- package/components.css +660 -423
- package/data/BarChart.d.ts +0 -2
- package/data/BarChart.js +1 -4
- package/data/Chart.d.ts +14 -0
- package/data/Chart.js +149 -0
- package/data/EmptyState.d.ts +8 -13
- package/data/EmptyState.js +62 -24
- package/data/LineChart.js +7 -4
- package/data/Skeleton.d.ts +2 -11
- package/data/Skeleton.js +8 -38
- package/data/Sparkline.js +4 -1
- package/data/StatusDot.d.ts +0 -4
- package/data/StatusDot.js +3 -6
- package/data/Table.d.ts +11 -4
- package/data/Table.js +39 -7
- package/dates/Calendar.d.ts +10 -27
- package/dates/Calendar.js +250 -184
- package/dates/TimePicker.js +2 -2
- package/display/Accordion.d.ts +47 -15
- package/display/Accordion.js +257 -27
- package/display/AspectRatio.d.ts +4 -6
- package/display/AspectRatio.js +7 -5
- package/display/Avatar.d.ts +17 -14
- package/display/Avatar.js +68 -43
- package/display/Badge.d.ts +9 -8
- package/display/Badge.js +32 -14
- package/display/Card.d.ts +11 -13
- package/display/Card.js +74 -29
- package/display/Carousel.d.ts +23 -15
- package/display/Carousel.js +217 -66
- package/display/Collapsible.d.ts +19 -9
- package/display/Collapsible.js +140 -28
- package/display/Direction.d.ts +10 -0
- package/display/Direction.js +24 -0
- package/display/Item.d.ts +19 -0
- package/display/Item.js +152 -0
- package/display/Kbd.d.ts +5 -7
- package/display/Kbd.js +22 -10
- package/display/Link.js +2 -4
- package/display/Resizable.d.ts +6 -16
- package/display/Resizable.js +141 -58
- package/display/ScrollArea.d.ts +3 -1
- package/display/ScrollArea.js +30 -5
- package/display/Separator.d.ts +9 -0
- package/display/Separator.js +18 -0
- package/display/Timeline.d.ts +24 -0
- package/display/Timeline.js +51 -0
- package/display/Toolbar.js +5 -4
- package/display/TreeList.d.ts +0 -2
- package/display/TreeList.js +2 -5
- package/feedback/Alert.d.ts +13 -13
- package/feedback/Alert.js +40 -36
- package/feedback/AlertDialog.d.ts +30 -0
- package/feedback/AlertDialog.js +249 -0
- package/feedback/Banner.d.ts +1 -3
- package/feedback/Banner.js +1 -5
- package/feedback/ConfirmDialog.d.ts +1 -1
- package/feedback/ConfirmDialog.js +18 -20
- package/feedback/Dialog.d.ts +13 -16
- package/feedback/Dialog.js +204 -62
- package/feedback/Progress.d.ts +8 -9
- package/feedback/Progress.js +42 -24
- package/feedback/Sonner.d.ts +8 -0
- package/feedback/Sonner.js +238 -0
- package/feedback/Spinner.d.ts +2 -9
- package/feedback/Spinner.js +19 -28
- package/feedback/Tooltip.d.ts +9 -10
- package/feedback/Tooltip.js +147 -96
- package/files/Attachment.d.ts +27 -0
- package/files/Attachment.js +111 -0
- package/files/FileDrop.js +3 -1
- package/finance/PaymentCard.js +3 -3
- package/forms/Button.d.ts +6 -5
- package/forms/Button.js +42 -8
- package/forms/ButtonGroup.d.ts +11 -3
- package/forms/ButtonGroup.js +57 -6
- package/forms/Checkbox.d.ts +14 -3
- package/forms/Checkbox.js +84 -16
- package/forms/Combobox.d.ts +24 -16
- package/forms/Combobox.js +466 -135
- package/forms/Field.d.ts +14 -0
- package/forms/Field.js +99 -0
- package/forms/IconButton.d.ts +1 -1
- package/forms/IconButton.js +4 -3
- package/forms/Input.d.ts +8 -8
- package/forms/Input.js +46 -33
- package/forms/InputGroup.d.ts +8 -15
- package/forms/InputGroup.js +74 -35
- package/forms/InputOTP.d.ts +13 -0
- package/forms/InputOTP.js +125 -0
- package/forms/Label.d.ts +2 -6
- package/forms/Label.js +6 -4
- package/forms/NativeSelect.d.ts +16 -0
- package/forms/NativeSelect.js +35 -0
- package/forms/NumberInput.js +2 -2
- package/forms/Radio.d.ts +12 -1
- package/forms/Radio.js +76 -6
- package/forms/Select.d.ts +12 -9
- package/forms/Select.js +254 -42
- package/forms/Slider.d.ts +10 -17
- package/forms/Slider.js +78 -39
- package/forms/Switch.d.ts +8 -2
- package/forms/Switch.js +46 -15
- package/forms/Textarea.d.ts +1 -1
- package/forms/Textarea.js +26 -18
- package/forms/Toggle.d.ts +18 -15
- package/forms/Toggle.js +96 -42
- package/icons/_svg.js +2 -0
- package/index.d.ts +20 -8
- package/index.js +50 -38
- package/navigation/Breadcrumbs.d.ts +18 -11
- package/navigation/Breadcrumbs.js +99 -26
- package/navigation/Menubar.d.ts +52 -10
- package/navigation/Menubar.js +191 -146
- package/navigation/NavigationMenu.d.ts +15 -0
- package/navigation/NavigationMenu.js +296 -0
- package/navigation/Pagination.d.ts +10 -9
- package/navigation/Pagination.js +94 -51
- package/navigation/SideNav.js +4 -3
- package/navigation/Sidebar.d.ts +29 -0
- package/navigation/Sidebar.js +311 -0
- package/navigation/Tabs.d.ts +9 -5
- package/navigation/Tabs.js +132 -44
- package/overlay/Command.d.ts +32 -0
- package/overlay/Command.js +257 -0
- package/overlay/ContextMenu.d.ts +40 -8
- package/overlay/ContextMenu.js +468 -107
- package/overlay/Drawer.d.ts +29 -14
- package/overlay/Drawer.js +178 -80
- package/overlay/DropdownMenu.d.ts +43 -0
- package/overlay/DropdownMenu.js +502 -0
- package/overlay/HoverCard.d.ts +21 -12
- package/overlay/HoverCard.js +129 -61
- package/overlay/Popover.d.ts +11 -13
- package/overlay/Popover.js +138 -65
- package/overlay/Portal.js +21 -7
- package/overlay/Sheet.d.ts +11 -0
- package/overlay/Sheet.js +62 -0
- package/package.json +4 -1
- package/tokens/base.css +1 -1
- package/dates/DatePicker.d.ts +0 -14
- package/dates/DatePicker.js +0 -111
- package/dates/DateRangePicker.d.ts +0 -23
- package/dates/DateRangePicker.js +0 -150
- package/display/ListItem.d.ts +0 -19
- package/display/ListItem.js +0 -50
- package/feedback/Toast.d.ts +0 -78
- package/feedback/Toast.js +0 -192
- package/forms/DigitEntry.d.ts +0 -15
- package/forms/DigitEntry.js +0 -79
- package/forms/FormField.d.ts +0 -82
- package/forms/FormField.js +0 -209
- package/overlay/CommandPalette.d.ts +0 -21
- package/overlay/CommandPalette.js +0 -148
- package/overlay/Menu.d.ts +0 -24
- package/overlay/Menu.js +0 -139
package/forms/Combobox.js
CHANGED
|
@@ -2,160 +2,491 @@
|
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Icon } from "../icons/Icon.js";
|
|
5
|
-
import {
|
|
6
|
-
import { useFieldProps } from "./FormField.js";
|
|
5
|
+
import { InputGroup, InputGroupAddon, InputGroupInput } from "./InputGroup.js";
|
|
7
6
|
import { Portal, useAnchoredStyle } from "../overlay/Portal.js";
|
|
7
|
+
const ComboboxContext = /*#__PURE__*/React.createContext(null);
|
|
8
|
+
const join = (...values) => values.filter(Boolean).join(' ');
|
|
9
|
+
const textOf = node => React.Children.toArray(node).map(child => typeof child === 'string' || typeof child === 'number' ? String(child) : /*#__PURE__*/React.isValidElement(child) ? textOf(child.props.children) : '').join(' ').trim();
|
|
10
|
+
const itemValue = item => typeof item === 'object' && item !== null ? item.value ?? item.id ?? item.name ?? item.label : item;
|
|
11
|
+
const itemText = item => typeof item === 'object' && item !== null ? String(item.label ?? item.name ?? item.value ?? item.id ?? '') : String(item ?? '');
|
|
12
|
+
const same = (a, b) => Object.is(a, b) || itemValue(a) === itemValue(b);
|
|
8
13
|
export function Combobox({
|
|
9
|
-
|
|
10
|
-
hint,
|
|
11
|
-
options,
|
|
14
|
+
items = [],
|
|
12
15
|
value,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
defaultValue,
|
|
17
|
+
onValueChange,
|
|
18
|
+
multiple = false,
|
|
19
|
+
open,
|
|
20
|
+
defaultOpen = false,
|
|
21
|
+
onOpenChange,
|
|
22
|
+
inputValue,
|
|
23
|
+
defaultInputValue = '',
|
|
24
|
+
onInputValueChange,
|
|
25
|
+
disabled = false,
|
|
26
|
+
autoHighlight = true,
|
|
27
|
+
children
|
|
19
28
|
}) {
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const [open, setOpen] = React.useState(false);
|
|
26
|
-
const [q, setQ] = React.useState('');
|
|
27
|
-
const [hi, setHi] = React.useState(0);
|
|
29
|
+
const [internalValue, setInternalValue] = React.useState(defaultValue ?? (multiple ? [] : null));
|
|
30
|
+
const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
|
|
31
|
+
const [internalInput, setInternalInput] = React.useState(defaultInputValue);
|
|
32
|
+
const [active, setActive] = React.useState('');
|
|
33
|
+
const [version, setVersion] = React.useState(0);
|
|
28
34
|
const listId = React.useId();
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
const records = React.useRef(new Map());
|
|
36
|
+
const anchorRef = React.useRef(null);
|
|
37
|
+
const currentValue = value === undefined ? internalValue : value;
|
|
38
|
+
const isOpen = open === undefined ? internalOpen : open;
|
|
39
|
+
const query = inputValue === undefined ? internalInput : inputValue;
|
|
40
|
+
const setOpen = React.useCallback(next => {
|
|
41
|
+
if (open === undefined) setInternalOpen(next);
|
|
42
|
+
onOpenChange?.(next);
|
|
43
|
+
}, [open, onOpenChange]);
|
|
44
|
+
const setQuery = React.useCallback(next => {
|
|
45
|
+
if (inputValue === undefined) setInternalInput(next);
|
|
46
|
+
onInputValueChange?.(next);
|
|
47
|
+
}, [inputValue, onInputValueChange]);
|
|
48
|
+
const setValue = React.useCallback(next => {
|
|
49
|
+
if (value === undefined) setInternalValue(next);
|
|
50
|
+
onValueChange?.(next);
|
|
51
|
+
}, [value, onValueChange]);
|
|
52
|
+
const selected = multiple ? Array.isArray(currentValue) ? currentValue : [] : currentValue;
|
|
53
|
+
const register = React.useCallback((id, record) => {
|
|
54
|
+
records.current.set(id, record);
|
|
55
|
+
setVersion(v => v + 1);
|
|
56
|
+
return () => {
|
|
57
|
+
records.current.delete(id);
|
|
58
|
+
setVersion(v => v + 1);
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
const matches = React.useCallback(record => !query || `${record.text} ${(record.keywords || []).join(' ')}`.toLocaleLowerCase().includes(query.toLocaleLowerCase()), [query]);
|
|
62
|
+
const visibleRecords = [...records.current.values()].filter(record => !record.disabled && matches(record));
|
|
47
63
|
React.useEffect(() => {
|
|
48
|
-
if (!
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
block: 'nearest'
|
|
52
|
-
});
|
|
53
|
-
}, [open, hi, listId]);
|
|
64
|
+
if (!isOpen || !autoHighlight || !visibleRecords.length) return;
|
|
65
|
+
if (!visibleRecords.some(record => record.id === active)) setActive(visibleRecords[0].id);
|
|
66
|
+
}, [isOpen, query, version, autoHighlight]);
|
|
54
67
|
React.useEffect(() => {
|
|
55
|
-
if (
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
document.addEventListener('mousedown', away);
|
|
62
|
-
return () => document.removeEventListener('mousedown', away);
|
|
63
|
-
}, [open]);
|
|
64
|
-
const pick = v => {
|
|
68
|
+
if (multiple || isOpen || query || currentValue == null) return;
|
|
69
|
+
const found = items.find(item => same(itemValue(item), currentValue));
|
|
70
|
+
if (found !== undefined) setQuery(itemText(found));
|
|
71
|
+
}, [currentValue, items, isOpen, multiple]);
|
|
72
|
+
const choose = React.useCallback((next, label) => {
|
|
65
73
|
if (multiple) {
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
const values = Array.isArray(selected) ? selected : [];
|
|
75
|
+
setValue(values.some(value => same(value, next)) ? values.filter(value => !same(value, next)) : [...values, next]);
|
|
76
|
+
setQuery('');
|
|
68
77
|
} else {
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
setValue(next);
|
|
79
|
+
setQuery(label);
|
|
71
80
|
setOpen(false);
|
|
72
81
|
}
|
|
73
|
-
};
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
}, [multiple, selected, setOpen, setQuery, setValue]);
|
|
83
|
+
const remove = React.useCallback(next => {
|
|
84
|
+
if (multiple) setValue(selected.filter(value => !same(value, next)));else {
|
|
85
|
+
setValue(null);
|
|
86
|
+
setQuery('');
|
|
87
|
+
}
|
|
88
|
+
}, [multiple, selected, setQuery, setValue]);
|
|
89
|
+
const clear = React.useCallback(() => {
|
|
90
|
+
setValue(multiple ? [] : null);
|
|
91
|
+
setQuery('');
|
|
92
|
+
}, [multiple, setQuery, setValue]);
|
|
93
|
+
const filteredItems = items.filter(item => !query || itemText(item).toLocaleLowerCase().includes(query.toLocaleLowerCase()));
|
|
94
|
+
const context = React.useMemo(() => ({
|
|
95
|
+
active,
|
|
96
|
+
anchorRef,
|
|
97
|
+
choose,
|
|
98
|
+
clear,
|
|
99
|
+
disabled,
|
|
100
|
+
filteredItems,
|
|
101
|
+
isOpen,
|
|
102
|
+
listId,
|
|
103
|
+
matches,
|
|
104
|
+
multiple,
|
|
105
|
+
query,
|
|
106
|
+
records,
|
|
107
|
+
register,
|
|
108
|
+
remove,
|
|
109
|
+
selected,
|
|
110
|
+
setActive,
|
|
111
|
+
setOpen,
|
|
112
|
+
setQuery,
|
|
113
|
+
visibleCount: visibleRecords.length
|
|
114
|
+
}), [active, choose, clear, disabled, filteredItems, isOpen, listId, matches, multiple, query, register, remove, selected, setOpen, setQuery, visibleRecords.length]);
|
|
115
|
+
return /*#__PURE__*/React.createElement(ComboboxContext.Provider, {
|
|
116
|
+
value: context
|
|
117
|
+
}, children);
|
|
118
|
+
}
|
|
119
|
+
export const ComboboxValue = /*#__PURE__*/React.forwardRef(function ComboboxValue({
|
|
120
|
+
children,
|
|
121
|
+
className,
|
|
122
|
+
...props
|
|
123
|
+
}, ref) {
|
|
124
|
+
const context = React.useContext(ComboboxContext);
|
|
125
|
+
const content = typeof children === 'function' ? children(context?.selected) : children ?? (Array.isArray(context?.selected) ? context.selected.map(itemText).join(', ') : itemText(context?.selected));
|
|
126
|
+
return /*#__PURE__*/React.createElement("span", _extends({
|
|
127
|
+
ref: ref,
|
|
128
|
+
"data-slot": "combobox-value",
|
|
129
|
+
className: className
|
|
130
|
+
}, props), content);
|
|
131
|
+
});
|
|
132
|
+
export const ComboboxTrigger = /*#__PURE__*/React.forwardRef(function ComboboxTrigger({
|
|
133
|
+
className,
|
|
134
|
+
children,
|
|
135
|
+
disabled,
|
|
136
|
+
onClick,
|
|
137
|
+
...props
|
|
138
|
+
}, ref) {
|
|
139
|
+
const context = React.useContext(ComboboxContext);
|
|
140
|
+
return /*#__PURE__*/React.createElement("button", _extends({
|
|
89
141
|
ref: ref,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
142
|
+
type: "button",
|
|
143
|
+
"data-slot": "combobox-trigger",
|
|
144
|
+
"aria-haspopup": "listbox",
|
|
145
|
+
"aria-expanded": context?.isOpen,
|
|
146
|
+
disabled: disabled ?? context?.disabled,
|
|
147
|
+
className: join('ef-combobox__button', className),
|
|
148
|
+
onClick: event => {
|
|
149
|
+
onClick?.(event);
|
|
150
|
+
if (!event.defaultPrevented) context?.setOpen(!context.isOpen);
|
|
96
151
|
}
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
152
|
+
}, props), children, /*#__PURE__*/React.createElement(Icon, {
|
|
153
|
+
name: "chevron-down",
|
|
154
|
+
size: 16
|
|
155
|
+
}));
|
|
156
|
+
});
|
|
157
|
+
export const ComboboxClear = /*#__PURE__*/React.forwardRef(function ComboboxClear({
|
|
158
|
+
className,
|
|
159
|
+
children,
|
|
160
|
+
disabled,
|
|
161
|
+
onClick,
|
|
162
|
+
...props
|
|
163
|
+
}, ref) {
|
|
164
|
+
const context = React.useContext(ComboboxContext);
|
|
165
|
+
return /*#__PURE__*/React.createElement("button", _extends({
|
|
166
|
+
ref: ref,
|
|
167
|
+
type: "button",
|
|
168
|
+
"data-slot": "combobox-clear",
|
|
169
|
+
"aria-label": "Clear selection",
|
|
170
|
+
disabled: disabled ?? context?.disabled,
|
|
171
|
+
className: join('ef-combobox__button', className),
|
|
172
|
+
onClick: event => {
|
|
173
|
+
onClick?.(event);
|
|
174
|
+
if (!event.defaultPrevented) context?.clear();
|
|
175
|
+
}
|
|
176
|
+
}, props), children || /*#__PURE__*/React.createElement(Icon, {
|
|
177
|
+
name: "x",
|
|
178
|
+
size: 14
|
|
179
|
+
}));
|
|
180
|
+
});
|
|
181
|
+
function useInputKeyboard(context, onKeyDown) {
|
|
182
|
+
return event => {
|
|
183
|
+
onKeyDown?.(event);
|
|
184
|
+
if (event.defaultPrevented || !context) return;
|
|
185
|
+
const current = [...context.records.current.values()].filter(record => !record.disabled && context.matches(record));
|
|
186
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
context.setOpen(true);
|
|
189
|
+
if (!current.length) return;
|
|
190
|
+
const index = current.findIndex(record => record.id === context.active);
|
|
191
|
+
const delta = event.key === 'ArrowDown' ? 1 : -1;
|
|
192
|
+
const next = Math.max(0, Math.min(current.length - 1, (index < 0 ? 0 : index) + delta));
|
|
193
|
+
context.setActive(current[next].id);
|
|
194
|
+
current[next].ref.current?.scrollIntoView?.({
|
|
195
|
+
block: 'nearest'
|
|
196
|
+
});
|
|
197
|
+
} else if (event.key === 'Home' || event.key === 'End') {
|
|
198
|
+
if (!context.isOpen || !current.length) return;
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
context.setActive(current[event.key === 'Home' ? 0 : current.length - 1].id);
|
|
201
|
+
} else if (event.key === 'Enter' && context.isOpen) {
|
|
202
|
+
const record = current.find(item => item.id === context.active);
|
|
203
|
+
if (record) {
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
record.ref.current?.click();
|
|
206
|
+
}
|
|
207
|
+
} else if (event.key === 'Escape') {
|
|
208
|
+
context.setOpen(false);
|
|
209
|
+
} else if (event.key === 'Backspace' && !context.query && context.multiple && context.selected.length) {
|
|
210
|
+
context.remove(context.selected[context.selected.length - 1]);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export const ComboboxInput = /*#__PURE__*/React.forwardRef(function ComboboxInput({
|
|
215
|
+
className,
|
|
216
|
+
children,
|
|
217
|
+
disabled = false,
|
|
218
|
+
showTrigger = true,
|
|
219
|
+
showClear = false,
|
|
220
|
+
onChange,
|
|
221
|
+
onFocus,
|
|
222
|
+
onKeyDown,
|
|
223
|
+
...props
|
|
224
|
+
}, forwardedRef) {
|
|
225
|
+
const context = React.useContext(ComboboxContext);
|
|
226
|
+
const localRef = React.useRef(null);
|
|
227
|
+
React.useImperativeHandle(forwardedRef, () => localRef.current);
|
|
228
|
+
const hasSelection = context?.multiple ? context.selected.length > 0 : context?.selected != null;
|
|
229
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
230
|
+
ref: context?.anchorRef,
|
|
231
|
+
className: "ef-combobox"
|
|
232
|
+
}, /*#__PURE__*/React.createElement(InputGroup, {
|
|
233
|
+
className: join('ef-combobox__input-group', className)
|
|
234
|
+
}, /*#__PURE__*/React.createElement(InputGroupInput, _extends({
|
|
235
|
+
ref: localRef,
|
|
236
|
+
"data-slot": "combobox-input",
|
|
105
237
|
role: "combobox",
|
|
106
|
-
"aria-expanded": open,
|
|
107
|
-
"aria-controls": listId,
|
|
108
238
|
"aria-autocomplete": "list",
|
|
109
|
-
"aria-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
239
|
+
"aria-expanded": context?.isOpen,
|
|
240
|
+
"aria-controls": context?.listId,
|
|
241
|
+
"aria-activedescendant": context?.active || undefined,
|
|
242
|
+
disabled: disabled || context?.disabled,
|
|
243
|
+
className: "ef-combobox__input",
|
|
244
|
+
value: context?.query ?? '',
|
|
245
|
+
onChange: event => {
|
|
246
|
+
context?.setQuery(event.target.value);
|
|
247
|
+
context?.setOpen(true);
|
|
248
|
+
onChange?.(event);
|
|
116
249
|
},
|
|
117
|
-
onFocus:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
250
|
+
onFocus: event => {
|
|
251
|
+
context?.setOpen(true);
|
|
252
|
+
onFocus?.(event);
|
|
253
|
+
},
|
|
254
|
+
onKeyDown: useInputKeyboard(context, onKeyDown)
|
|
255
|
+
}, props)), /*#__PURE__*/React.createElement(InputGroupAddon, {
|
|
256
|
+
align: "inline-end",
|
|
257
|
+
className: "ef-combobox__actions"
|
|
258
|
+
}, showClear && hasSelection ? /*#__PURE__*/React.createElement(ComboboxClear, null) : showTrigger ? /*#__PURE__*/React.createElement(ComboboxTrigger, null) : null), children));
|
|
259
|
+
});
|
|
260
|
+
export const ComboboxContent = /*#__PURE__*/React.forwardRef(function ComboboxContent({
|
|
261
|
+
className,
|
|
262
|
+
side = 'bottom',
|
|
263
|
+
sideOffset = 6,
|
|
264
|
+
align = 'start',
|
|
265
|
+
alignOffset = 0,
|
|
266
|
+
anchor,
|
|
267
|
+
children,
|
|
268
|
+
...props
|
|
269
|
+
}, forwardedRef) {
|
|
270
|
+
const context = React.useContext(ComboboxContext);
|
|
271
|
+
const popupRef = React.useRef(null);
|
|
272
|
+
React.useImperativeHandle(forwardedRef, () => popupRef.current);
|
|
273
|
+
const target = anchor || context?.anchorRef;
|
|
274
|
+
const {
|
|
275
|
+
style
|
|
276
|
+
} = useAnchoredStyle(target, popupRef, {
|
|
277
|
+
open: context?.isOpen,
|
|
278
|
+
placement: side,
|
|
279
|
+
align,
|
|
280
|
+
offset: sideOffset,
|
|
281
|
+
crossOffset: alignOffset,
|
|
282
|
+
matchWidth: side === 'top' || side === 'bottom'
|
|
283
|
+
});
|
|
284
|
+
React.useEffect(() => {
|
|
285
|
+
if (!context?.isOpen) return;
|
|
286
|
+
const close = event => {
|
|
287
|
+
if (!target?.current?.contains(event.target) && !popupRef.current?.contains(event.target)) context.setOpen(false);
|
|
288
|
+
};
|
|
289
|
+
document.addEventListener('mousedown', close);
|
|
290
|
+
return () => document.removeEventListener('mousedown', close);
|
|
291
|
+
}, [context?.isOpen, context?.setOpen, target]);
|
|
292
|
+
if (!context?.isOpen) return null;
|
|
293
|
+
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
294
|
+
ref: popupRef,
|
|
295
|
+
"data-slot": "combobox-content",
|
|
296
|
+
className: join('ef-combobox__content', className),
|
|
297
|
+
style: style
|
|
298
|
+
}, props), children));
|
|
299
|
+
});
|
|
300
|
+
export const ComboboxList = /*#__PURE__*/React.forwardRef(function ComboboxList({
|
|
301
|
+
className,
|
|
302
|
+
children,
|
|
303
|
+
...props
|
|
304
|
+
}, ref) {
|
|
305
|
+
const context = React.useContext(ComboboxContext);
|
|
306
|
+
const content = typeof children === 'function' ? context?.filteredItems.map((item, index) => /*#__PURE__*/React.createElement(React.Fragment, {
|
|
307
|
+
key: String(itemValue(item) ?? index)
|
|
308
|
+
}, children(item))) : children;
|
|
309
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
310
|
+
ref: ref,
|
|
311
|
+
id: props.id || context?.listId,
|
|
312
|
+
"data-slot": "combobox-list",
|
|
127
313
|
role: "listbox",
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
314
|
+
"aria-multiselectable": context?.multiple || undefined,
|
|
315
|
+
className: join('ef-combobox__list', className)
|
|
316
|
+
}, props), content);
|
|
317
|
+
});
|
|
318
|
+
export const ComboboxItem = /*#__PURE__*/React.forwardRef(function ComboboxItem({
|
|
319
|
+
value,
|
|
320
|
+
keywords = [],
|
|
321
|
+
disabled = false,
|
|
322
|
+
className,
|
|
323
|
+
children,
|
|
324
|
+
onClick,
|
|
325
|
+
...props
|
|
326
|
+
}, forwardedRef) {
|
|
327
|
+
const context = React.useContext(ComboboxContext);
|
|
328
|
+
const reactId = React.useId();
|
|
329
|
+
const id = props.id || reactId;
|
|
330
|
+
const localRef = React.useRef(null);
|
|
331
|
+
React.useImperativeHandle(forwardedRef, () => localRef.current);
|
|
332
|
+
const nextValue = value ?? textOf(children);
|
|
333
|
+
const text = textOf(children) || itemText(nextValue);
|
|
334
|
+
React.useEffect(() => context?.register(id, {
|
|
335
|
+
id,
|
|
336
|
+
value: nextValue,
|
|
337
|
+
text,
|
|
338
|
+
keywords,
|
|
339
|
+
disabled,
|
|
340
|
+
ref: localRef
|
|
341
|
+
}), [context?.register, disabled, id, keywords.join('\0'), nextValue, text]);
|
|
342
|
+
const hidden = context ? !context.matches({
|
|
343
|
+
text,
|
|
344
|
+
keywords
|
|
345
|
+
}) : false;
|
|
346
|
+
const selected = context?.multiple ? context.selected.some(item => same(item, nextValue)) : same(context?.selected, nextValue);
|
|
347
|
+
return /*#__PURE__*/React.createElement("button", _extends({
|
|
348
|
+
ref: localRef,
|
|
349
|
+
type: "button",
|
|
350
|
+
id: id,
|
|
351
|
+
"data-slot": "combobox-item",
|
|
352
|
+
"data-highlighted": context?.active === id ? 'true' : 'false',
|
|
353
|
+
"data-disabled": disabled ? 'true' : 'false',
|
|
134
354
|
role: "option",
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
355
|
+
"aria-selected": selected,
|
|
356
|
+
disabled: disabled,
|
|
357
|
+
hidden: hidden,
|
|
358
|
+
className: join('ef-combobox__item', className),
|
|
359
|
+
onMouseEnter: () => !disabled && context?.setActive(id),
|
|
360
|
+
onClick: event => {
|
|
361
|
+
onClick?.(event);
|
|
362
|
+
if (!event.defaultPrevented && !disabled) context?.choose(nextValue, text);
|
|
363
|
+
}
|
|
364
|
+
}, props), children, selected ? /*#__PURE__*/React.createElement("span", {
|
|
365
|
+
"data-slot": "combobox-item-indicator",
|
|
366
|
+
className: "ef-combobox__indicator"
|
|
145
367
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
146
368
|
name: "check",
|
|
147
369
|
size: 15
|
|
148
|
-
})) : null)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
370
|
+
})) : null);
|
|
371
|
+
});
|
|
372
|
+
export const ComboboxGroup = /*#__PURE__*/React.forwardRef(function ComboboxGroup({
|
|
373
|
+
className,
|
|
374
|
+
...props
|
|
375
|
+
}, ref) {
|
|
376
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
377
|
+
ref: ref,
|
|
378
|
+
"data-slot": "combobox-group",
|
|
379
|
+
role: "group",
|
|
380
|
+
className: join('ef-combobox__group', className)
|
|
381
|
+
}, props));
|
|
382
|
+
});
|
|
383
|
+
export const ComboboxLabel = /*#__PURE__*/React.forwardRef(function ComboboxLabel({
|
|
384
|
+
className,
|
|
385
|
+
...props
|
|
386
|
+
}, ref) {
|
|
387
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
388
|
+
ref: ref,
|
|
389
|
+
"data-slot": "combobox-label",
|
|
390
|
+
className: join('ef-combobox__label', className)
|
|
391
|
+
}, props));
|
|
392
|
+
});
|
|
393
|
+
export function ComboboxCollection({
|
|
394
|
+
children
|
|
395
|
+
}) {
|
|
396
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
397
|
+
}
|
|
398
|
+
export const ComboboxEmpty = /*#__PURE__*/React.forwardRef(function ComboboxEmpty({
|
|
399
|
+
className,
|
|
400
|
+
...props
|
|
401
|
+
}, ref) {
|
|
402
|
+
const context = React.useContext(ComboboxContext);
|
|
403
|
+
return context?.visibleCount === 0 && context.filteredItems.length === 0 ? /*#__PURE__*/React.createElement("div", _extends({
|
|
404
|
+
ref: ref,
|
|
405
|
+
"data-slot": "combobox-empty",
|
|
406
|
+
className: join('ef-combobox__empty', className)
|
|
407
|
+
}, props)) : null;
|
|
408
|
+
});
|
|
409
|
+
export const ComboboxSeparator = /*#__PURE__*/React.forwardRef(function ComboboxSeparator({
|
|
410
|
+
className,
|
|
411
|
+
...props
|
|
412
|
+
}, ref) {
|
|
413
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
414
|
+
ref: ref,
|
|
415
|
+
"data-slot": "combobox-separator",
|
|
416
|
+
role: "separator",
|
|
417
|
+
className: join('ef-combobox__separator', className)
|
|
418
|
+
}, props));
|
|
419
|
+
});
|
|
420
|
+
export const ComboboxChips = /*#__PURE__*/React.forwardRef(function ComboboxChips({
|
|
421
|
+
className,
|
|
422
|
+
...props
|
|
423
|
+
}, forwardedRef) {
|
|
424
|
+
const context = React.useContext(ComboboxContext);
|
|
425
|
+
const localRef = React.useRef(null);
|
|
426
|
+
React.useImperativeHandle(forwardedRef, () => localRef.current);
|
|
427
|
+
React.useEffect(() => {
|
|
428
|
+
if (context) context.anchorRef.current = localRef.current;
|
|
429
|
+
}, [context]);
|
|
430
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
431
|
+
ref: localRef,
|
|
432
|
+
"data-slot": "combobox-chips",
|
|
433
|
+
className: join('ef-combobox__chips', className)
|
|
434
|
+
}, props));
|
|
435
|
+
});
|
|
436
|
+
export const ComboboxChip = /*#__PURE__*/React.forwardRef(function ComboboxChip({
|
|
437
|
+
value,
|
|
438
|
+
className,
|
|
439
|
+
children,
|
|
440
|
+
showRemove = true,
|
|
441
|
+
...props
|
|
442
|
+
}, ref) {
|
|
443
|
+
const context = React.useContext(ComboboxContext);
|
|
444
|
+
const nextValue = value ?? textOf(children);
|
|
445
|
+
return /*#__PURE__*/React.createElement("span", _extends({
|
|
446
|
+
ref: ref,
|
|
447
|
+
"data-slot": "combobox-chip",
|
|
448
|
+
className: join('ef-combobox__chip', className)
|
|
449
|
+
}, props), children, showRemove ? /*#__PURE__*/React.createElement("button", {
|
|
450
|
+
type: "button",
|
|
451
|
+
"data-slot": "combobox-chip-remove",
|
|
452
|
+
className: "ef-combobox__chip-remove",
|
|
453
|
+
"aria-label": `Remove ${itemText(nextValue)}`,
|
|
454
|
+
onClick: () => context?.remove(nextValue)
|
|
455
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
456
|
+
name: "x",
|
|
457
|
+
size: 12
|
|
458
|
+
})) : null);
|
|
459
|
+
});
|
|
460
|
+
export const ComboboxChipsInput = /*#__PURE__*/React.forwardRef(function ComboboxChipsInput({
|
|
461
|
+
className,
|
|
462
|
+
onChange,
|
|
463
|
+
onFocus,
|
|
464
|
+
onKeyDown,
|
|
465
|
+
...props
|
|
466
|
+
}, ref) {
|
|
467
|
+
const context = React.useContext(ComboboxContext);
|
|
468
|
+
return /*#__PURE__*/React.createElement("input", _extends({
|
|
469
|
+
ref: ref,
|
|
470
|
+
"data-slot": "combobox-chips-input",
|
|
471
|
+
role: "combobox",
|
|
472
|
+
"aria-autocomplete": "list",
|
|
473
|
+
"aria-expanded": context?.isOpen,
|
|
474
|
+
"aria-controls": context?.listId,
|
|
475
|
+
"aria-activedescendant": context?.active || undefined,
|
|
476
|
+
className: join('ef-combobox__chips-input', className),
|
|
477
|
+
value: context?.query ?? '',
|
|
478
|
+
onChange: event => {
|
|
479
|
+
context?.setQuery(event.target.value);
|
|
480
|
+
context?.setOpen(true);
|
|
481
|
+
onChange?.(event);
|
|
482
|
+
},
|
|
483
|
+
onFocus: event => {
|
|
484
|
+
context?.setOpen(true);
|
|
485
|
+
onFocus?.(event);
|
|
486
|
+
},
|
|
487
|
+
onKeyDown: useInputKeyboard(context, onKeyDown)
|
|
488
|
+
}, props));
|
|
489
|
+
});
|
|
490
|
+
export function useComboboxAnchor() {
|
|
491
|
+
return React.useRef(null);
|
|
161
492
|
}
|
package/forms/Field.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type FieldOrientation = 'vertical' | 'horizontal' | 'responsive';
|
|
2
|
+
export type FieldProps = React.ComponentPropsWithoutRef<'div'> & { orientation?: FieldOrientation };
|
|
3
|
+
export type FieldLegendProps = React.ComponentPropsWithoutRef<'legend'> & { variant?: 'legend' | 'label' };
|
|
4
|
+
export type FieldErrorProps = React.ComponentPropsWithoutRef<'div'> & { errors?: Array<{ message?: string } | undefined> };
|
|
5
|
+
export declare const FieldSet: React.ForwardRefExoticComponent<React.ComponentPropsWithoutRef<'fieldset'> & React.RefAttributes<HTMLFieldSetElement>>;
|
|
6
|
+
export declare const FieldLegend: React.ForwardRefExoticComponent<FieldLegendProps & React.RefAttributes<HTMLLegendElement>>;
|
|
7
|
+
export declare const FieldGroup: React.ForwardRefExoticComponent<React.ComponentPropsWithoutRef<'div'> & React.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
export declare const FieldContent: React.ForwardRefExoticComponent<React.ComponentPropsWithoutRef<'div'> & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export declare const FieldLabel: React.ForwardRefExoticComponent<React.ComponentPropsWithoutRef<'label'> & React.RefAttributes<HTMLLabelElement>>;
|
|
11
|
+
export declare const FieldTitle: React.ForwardRefExoticComponent<React.ComponentPropsWithoutRef<'div'> & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
+
export declare const FieldDescription: React.ForwardRefExoticComponent<React.ComponentPropsWithoutRef<'p'> & React.RefAttributes<HTMLParagraphElement>>;
|
|
13
|
+
export declare const FieldSeparator: React.ForwardRefExoticComponent<React.ComponentPropsWithoutRef<'div'> & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
export declare const FieldError: React.ForwardRefExoticComponent<FieldErrorProps & React.RefAttributes<HTMLDivElement>>;
|