@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
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
'use client';
|
|
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
|
+
import React from 'react';
|
|
4
|
+
import { mergeRefs, useIsoLayoutEffect } from "../forms/Button.js";
|
|
5
|
+
import { Icon } from "../icons/Icon.js";
|
|
6
|
+
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
7
|
+
const RootCtx = /*#__PURE__*/React.createContext(null);
|
|
8
|
+
const SubCtx = /*#__PURE__*/React.createContext(null);
|
|
9
|
+
const RadioCtx = /*#__PURE__*/React.createContext(null);
|
|
10
|
+
const join = (...values) => values.filter(Boolean).join(' ');
|
|
11
|
+
const compose = (theirs, ours) => event => {
|
|
12
|
+
theirs?.(event);
|
|
13
|
+
if (!event.defaultPrevented) ours?.(event);
|
|
14
|
+
};
|
|
15
|
+
function menuItems(node) {
|
|
16
|
+
return node ? Array.from(node.querySelectorAll('[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]')).filter(item => !item.disabled && item.dataset.disabled !== 'true') : [];
|
|
17
|
+
}
|
|
18
|
+
function focusRelative(node, direction, loop = true) {
|
|
19
|
+
const items = menuItems(node);
|
|
20
|
+
if (!items.length) return;
|
|
21
|
+
const current = items.indexOf(document.activeElement);
|
|
22
|
+
const raw = Math.max(0, current) + direction;
|
|
23
|
+
const index = direction === 'first' ? 0 : direction === 'last' ? items.length - 1 : loop ? (raw + items.length) % items.length : Math.max(0, Math.min(items.length - 1, raw));
|
|
24
|
+
items[index]?.focus();
|
|
25
|
+
}
|
|
26
|
+
function useMenuKeyboard(ref, close, {
|
|
27
|
+
sub = false,
|
|
28
|
+
loop = true
|
|
29
|
+
} = {}) {
|
|
30
|
+
return event => {
|
|
31
|
+
if (event.defaultPrevented) return;
|
|
32
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
focusRelative(ref.current, event.key === 'ArrowDown' ? 1 : -1, loop);
|
|
35
|
+
} else if (event.key === 'Home' || event.key === 'End') {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
focusRelative(ref.current, event.key === 'Home' ? 'first' : 'last');
|
|
38
|
+
} else if (event.key === 'Escape' || sub && event.key === 'ArrowLeft') {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
close?.();
|
|
41
|
+
} else if (event.key.length === 1 && /\S/.test(event.key) && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
42
|
+
const items = menuItems(ref.current);
|
|
43
|
+
const start = Math.max(0, items.indexOf(document.activeElement));
|
|
44
|
+
const key = event.key.toLocaleLowerCase();
|
|
45
|
+
for (let offset = 1; offset <= items.length; offset += 1) {
|
|
46
|
+
const item = items[(start + offset) % items.length];
|
|
47
|
+
if ((item.textContent || '').trim().toLocaleLowerCase().startsWith(key)) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
item.focus();
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function DropdownMenu({
|
|
57
|
+
open: controlled,
|
|
58
|
+
defaultOpen = false,
|
|
59
|
+
onOpenChange,
|
|
60
|
+
modal = true,
|
|
61
|
+
children
|
|
62
|
+
}) {
|
|
63
|
+
const [inner, setInner] = React.useState(defaultOpen);
|
|
64
|
+
const open = controlled !== undefined ? controlled : inner;
|
|
65
|
+
const triggerRef = React.useRef(null);
|
|
66
|
+
const contentRef = React.useRef(null);
|
|
67
|
+
const setOpen = React.useCallback(next => {
|
|
68
|
+
if (controlled === undefined) setInner(next);
|
|
69
|
+
onOpenChange?.(next);
|
|
70
|
+
}, [controlled, onOpenChange]);
|
|
71
|
+
const value = React.useMemo(() => ({
|
|
72
|
+
open,
|
|
73
|
+
setOpen,
|
|
74
|
+
triggerRef,
|
|
75
|
+
contentRef,
|
|
76
|
+
modal
|
|
77
|
+
}), [open, setOpen, modal]);
|
|
78
|
+
return /*#__PURE__*/React.createElement(RootCtx.Provider, {
|
|
79
|
+
value: value
|
|
80
|
+
}, children);
|
|
81
|
+
}
|
|
82
|
+
export const DropdownMenuTrigger = /*#__PURE__*/React.forwardRef(function DropdownMenuTrigger({
|
|
83
|
+
asChild = false,
|
|
84
|
+
disabled = false,
|
|
85
|
+
children,
|
|
86
|
+
slot = 'dropdown-menu-trigger',
|
|
87
|
+
...rest
|
|
88
|
+
}, forwardedRef) {
|
|
89
|
+
const root = React.useContext(RootCtx);
|
|
90
|
+
const toggle = () => {
|
|
91
|
+
if (!disabled) root?.setOpen(!root.open);
|
|
92
|
+
};
|
|
93
|
+
const keyboard = event => {
|
|
94
|
+
if (disabled || !['Enter', ' ', 'ArrowDown'].includes(event.key)) return;
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
root?.setOpen(true);
|
|
97
|
+
};
|
|
98
|
+
const props = {
|
|
99
|
+
...rest,
|
|
100
|
+
ref: mergeRefs(forwardedRef, root?.triggerRef),
|
|
101
|
+
'data-slot': slot,
|
|
102
|
+
'data-state': root?.open ? 'open' : 'closed',
|
|
103
|
+
'data-disabled': disabled ? 'true' : undefined,
|
|
104
|
+
'aria-haspopup': 'menu',
|
|
105
|
+
'aria-expanded': !!root?.open,
|
|
106
|
+
onClick: compose(rest.onClick, toggle),
|
|
107
|
+
onKeyDown: compose(rest.onKeyDown, keyboard)
|
|
108
|
+
};
|
|
109
|
+
if (asChild && /*#__PURE__*/React.isValidElement(children)) {
|
|
110
|
+
return /*#__PURE__*/React.cloneElement(children, {
|
|
111
|
+
...props,
|
|
112
|
+
...children.props,
|
|
113
|
+
ref: mergeRefs(children.ref, props.ref),
|
|
114
|
+
onClick: compose(children.props.onClick, props.onClick),
|
|
115
|
+
onKeyDown: compose(children.props.onKeyDown, props.onKeyDown),
|
|
116
|
+
'data-slot': props['data-slot'],
|
|
117
|
+
'data-state': props['data-state'],
|
|
118
|
+
'data-disabled': props['data-disabled'],
|
|
119
|
+
'aria-haspopup': 'menu',
|
|
120
|
+
'aria-expanded': !!root?.open
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return /*#__PURE__*/React.createElement("button", _extends({
|
|
124
|
+
type: "button"
|
|
125
|
+
}, props), children);
|
|
126
|
+
});
|
|
127
|
+
export function DropdownMenuPortal({
|
|
128
|
+
children,
|
|
129
|
+
container
|
|
130
|
+
}) {
|
|
131
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
|
132
|
+
container: container
|
|
133
|
+
}, children);
|
|
134
|
+
}
|
|
135
|
+
export const DropdownMenuContent = /*#__PURE__*/React.forwardRef(function DropdownMenuContent({
|
|
136
|
+
loop = true,
|
|
137
|
+
align = 'center',
|
|
138
|
+
side = 'bottom',
|
|
139
|
+
sideOffset = 4,
|
|
140
|
+
alignOffset = 0,
|
|
141
|
+
className,
|
|
142
|
+
style,
|
|
143
|
+
onKeyDown,
|
|
144
|
+
onCloseAutoFocus,
|
|
145
|
+
children,
|
|
146
|
+
slot = 'dropdown-menu-content',
|
|
147
|
+
...rest
|
|
148
|
+
}, forwardedRef) {
|
|
149
|
+
const root = React.useContext(RootCtx);
|
|
150
|
+
const localRef = React.useRef(null);
|
|
151
|
+
const ref = mergeRefs(forwardedRef, localRef, root?.contentRef);
|
|
152
|
+
const fallbackTriggerRef = React.useRef(null);
|
|
153
|
+
const fallbackContentRef = React.useRef(null);
|
|
154
|
+
const {
|
|
155
|
+
style: anchored,
|
|
156
|
+
side: resolvedSide
|
|
157
|
+
} = useAnchoredStyle(root?.triggerRef ?? fallbackTriggerRef, root?.contentRef ?? fallbackContentRef, {
|
|
158
|
+
open: !!root?.open,
|
|
159
|
+
placement: side,
|
|
160
|
+
align,
|
|
161
|
+
offset: sideOffset,
|
|
162
|
+
crossOffset: alignOffset
|
|
163
|
+
});
|
|
164
|
+
const close = React.useCallback(() => {
|
|
165
|
+
root?.setOpen(false);
|
|
166
|
+
const event = {
|
|
167
|
+
defaultPrevented: false,
|
|
168
|
+
preventDefault() {
|
|
169
|
+
this.defaultPrevented = true;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
onCloseAutoFocus?.(event);
|
|
173
|
+
if (!event.defaultPrevented) root?.triggerRef.current?.focus?.();
|
|
174
|
+
}, [root, onCloseAutoFocus]);
|
|
175
|
+
const keyboard = useMenuKeyboard(localRef, close, {
|
|
176
|
+
loop
|
|
177
|
+
});
|
|
178
|
+
useIsoLayoutEffect(() => {
|
|
179
|
+
if (root?.open) menuItems(localRef.current)[0]?.focus();
|
|
180
|
+
}, [root?.open]);
|
|
181
|
+
React.useEffect(() => {
|
|
182
|
+
if (!root?.open) return;
|
|
183
|
+
const away = event => {
|
|
184
|
+
if (!localRef.current?.contains(event.target) && !root.triggerRef.current?.contains(event.target)) close();
|
|
185
|
+
};
|
|
186
|
+
const blur = () => close();
|
|
187
|
+
document.addEventListener('pointerdown', away);
|
|
188
|
+
window.addEventListener('blur', blur);
|
|
189
|
+
return () => {
|
|
190
|
+
document.removeEventListener('pointerdown', away);
|
|
191
|
+
window.removeEventListener('blur', blur);
|
|
192
|
+
};
|
|
193
|
+
}, [root?.open, close]);
|
|
194
|
+
if (!root?.open) return null;
|
|
195
|
+
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
196
|
+
ref: ref,
|
|
197
|
+
role: "menu",
|
|
198
|
+
"data-slot": slot,
|
|
199
|
+
"data-state": "open",
|
|
200
|
+
"data-side": resolvedSide,
|
|
201
|
+
"data-align": align,
|
|
202
|
+
className: join('ef-dropdown-menu__content', className),
|
|
203
|
+
style: {
|
|
204
|
+
...anchored,
|
|
205
|
+
...style
|
|
206
|
+
},
|
|
207
|
+
onKeyDown: compose(onKeyDown, keyboard)
|
|
208
|
+
}), children));
|
|
209
|
+
});
|
|
210
|
+
export const DropdownMenuGroup = /*#__PURE__*/React.forwardRef(function DropdownMenuGroup({
|
|
211
|
+
slot = 'dropdown-menu-group',
|
|
212
|
+
...props
|
|
213
|
+
}, ref) {
|
|
214
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
215
|
+
ref: ref,
|
|
216
|
+
role: "group",
|
|
217
|
+
"data-slot": slot
|
|
218
|
+
}));
|
|
219
|
+
});
|
|
220
|
+
export const DropdownMenuLabel = /*#__PURE__*/React.forwardRef(function DropdownMenuLabel({
|
|
221
|
+
inset = false,
|
|
222
|
+
className,
|
|
223
|
+
slot = 'dropdown-menu-label',
|
|
224
|
+
...props
|
|
225
|
+
}, ref) {
|
|
226
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
227
|
+
ref: ref,
|
|
228
|
+
"data-slot": slot,
|
|
229
|
+
"data-inset": inset ? 'true' : undefined,
|
|
230
|
+
className: join('ef-dropdown-menu__label', className)
|
|
231
|
+
}));
|
|
232
|
+
});
|
|
233
|
+
export const DropdownMenuSeparator = /*#__PURE__*/React.forwardRef(function DropdownMenuSeparator({
|
|
234
|
+
className,
|
|
235
|
+
slot = 'dropdown-menu-separator',
|
|
236
|
+
...props
|
|
237
|
+
}, ref) {
|
|
238
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
239
|
+
ref: ref,
|
|
240
|
+
role: "separator",
|
|
241
|
+
"data-slot": slot,
|
|
242
|
+
className: join('ef-dropdown-menu__separator', className)
|
|
243
|
+
}));
|
|
244
|
+
});
|
|
245
|
+
export const DropdownMenuShortcut = /*#__PURE__*/React.forwardRef(function DropdownMenuShortcut({
|
|
246
|
+
className,
|
|
247
|
+
slot = 'dropdown-menu-shortcut',
|
|
248
|
+
...props
|
|
249
|
+
}, ref) {
|
|
250
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, props, {
|
|
251
|
+
ref: ref,
|
|
252
|
+
"data-slot": slot,
|
|
253
|
+
className: join('ef-dropdown-menu__shortcut', className)
|
|
254
|
+
}));
|
|
255
|
+
});
|
|
256
|
+
export const DropdownMenuItem = /*#__PURE__*/React.forwardRef(function DropdownMenuItem({
|
|
257
|
+
inset = false,
|
|
258
|
+
variant = 'default',
|
|
259
|
+
disabled = false,
|
|
260
|
+
onSelect,
|
|
261
|
+
onClick,
|
|
262
|
+
className,
|
|
263
|
+
children,
|
|
264
|
+
slot = 'dropdown-menu-item',
|
|
265
|
+
...props
|
|
266
|
+
}, ref) {
|
|
267
|
+
const root = React.useContext(RootCtx);
|
|
268
|
+
const activate = event => {
|
|
269
|
+
onClick?.(event);
|
|
270
|
+
if (!event.defaultPrevented && !disabled) {
|
|
271
|
+
onSelect?.(event);
|
|
272
|
+
if (!event.defaultPrevented) root?.setOpen(false);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
return /*#__PURE__*/React.createElement("button", _extends({}, props, {
|
|
276
|
+
ref: ref,
|
|
277
|
+
type: "button",
|
|
278
|
+
role: "menuitem",
|
|
279
|
+
disabled: disabled,
|
|
280
|
+
"data-slot": slot,
|
|
281
|
+
"data-inset": inset ? 'true' : undefined,
|
|
282
|
+
"data-variant": variant,
|
|
283
|
+
"data-disabled": disabled ? 'true' : undefined,
|
|
284
|
+
className: join('ef-dropdown-menu__item', className),
|
|
285
|
+
onClick: activate
|
|
286
|
+
}), children);
|
|
287
|
+
});
|
|
288
|
+
export const DropdownMenuCheckboxItem = /*#__PURE__*/React.forwardRef(function DropdownMenuCheckboxItem({
|
|
289
|
+
checked: controlled,
|
|
290
|
+
defaultChecked = false,
|
|
291
|
+
onCheckedChange,
|
|
292
|
+
disabled = false,
|
|
293
|
+
onSelect,
|
|
294
|
+
onClick,
|
|
295
|
+
className,
|
|
296
|
+
children,
|
|
297
|
+
slot = 'dropdown-menu-checkbox-item',
|
|
298
|
+
...props
|
|
299
|
+
}, ref) {
|
|
300
|
+
const root = React.useContext(RootCtx);
|
|
301
|
+
const [inner, setInner] = React.useState(defaultChecked);
|
|
302
|
+
const checked = controlled !== undefined ? controlled : inner;
|
|
303
|
+
const activate = event => {
|
|
304
|
+
onClick?.(event);
|
|
305
|
+
if (event.defaultPrevented || disabled) return;
|
|
306
|
+
const next = !checked;
|
|
307
|
+
if (controlled === undefined) setInner(next);
|
|
308
|
+
onCheckedChange?.(next);
|
|
309
|
+
onSelect?.(event);
|
|
310
|
+
if (!event.defaultPrevented) root?.setOpen(false);
|
|
311
|
+
};
|
|
312
|
+
return /*#__PURE__*/React.createElement("button", _extends({}, props, {
|
|
313
|
+
ref: ref,
|
|
314
|
+
type: "button",
|
|
315
|
+
role: "menuitemcheckbox",
|
|
316
|
+
"aria-checked": checked,
|
|
317
|
+
disabled: disabled,
|
|
318
|
+
"data-slot": slot,
|
|
319
|
+
"data-state": checked ? 'checked' : 'unchecked',
|
|
320
|
+
"data-disabled": disabled ? 'true' : undefined,
|
|
321
|
+
className: join('ef-dropdown-menu__item', className),
|
|
322
|
+
onClick: activate
|
|
323
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
324
|
+
className: "ef-dropdown-menu__indicator"
|
|
325
|
+
}, checked ? /*#__PURE__*/React.createElement(Icon, {
|
|
326
|
+
name: "check",
|
|
327
|
+
size: 14
|
|
328
|
+
}) : null), children);
|
|
329
|
+
});
|
|
330
|
+
export function DropdownMenuRadioGroup({
|
|
331
|
+
value: controlled,
|
|
332
|
+
defaultValue = '',
|
|
333
|
+
onValueChange,
|
|
334
|
+
children,
|
|
335
|
+
slot = 'dropdown-menu-radio-group',
|
|
336
|
+
...props
|
|
337
|
+
}) {
|
|
338
|
+
const [inner, setInner] = React.useState(defaultValue);
|
|
339
|
+
const value = controlled !== undefined ? controlled : inner;
|
|
340
|
+
const setValue = next => {
|
|
341
|
+
if (controlled === undefined) setInner(next);
|
|
342
|
+
onValueChange?.(next);
|
|
343
|
+
};
|
|
344
|
+
return /*#__PURE__*/React.createElement(RadioCtx.Provider, {
|
|
345
|
+
value: {
|
|
346
|
+
value,
|
|
347
|
+
setValue
|
|
348
|
+
}
|
|
349
|
+
}, /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
350
|
+
role: "group",
|
|
351
|
+
"data-slot": slot
|
|
352
|
+
}), children));
|
|
353
|
+
}
|
|
354
|
+
export const DropdownMenuRadioItem = /*#__PURE__*/React.forwardRef(function DropdownMenuRadioItem({
|
|
355
|
+
value,
|
|
356
|
+
disabled = false,
|
|
357
|
+
onSelect,
|
|
358
|
+
onClick,
|
|
359
|
+
className,
|
|
360
|
+
children,
|
|
361
|
+
slot = 'dropdown-menu-radio-item',
|
|
362
|
+
...props
|
|
363
|
+
}, ref) {
|
|
364
|
+
const root = React.useContext(RootCtx);
|
|
365
|
+
const radio = React.useContext(RadioCtx);
|
|
366
|
+
const checked = radio?.value === value;
|
|
367
|
+
const activate = event => {
|
|
368
|
+
onClick?.(event);
|
|
369
|
+
if (event.defaultPrevented || disabled) return;
|
|
370
|
+
radio?.setValue(value);
|
|
371
|
+
onSelect?.(event);
|
|
372
|
+
if (!event.defaultPrevented) root?.setOpen(false);
|
|
373
|
+
};
|
|
374
|
+
return /*#__PURE__*/React.createElement("button", _extends({}, props, {
|
|
375
|
+
ref: ref,
|
|
376
|
+
type: "button",
|
|
377
|
+
role: "menuitemradio",
|
|
378
|
+
"aria-checked": checked,
|
|
379
|
+
disabled: disabled,
|
|
380
|
+
"data-slot": slot,
|
|
381
|
+
"data-state": checked ? 'checked' : 'unchecked',
|
|
382
|
+
"data-disabled": disabled ? 'true' : undefined,
|
|
383
|
+
className: join('ef-dropdown-menu__item', className),
|
|
384
|
+
onClick: activate
|
|
385
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
386
|
+
className: "ef-dropdown-menu__indicator"
|
|
387
|
+
}, checked ? /*#__PURE__*/React.createElement(Icon, {
|
|
388
|
+
name: "circle",
|
|
389
|
+
size: 8
|
|
390
|
+
}) : null), children);
|
|
391
|
+
});
|
|
392
|
+
export function DropdownMenuSub({
|
|
393
|
+
open: controlled,
|
|
394
|
+
defaultOpen = false,
|
|
395
|
+
onOpenChange,
|
|
396
|
+
children
|
|
397
|
+
}) {
|
|
398
|
+
const [inner, setInner] = React.useState(defaultOpen);
|
|
399
|
+
const open = controlled !== undefined ? controlled : inner;
|
|
400
|
+
const triggerRef = React.useRef(null);
|
|
401
|
+
const contentRef = React.useRef(null);
|
|
402
|
+
const setOpen = next => {
|
|
403
|
+
if (controlled === undefined) setInner(next);
|
|
404
|
+
onOpenChange?.(next);
|
|
405
|
+
};
|
|
406
|
+
return /*#__PURE__*/React.createElement(SubCtx.Provider, {
|
|
407
|
+
value: {
|
|
408
|
+
open,
|
|
409
|
+
setOpen,
|
|
410
|
+
triggerRef,
|
|
411
|
+
contentRef
|
|
412
|
+
}
|
|
413
|
+
}, children);
|
|
414
|
+
}
|
|
415
|
+
export const DropdownMenuSubTrigger = /*#__PURE__*/React.forwardRef(function DropdownMenuSubTrigger({
|
|
416
|
+
inset = false,
|
|
417
|
+
disabled = false,
|
|
418
|
+
className,
|
|
419
|
+
children,
|
|
420
|
+
onKeyDown,
|
|
421
|
+
slot = 'dropdown-menu-sub-trigger',
|
|
422
|
+
...props
|
|
423
|
+
}, forwardedRef) {
|
|
424
|
+
const sub = React.useContext(SubCtx);
|
|
425
|
+
const keyboard = event => {
|
|
426
|
+
if (!disabled && event.key === 'ArrowRight') {
|
|
427
|
+
event.preventDefault();
|
|
428
|
+
sub?.setOpen(true);
|
|
429
|
+
requestAnimationFrame(() => menuItems(sub?.contentRef.current)[0]?.focus());
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
return /*#__PURE__*/React.createElement("button", _extends({}, props, {
|
|
433
|
+
ref: mergeRefs(forwardedRef, sub?.triggerRef),
|
|
434
|
+
type: "button",
|
|
435
|
+
role: "menuitem",
|
|
436
|
+
disabled: disabled,
|
|
437
|
+
"data-slot": slot,
|
|
438
|
+
"data-state": sub?.open ? 'open' : 'closed',
|
|
439
|
+
"data-inset": inset ? 'true' : undefined,
|
|
440
|
+
"data-disabled": disabled ? 'true' : undefined,
|
|
441
|
+
className: join('ef-dropdown-menu__item', className),
|
|
442
|
+
onMouseEnter: () => !disabled && sub?.setOpen(true),
|
|
443
|
+
onKeyDown: compose(onKeyDown, keyboard)
|
|
444
|
+
}), children, /*#__PURE__*/React.createElement("span", {
|
|
445
|
+
className: "ef-dropdown-menu__chevron"
|
|
446
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
447
|
+
name: "chevron-right",
|
|
448
|
+
size: 14
|
|
449
|
+
})));
|
|
450
|
+
});
|
|
451
|
+
export const DropdownMenuSubContent = /*#__PURE__*/React.forwardRef(function DropdownMenuSubContent({
|
|
452
|
+
sideOffset = 4,
|
|
453
|
+
alignOffset = -4,
|
|
454
|
+
loop = true,
|
|
455
|
+
className,
|
|
456
|
+
style,
|
|
457
|
+
onKeyDown,
|
|
458
|
+
children,
|
|
459
|
+
slot = 'dropdown-menu-sub-content',
|
|
460
|
+
...props
|
|
461
|
+
}, forwardedRef) {
|
|
462
|
+
const sub = React.useContext(SubCtx);
|
|
463
|
+
const localRef = React.useRef(null);
|
|
464
|
+
const fallbackTriggerRef = React.useRef(null);
|
|
465
|
+
const fallbackContentRef = React.useRef(null);
|
|
466
|
+
const {
|
|
467
|
+
style: anchored,
|
|
468
|
+
side
|
|
469
|
+
} = useAnchoredStyle(sub?.triggerRef ?? fallbackTriggerRef, sub?.contentRef ?? fallbackContentRef, {
|
|
470
|
+
open: !!sub?.open,
|
|
471
|
+
placement: 'right',
|
|
472
|
+
align: 'start',
|
|
473
|
+
offset: sideOffset,
|
|
474
|
+
crossOffset: alignOffset
|
|
475
|
+
});
|
|
476
|
+
const close = () => {
|
|
477
|
+
sub?.setOpen(false);
|
|
478
|
+
sub?.triggerRef.current?.focus();
|
|
479
|
+
};
|
|
480
|
+
const keyboard = useMenuKeyboard(localRef, close, {
|
|
481
|
+
sub: true,
|
|
482
|
+
loop
|
|
483
|
+
});
|
|
484
|
+
useIsoLayoutEffect(() => {
|
|
485
|
+
if (sub?.open) menuItems(localRef.current)[0]?.focus();
|
|
486
|
+
}, [sub?.open]);
|
|
487
|
+
if (!sub?.open) return null;
|
|
488
|
+
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
489
|
+
ref: mergeRefs(forwardedRef, localRef, sub.contentRef),
|
|
490
|
+
role: "menu",
|
|
491
|
+
"data-slot": slot,
|
|
492
|
+
"data-state": "open",
|
|
493
|
+
"data-side": side,
|
|
494
|
+
className: join('ef-dropdown-menu__content', className),
|
|
495
|
+
style: {
|
|
496
|
+
...anchored,
|
|
497
|
+
...style
|
|
498
|
+
},
|
|
499
|
+
onMouseLeave: () => sub.setOpen(false),
|
|
500
|
+
onKeyDown: compose(onKeyDown, keyboard)
|
|
501
|
+
}), children));
|
|
502
|
+
});
|
package/overlay/HoverCard.d.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
|
|
1
3
|
export interface HoverCardProps {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** @default 'bottom' */
|
|
7
|
-
side?: 'top' | 'bottom';
|
|
8
|
-
/** Ms before opening @default 350 */
|
|
4
|
+
open?: boolean;
|
|
5
|
+
defaultOpen?: boolean;
|
|
6
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
|
+
/** Delay before a pointer opens the card. @default 700 */
|
|
9
8
|
openDelay?: number;
|
|
10
|
-
/**
|
|
9
|
+
/** Delay before a pointer closes the card. @default 300 */
|
|
11
10
|
closeDelay?: number;
|
|
12
|
-
|
|
13
|
-
width?: number;
|
|
14
|
-
style?: React.CSSProperties;
|
|
15
|
-
className?: string;
|
|
11
|
+
children?: React.ReactNode;
|
|
16
12
|
}
|
|
17
13
|
export declare function HoverCard(props: HoverCardProps): React.JSX.Element;
|
|
14
|
+
|
|
15
|
+
export interface HoverCardTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
16
|
+
asChild?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const HoverCardTrigger: React.ForwardRefExoticComponent<HoverCardTriggerProps & React.RefAttributes<HTMLElement>>;
|
|
19
|
+
|
|
20
|
+
export interface HoverCardContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
21
|
+
align?: 'start' | 'center' | 'end';
|
|
22
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
23
|
+
sideOffset?: number;
|
|
24
|
+
alignOffset?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare const HoverCardContent: React.ForwardRefExoticComponent<HoverCardContentProps & React.RefAttributes<HTMLDivElement>>;
|