@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.
Files changed (183) hide show
  1. package/README.md +1 -1
  2. package/ai/Bubble.d.ts +16 -0
  3. package/ai/Bubble.js +71 -0
  4. package/ai/ChatMessage.js +2 -5
  5. package/ai/Confirmation.d.ts +0 -7
  6. package/ai/Confirmation.js +3 -6
  7. package/ai/GeneratedImage.d.ts +0 -2
  8. package/ai/GeneratedImage.js +2 -4
  9. package/ai/Marker.d.ts +26 -0
  10. package/ai/Marker.js +67 -0
  11. package/ai/Message.d.ts +13 -0
  12. package/ai/Message.js +68 -0
  13. package/ai/MessageScroller.d.ts +21 -0
  14. package/ai/MessageScroller.js +283 -0
  15. package/ai/ModelSelector.d.ts +2 -2
  16. package/ai/ModelSelector.js +1 -2
  17. package/ai/Player.js +1 -1
  18. package/ai/PromptSteps.js +4 -2
  19. package/ai/Sandbox.d.ts +0 -2
  20. package/ai/Sandbox.js +2 -4
  21. package/ai/Suggestions.d.ts +0 -2
  22. package/ai/Suggestions.js +1 -4
  23. package/ai/WebPreview.d.ts +0 -2
  24. package/ai/WebPreview.js +2 -4
  25. package/code/Console.js +1 -1
  26. package/code/EnvList.d.ts +0 -2
  27. package/code/EnvList.js +2 -3
  28. package/components.css +660 -423
  29. package/data/BarChart.d.ts +0 -2
  30. package/data/BarChart.js +1 -4
  31. package/data/Chart.d.ts +14 -0
  32. package/data/Chart.js +149 -0
  33. package/data/EmptyState.d.ts +8 -13
  34. package/data/EmptyState.js +62 -24
  35. package/data/LineChart.js +7 -4
  36. package/data/Skeleton.d.ts +2 -11
  37. package/data/Skeleton.js +8 -38
  38. package/data/Sparkline.js +4 -1
  39. package/data/StatusDot.d.ts +0 -4
  40. package/data/StatusDot.js +3 -6
  41. package/data/Table.d.ts +11 -4
  42. package/data/Table.js +39 -7
  43. package/dates/Calendar.d.ts +10 -27
  44. package/dates/Calendar.js +250 -184
  45. package/dates/TimePicker.js +2 -2
  46. package/display/Accordion.d.ts +47 -15
  47. package/display/Accordion.js +257 -27
  48. package/display/AspectRatio.d.ts +4 -6
  49. package/display/AspectRatio.js +7 -5
  50. package/display/Avatar.d.ts +17 -14
  51. package/display/Avatar.js +68 -43
  52. package/display/Badge.d.ts +9 -8
  53. package/display/Badge.js +32 -14
  54. package/display/Card.d.ts +11 -13
  55. package/display/Card.js +74 -29
  56. package/display/Carousel.d.ts +23 -15
  57. package/display/Carousel.js +217 -66
  58. package/display/Collapsible.d.ts +19 -9
  59. package/display/Collapsible.js +140 -28
  60. package/display/Direction.d.ts +10 -0
  61. package/display/Direction.js +24 -0
  62. package/display/Item.d.ts +19 -0
  63. package/display/Item.js +152 -0
  64. package/display/Kbd.d.ts +5 -7
  65. package/display/Kbd.js +22 -10
  66. package/display/Link.js +2 -4
  67. package/display/Resizable.d.ts +6 -16
  68. package/display/Resizable.js +141 -58
  69. package/display/ScrollArea.d.ts +3 -1
  70. package/display/ScrollArea.js +30 -5
  71. package/display/Separator.d.ts +9 -0
  72. package/display/Separator.js +18 -0
  73. package/display/Timeline.d.ts +24 -0
  74. package/display/Timeline.js +51 -0
  75. package/display/Toolbar.js +5 -4
  76. package/display/TreeList.d.ts +0 -2
  77. package/display/TreeList.js +2 -5
  78. package/feedback/Alert.d.ts +13 -13
  79. package/feedback/Alert.js +40 -36
  80. package/feedback/AlertDialog.d.ts +30 -0
  81. package/feedback/AlertDialog.js +249 -0
  82. package/feedback/Banner.d.ts +1 -3
  83. package/feedback/Banner.js +1 -5
  84. package/feedback/ConfirmDialog.d.ts +1 -1
  85. package/feedback/ConfirmDialog.js +18 -20
  86. package/feedback/Dialog.d.ts +13 -16
  87. package/feedback/Dialog.js +204 -62
  88. package/feedback/Progress.d.ts +8 -9
  89. package/feedback/Progress.js +42 -24
  90. package/feedback/Sonner.d.ts +8 -0
  91. package/feedback/Sonner.js +238 -0
  92. package/feedback/Spinner.d.ts +2 -9
  93. package/feedback/Spinner.js +19 -28
  94. package/feedback/Tooltip.d.ts +9 -10
  95. package/feedback/Tooltip.js +147 -96
  96. package/files/Attachment.d.ts +27 -0
  97. package/files/Attachment.js +111 -0
  98. package/files/FileDrop.js +3 -1
  99. package/finance/PaymentCard.js +3 -3
  100. package/forms/Button.d.ts +6 -5
  101. package/forms/Button.js +42 -8
  102. package/forms/ButtonGroup.d.ts +11 -3
  103. package/forms/ButtonGroup.js +57 -6
  104. package/forms/Checkbox.d.ts +14 -3
  105. package/forms/Checkbox.js +84 -16
  106. package/forms/Combobox.d.ts +24 -16
  107. package/forms/Combobox.js +466 -135
  108. package/forms/Field.d.ts +14 -0
  109. package/forms/Field.js +99 -0
  110. package/forms/IconButton.d.ts +1 -1
  111. package/forms/IconButton.js +4 -3
  112. package/forms/Input.d.ts +8 -8
  113. package/forms/Input.js +46 -33
  114. package/forms/InputGroup.d.ts +8 -15
  115. package/forms/InputGroup.js +74 -35
  116. package/forms/InputOTP.d.ts +13 -0
  117. package/forms/InputOTP.js +125 -0
  118. package/forms/Label.d.ts +2 -6
  119. package/forms/Label.js +6 -4
  120. package/forms/NativeSelect.d.ts +16 -0
  121. package/forms/NativeSelect.js +35 -0
  122. package/forms/NumberInput.js +2 -2
  123. package/forms/Radio.d.ts +12 -1
  124. package/forms/Radio.js +76 -6
  125. package/forms/Select.d.ts +12 -9
  126. package/forms/Select.js +254 -42
  127. package/forms/Slider.d.ts +10 -17
  128. package/forms/Slider.js +78 -39
  129. package/forms/Switch.d.ts +8 -2
  130. package/forms/Switch.js +46 -15
  131. package/forms/Textarea.d.ts +1 -1
  132. package/forms/Textarea.js +26 -18
  133. package/forms/Toggle.d.ts +18 -15
  134. package/forms/Toggle.js +96 -42
  135. package/icons/_svg.js +2 -0
  136. package/index.d.ts +20 -8
  137. package/index.js +50 -38
  138. package/navigation/Breadcrumbs.d.ts +18 -11
  139. package/navigation/Breadcrumbs.js +99 -26
  140. package/navigation/Menubar.d.ts +52 -10
  141. package/navigation/Menubar.js +191 -146
  142. package/navigation/NavigationMenu.d.ts +15 -0
  143. package/navigation/NavigationMenu.js +296 -0
  144. package/navigation/Pagination.d.ts +10 -9
  145. package/navigation/Pagination.js +94 -51
  146. package/navigation/SideNav.js +4 -3
  147. package/navigation/Sidebar.d.ts +29 -0
  148. package/navigation/Sidebar.js +311 -0
  149. package/navigation/Tabs.d.ts +9 -5
  150. package/navigation/Tabs.js +132 -44
  151. package/overlay/Command.d.ts +32 -0
  152. package/overlay/Command.js +257 -0
  153. package/overlay/ContextMenu.d.ts +40 -8
  154. package/overlay/ContextMenu.js +468 -107
  155. package/overlay/Drawer.d.ts +29 -14
  156. package/overlay/Drawer.js +178 -80
  157. package/overlay/DropdownMenu.d.ts +43 -0
  158. package/overlay/DropdownMenu.js +502 -0
  159. package/overlay/HoverCard.d.ts +21 -12
  160. package/overlay/HoverCard.js +129 -61
  161. package/overlay/Popover.d.ts +11 -13
  162. package/overlay/Popover.js +138 -65
  163. package/overlay/Portal.js +21 -7
  164. package/overlay/Sheet.d.ts +11 -0
  165. package/overlay/Sheet.js +62 -0
  166. package/package.json +4 -1
  167. package/tokens/base.css +1 -1
  168. package/dates/DatePicker.d.ts +0 -14
  169. package/dates/DatePicker.js +0 -111
  170. package/dates/DateRangePicker.d.ts +0 -23
  171. package/dates/DateRangePicker.js +0 -150
  172. package/display/ListItem.d.ts +0 -19
  173. package/display/ListItem.js +0 -50
  174. package/feedback/Toast.d.ts +0 -78
  175. package/feedback/Toast.js +0 -192
  176. package/forms/DigitEntry.d.ts +0 -15
  177. package/forms/DigitEntry.js +0 -79
  178. package/forms/FormField.d.ts +0 -82
  179. package/forms/FormField.js +0 -209
  180. package/overlay/CommandPalette.d.ts +0 -21
  181. package/overlay/CommandPalette.js +0 -148
  182. package/overlay/Menu.d.ts +0 -24
  183. 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 { Tag } from "../display/Tag.js";
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
- label,
10
- hint,
11
- options,
14
+ items = [],
12
15
  value,
