@efolusi/meridian 1.5.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 +12 -0
- package/ai/AgentRun.d.ts +20 -0
- package/ai/AgentRun.js +100 -0
- package/ai/ChatMessage.d.ts +19 -0
- package/ai/ChatMessage.js +81 -0
- package/ai/Citation.d.ts +23 -0
- package/ai/Citation.js +146 -0
- package/ai/Confirmation.d.ts +26 -0
- package/ai/Confirmation.js +84 -0
- package/ai/Conversation.d.ts +15 -0
- package/ai/Conversation.js +81 -0
- package/ai/DocumentCard.d.ts +17 -0
- package/ai/DocumentCard.js +101 -0
- package/ai/FeedbackBar.d.ts +14 -0
- package/ai/FeedbackBar.js +84 -0
- package/ai/GeneratedImage.d.ts +22 -0
- package/ai/GeneratedImage.js +100 -0
- package/ai/ModelSelector.d.ts +21 -0
- package/ai/ModelSelector.js +112 -0
- package/ai/Player.d.ts +18 -0
- package/ai/Player.js +201 -0
- package/ai/PromptComposer.d.ts +28 -0
- package/ai/PromptComposer.js +111 -0
- package/ai/PromptSteps.d.ts +18 -0
- package/ai/PromptSteps.js +167 -0
- package/ai/Reasoning.d.ts +17 -0
- package/ai/Reasoning.js +57 -0
- package/ai/RichComposer.d.ts +25 -0
- package/ai/RichComposer.js +247 -0
- package/ai/Sandbox.d.ts +20 -0
- package/ai/Sandbox.js +96 -0
- package/ai/SelectionQuote.d.ts +15 -0
- package/ai/SelectionQuote.js +123 -0
- package/ai/SourceCard.d.ts +17 -0
- package/ai/SourceCard.js +57 -0
- package/ai/Suggestions.d.ts +10 -0
- package/ai/Suggestions.js +38 -0
- package/ai/Task.d.ts +15 -0
- package/ai/Task.js +49 -0
- package/ai/Todo.d.ts +13 -0
- package/ai/Todo.js +87 -0
- package/ai/ToolCall.d.ts +30 -0
- package/ai/ToolCall.js +147 -0
- package/ai/Transcript.d.ts +27 -0
- package/ai/Transcript.js +96 -0
- package/ai/UsageMeter.d.ts +21 -0
- package/ai/UsageMeter.js +81 -0
- package/ai/WebPreview.d.ts +19 -0
- package/ai/WebPreview.js +179 -0
- package/assets/fonts/BricolageGrotesque-Variable.ttf +0 -0
- package/assets/fonts/Figtree-Italic-Variable.ttf +0 -0
- package/assets/fonts/Figtree-Variable.ttf +0 -0
- package/assets/fonts/JetBrainsMono-Italic-Variable.ttf +0 -0
- package/assets/fonts/JetBrainsMono-Variable.ttf +0 -0
- package/assets/fonts/OFL-BricolageGrotesque.txt +93 -0
- package/assets/fonts/OFL-Figtree.txt +93 -0
- package/assets/fonts/OFL-JetBrainsMono.txt +93 -0
- package/code/CodeBlock.d.ts +17 -0
- package/code/CodeBlock.js +99 -0
- package/code/Console.d.ts +19 -0
- package/code/Console.js +124 -0
- package/code/CopyField.d.ts +10 -0
- package/code/CopyField.js +54 -0
- package/code/Diff.d.ts +26 -0
- package/code/Diff.js +358 -0
- package/code/EnvList.d.ts +14 -0
- package/code/EnvList.js +89 -0
- package/code/Exception.d.ts +25 -0
- package/code/Exception.js +90 -0
- package/code/Terminal.d.ts +20 -0
- package/code/Terminal.js +58 -0
- package/data/BarChart.d.ts +14 -0
- package/data/BarChart.js +44 -0
- package/data/DonutChart.d.ts +17 -0
- package/data/DonutChart.js +114 -0
- package/data/EmptyState.d.ts +13 -0
- package/data/EmptyState.js +39 -0
- package/data/KeyValueList.d.ts +14 -0
- package/data/KeyValueList.js +34 -0
- package/data/LineChart.d.ts +15 -0
- package/data/LineChart.js +85 -0
- package/data/Skeleton.d.ts +11 -0
- package/data/Skeleton.js +49 -0
- package/data/Sparkline.d.ts +14 -0
- package/data/Sparkline.js +42 -0
- package/data/Stat.d.ts +14 -0
- package/data/Stat.js +40 -0
- package/data/StatusDot.d.ts +10 -0
- package/data/StatusDot.js +34 -0
- package/data/Table.d.ts +53 -0
- package/data/Table.js +174 -0
- package/dates/Calendar.d.ts +8 -0
- package/dates/Calendar.js +143 -0
- package/dates/DatePicker.d.ts +12 -0
- package/dates/DatePicker.js +118 -0
- package/display/Accordion.d.ts +15 -0
- package/display/Accordion.js +52 -0
- package/display/AspectRatio.d.ts +8 -0
- package/display/AspectRatio.js +24 -0
- package/display/Avatar.d.ts +17 -0
- package/display/Avatar.js +52 -0
- package/display/Badge.d.ts +10 -0
- package/display/Badge.js +34 -0
- package/display/Card.d.ts +17 -0
- package/display/Card.js +51 -0
- package/display/Carousel.d.ts +16 -0
- package/display/Carousel.js +97 -0
- package/display/Collapsible.d.ts +12 -0
- package/display/Collapsible.js +46 -0
- package/display/Divider.d.ts +9 -0
- package/display/Divider.js +33 -0
- package/display/Kbd.d.ts +7 -0
- package/display/Kbd.js +18 -0
- package/display/Link.d.ts +12 -0
- package/display/Link.js +41 -0
- package/display/ListItem.d.ts +19 -0
- package/display/ListItem.js +61 -0
- package/display/Resizable.d.ts +16 -0
- package/display/Resizable.js +90 -0
- package/display/ScrollArea.d.ts +8 -0
- package/display/ScrollArea.js +28 -0
- package/display/Tag.d.ts +9 -0
- package/display/Tag.js +41 -0
- package/display/Toolbar.d.ts +22 -0
- package/display/Toolbar.js +55 -0
- package/display/TreeList.d.ts +20 -0
- package/display/TreeList.js +101 -0
- package/feedback/Alert.d.ts +14 -0
- package/feedback/Alert.js +56 -0
- package/feedback/Banner.d.ts +15 -0
- package/feedback/Banner.js +49 -0
- package/feedback/ConfirmDialog.d.ts +18 -0
- package/feedback/ConfirmDialog.js +49 -0
- package/feedback/Dialog.d.ts +13 -0
- package/feedback/Dialog.js +107 -0
- package/feedback/Loader.d.ts +12 -0
- package/feedback/Loader.js +41 -0
- package/feedback/Progress.d.ts +15 -0
- package/feedback/Progress.js +48 -0
- package/feedback/Spinner.d.ts +9 -0
- package/feedback/Spinner.js +38 -0
- package/feedback/Toast.d.ts +70 -0
- package/feedback/Toast.js +216 -0
- package/feedback/Tooltip.d.ts +12 -0
- package/feedback/Tooltip.js +86 -0
- package/files/FileDrop.d.ts +15 -0
- package/files/FileDrop.js +75 -0
- package/files/FileTile.d.ts +19 -0
- package/files/FileTile.js +96 -0
- package/files/FileTypeIcon.d.ts +11 -0
- package/files/FileTypeIcon.js +121 -0
- package/finance/PaymentCard.d.ts +17 -0
- package/finance/PaymentCard.js +109 -0
- package/forms/Button.d.ts +15 -0
- package/forms/Button.js +82 -0
- package/forms/ButtonGroup.d.ts +5 -0
- package/forms/ButtonGroup.js +22 -0
- package/forms/ButtonTile.d.ts +21 -0
- package/forms/ButtonTile.js +69 -0
- package/forms/Checkbox.d.ts +6 -0
- package/forms/Checkbox.js +52 -0
- package/forms/Combobox.d.ts +17 -0
- package/forms/Combobox.js +162 -0
- package/forms/DigitEntry.d.ts +15 -0
- package/forms/DigitEntry.js +88 -0
- package/forms/FormField.d.ts +39 -0
- package/forms/FormField.js +127 -0
- package/forms/IconButton.d.ts +11 -0
- package/forms/IconButton.js +41 -0
- package/forms/Input.d.ts +14 -0
- package/forms/Input.js +75 -0
- package/forms/InputGroup.d.ts +15 -0
- package/forms/InputGroup.js +59 -0
- package/forms/Label.d.ts +11 -0
- package/forms/Label.js +29 -0
- package/forms/Radio.d.ts +6 -0
- package/forms/Radio.js +46 -0
- package/forms/Select.d.ts +10 -0
- package/forms/Select.js +68 -0
- package/forms/Slider.d.ts +18 -0
- package/forms/Slider.js +75 -0
- package/forms/Switch.d.ts +6 -0
- package/forms/Switch.js +46 -0
- package/forms/Textarea.d.ts +8 -0
- package/forms/Textarea.js +58 -0
- package/forms/Toggle.d.ts +26 -0
- package/forms/Toggle.js +85 -0
- package/icons/Icon.d.ts +13 -0
- package/icons/Icon.js +54 -0
- package/index.d.ts +106 -0
- package/index.js +106 -0
- package/navigation/Breadcrumbs.d.ts +12 -0
- package/navigation/Breadcrumbs.js +41 -0
- package/navigation/Menubar.d.ts +10 -0
- package/navigation/Menubar.js +173 -0
- package/navigation/PageControl.d.ts +11 -0
- package/navigation/PageControl.js +36 -0
- package/navigation/Pagination.d.ts +9 -0
- package/navigation/Pagination.js +68 -0
- package/navigation/SegmentedControl.d.ts +17 -0
- package/navigation/SegmentedControl.js +42 -0
- package/navigation/SideNav.d.ts +18 -0
- package/navigation/SideNav.js +87 -0
- package/navigation/Steps.d.ts +15 -0
- package/navigation/Steps.js +61 -0
- package/navigation/Tabs.d.ts +17 -0
- package/navigation/Tabs.js +76 -0
- package/navigation/TopNav.d.ts +10 -0
- package/navigation/TopNav.js +26 -0
- package/overlay/CommandPalette.d.ts +21 -0
- package/overlay/CommandPalette.js +164 -0
- package/overlay/ContextMenu.d.ts +11 -0
- package/overlay/ContextMenu.js +140 -0
- package/overlay/Drawer.d.ts +14 -0
- package/overlay/Drawer.js +99 -0
- package/overlay/HoverCard.d.ts +17 -0
- package/overlay/HoverCard.js +74 -0
- package/overlay/Menu.d.ts +24 -0
- package/overlay/Menu.js +153 -0
- package/overlay/Popover.d.ts +16 -0
- package/overlay/Popover.js +96 -0
- package/overlay/Portal.d.ts +10 -0
- package/overlay/Portal.js +127 -0
- package/package.json +41 -0
- package/styles.css +6 -0
- package/tokens/base.css +10 -0
- package/tokens/colors.css +38 -0
- package/tokens/effects.css +22 -0
- package/tokens/fonts.css +5 -0
- package/tokens/spacing.css +12 -0
- package/tokens/typography.css +9 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { injectEfCss } from "../forms/Button.js";
|
|
4
|
+
import { Portal } from "./Portal.js";
|
|
5
|
+
import { Icon } from "../icons/Icon.js";
|
|
6
|
+
const CSS = `
|
|
7
|
+
.ef-ctx__panel{position:fixed;min-width:190px;background:var(--surface-card);border:1px solid var(--border-strong);border-radius:var(--radius-md);box-shadow:var(--shadow-md);padding:4px;z-index:var(--z-dropdown);animation:ef-ctx-in var(--dur-fast) var(--ease-out)}
|
|
8
|
+
@keyframes ef-ctx-in{from{opacity:0;transform:scale(.98)}}
|
|
9
|
+
.ef-ctx__item{display:flex;align-items:center;gap:9px;width:100%;height:32px;padding:0 10px;border:none;border-radius:var(--radius-sm);background:none;cursor:pointer;text-align:left;font-family:var(--font-sans);font-size:var(--text-sm);color:var(--text-primary);transition:background var(--dur-fast) var(--ease-out)}
|
|
10
|
+
.ef-ctx__item:hover:not(:disabled){background:var(--surface-sunken)}
|
|
11
|
+
.ef-ctx__item:disabled{opacity:.4;cursor:not-allowed}
|
|
12
|
+
.ef-ctx__item--danger{color:var(--danger-600)}
|
|
13
|
+
.ef-ctx__item__icon{color:var(--text-muted);display:inline-flex}
|
|
14
|
+
.ef-ctx__item--danger .ef-ctx__item__icon{color:var(--danger-600)}
|
|
15
|
+
.ef-ctx__sep{height:1px;background:var(--border-default);margin:4px 6px}
|
|
16
|
+
.ef-ctx__kbd{margin-left:auto;font-family:var(--font-mono);font-size:11px;color:var(--text-muted)}
|
|
17
|
+
`;
|
|
18
|
+
export function ContextMenu({
|
|
19
|
+
items,
|
|
20
|
+
onSelect,
|
|
21
|
+
children,
|
|
22
|
+
style,
|
|
23
|
+
className,
|
|
24
|
+
...rest
|
|
25
|
+
}) {
|
|
26
|
+
injectEfCss('ef-css-ctx', CSS);
|
|
27
|
+
const [pos, setPos] = React.useState(null);
|
|
28
|
+
const panelRef = React.useRef(null);
|
|
29
|
+
const focusItem = which => {
|
|
30
|
+
const panel = panelRef.current;
|
|
31
|
+
const nodes = panel ? Array.from(panel.querySelectorAll('[role="menuitem"]:not(:disabled)')) : [];
|
|
32
|
+
if (!nodes.length) return;
|
|
33
|
+
const i = nodes.indexOf(document.activeElement);
|
|
34
|
+
const next = which === 'first' ? 0 : which === 'last' ? nodes.length - 1 : (i + which + nodes.length) % nodes.length;
|
|
35
|
+
nodes[next].focus();
|
|
36
|
+
};
|
|
37
|
+
// A fixed panel still escapes overflow, but nothing kept it inside the viewport:
|
|
38
|
+
// right-clicking near the bottom or right edge pushed items off-screen.
|
|
39
|
+
React.useLayoutEffect(() => {
|
|
40
|
+
const panel = panelRef.current;
|
|
41
|
+
if (!pos || !panel) return;
|
|
42
|
+
const r = panel.getBoundingClientRect();
|
|
43
|
+
const vw = document.documentElement.clientWidth,
|
|
44
|
+
vh = document.documentElement.clientHeight,
|
|
45
|
+
edge = 8;
|
|
46
|
+
const x = Math.max(edge, Math.min(pos.x, vw - r.width - edge));
|
|
47
|
+
const y = Math.max(edge, Math.min(pos.y, vh - r.height - edge));
|
|
48
|
+
if (x !== pos.x || y !== pos.y) setPos({
|
|
49
|
+
x,
|
|
50
|
+
y
|
|
51
|
+
});
|
|
52
|
+
}, [pos]);
|
|
53
|
+
const onPanelKey = e => {
|
|
54
|
+
if (e.key === 'ArrowDown') {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
focusItem(1);
|
|
57
|
+
} else if (e.key === 'ArrowUp') {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
focusItem(-1);
|
|
60
|
+
} else if (e.key === 'Home') {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
focusItem('first');
|
|
63
|
+
} else if (e.key === 'End') {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
focusItem('last');
|
|
66
|
+
} else if (e.key.length === 1 && /\S/.test(e.key) && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
67
|
+
const nodes = panelRef.current ? Array.from(panelRef.current.querySelectorAll('[role="menuitem"]:not(:disabled)')) : [];
|
|
68
|
+
const cur = nodes.indexOf(document.activeElement),
|
|
69
|
+
ch = e.key.toLowerCase();
|
|
70
|
+
for (let k = 1; k <= nodes.length; k++) {
|
|
71
|
+
const n = nodes[(cur + k) % nodes.length];
|
|
72
|
+
if ((n.textContent || '').trim().toLowerCase().startsWith(ch)) {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
n.focus();
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (!pos) return;
|
|
82
|
+
const first = panelRef.current && panelRef.current.querySelector('[role="menuitem"]:not(:disabled)');
|
|
83
|
+
if (first) first.focus();
|
|
84
|
+
const close = () => setPos(null);
|
|
85
|
+
const key = e => {
|
|
86
|
+
if (e.key === 'Escape') close();
|
|
87
|
+
};
|
|
88
|
+
document.addEventListener('mousedown', close);
|
|
89
|
+
document.addEventListener('keydown', key);
|
|
90
|
+
window.addEventListener('blur', close);
|
|
91
|
+
return () => {
|
|
92
|
+
document.removeEventListener('mousedown', close);
|
|
93
|
+
document.removeEventListener('keydown', key);
|
|
94
|
+
window.removeEventListener('blur', close);
|
|
95
|
+
};
|
|
96
|
+
}, [pos]);
|
|
97
|
+
const openAt = e => {
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
setPos({
|
|
100
|
+
x: e.clientX,
|
|
101
|
+
y: e.clientY
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
|
|
105
|
+
className: className,
|
|
106
|
+
style: style,
|
|
107
|
+
onContextMenu: openAt
|
|
108
|
+
}), children, pos ? /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
role: "menu",
|
|
110
|
+
ref: panelRef,
|
|
111
|
+
onKeyDown: onPanelKey,
|
|
112
|
+
className: "ef-ctx__panel",
|
|
113
|
+
style: {
|
|
114
|
+
left: pos.x,
|
|
115
|
+
top: pos.y
|
|
116
|
+
},
|
|
117
|
+
onMouseDown: e => e.stopPropagation()
|
|
118
|
+
}, items.map((it, i) => it === 'separator' ? /*#__PURE__*/React.createElement("div", {
|
|
119
|
+
key: 's' + i,
|
|
120
|
+
className: "ef-ctx__sep"
|
|
121
|
+
}) : /*#__PURE__*/React.createElement("button", {
|
|
122
|
+
key: it.id,
|
|
123
|
+
type: "button",
|
|
124
|
+
role: "menuitem",
|
|
125
|
+
disabled: it.disabled,
|
|
126
|
+
className: `ef-ctx__item${it.danger ? ' ef-ctx__item--danger' : ''}`,
|
|
127
|
+
onClick: () => {
|
|
128
|
+
setPos(null);
|
|
129
|
+
if (onSelect) onSelect(it.id);
|
|
130
|
+
if (it.onClick) it.onClick();
|
|
131
|
+
}
|
|
132
|
+
}, it.icon ? /*#__PURE__*/React.createElement("span", {
|
|
133
|
+
className: "ef-ctx__item__icon"
|
|
134
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
135
|
+
name: it.icon,
|
|
136
|
+
size: 15
|
|
137
|
+
})) : null, it.label, it.kbd ? /*#__PURE__*/React.createElement("span", {
|
|
138
|
+
className: "ef-ctx__kbd"
|
|
139
|
+
}, it.kbd) : null)))) : null);
|
|
140
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface DrawerProps {
|
|
2
|
+
open: boolean;
|
|
3
|
+
/** Called on ✕, ESC, or overlay click */
|
|
4
|
+
onClose?: () => void;
|
|
5
|
+
title: React.ReactNode;
|
|
6
|
+
/** Right-aligned action row on sunken strip */
|
|
7
|
+
footer?: React.ReactNode;
|
|
8
|
+
/** Px @default 400 */
|
|
9
|
+
width?: number;
|
|
10
|
+
/** @default 'right' */
|
|
11
|
+
side?: 'left' | 'right';
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare const Drawer: React.ForwardRefExoticComponent<DrawerProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { IconButton } from "../forms/IconButton.js";
|
|
4
|
+
import { injectEfCss, mergeRefs } from "../forms/Button.js";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.ef-drawer__overlay{position:fixed;inset:0;background:var(--overlay-scrim);z-index:var(--z-overlay);animation:ef-fade-in var(--dur-med) var(--ease-out)}
|
|
7
|
+
@keyframes ef-fade-in{from{opacity:0}}
|
|
8
|
+
.ef-drawer{position:fixed;top:0;bottom:0;background:var(--surface-card);z-index:var(--z-modal);display:flex;flex-direction:column;box-shadow:var(--shadow-pop)}
|
|
9
|
+
.ef-drawer:focus{outline:none}
|
|
10
|
+
.ef-drawer--right{right:0;border-left:1px solid var(--border-default);animation:ef-drawer-r var(--dur-slow) var(--ease-out)}
|
|
11
|
+
.ef-drawer--left{left:0;border-right:1px solid var(--border-default);animation:ef-drawer-l var(--dur-slow) var(--ease-out)}
|
|
12
|
+
@keyframes ef-drawer-r{from{transform:translateX(24px);opacity:0}}
|
|
13
|
+
@keyframes ef-drawer-l{from{transform:translateX(-24px);opacity:0}}
|
|
14
|
+
.ef-drawer__head{display:flex;align-items:center;gap:12px;padding:16px 20px;border-bottom:1px solid var(--border-default)}
|
|
15
|
+
.ef-drawer__title{font-family:var(--font-display);font-size:var(--text-lg);font-weight:var(--weight-bold);letter-spacing:var(--tracking-tight);flex:1}
|
|
16
|
+
.ef-drawer__body{flex:1;overflow-y:auto;padding:20px}
|
|
17
|
+
.ef-drawer__foot{display:flex;justify-content:flex-end;gap:8px;padding:14px 20px;border-top:1px solid var(--border-default);background:var(--surface-subtle)}
|
|
18
|
+
`;
|
|
19
|
+
const FOCUSABLE = 'button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])';
|
|
20
|
+
export const Drawer = /*#__PURE__*/React.forwardRef(function Drawer({
|
|
21
|
+
open,
|
|
22
|
+
onClose,
|
|
23
|
+
title,
|
|
24
|
+
footer,
|
|
25
|
+
width = 400,
|
|
26
|
+
side = 'right',
|
|
27
|
+
children,
|
|
28
|
+
...rest
|
|
29
|
+
}, ref) {
|
|
30
|
+
injectEfCss('ef-css-drawer', CSS);
|
|
31
|
+
const panelRef = React.useRef(null);
|
|
32
|
+
const prevFocus = React.useRef(null);
|
|
33
|
+
const titleId = React.useId();
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (!open) return;
|
|
36
|
+
prevFocus.current = document.activeElement;
|
|
37
|
+
const panel = panelRef.current;
|
|
38
|
+
const first = panel && panel.querySelector(FOCUSABLE);
|
|
39
|
+
(first || panel).focus();
|
|
40
|
+
return () => {
|
|
41
|
+
if (prevFocus.current && prevFocus.current.focus) prevFocus.current.focus();
|
|
42
|
+
};
|
|
43
|
+
}, [open]);
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (!open) return;
|
|
46
|
+
const key = e => {
|
|
47
|
+
if (e.key === 'Escape') {
|
|
48
|
+
if (onClose) onClose();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (e.key !== 'Tab') return;
|
|
52
|
+
const panel = panelRef.current;
|
|
53
|
+
const f = panel ? Array.from(panel.querySelectorAll(FOCUSABLE)).filter(el => !el.disabled) : [];
|
|
54
|
+
if (!f.length) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const i = f.indexOf(document.activeElement);
|
|
59
|
+
if (e.shiftKey && i <= 0) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
f[f.length - 1].focus();
|
|
62
|
+
} else if (!e.shiftKey && (i === -1 || i === f.length - 1)) {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
f[0].focus();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
document.addEventListener('keydown', key);
|
|
68
|
+
return () => document.removeEventListener('keydown', key);
|
|
69
|
+
}, [open, onClose]);
|
|
70
|
+
if (!open) return null;
|
|
71
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
className: "ef-drawer__overlay",
|
|
73
|
+
onMouseDown: onClose
|
|
74
|
+
}), /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
75
|
+
className: `ef-drawer ef-drawer--${side}`,
|
|
76
|
+
role: "dialog",
|
|
77
|
+
"aria-modal": "true",
|
|
78
|
+
ref: mergeRefs(ref, panelRef),
|
|
79
|
+
tabIndex: -1,
|
|
80
|
+
"aria-labelledby": title ? titleId : undefined,
|
|
81
|
+
style: {
|
|
82
|
+
width
|
|
83
|
+
}
|
|
84
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
85
|
+
className: "ef-drawer__head"
|
|
86
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
87
|
+
className: "ef-drawer__title",
|
|
88
|
+
id: titleId
|
|
89
|
+
}, title), onClose ? /*#__PURE__*/React.createElement(IconButton, {
|
|
90
|
+
icon: "x",
|
|
91
|
+
label: "Close",
|
|
92
|
+
size: "sm",
|
|
93
|
+
onClick: onClose
|
|
94
|
+
}) : null), /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: "ef-drawer__body"
|
|
96
|
+
}, children), footer ? /*#__PURE__*/React.createElement("div", {
|
|
97
|
+
className: "ef-drawer__foot"
|
|
98
|
+
}, footer) : null));
|
|
99
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface HoverCardProps {
|
|
2
|
+
/** Hover / focus target */
|
|
3
|
+
trigger: React.ReactNode;
|
|
4
|
+
/** Panel contents */
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
/** @default 'bottom' */
|
|
7
|
+
side?: 'top' | 'bottom';
|
|
8
|
+
/** Ms before opening @default 350 */
|
|
9
|
+
openDelay?: number;
|
|
10
|
+
/** Ms before closing @default 150 */
|
|
11
|
+
closeDelay?: number;
|
|
12
|
+
/** Panel width px @default 300 */
|
|
13
|
+
width?: number;
|
|
14
|
+
style?: React.CSSProperties;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function HoverCard(props: HoverCardProps): React.JSX.Element;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { injectEfCss } from "../forms/Button.js";
|
|
4
|
+
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.ef-hovercard{position:relative;display:inline-flex}
|
|
7
|
+
.ef-hovercard__trigger{display:inline-flex;border-radius:var(--radius-sm)}
|
|
8
|
+
.ef-hovercard__trigger:focus-visible{outline:none;box-shadow:var(--focus-ring)}
|
|
9
|
+
.ef-hovercard__panel{position:absolute;left:0;background:var(--surface-card);border:1px solid var(--border-strong);border-radius:var(--radius-md);box-shadow:var(--shadow-md);padding:14px;z-index:var(--z-popover);animation:ef-hovercard-in var(--dur-med) var(--ease-out)}
|
|
10
|
+
.ef-hovercard__panel--bottom{top:calc(100% + 8px)}
|
|
11
|
+
.ef-hovercard__panel--top{bottom:calc(100% + 8px)}
|
|
12
|
+
@keyframes ef-hovercard-in{from{opacity:0;transform:translateY(2px)}}
|
|
13
|
+
`;
|
|
14
|
+
export function HoverCard({
|
|
15
|
+
trigger,
|
|
16
|
+
side = 'bottom',
|
|
17
|
+
openDelay = 350,
|
|
18
|
+
closeDelay = 150,
|
|
19
|
+
width = 300,
|
|
20
|
+
children,
|
|
21
|
+
style,
|
|
22
|
+
className,
|
|
23
|
+
...rest
|
|
24
|
+
}) {
|
|
25
|
+
injectEfCss('ef-css-hovercard', CSS);
|
|
26
|
+
const [open, setOpen] = React.useState(false);
|
|
27
|
+
const t = React.useRef(null);
|
|
28
|
+
const ref = React.useRef(null);
|
|
29
|
+
const panelRef = React.useRef(null);
|
|
30
|
+
const {
|
|
31
|
+
style: anchored
|
|
32
|
+
} = useAnchoredStyle(ref, panelRef, {
|
|
33
|
+
open,
|
|
34
|
+
placement: side === 'top' ? 'top' : 'bottom',
|
|
35
|
+
align: 'start',
|
|
36
|
+
offset: 8
|
|
37
|
+
});
|
|
38
|
+
const enter = () => {
|
|
39
|
+
clearTimeout(t.current);
|
|
40
|
+
t.current = setTimeout(() => setOpen(true), openDelay);
|
|
41
|
+
};
|
|
42
|
+
const leave = () => {
|
|
43
|
+
clearTimeout(t.current);
|
|
44
|
+
t.current = setTimeout(() => setOpen(false), closeDelay);
|
|
45
|
+
};
|
|
46
|
+
React.useEffect(() => () => clearTimeout(t.current), []);
|
|
47
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
|
|
48
|
+
ref: ref,
|
|
49
|
+
className: `ef-hovercard${className ? ' ' + className : ''}`,
|
|
50
|
+
style: style,
|
|
51
|
+
onMouseEnter: enter,
|
|
52
|
+
onMouseLeave: leave,
|
|
53
|
+
onKeyDown: e => {
|
|
54
|
+
if (e.key === 'Escape') {
|
|
55
|
+
clearTimeout(t.current);
|
|
56
|
+
setOpen(false);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
60
|
+
className: "ef-hovercard__trigger",
|
|
61
|
+
tabIndex: 0,
|
|
62
|
+
onFocus: () => setOpen(true),
|
|
63
|
+
onBlur: () => setOpen(false)
|
|
64
|
+
}, trigger), open ? /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
ref: panelRef,
|
|
66
|
+
onMouseEnter: enter,
|
|
67
|
+
onMouseLeave: leave,
|
|
68
|
+
className: `ef-hovercard__panel ef-hovercard__panel--${side}`,
|
|
69
|
+
style: {
|
|
70
|
+
...anchored,
|
|
71
|
+
width
|
|
72
|
+
}
|
|
73
|
+
}, children)) : null);
|
|
74
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface MenuItem {
|
|
2
|
+
id: string;
|
|
3
|
+
label: React.ReactNode;
|
|
4
|
+
/** Lucide icon name */
|
|
5
|
+
icon?: string;
|
|
6
|
+
/** Red destructive styling */
|
|
7
|
+
danger?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
/** Shortcut hint, e.g. "⌘D" */
|
|
10
|
+
kbd?: string;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface MenuProps {
|
|
14
|
+
/** The element that toggles the menu (Button, IconButton, …) */
|
|
15
|
+
trigger: React.ReactNode;
|
|
16
|
+
/** Items; the string 'separator' inserts a rule */
|
|
17
|
+
items: Array<MenuItem | 'separator'>;
|
|
18
|
+
onSelect?: (id: string) => void;
|
|
19
|
+
/** Panel edge alignment @default 'left' */
|
|
20
|
+
align?: 'left' | 'right';
|
|
21
|
+
style?: React.CSSProperties;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare const Menu: React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<HTMLSpanElement>>;
|
package/overlay/Menu.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Icon } from "../icons/Icon.js";
|
|
4
|
+
import { injectEfCss, mergeRefs } from "../forms/Button.js";
|
|
5
|
+
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
6
|
+
const CSS = `
|
|
7
|
+
.ef-menu{position:relative;display:inline-flex}
|
|
8
|
+
.ef-menu__panel{position:absolute;top:calc(100% + 6px);min-width:190px;background:var(--surface-card);border:1px solid var(--border-strong);border-radius:var(--radius-md);box-shadow:var(--shadow-md);padding:4px;z-index:var(--z-dropdown);animation:ef-menu-in var(--dur-fast) var(--ease-out)}
|
|
9
|
+
.ef-menu__panel--left{left:0}
|
|
10
|
+
.ef-menu__panel--right{right:0}
|
|
11
|
+
@keyframes ef-menu-in{from{opacity:0;transform:translateY(-3px)}to{opacity:1;transform:translateY(0)}}
|
|
12
|
+
.ef-menu__item{display:flex;align-items:center;gap:9px;width:100%;height:32px;padding:0 10px;border:none;border-radius:var(--radius-sm);background:none;cursor:pointer;text-align:left;font-family:var(--font-sans);font-size:var(--text-sm);color:var(--text-primary);transition:background var(--dur-fast) var(--ease-out)}
|
|
13
|
+
.ef-menu__item:hover:not(:disabled){background:var(--surface-sunken)}
|
|
14
|
+
.ef-menu__item:focus-visible{outline:none;box-shadow:var(--focus-ring)}
|
|
15
|
+
.ef-menu__item:disabled{opacity:.4;cursor:not-allowed}
|
|
16
|
+
.ef-menu__item--danger{color:var(--danger-600)}
|
|
17
|
+
.ef-menu__item__icon{color:var(--text-muted);display:inline-flex}
|
|
18
|
+
.ef-menu__item--danger .ef-menu__item__icon{color:var(--danger-600)}
|
|
19
|
+
.ef-menu__sep{height:1px;background:var(--border-default);margin:4px 6px}
|
|
20
|
+
.ef-menu__kbd{margin-left:auto;font-family:var(--font-mono);font-size:11px;color:var(--text-muted)}
|
|
21
|
+
`;
|
|
22
|
+
export const Menu = /*#__PURE__*/React.forwardRef(function Menu({
|
|
23
|
+
trigger,
|
|
24
|
+
items,
|
|
25
|
+
onSelect,
|
|
26
|
+
align = 'left',
|
|
27
|
+
style,
|
|
28
|
+
className,
|
|
29
|
+
...rest
|
|
30
|
+
}, fRef) {
|
|
31
|
+
injectEfCss('ef-css-menu', CSS);
|
|
32
|
+
const [open, setOpen] = React.useState(false);
|
|
33
|
+
const ref = React.useRef(null);
|
|
34
|
+
const panelRef = React.useRef(null);
|
|
35
|
+
const {
|
|
36
|
+
style: anchored
|
|
37
|
+
} = useAnchoredStyle(ref, panelRef, {
|
|
38
|
+
open,
|
|
39
|
+
placement: 'bottom',
|
|
40
|
+
align: align === 'right' ? 'end' : 'start'
|
|
41
|
+
});
|
|
42
|
+
const focusItem = which => {
|
|
43
|
+
const panel = panelRef.current;
|
|
44
|
+
const nodes = panel ? Array.from(panel.querySelectorAll('[role="menuitem"]:not(:disabled)')) : [];
|
|
45
|
+
if (!nodes.length) return;
|
|
46
|
+
const i = nodes.indexOf(document.activeElement);
|
|
47
|
+
const next = which === 'first' ? 0 : which === 'last' ? nodes.length - 1 : (i + which + nodes.length) % nodes.length;
|
|
48
|
+
nodes[next].focus();
|
|
49
|
+
};
|
|
50
|
+
const restoreFocus = () => {
|
|
51
|
+
const t = ref.current && ref.current.querySelector('button,[href],[tabindex]');
|
|
52
|
+
if (t) t.focus();
|
|
53
|
+
};
|
|
54
|
+
const close = restore => {
|
|
55
|
+
setOpen(false);
|
|
56
|
+
if (restore) restoreFocus();
|
|
57
|
+
};
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
if (!open) return;
|
|
60
|
+
focusItem('first');
|
|
61
|
+
// the panel is portaled, so "outside" means outside the trigger AND the panel
|
|
62
|
+
const away = e => {
|
|
63
|
+
const inTrigger = ref.current && ref.current.contains(e.target);
|
|
64
|
+
const inPanel = panelRef.current && panelRef.current.contains(e.target);
|
|
65
|
+
if (!inTrigger && !inPanel) setOpen(false);
|
|
66
|
+
};
|
|
67
|
+
document.addEventListener('mousedown', away);
|
|
68
|
+
return () => document.removeEventListener('mousedown', away);
|
|
69
|
+
}, [open]);
|
|
70
|
+
const onTriggerKey = e => {
|
|
71
|
+
if (e.key === 'Enter' || e.key === ' ' || e.key === 'ArrowDown') {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
setOpen(true);
|
|
74
|
+
} else if (e.key === 'Escape' && open) close(true);
|
|
75
|
+
};
|
|
76
|
+
const triggerProps = {
|
|
77
|
+
onClick: e => {
|
|
78
|
+
if (/*#__PURE__*/React.isValidElement(trigger) && trigger.props.onClick) trigger.props.onClick(e);
|
|
79
|
+
setOpen(o => !o);
|
|
80
|
+
},
|
|
81
|
+
onKeyDown: onTriggerKey,
|
|
82
|
+
'aria-haspopup': 'menu',
|
|
83
|
+
'aria-expanded': open
|
|
84
|
+
};
|
|
85
|
+
const onPanelKey = e => {
|
|
86
|
+
if (e.key === 'Escape') {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
close(true);
|
|
89
|
+
} else if (e.key === 'ArrowDown') {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
focusItem(1);
|
|
92
|
+
} else if (e.key === 'ArrowUp') {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
focusItem(-1);
|
|
95
|
+
} else if (e.key === 'Home') {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
focusItem('first');
|
|
98
|
+
} else if (e.key === 'End') {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
focusItem('last');
|
|
101
|
+
} else if (e.key === 'Tab') close(false);else if (e.key.length === 1 && /\S/.test(e.key) && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
102
|
+
const panel = panelRef.current;
|
|
103
|
+
const nodes = panel ? Array.from(panel.querySelectorAll('[role="menuitem"]:not(:disabled)')) : [];
|
|
104
|
+
const cur = nodes.indexOf(document.activeElement);
|
|
105
|
+
const ch = e.key.toLowerCase();
|
|
106
|
+
for (let k = 1; k <= nodes.length; k++) {
|
|
107
|
+
const n = nodes[(cur + k) % nodes.length];
|
|
108
|
+
if ((n.textContent || '').trim().toLowerCase().startsWith(ch)) {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
n.focus();
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
|
|
117
|
+
ref: mergeRefs(fRef, ref),
|
|
118
|
+
className: `ef-menu${className ? ' ' + className : ''}`,
|
|
119
|
+
style: style
|
|
120
|
+
}), /*#__PURE__*/React.isValidElement(trigger) ? /*#__PURE__*/React.cloneElement(trigger, triggerProps) : /*#__PURE__*/React.createElement("span", _extends({
|
|
121
|
+
role: "button",
|
|
122
|
+
tabIndex: 0,
|
|
123
|
+
style: {
|
|
124
|
+
display: 'inline-flex'
|
|
125
|
+
}
|
|
126
|
+
}, triggerProps), trigger), open && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
|
|
127
|
+
role: "menu",
|
|
128
|
+
ref: panelRef,
|
|
129
|
+
onKeyDown: onPanelKey,
|
|
130
|
+
style: anchored,
|
|
131
|
+
className: `ef-menu__panel ef-menu__panel--${align}`
|
|
132
|
+
}, items.map((it, i) => it === 'separator' ? /*#__PURE__*/React.createElement("div", {
|
|
133
|
+
key: 's' + i,
|
|
134
|
+
className: "ef-menu__sep"
|
|
135
|
+
}) : /*#__PURE__*/React.createElement("button", {
|
|
136
|
+
key: it.id,
|
|
137
|
+
role: "menuitem",
|
|
138
|
+
disabled: it.disabled,
|
|
139
|
+
className: `ef-menu__item${it.danger ? ' ef-menu__item--danger' : ''}`,
|
|
140
|
+
onClick: () => {
|
|
141
|
+
close(true);
|
|
142
|
+
if (onSelect) onSelect(it.id);
|
|
143
|
+
if (it.onClick) it.onClick();
|
|
144
|
+
}
|
|
145
|
+
}, it.icon ? /*#__PURE__*/React.createElement("span", {
|
|
146
|
+
className: "ef-menu__item__icon"
|
|
147
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
148
|
+
name: it.icon,
|
|
149
|
+
size: 15
|
|
150
|
+
})) : null, it.label, it.kbd ? /*#__PURE__*/React.createElement("span", {
|
|
151
|
+
className: "ef-menu__kbd"
|
|
152
|
+
}, it.kbd) : null)))));
|
|
153
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface PopoverProps {
|
|
2
|
+
/** The element that toggles the popover */
|
|
3
|
+
trigger: React.ReactNode;
|
|
4
|
+
/** Panel content */
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
/** @default 'left' */
|
|
7
|
+
align?: 'left' | 'right';
|
|
8
|
+
/** Panel width @default 280 */
|
|
9
|
+
width?: number;
|
|
10
|
+
/** Controlled open state */
|
|
11
|
+
open?: boolean;
|
|
12
|
+
onOpenChange?: (open: boolean) => void;
|
|
13
|
+
style?: React.CSSProperties;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const Popover: React.ForwardRefExoticComponent<PopoverProps & React.RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { injectEfCss, mergeRefs } from "../forms/Button.js";
|
|
4
|
+
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.ef-popover{position:relative;display:inline-flex}
|
|
7
|
+
.ef-popover__panel{position:absolute;top:calc(100% + 8px);width:280px;background:var(--surface-card);border:1px solid var(--border-strong);border-radius:var(--radius-md);box-shadow:var(--shadow-md);padding:14px;z-index:var(--z-dropdown);animation:ef-pop-in var(--dur-fast) var(--ease-out)}
|
|
8
|
+
.ef-popover__panel--left{left:0}
|
|
9
|
+
.ef-popover__panel--right{right:0}
|
|
10
|
+
@keyframes ef-pop-in{from{opacity:0;transform:translateY(-3px)}}
|
|
11
|
+
`;
|
|
12
|
+
export const Popover = /*#__PURE__*/React.forwardRef(function Popover({
|
|
13
|
+
trigger,
|
|
14
|
+
children,
|
|
15
|
+
align = 'left',
|
|
16
|
+
width = 280,
|
|
17
|
+
open: controlled,
|
|
18
|
+
onOpenChange,
|
|
19
|
+
style,
|
|
20
|
+
className,
|
|
21
|
+
...rest
|
|
22
|
+
}, fRef) {
|
|
23
|
+
injectEfCss('ef-css-popover', CSS);
|
|
24
|
+
const [inner, setInner] = React.useState(false);
|
|
25
|
+
const open = controlled != null ? controlled : inner;
|
|
26
|
+
const setOpen = v => {
|
|
27
|
+
if (controlled == null) setInner(v);
|
|
28
|
+
if (onOpenChange) onOpenChange(v);
|
|
29
|
+
};
|
|
30
|
+
const ref = React.useRef(null);
|
|
31
|
+
const panelRef = React.useRef(null);
|
|
32
|
+
const {
|
|
33
|
+
style: anchored
|
|
34
|
+
} = useAnchoredStyle(ref, panelRef, {
|
|
35
|
+
open,
|
|
36
|
+
placement: 'bottom',
|
|
37
|
+
align: align === 'right' ? 'end' : 'start',
|
|
38
|
+
offset: 8
|
|
39
|
+
});
|
|
40
|
+
const restoreFocus = () => {
|
|
41
|
+
const t = ref.current && ref.current.querySelector('button,[href],[tabindex]');
|
|
42
|
+
if (t) t.focus();
|
|
43
|
+
};
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (!open) return;
|
|
46
|
+
const away = e => {
|
|
47
|
+
const inTrigger = ref.current && ref.current.contains(e.target);
|
|
48
|
+
const inPanel = panelRef.current && panelRef.current.contains(e.target);
|
|
49
|
+
if (!inTrigger && !inPanel) setOpen(false);
|
|
50
|
+
};
|
|
51
|
+
const key = e => {
|
|
52
|
+
if (e.key === 'Escape') {
|
|
53
|
+
setOpen(false);
|
|
54
|
+
restoreFocus();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
document.addEventListener('mousedown', away);
|
|
58
|
+
document.addEventListener('keydown', key);
|
|
59
|
+
return () => {
|
|
60
|
+
document.removeEventListener('mousedown', away);
|
|
61
|
+
document.removeEventListener('keydown', key);
|
|
62
|
+
};
|
|
63
|
+
}, [open]);
|
|
64
|
+
const triggerProps = {
|
|
65
|
+
onClick: e => {
|
|
66
|
+
if (/*#__PURE__*/React.isValidElement(trigger) && trigger.props.onClick) trigger.props.onClick(e);
|
|
67
|
+
setOpen(!open);
|
|
68
|
+
},
|
|
69
|
+
onKeyDown: e => {
|
|
70
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
setOpen(!open);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
'aria-haspopup': 'dialog',
|
|
76
|
+
'aria-expanded': open
|
|
77
|
+
};
|
|
78
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
|
|
79
|
+
ref: mergeRefs(fRef, ref),
|
|
80
|
+
className: `ef-popover${className ? ' ' + className : ''}`,
|
|
81
|
+
style: style
|
|
82
|
+
}), /*#__PURE__*/React.isValidElement(trigger) ? /*#__PURE__*/React.cloneElement(trigger, triggerProps) : /*#__PURE__*/React.createElement("span", _extends({
|
|
83
|
+
role: "button",
|
|
84
|
+
tabIndex: 0,
|
|
85
|
+
style: {
|
|
86
|
+
display: 'inline-flex'
|
|
87
|
+
}
|
|
88
|
+
}, triggerProps), trigger), open && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
|
|
89
|
+
ref: panelRef,
|
|
90
|
+
className: `ef-popover__panel ef-popover__panel--${align}`,
|
|
91
|
+
style: {
|
|
92
|
+
...anchored,
|
|
93
|
+
width
|
|
94
|
+
}
|
|
95
|
+
}, children)));
|
|
96
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface PortalProps {
|
|
2
|
+
children?: React.ReactNode;
|
|
3
|
+
/** Where to mount. @default document.body */
|
|
4
|
+
container?: HTMLElement;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Render children outside the current DOM subtree so they cannot be clipped by
|
|
8
|
+
* an ancestor's overflow. Used by every floating surface in the system.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Portal(props: PortalProps): React.JSX.Element | null;
|