13
- onChange,
14
- multiple,
15
- placeholder = 'Search…',
16
- style,
17
- className,
18
- ...rest
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
- // Picks up id / aria wiring when nested in a FormField; standalone this is a no-op.
21
- const field = useFieldProps({
22
- id: rest.id,
23
- 'aria-describedby': rest['aria-describedby']
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 ref = React.useRef(null);
30
- const panelRef = React.useRef(null);
31
- const {
32
- style: anchored
33
- } = useAnchoredStyle(ref, panelRef, {
34
- open,
35
- placement: 'bottom',
36
- align: 'start',
37
- matchWidth: true
38
- });
39
- const sel = multiple ? value || [] : value != null ? [value] : [];
40
- const opts = options.map(o => typeof o === 'string' ? {
41
- value: o,
42
- label: o
43
- } : o);
44
- const shown = opts.filter(o => o.label.toLowerCase().includes(q.toLowerCase()) && (!multiple || !sel.includes(o.value)));
45
- // Keep the highlighted option visible to sighted users the same way
46
- // aria-activedescendant keeps it visible to screen readers.
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 (!open) return;
49
- const el = document.getElementById(`${listId}-opt-${hi}`);
50
- if (el && el.scrollIntoView) el.scrollIntoView({
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 (!open) return;
56
- const away = e => {
57
- const inControl = ref.current && ref.current.contains(e.target);
58
- const inPanel = panelRef.current && panelRef.current.contains(e.target);
59
- if (!inControl && !inPanel) setOpen(false);
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
- onChange && onChange([...sel, v]);
67
- setQ('');
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
- onChange && onChange(v);
70
- setQ('');
78
+ setValue(next);
79
+ setQuery(label);
71
80
  setOpen(false);
72
81
  }
73
- };
74
- const unpick = v => onChange && onChange(multiple ? sel.filter(x => x !== v) : null);
75
- const key = e => {
76
- if (e.key === 'ArrowDown') {
77
- e.preventDefault();
78
- setHi(h => Math.min(h + 1, shown.length - 1));
79
- setOpen(true);
80
- } else if (e.key === 'ArrowUp') {
81
- e.preventDefault();
82
- setHi(h => Math.max(h - 1, 0));
83
- } else if (e.key === 'Enter' && open && shown[hi]) {
84
- e.preventDefault();
85
- pick(shown[hi].value);
86
- } else if (e.key === 'Escape') setOpen(false);else if (e.key === 'Backspace' && !q && multiple && sel.length) unpick(sel[sel.length - 1]);
87
- };
88
- const control = /*#__PURE__*/React.createElement("div", {
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
- className: `ef-combo${open ? ' ef-combo--open' : ''}`
91
- }, /*#__PURE__*/React.createElement("div", {
92
- className: "ef-combo__control",
93
- onClick: () => {
94
- setOpen(true);
95
- ref.current.querySelector('input').focus();
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
- }, multiple && sel.map(v => {
98
- const o = opts.find(x => x.value === v);
99
- return /*#__PURE__*/React.createElement(Tag, {
100
- key: v,
101
- onRemove: () => unpick(v)
102
- }, o ? o.label : v);
103
- }), /*#__PURE__*/React.createElement("input", _extends({}, field.controlProps, {
104
- className: "ef-combo__input",
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-activedescendant": open && shown.length ? `${listId}-opt-${hi}` : undefined,
110
- placeholder: sel.length && multiple ? '' : !multiple && sel.length ? (opts.find(x => x.value === sel[0]) || {}).label : placeholder,
111
- value: q,
112
- onChange: e => {
113
- setQ(e.target.value);
114
- setOpen(true);
115
- setHi(0);
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: () => setOpen(true),
118
- onKeyDown: key
119
- })), /*#__PURE__*/React.createElement("span", {
120
- className: "ef-combo__chevron"
121
- }, /*#__PURE__*/React.createElement(Icon, {
122
- name: "chevron-down",
123
- size: 16
124
- }))), open && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
125
- ref: panelRef,
126
- className: "ef-combo__panel",
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
- id: listId,
129
- style: anchored
130
- }, shown.length === 0 && /*#__PURE__*/React.createElement("div", {
131
- className: "ef-combo__empty"
132
- }, "Nothing matches \u201C", q, "\u201D."), shown.map((o, i) => /*#__PURE__*/React.createElement("button", {
133
- key: o.value,
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
- id: `${listId}-opt-${i}`,
136
- "aria-selected": !multiple && sel.includes(o.value),
137
- className: `ef-combo__opt${i === hi ? ' ef-combo__opt--hi' : ''}`,
138
- onMouseEnter: () => setHi(i),
139
- onClick: () => pick(o.value)
140
- }, o.icon ? /*#__PURE__*/React.createElement(Icon, {
141
- name: o.icon,
142
- size: 15
143
- }) : null, o.label, !multiple && sel.includes(o.value) ? /*#__PURE__*/React.createElement("span", {
144
- className: "ef-combo__opt__check"
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
- if (!label && !hint) return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
150
- className: className,
151
- style: style
152
- }), control);
153
- return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
154
- className: `ef-field${className ? ' ' + className : ''}`,
155
- style: style
156
- }), label ? /*#__PURE__*/React.createElement("span", {
157
- className: "ef-field__label"
158
- }, label) : null, control, hint ? /*#__PURE__*/React.createElement("span", {
159
- className: "ef-field__hint"
160
- }, hint) : null);
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
  }
@@ -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>>;