@robert-stackflow/oneui 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +72 -2
- package/assets/LUCIDE-LICENSE.txt +43 -0
- package/assets/character-metadata.json +1 -0
- package/assets/emoji.json +1 -0
- package/assets/icon-catalog.json +1 -0
- package/assets/symbols.json +1 -0
- package/components/Accessibility.module.css +8 -0
- package/components/Accordion.d.ts +7 -0
- package/components/Accordion.js +41 -0
- package/components/Accordion.module.css +38 -0
- package/components/Alert.d.ts +9 -0
- package/components/Alert.js +42 -0
- package/components/Alert.module.css +56 -0
- package/components/AppShell.d.ts +30 -0
- package/components/AppShell.js +152 -0
- package/components/AppShell.module.css +239 -0
- package/components/AppearanceSettings.d.ts +7 -0
- package/components/AppearanceSettings.js +201 -0
- package/components/AppearanceSettings.module.css +32 -0
- package/components/Avatar.d.ts +14 -0
- package/components/Avatar.js +69 -0
- package/components/Avatar.module.css +70 -0
- package/components/AvatarGroup.d.ts +15 -0
- package/components/AvatarGroup.js +115 -0
- package/components/AvatarGroup.module.css +54 -0
- package/components/Badge.d.ts +5 -0
- package/components/Badge.js +11 -0
- package/components/Badge.module.css +30 -0
- package/components/BlockedTab.d.ts +4 -0
- package/components/BlockedTab.js +10 -0
- package/components/Breadcrumb.d.ts +16 -0
- package/components/Breadcrumb.js +157 -0
- package/components/Breadcrumb.module.css +97 -0
- package/components/Button.d.ts +13 -0
- package/components/Button.js +52 -0
- package/components/Button.module.css +88 -0
- package/components/Calendar.d.ts +10 -0
- package/components/Calendar.js +260 -0
- package/components/Calendar.module.css +106 -0
- package/components/Card.d.ts +8 -0
- package/components/Card.js +29 -0
- package/components/Card.module.css +47 -0
- package/components/Cascader.d.ts +14 -0
- package/components/Cascader.js +296 -0
- package/components/CatalogIcon.d.ts +3 -0
- package/components/CatalogIcon.js +11 -0
- package/components/CharacterPicker.d.ts +15 -0
- package/components/CharacterPicker.js +200 -0
- package/components/Checkbox.d.ts +12 -0
- package/components/Checkbox.js +82 -0
- package/components/Checkbox.module.css +95 -0
- package/components/ColorField.d.ts +6 -0
- package/components/ColorField.js +61 -0
- package/components/ColorField.module.css +15 -0
- package/components/ColorPicker.d.ts +5 -0
- package/components/ColorPicker.js +188 -0
- package/components/ColorPicker.module.css +90 -0
- package/components/Combobox.d.ts +13 -0
- package/components/Combobox.js +338 -0
- package/components/Combobox.module.css +24 -0
- package/components/CommandPalette.d.ts +25 -0
- package/components/CommandPalette.js +269 -0
- package/components/CommandPalette.module.css +49 -0
- package/components/ContextMenu.d.ts +9 -0
- package/components/ContextMenu.js +363 -0
- package/components/ContextMenu.module.css +42 -0
- package/components/ContextMenuPanel.d.ts +22 -0
- package/components/ContextMenuPanel.js +155 -0
- package/components/ContributionCalendar.d.ts +18 -0
- package/components/ContributionCalendar.js +201 -0
- package/components/ContributionCalendar.module.css +114 -0
- package/components/ContributionCell.d.ts +11 -0
- package/components/ContributionCell.js +41 -0
- package/components/Control.module.css +86 -0
- package/components/DataTable.d.ts +49 -0
- package/components/DataTable.js +220 -0
- package/components/DataTable.module.css +112 -0
- package/components/DatePicker.d.ts +15 -0
- package/components/DatePicker.js +186 -0
- package/components/DatePicker.module.css +85 -0
- package/components/DateRangePicker.d.ts +9 -0
- package/components/DateRangePicker.js +168 -0
- package/components/Descriptions.d.ts +21 -0
- package/components/Descriptions.js +162 -0
- package/components/Descriptions.module.css +117 -0
- package/components/Dialog.d.ts +14 -0
- package/components/Dialog.js +125 -0
- package/components/Dialog.module.css +88 -0
- package/components/DialogVariants.d.ts +27 -0
- package/components/DialogVariants.js +161 -0
- package/components/DialogVariants.module.css +29 -0
- package/components/DisclosureChevron.d.ts +3 -0
- package/components/DisclosureChevron.js +17 -0
- package/components/DisclosureChevron.module.css +17 -0
- package/components/Divider.d.ts +5 -0
- package/components/Divider.js +24 -0
- package/components/Divider.module.css +19 -0
- package/components/Drawer.d.ts +18 -0
- package/components/Drawer.js +145 -0
- package/components/Drawer.module.css +109 -0
- package/components/EmojiPicker.d.ts +6 -0
- package/components/EmojiPicker.js +19 -0
- package/components/EmptyState.d.ts +8 -0
- package/components/EmptyState.js +20 -0
- package/components/EmptyState.module.css +30 -0
- package/components/FieldLabel.d.ts +8 -0
- package/components/FieldLabel.js +20 -0
- package/components/FieldMessages.d.ts +5 -0
- package/components/FieldMessages.js +15 -0
- package/components/FileDropOverlay.d.ts +5 -0
- package/components/FileDropOverlay.js +26 -0
- package/components/FileDropOverlay.module.css +55 -0
- package/components/FileDropZone.d.ts +15 -0
- package/components/FileDropZone.js +113 -0
- package/components/FileDropZone.module.css +6 -0
- package/components/FilePicker.d.ts +10 -0
- package/components/FilePicker.js +59 -0
- package/components/FileSelectionFeedback.d.ts +5 -0
- package/components/FileSelectionFeedback.js +23 -0
- package/components/FileSelectionFeedback.module.css +14 -0
- package/components/FileTree.d.ts +13 -0
- package/components/FileTree.js +125 -0
- package/components/FileTree.module.css +66 -0
- package/components/Form.d.ts +7 -0
- package/components/Form.js +26 -0
- package/components/Form.module.css +7 -0
- package/components/FormErrorSummary.d.ts +6 -0
- package/components/FormErrorSummary.js +27 -0
- package/components/FormErrorSummary.module.css +27 -0
- package/components/FormField.d.ts +9 -0
- package/components/FormField.js +59 -0
- package/components/FormField.module.css +85 -0
- package/components/FormGroup.d.ts +9 -0
- package/components/FormGroup.js +32 -0
- package/components/HierarchyPicker.module.css +181 -0
- package/components/IconButton.d.ts +7 -0
- package/components/IconButton.js +30 -0
- package/components/IconButton.module.css +42 -0
- package/components/IconPicker.d.ts +6 -0
- package/components/IconPicker.js +111 -0
- package/components/Indicator.d.ts +18 -0
- package/components/Indicator.js +97 -0
- package/components/Indicator.module.css +83 -0
- package/components/Input.d.ts +8 -0
- package/components/Input.js +37 -0
- package/components/Input.module.css +40 -0
- package/components/LoadingOverlay.d.ts +6 -0
- package/components/LoadingOverlay.js +16 -0
- package/components/LoadingOverlay.module.css +22 -0
- package/components/LoadingState.d.ts +7 -0
- package/components/LoadingState.js +40 -0
- package/components/LoadingState.module.css +17 -0
- package/components/Menu.d.ts +11 -0
- package/components/Menu.js +82 -0
- package/components/MenuItem.d.ts +15 -0
- package/components/MenuItem.js +51 -0
- package/components/MenuItem.module.css +172 -0
- package/components/MenuItemContent.d.ts +8 -0
- package/components/MenuItemContent.js +19 -0
- package/components/MultiSelect.d.ts +13 -0
- package/components/MultiSelect.js +225 -0
- package/components/MultiSelect.module.css +99 -0
- package/components/NumberInput.d.ts +12 -0
- package/components/NumberInput.js +114 -0
- package/components/NumberInput.module.css +33 -0
- package/components/OptionList.module.css +12 -0
- package/components/Page.d.ts +7 -0
- package/components/Page.js +22 -0
- package/components/Page.module.css +44 -0
- package/components/Pagination.d.ts +11 -0
- package/components/Pagination.js +160 -0
- package/components/Pagination.module.css +70 -0
- package/components/PasswordField.d.ts +9 -0
- package/components/PasswordField.js +102 -0
- package/components/PasswordField.module.css +64 -0
- package/components/Picker.module.css +52 -0
- package/components/PinInput.d.ts +13 -0
- package/components/PinInput.js +173 -0
- package/components/PinInput.module.css +72 -0
- package/components/Placeholder.d.ts +31 -0
- package/components/Placeholder.js +36 -0
- package/components/Popconfirm.d.ts +17 -0
- package/components/Popconfirm.js +159 -0
- package/components/Popconfirm.module.css +49 -0
- package/components/Popover.d.ts +16 -0
- package/components/Popover.js +156 -0
- package/components/Popover.module.css +19 -0
- package/components/Progress.d.ts +5 -0
- package/components/Progress.js +31 -0
- package/components/Progress.module.css +33 -0
- package/components/RadioGroup.d.ts +15 -0
- package/components/RadioGroup.js +73 -0
- package/components/RadioGroup.module.css +87 -0
- package/components/RangeSlider.d.ts +22 -0
- package/components/RangeSlider.js +278 -0
- package/components/RangeSlider.module.css +141 -0
- package/components/ResizablePanel.d.ts +21 -0
- package/components/ResizablePanel.js +219 -0
- package/components/ResizablePanel.module.css +101 -0
- package/components/SearchField.d.ts +11 -0
- package/components/SearchField.js +67 -0
- package/components/SearchField.module.css +37 -0
- package/components/Section.d.ts +6 -0
- package/components/Section.js +18 -0
- package/components/Section.module.css +14 -0
- package/components/Segmented.d.ts +11 -0
- package/components/Segmented.js +77 -0
- package/components/Segmented.module.css +82 -0
- package/components/Select.d.ts +11 -0
- package/components/Select.js +172 -0
- package/components/Select.module.css +24 -0
- package/components/SelectOptionContent.d.ts +5 -0
- package/components/SelectOptionContent.js +20 -0
- package/components/SelectOptionContent.module.css +7 -0
- package/components/SelectTrigger.d.ts +5 -0
- package/components/SelectTrigger.js +32 -0
- package/components/SelectTrigger.module.css +24 -0
- package/components/SelectionTag.d.ts +8 -0
- package/components/SelectionTag.js +39 -0
- package/components/SettingRow.d.ts +7 -0
- package/components/SettingRow.js +19 -0
- package/components/SettingRow.module.css +44 -0
- package/components/SettingsLayout.d.ts +11 -0
- package/components/SettingsLayout.js +61 -0
- package/components/SettingsLayout.module.css +68 -0
- package/components/ShortcutInput.d.ts +8 -0
- package/components/ShortcutInput.js +131 -0
- package/components/ShortcutInput.module.css +39 -0
- package/components/Skeleton.d.ts +5 -0
- package/components/Skeleton.js +19 -0
- package/components/Skeleton.module.css +27 -0
- package/components/SkeletonRows.d.ts +4 -0
- package/components/SkeletonRows.js +19 -0
- package/components/SkeletonRows.module.css +19 -0
- package/components/SkinTonePicker.d.ts +4 -0
- package/components/SkinTonePicker.js +43 -0
- package/components/SkinTonePicker.module.css +50 -0
- package/components/Slider.d.ts +10 -0
- package/components/Slider.js +40 -0
- package/components/Slider.module.css +19 -0
- package/components/Spinner.d.ts +6 -0
- package/components/Spinner.js +31 -0
- package/components/Spinner.module.css +57 -0
- package/components/SplitButton.d.ts +17 -0
- package/components/SplitButton.js +102 -0
- package/components/SplitButton.module.css +56 -0
- package/components/Statistic.d.ts +22 -0
- package/components/Statistic.js +102 -0
- package/components/Statistic.module.css +55 -0
- package/components/Steps.d.ts +19 -0
- package/components/Steps.js +102 -0
- package/components/Steps.module.css +176 -0
- package/components/Switch.d.ts +6 -0
- package/components/Switch.js +25 -0
- package/components/Switch.module.css +59 -0
- package/components/SymbolPicker.d.ts +6 -0
- package/components/SymbolPicker.js +18 -0
- package/components/Tab.module.css +145 -0
- package/components/TabList.d.ts +11 -0
- package/components/TabList.js +51 -0
- package/components/Table.d.ts +16 -0
- package/components/Table.js +30 -0
- package/components/Table.module.css +48 -0
- package/components/TableColumnFilter.d.ts +6 -0
- package/components/TableColumnFilter.js +76 -0
- package/components/TableColumnVisibility.d.ts +11 -0
- package/components/TableColumnVisibility.js +76 -0
- package/components/Tabs.d.ts +13 -0
- package/components/Tabs.js +49 -0
- package/components/Tabs.module.css +3 -0
- package/components/TagInput.d.ts +11 -0
- package/components/TagInput.js +142 -0
- package/components/TagInput.module.css +64 -0
- package/components/Textarea.d.ts +6 -0
- package/components/Textarea.js +24 -0
- package/components/Textarea.module.css +9 -0
- package/components/ThemePicker.d.ts +6 -0
- package/components/ThemePicker.js +78 -0
- package/components/ThemePicker.module.css +178 -0
- package/components/ThemeProvider.d.ts +11 -0
- package/components/ThemeProvider.js +94 -0
- package/components/ThemeStylePicker.d.ts +5 -0
- package/components/ThemeStylePicker.js +22 -0
- package/components/TimeColumns.d.ts +6 -0
- package/components/TimeColumns.js +55 -0
- package/components/TimeColumns.module.css +47 -0
- package/components/Timeline.d.ts +26 -0
- package/components/Timeline.js +131 -0
- package/components/Timeline.module.css +202 -0
- package/components/Toast.d.ts +6 -0
- package/components/Toast.js +181 -0
- package/components/Toast.module.css +175 -0
- package/components/ToastProvider.d.ts +35 -0
- package/components/ToastProvider.js +47 -0
- package/components/Tooltip.d.ts +10 -0
- package/components/Tooltip.js +169 -0
- package/components/Tooltip.module.css +53 -0
- package/components/TreeGuides.d.ts +9 -0
- package/components/TreeGuides.js +39 -0
- package/components/TreeGuides.module.css +45 -0
- package/components/TreeSelect.d.ts +26 -0
- package/components/TreeSelect.js +337 -0
- package/components/TreeTable.d.ts +15 -0
- package/components/TreeTable.js +151 -0
- package/components/TreeTable.module.css +53 -0
- package/components/UIProvider.d.ts +10 -0
- package/components/UIProvider.js +20 -0
- package/components/UnderlinedTab.d.ts +2 -0
- package/components/UnderlinedTab.js +8 -0
- package/components/Upload.d.ts +22 -0
- package/components/Upload.js +165 -0
- package/components/Upload.module.css +36 -0
- package/components/UploadList.d.ts +9 -0
- package/components/UploadList.js +14 -0
- package/components/UploadList.module.css +130 -0
- package/components/UploadListItem.d.ts +13 -0
- package/components/UploadListItem.js +122 -0
- package/components/VirtualPickerList.d.ts +25 -0
- package/components/VirtualPickerList.js +269 -0
- package/components/VirtualPickerList.module.css +93 -0
- package/components/appearance.d.ts +20 -0
- package/components/appearance.js +69 -0
- package/components/characterCatalog.d.ts +9 -0
- package/components/characterCatalog.js +55 -0
- package/components/color.d.ts +7 -0
- package/components/color.js +18 -0
- package/components/contribution.d.ts +57 -0
- package/components/contribution.js +86 -0
- package/components/dateConstraints.d.ts +13 -0
- package/components/dateConstraints.js +44 -0
- package/components/field.d.ts +58 -0
- package/components/field.js +57 -0
- package/components/fileSelection.d.ts +21 -0
- package/components/fileSelection.js +43 -0
- package/components/hierarchy.d.ts +23 -0
- package/components/hierarchy.js +33 -0
- package/components/iconCatalog.d.ts +13 -0
- package/components/iconCatalog.js +80 -0
- package/components/index.d.ts +152 -0
- package/components/index.js +225 -0
- package/components/menuFocus.d.ts +7 -0
- package/components/menuFocus.js +21 -0
- package/components/menuPointer.d.ts +6 -0
- package/components/menuPointer.js +13 -0
- package/components/menuTypes.d.ts +24 -0
- package/components/menuTypes.js +0 -0
- package/components/motion.d.ts +9 -0
- package/components/motion.js +82 -0
- package/components/rangeMath.d.ts +12 -0
- package/components/rangeMath.js +30 -0
- package/components/surfacePortal.d.ts +13 -0
- package/components/surfacePortal.js +22 -0
- package/components/tooltipState.d.ts +5 -0
- package/components/tooltipState.js +48 -0
- package/components/types.d.ts +9 -0
- package/components/types.js +0 -0
- package/components/uploadTypes.d.ts +21 -0
- package/components/uploadTypes.js +0 -0
- package/components/useFormState.d.ts +51 -0
- package/components/useFormState.js +218 -0
- package/components/useHierarchy.d.ts +8 -0
- package/components/useHierarchy.js +80 -0
- package/components/useMenuLayers.d.ts +17 -0
- package/components/useMenuLayers.js +23 -0
- package/components/useModalScrollLock.d.ts +1 -0
- package/components/useModalScrollLock.js +18 -0
- package/components/usePopover.d.ts +8 -0
- package/components/usePopover.js +22 -0
- package/components/useTabIndicator.d.ts +12 -0
- package/components/useTabIndicator.js +63 -0
- package/components/useUploadQueue.d.ts +20 -0
- package/components/useUploadQueue.js +175 -0
- package/package.json +810 -3
- package/styles/base.css +206 -0
- package/styles/blue.css +268 -0
- package/styles/desktop.css +2 -0
- package/styles/minimal.css +337 -0
- package/styles/themes.css +2 -0
- package/styles/web.css +2 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
cloneElement,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useId,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState
|
|
10
|
+
} from "react";
|
|
11
|
+
import { useUIConfig } from "./UIProvider.js";
|
|
12
|
+
import { createPortal } from "react-dom";
|
|
13
|
+
import { surfaceMotion, cancelMotion } from "./motion.js";
|
|
14
|
+
import {
|
|
15
|
+
claimTooltip,
|
|
16
|
+
releaseTooltip,
|
|
17
|
+
retainTooltipEvents,
|
|
18
|
+
keyboardTooltip,
|
|
19
|
+
tooltipDelay
|
|
20
|
+
} from "./tooltipState.js";
|
|
21
|
+
import s from "./Tooltip.module.css";
|
|
22
|
+
import { useSurfacePortal } from "./surfacePortal.js";
|
|
23
|
+
function Tooltip({
|
|
24
|
+
content,
|
|
25
|
+
placement,
|
|
26
|
+
children
|
|
27
|
+
}) {
|
|
28
|
+
const config = useUIConfig();
|
|
29
|
+
const preferred = placement || config.tooltipPlacement, id = useId();
|
|
30
|
+
const anchor = useRef(null), popup = useRef(null), timer = useRef(void 0);
|
|
31
|
+
const owner = useSurfacePortal(), portalHost = owner?.host || document.body;
|
|
32
|
+
const [requestedOpen, setOpen] = useState(false), opened = useRef(false), visible = useRef(false);
|
|
33
|
+
const open = requestedOpen && owner?.active !== false;
|
|
34
|
+
const hide = useCallback((immediate = false) => {
|
|
35
|
+
clearTimeout(timer.current);
|
|
36
|
+
opened.current = false;
|
|
37
|
+
setOpen(false);
|
|
38
|
+
releaseTooltip(hide, visible.current);
|
|
39
|
+
visible.current = false;
|
|
40
|
+
if (immediate && popup.current) {
|
|
41
|
+
cancelMotion(popup.current);
|
|
42
|
+
if (popup.current.matches(":popover-open")) popup.current.hidePopover();
|
|
43
|
+
}
|
|
44
|
+
}, []);
|
|
45
|
+
const schedule = () => {
|
|
46
|
+
if (owner?.active === false) return;
|
|
47
|
+
clearTimeout(timer.current);
|
|
48
|
+
claimTooltip(hide);
|
|
49
|
+
timer.current = setTimeout(() => {
|
|
50
|
+
opened.current = true;
|
|
51
|
+
setOpen(true);
|
|
52
|
+
}, tooltipDelay());
|
|
53
|
+
};
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const release = retainTooltipEvents(), node = popup.current;
|
|
56
|
+
return () => {
|
|
57
|
+
clearTimeout(timer.current);
|
|
58
|
+
releaseTooltip(hide, visible.current);
|
|
59
|
+
cancelMotion(node);
|
|
60
|
+
release();
|
|
61
|
+
};
|
|
62
|
+
}, [hide, portalHost]);
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
if (owner?.active === false) hide(true);
|
|
65
|
+
}, [owner?.active, hide]);
|
|
66
|
+
useLayoutEffect(() => {
|
|
67
|
+
const node = popup.current;
|
|
68
|
+
if (!open) {
|
|
69
|
+
if (node.matches(":popover-open"))
|
|
70
|
+
void surfaceMotion(node, "exit", node.dataset.offset).then((done) => {
|
|
71
|
+
if (done && !opened.current && node.matches(":popover-open"))
|
|
72
|
+
node.hidePopover();
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!node.matches(":popover-open")) node.showPopover();
|
|
77
|
+
visible.current = true;
|
|
78
|
+
const a = anchor.current.getBoundingClientRect(), w = node.offsetWidth, h = node.offsetHeight, gap = 10;
|
|
79
|
+
const spaces = {
|
|
80
|
+
top: a.top,
|
|
81
|
+
bottom: innerHeight - a.bottom,
|
|
82
|
+
left: a.left,
|
|
83
|
+
right: innerWidth - a.right
|
|
84
|
+
};
|
|
85
|
+
const opposite = {
|
|
86
|
+
top: "bottom",
|
|
87
|
+
bottom: "top",
|
|
88
|
+
left: "right",
|
|
89
|
+
right: "left"
|
|
90
|
+
};
|
|
91
|
+
const sides = Object.keys(spaces);
|
|
92
|
+
const order = [
|
|
93
|
+
preferred,
|
|
94
|
+
opposite[preferred],
|
|
95
|
+
...sides.sort((x2, y2) => spaces[y2] - spaces[x2])
|
|
96
|
+
];
|
|
97
|
+
const actual = order.find(
|
|
98
|
+
(v) => spaces[v] >= (v === "top" || v === "bottom" ? h : w) + gap + 8
|
|
99
|
+
) || order[2];
|
|
100
|
+
let x = a.left + a.width / 2 - w / 2, y = a.top - h - gap;
|
|
101
|
+
if (actual === "bottom") y = a.bottom + gap;
|
|
102
|
+
if (actual === "left" || actual === "right") {
|
|
103
|
+
x = actual === "left" ? a.left - w - gap : a.right + gap;
|
|
104
|
+
y = a.top + a.height / 2 - h / 2;
|
|
105
|
+
}
|
|
106
|
+
x = Math.max(8, Math.min(x, innerWidth - w - 8));
|
|
107
|
+
y = Math.max(8, Math.min(y, innerHeight - h - 8));
|
|
108
|
+
const vertical = actual === "top" || actual === "bottom", extent = vertical ? w : h, margin = Math.min(17, extent / 2);
|
|
109
|
+
node.style.left = x + "px";
|
|
110
|
+
node.style.top = y + "px";
|
|
111
|
+
node.style.setProperty(
|
|
112
|
+
"--arrow",
|
|
113
|
+
Math.max(
|
|
114
|
+
margin,
|
|
115
|
+
Math.min(
|
|
116
|
+
extent - margin,
|
|
117
|
+
vertical ? a.left + a.width / 2 - x : a.top + a.height / 2 - y
|
|
118
|
+
)
|
|
119
|
+
) + "px"
|
|
120
|
+
);
|
|
121
|
+
node.dataset.side = actual;
|
|
122
|
+
node.dataset.offset = {
|
|
123
|
+
top: "0 3px",
|
|
124
|
+
bottom: "0 -3px",
|
|
125
|
+
left: "3px 0",
|
|
126
|
+
right: "-3px 0"
|
|
127
|
+
}[actual];
|
|
128
|
+
void surfaceMotion(node, "enter", node.dataset.offset);
|
|
129
|
+
}, [open, preferred, portalHost]);
|
|
130
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
131
|
+
/* @__PURE__ */ jsx(
|
|
132
|
+
"span",
|
|
133
|
+
{
|
|
134
|
+
ref: anchor,
|
|
135
|
+
className: s.anchor,
|
|
136
|
+
onPointerEnter: (e) => {
|
|
137
|
+
if (e.pointerType !== "touch" && !e.buttons) schedule();
|
|
138
|
+
},
|
|
139
|
+
onPointerLeave: () => hide(),
|
|
140
|
+
onPointerDown: () => hide(),
|
|
141
|
+
onFocus: (e) => {
|
|
142
|
+
if (keyboardTooltip() && e.target.matches(":focus-visible"))
|
|
143
|
+
schedule();
|
|
144
|
+
},
|
|
145
|
+
onBlur: () => hide(),
|
|
146
|
+
children: cloneElement(children, {
|
|
147
|
+
"aria-describedby": [children.props["aria-describedby"], open ? id : void 0].filter(Boolean).join(" ") || void 0
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
createPortal(
|
|
152
|
+
/* @__PURE__ */ jsx(
|
|
153
|
+
"div",
|
|
154
|
+
{
|
|
155
|
+
ref: popup,
|
|
156
|
+
id,
|
|
157
|
+
role: "tooltip",
|
|
158
|
+
popover: "manual",
|
|
159
|
+
className: s.tooltip,
|
|
160
|
+
children: content
|
|
161
|
+
}
|
|
162
|
+
),
|
|
163
|
+
portalHost
|
|
164
|
+
)
|
|
165
|
+
] });
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
Tooltip
|
|
169
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.anchor {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
}
|
|
5
|
+
.tooltip {
|
|
6
|
+
position: fixed;
|
|
7
|
+
inset: auto;
|
|
8
|
+
margin: 0;
|
|
9
|
+
max-width: min(320px, calc(100vw - 16px));
|
|
10
|
+
padding: 6px 9px;
|
|
11
|
+
border-radius: 10px;
|
|
12
|
+
background: #303030;
|
|
13
|
+
color: #fff;
|
|
14
|
+
border: 1px solid #303030;
|
|
15
|
+
box-shadow: 0 3px 12px rgb(0 0 0 / 0.14);
|
|
16
|
+
font: 400 11px/16px var(--ui-font);
|
|
17
|
+
overflow: visible;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
:global([data-theme="dark"]) .tooltip {
|
|
21
|
+
box-shadow: 0 3px 12px rgb(0 0 0 / 0.22);
|
|
22
|
+
}
|
|
23
|
+
.tooltip::before {
|
|
24
|
+
content: "";
|
|
25
|
+
position: absolute;
|
|
26
|
+
background: inherit;
|
|
27
|
+
width: 14px;
|
|
28
|
+
height: 8px;
|
|
29
|
+
}
|
|
30
|
+
.tooltip[data-side="top"]::before {
|
|
31
|
+
bottom: -7px;
|
|
32
|
+
left: calc(var(--arrow) - 7px);
|
|
33
|
+
clip-path: polygon(0 0, 100% 0, 50% 100%);
|
|
34
|
+
}
|
|
35
|
+
.tooltip[data-side="bottom"]::before {
|
|
36
|
+
top: -7px;
|
|
37
|
+
left: calc(var(--arrow) - 7px);
|
|
38
|
+
clip-path: polygon(50% 0, 100% 100%, 0 100%);
|
|
39
|
+
}
|
|
40
|
+
.tooltip[data-side="left"]::before {
|
|
41
|
+
right: -7px;
|
|
42
|
+
top: calc(var(--arrow) - 7px);
|
|
43
|
+
width: 8px;
|
|
44
|
+
height: 14px;
|
|
45
|
+
clip-path: polygon(100% 50%, 0 0, 0 100%);
|
|
46
|
+
}
|
|
47
|
+
.tooltip[data-side="right"]::before {
|
|
48
|
+
left: -7px;
|
|
49
|
+
top: calc(var(--arrow) - 7px);
|
|
50
|
+
width: 8px;
|
|
51
|
+
height: 14px;
|
|
52
|
+
clip-path: polygon(0 50%, 100% 0, 100% 100%);
|
|
53
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Shared connector geometry for hierarchy menus and tables. */
|
|
2
|
+
export declare function TreeGuides({ depth, continuations, last, expanded, indent, offset, }: {
|
|
3
|
+
depth: number;
|
|
4
|
+
continuations: boolean[];
|
|
5
|
+
last: boolean;
|
|
6
|
+
expanded?: boolean;
|
|
7
|
+
indent?: number;
|
|
8
|
+
offset?: number;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import s from "./TreeGuides.module.css";
|
|
3
|
+
function TreeGuides({
|
|
4
|
+
depth,
|
|
5
|
+
continuations,
|
|
6
|
+
last,
|
|
7
|
+
expanded,
|
|
8
|
+
indent = 24,
|
|
9
|
+
offset = 12
|
|
10
|
+
}) {
|
|
11
|
+
return /* @__PURE__ */ jsxs(
|
|
12
|
+
"span",
|
|
13
|
+
{
|
|
14
|
+
"aria-hidden": "true",
|
|
15
|
+
className: s.guides,
|
|
16
|
+
style: {
|
|
17
|
+
"--tree-indent": indent + "px",
|
|
18
|
+
"--tree-offset": offset + "px"
|
|
19
|
+
},
|
|
20
|
+
children: [
|
|
21
|
+
continuations.map(
|
|
22
|
+
(visible, i) => visible && /* @__PURE__ */ jsx("i", { className: s.line, style: { left: i * indent } }, i)
|
|
23
|
+
),
|
|
24
|
+
depth > 0 && /* @__PURE__ */ jsx(
|
|
25
|
+
"i",
|
|
26
|
+
{
|
|
27
|
+
className: s.elbow,
|
|
28
|
+
"data-last": last,
|
|
29
|
+
style: { left: (depth - 1) * indent }
|
|
30
|
+
}
|
|
31
|
+
),
|
|
32
|
+
expanded && /* @__PURE__ */ jsx("i", { className: s.stem, style: { left: depth * indent } })
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
TreeGuides
|
|
39
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
.guides {
|
|
2
|
+
position: absolute;
|
|
3
|
+
inset-block: 0;
|
|
4
|
+
left: var(--tree-offset);
|
|
5
|
+
width: 0;
|
|
6
|
+
pointer-events: none;
|
|
7
|
+
color: var(--line);
|
|
8
|
+
}
|
|
9
|
+
.line {
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: 0;
|
|
12
|
+
bottom: 0;
|
|
13
|
+
border-left: 1px solid currentColor;
|
|
14
|
+
}
|
|
15
|
+
.elbow {
|
|
16
|
+
position: absolute;
|
|
17
|
+
top: 0;
|
|
18
|
+
bottom: 0;
|
|
19
|
+
width: var(--tree-indent);
|
|
20
|
+
}
|
|
21
|
+
.elbow::before {
|
|
22
|
+
content: "";
|
|
23
|
+
position: absolute;
|
|
24
|
+
top: 0;
|
|
25
|
+
height: 50%;
|
|
26
|
+
left: 0;
|
|
27
|
+
right: var(--tree-elbow-gap, 0px);
|
|
28
|
+
border-left: 1px solid currentColor;
|
|
29
|
+
border-bottom: 1px solid currentColor;
|
|
30
|
+
border-bottom-left-radius: 8px;
|
|
31
|
+
}
|
|
32
|
+
.elbow:not([data-last="true"])::after {
|
|
33
|
+
content: "";
|
|
34
|
+
position: absolute;
|
|
35
|
+
top: 50%;
|
|
36
|
+
bottom: 0;
|
|
37
|
+
left: 0;
|
|
38
|
+
border-left: 1px solid currentColor;
|
|
39
|
+
}
|
|
40
|
+
.stem {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: calc(50% + var(--tree-stem-inset, 0px));
|
|
43
|
+
bottom: 0;
|
|
44
|
+
border-left: 1px solid currentColor;
|
|
45
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type FieldOptions } from "./field";
|
|
3
|
+
import { type HierarchyLoader, type HierarchyOption } from "./hierarchy";
|
|
4
|
+
type Base = FieldOptions & {
|
|
5
|
+
options: HierarchyOption[];
|
|
6
|
+
label: string;
|
|
7
|
+
searchable?: boolean;
|
|
8
|
+
clearable?: boolean;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
loadChildren?: HierarchyLoader;
|
|
11
|
+
defaultExpanded?: string[];
|
|
12
|
+
variant?: "tree" | "category";
|
|
13
|
+
icon?: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export type TreeSelectProps = Base & ({
|
|
16
|
+
multiple?: false;
|
|
17
|
+
value: string;
|
|
18
|
+
onChange(value: string): void;
|
|
19
|
+
} | {
|
|
20
|
+
multiple: true;
|
|
21
|
+
value: string[];
|
|
22
|
+
onChange(value: string[]): void;
|
|
23
|
+
checkStrictly?: boolean;
|
|
24
|
+
});
|
|
25
|
+
export declare function TreeSelect(props: TreeSelectProps): import("react").JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
useId,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState
|
|
7
|
+
} from "react";
|
|
8
|
+
import { ChevronDown, Minus } from "lucide-react";
|
|
9
|
+
import { SelectTrigger } from "./SelectTrigger.js";
|
|
10
|
+
import { Popover } from "./Popover.js";
|
|
11
|
+
import { MenuItem } from "./MenuItem.js";
|
|
12
|
+
import { SearchField } from "./SearchField.js";
|
|
13
|
+
import { Spinner } from "./Spinner.js";
|
|
14
|
+
import { Button } from "./Button.js";
|
|
15
|
+
import { usePopover } from "./usePopover.js";
|
|
16
|
+
import { fieldTriggerProps, useFieldControl } from "./field.js";
|
|
17
|
+
import { useHierarchy } from "./useHierarchy.js";
|
|
18
|
+
import {
|
|
19
|
+
hierarchyMatches
|
|
20
|
+
} from "./hierarchy.js";
|
|
21
|
+
import s from "./HierarchyPicker.module.css";
|
|
22
|
+
import { Badge } from "./Badge.js";
|
|
23
|
+
import { TreeGuides } from "./TreeGuides.js";
|
|
24
|
+
function TreeSelect(props) {
|
|
25
|
+
const {
|
|
26
|
+
options,
|
|
27
|
+
label,
|
|
28
|
+
searchable = true,
|
|
29
|
+
clearable = true,
|
|
30
|
+
placeholder = "\u8BF7\u9009\u62E9",
|
|
31
|
+
loadChildren,
|
|
32
|
+
defaultExpanded = [],
|
|
33
|
+
variant = "tree"
|
|
34
|
+
} = props;
|
|
35
|
+
const field = useFieldControl(props), pop = usePopover(field.disabled || field.readOnly), id = useId(), list = useRef(null), [query, setQuery] = useState(""), [expanded, setExpanded] = useState(new Set(defaultExpanded)), [focused, setFocused] = useState("");
|
|
36
|
+
const data = useHierarchy(options, loadChildren), selected = props.multiple ? props.value : props.value ? [props.value] : [];
|
|
37
|
+
const rows = useMemo(() => {
|
|
38
|
+
const matches = query.trim() ? new Set(
|
|
39
|
+
[...data.entries.values()].filter((entry) => hierarchyMatches(entry, query)).flatMap((entry) => entry.path.map((node) => node.value))
|
|
40
|
+
) : null;
|
|
41
|
+
return [...data.entries.values()].filter(
|
|
42
|
+
(entry) => (!matches || matches.has(entry.node.value)) && (query.trim() || entry.path.slice(0, -1).every((node) => expanded.has(node.value)))
|
|
43
|
+
);
|
|
44
|
+
}, [data.entries, query, expanded]);
|
|
45
|
+
const siblings = (entry) => entry.parent ? data.children(data.entries.get(entry.parent).node) || [] : options;
|
|
46
|
+
const last = (entry) => siblings(entry).at(-1)?.value === entry.node.value;
|
|
47
|
+
const close = pop.closeAndFocus;
|
|
48
|
+
const show = () => {
|
|
49
|
+
if (field.disabled || field.readOnly) return;
|
|
50
|
+
if (pop.open) {
|
|
51
|
+
pop.close();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setQuery("");
|
|
55
|
+
setExpanded(
|
|
56
|
+
(old) => /* @__PURE__ */ new Set([
|
|
57
|
+
...old,
|
|
58
|
+
...selected.flatMap(
|
|
59
|
+
(value) => data.entries.get(value)?.path.slice(0, -1).map((n) => n.value) || []
|
|
60
|
+
)
|
|
61
|
+
])
|
|
62
|
+
);
|
|
63
|
+
pop.show();
|
|
64
|
+
};
|
|
65
|
+
const focus = (value) => {
|
|
66
|
+
setFocused(value);
|
|
67
|
+
list.current?.querySelectorAll('[role="treeitem"]').forEach((n) => {
|
|
68
|
+
if (n.dataset.value === value) n.focus({ preventScroll: true });
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const toggleExpand = (entry) => {
|
|
72
|
+
if (entry.disabled || !entry.branch) return;
|
|
73
|
+
setExpanded((old) => {
|
|
74
|
+
const next = new Set(old);
|
|
75
|
+
next.has(entry.node.value) ? next.delete(entry.node.value) : next.add(entry.node.value);
|
|
76
|
+
return next;
|
|
77
|
+
});
|
|
78
|
+
if (!expanded.has(entry.node.value)) void data.load(entry.node);
|
|
79
|
+
};
|
|
80
|
+
const selectedSet = new Set(selected);
|
|
81
|
+
const leafMap = useMemo(() => {
|
|
82
|
+
const map = /* @__PURE__ */ new Map();
|
|
83
|
+
for (const entry of data.entries.values())
|
|
84
|
+
if (!entry.disabled && !entry.branch && entry.node.selectable !== false)
|
|
85
|
+
for (const node of entry.path) {
|
|
86
|
+
const values = map.get(node.value) || [];
|
|
87
|
+
values.push(entry.node.value);
|
|
88
|
+
map.set(node.value, values);
|
|
89
|
+
}
|
|
90
|
+
return map;
|
|
91
|
+
}, [data.entries]);
|
|
92
|
+
const selection = (entry) => {
|
|
93
|
+
if (!props.multiple) return selectedSet.has(entry.node.value);
|
|
94
|
+
if (entry.disabled) return selectedSet.has(entry.node.value);
|
|
95
|
+
if (props.checkStrictly) return selectedSet.has(entry.node.value);
|
|
96
|
+
const leaves = leafMap.get(entry.node.value) || [], count = leaves.filter((value) => selectedSet.has(value)).length;
|
|
97
|
+
return count && count < leaves.length ? "mixed" : !!leaves.length && count === leaves.length;
|
|
98
|
+
};
|
|
99
|
+
const choose = (entry) => {
|
|
100
|
+
if (field.disabled || field.readOnly || entry.disabled) return;
|
|
101
|
+
if (entry.node.selectable === false || props.multiple && !props.checkStrictly && entry.branch && data.children(entry.node) === void 0) {
|
|
102
|
+
toggleExpand(entry);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!props.multiple) {
|
|
106
|
+
props.onChange(entry.node.value);
|
|
107
|
+
close();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const targets = props.checkStrictly ? [entry.node.value] : leafMap.get(entry.node.value) || [];
|
|
111
|
+
if (!targets.length) return;
|
|
112
|
+
const remove = targets.every((value) => selectedSet.has(value));
|
|
113
|
+
props.onChange(
|
|
114
|
+
remove ? selected.filter((value) => !targets.includes(value)) : [.../* @__PURE__ */ new Set([...selected, ...targets])]
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
const first = rows.find((entry) => !entry.disabled)?.node.value;
|
|
118
|
+
const active = rows.some(
|
|
119
|
+
(entry) => entry.node.value === focused && !entry.disabled
|
|
120
|
+
) ? focused : first;
|
|
121
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
122
|
+
/* @__PURE__ */ jsx(
|
|
123
|
+
SelectTrigger,
|
|
124
|
+
{
|
|
125
|
+
...fieldTriggerProps(field),
|
|
126
|
+
ref: pop.anchor,
|
|
127
|
+
expanded: pop.open,
|
|
128
|
+
icon: props.icon,
|
|
129
|
+
className: s.trigger,
|
|
130
|
+
"aria-haspopup": "dialog",
|
|
131
|
+
"aria-controls": id,
|
|
132
|
+
onClick: show,
|
|
133
|
+
onKeyDown: (event) => {
|
|
134
|
+
if (event.key === "ArrowDown" && !pop.open) {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
show();
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
children: selected.length ? props.multiple ? `\u5DF2\u9009\u62E9 ${selected.length} \u9879` : data.entries.get(selected[0])?.path.map((n) => n.label).join(" / ") || selected[0] : placeholder
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
field.name && (props.multiple ? selected.map((value) => /* @__PURE__ */ jsx(
|
|
143
|
+
"input",
|
|
144
|
+
{
|
|
145
|
+
type: "hidden",
|
|
146
|
+
name: field.name,
|
|
147
|
+
value,
|
|
148
|
+
disabled: field.disabled
|
|
149
|
+
},
|
|
150
|
+
value
|
|
151
|
+
)) : /* @__PURE__ */ jsx(
|
|
152
|
+
"input",
|
|
153
|
+
{
|
|
154
|
+
type: "hidden",
|
|
155
|
+
name: field.name,
|
|
156
|
+
value: props.value,
|
|
157
|
+
disabled: field.disabled
|
|
158
|
+
}
|
|
159
|
+
)),
|
|
160
|
+
/* @__PURE__ */ jsxs(
|
|
161
|
+
Popover,
|
|
162
|
+
{
|
|
163
|
+
anchor: pop.anchor,
|
|
164
|
+
open: pop.open,
|
|
165
|
+
onClose: pop.close,
|
|
166
|
+
label,
|
|
167
|
+
id,
|
|
168
|
+
width: 340,
|
|
169
|
+
children: [
|
|
170
|
+
searchable && /* @__PURE__ */ jsx("div", { className: s.search, children: /* @__PURE__ */ jsx(
|
|
171
|
+
SearchField,
|
|
172
|
+
{
|
|
173
|
+
label: `\u641C\u7D22${label}`,
|
|
174
|
+
placeholder: "\u641C\u7D22\u540D\u79F0\u6216\u8DEF\u5F84",
|
|
175
|
+
value: query,
|
|
176
|
+
onChange: setQuery,
|
|
177
|
+
onKeyDown: (event) => {
|
|
178
|
+
if (event.key === "ArrowDown") {
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
if (first) focus(first);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
) }),
|
|
185
|
+
/* @__PURE__ */ jsxs(
|
|
186
|
+
"div",
|
|
187
|
+
{
|
|
188
|
+
ref: list,
|
|
189
|
+
role: "tree",
|
|
190
|
+
"aria-label": `${label}\u9009\u9879`,
|
|
191
|
+
"aria-multiselectable": props.multiple || void 0,
|
|
192
|
+
className: s.tree,
|
|
193
|
+
onKeyDown: (event) => {
|
|
194
|
+
if (event.target instanceof HTMLButtonElement) return;
|
|
195
|
+
const available = rows.filter((entry2) => !entry2.disabled), current = available.findIndex(
|
|
196
|
+
(entry2) => entry2.node.value === focused
|
|
197
|
+
), entry = available[current];
|
|
198
|
+
let next;
|
|
199
|
+
if (event.key === "ArrowDown")
|
|
200
|
+
next = available[Math.min(available.length - 1, current + 1)];
|
|
201
|
+
else if (event.key === "ArrowUp")
|
|
202
|
+
next = available[Math.max(0, current - 1)];
|
|
203
|
+
else if (event.key === "Home") next = available[0];
|
|
204
|
+
else if (event.key === "End") next = available.at(-1);
|
|
205
|
+
else if (entry && event.key === "ArrowRight") {
|
|
206
|
+
if (entry.branch && !expanded.has(entry.node.value))
|
|
207
|
+
toggleExpand(entry);
|
|
208
|
+
else
|
|
209
|
+
next = available.find(
|
|
210
|
+
(item) => item.parent === entry.node.value
|
|
211
|
+
);
|
|
212
|
+
} else if (entry && event.key === "ArrowLeft") {
|
|
213
|
+
if (expanded.has(entry.node.value)) toggleExpand(entry);
|
|
214
|
+
else
|
|
215
|
+
next = available.find(
|
|
216
|
+
(item) => item.node.value === entry.parent
|
|
217
|
+
);
|
|
218
|
+
} else if (entry && (event.key === "Enter" || event.key === " "))
|
|
219
|
+
choose(entry);
|
|
220
|
+
else return;
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
event.stopPropagation();
|
|
223
|
+
if (next) focus(next.node.value);
|
|
224
|
+
},
|
|
225
|
+
children: [
|
|
226
|
+
!rows.length && /* @__PURE__ */ jsx("div", { role: "status", className: s.empty, children: "\u6CA1\u6709\u5339\u914D\u9009\u9879" }),
|
|
227
|
+
rows.map((entry) => {
|
|
228
|
+
const state = selection(entry), isExpanded = !!query.trim() || expanded.has(entry.node.value), error = data.error(entry.node);
|
|
229
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
230
|
+
/* @__PURE__ */ jsx(
|
|
231
|
+
MenuItem,
|
|
232
|
+
{
|
|
233
|
+
as: "div",
|
|
234
|
+
role: "treeitem",
|
|
235
|
+
"aria-label": entry.node.label,
|
|
236
|
+
"aria-level": entry.path.length,
|
|
237
|
+
"aria-expanded": entry.branch ? isExpanded : void 0,
|
|
238
|
+
"aria-checked": props.multiple ? state : void 0,
|
|
239
|
+
"aria-selected": !props.multiple && !!state,
|
|
240
|
+
"aria-disabled": entry.disabled || void 0,
|
|
241
|
+
tabIndex: entry.node.value === active ? 0 : -1,
|
|
242
|
+
"data-value": entry.node.value,
|
|
243
|
+
className: `${s.row} ${s.treeRow} ${variant === "category" ? s.categoryRow : ""}`,
|
|
244
|
+
"data-branch": entry.branch,
|
|
245
|
+
style: { "--level": entry.path.length - 1 },
|
|
246
|
+
label: entry.node.label,
|
|
247
|
+
description: query.trim() ? entry.path.slice(0, -1).map((n) => n.label).join(" / ") : void 0,
|
|
248
|
+
icon: entry.node.icon,
|
|
249
|
+
meta: variant === "category" && entry.branch ? /* @__PURE__ */ jsx(Badge, { children: entry.node.count ?? data.children(entry.node)?.length ?? 0 }) : void 0,
|
|
250
|
+
selected: state === true,
|
|
251
|
+
selection: props.multiple ? "checkbox" : "check",
|
|
252
|
+
disabled: entry.disabled,
|
|
253
|
+
trailing: state === "mixed" ? /* @__PURE__ */ jsx("span", { className: s.mixed, children: /* @__PURE__ */ jsx(Minus, {}) }) : void 0,
|
|
254
|
+
onFocus: () => setFocused(entry.node.value),
|
|
255
|
+
onClick: () => {
|
|
256
|
+
if (entry.disabled) return;
|
|
257
|
+
focus(entry.node.value);
|
|
258
|
+
choose(entry);
|
|
259
|
+
},
|
|
260
|
+
prefix: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
261
|
+
variant === "category" && /* @__PURE__ */ jsx(
|
|
262
|
+
TreeGuides,
|
|
263
|
+
{
|
|
264
|
+
depth: entry.path.length - 1,
|
|
265
|
+
indent: 18,
|
|
266
|
+
offset: 20,
|
|
267
|
+
last: last(entry),
|
|
268
|
+
expanded: entry.branch && isExpanded,
|
|
269
|
+
continuations: entry.path.slice(1, -1).map(
|
|
270
|
+
(node) => !last(data.entries.get(node.value))
|
|
271
|
+
)
|
|
272
|
+
}
|
|
273
|
+
),
|
|
274
|
+
entry.branch ? /* @__PURE__ */ jsx(
|
|
275
|
+
"button",
|
|
276
|
+
{
|
|
277
|
+
type: "button",
|
|
278
|
+
tabIndex: -1,
|
|
279
|
+
className: s.expander,
|
|
280
|
+
"data-expanded": isExpanded,
|
|
281
|
+
"aria-label": `${isExpanded ? "\u6298\u53E0" : "\u5C55\u5F00"} ${entry.node.label}`,
|
|
282
|
+
disabled: entry.disabled || data.loading.has(entry.node.value),
|
|
283
|
+
onClick: (event) => {
|
|
284
|
+
event.stopPropagation();
|
|
285
|
+
focus(entry.node.value);
|
|
286
|
+
toggleExpand(entry);
|
|
287
|
+
},
|
|
288
|
+
children: data.loading.has(entry.node.value) ? /* @__PURE__ */ jsx(Spinner, { size: 12, decorative: true }) : /* @__PURE__ */ jsx(ChevronDown, {})
|
|
289
|
+
}
|
|
290
|
+
) : /* @__PURE__ */ jsx("span", { className: s.spacer })
|
|
291
|
+
] })
|
|
292
|
+
}
|
|
293
|
+
),
|
|
294
|
+
isExpanded && error && /* @__PURE__ */ jsxs("div", { role: "alert", className: s.error, children: [
|
|
295
|
+
/* @__PURE__ */ jsx("span", { children: error }),
|
|
296
|
+
/* @__PURE__ */ jsx(
|
|
297
|
+
Button,
|
|
298
|
+
{
|
|
299
|
+
size: "small",
|
|
300
|
+
variant: "ghost",
|
|
301
|
+
onClick: () => void data.load(entry.node),
|
|
302
|
+
children: "\u91CD\u8BD5"
|
|
303
|
+
}
|
|
304
|
+
)
|
|
305
|
+
] })
|
|
306
|
+
] }, entry.node.value);
|
|
307
|
+
})
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
/* @__PURE__ */ jsxs("div", { className: s.footer, children: [
|
|
312
|
+
/* @__PURE__ */ jsx("span", { children: props.multiple ? `${selected.length} \u9879\u5DF2\u9009` : "" }),
|
|
313
|
+
/* @__PURE__ */ jsxs("div", { className: s.footerActions, children: [
|
|
314
|
+
clearable && /* @__PURE__ */ jsx(
|
|
315
|
+
Button,
|
|
316
|
+
{
|
|
317
|
+
size: "small",
|
|
318
|
+
variant: "ghost",
|
|
319
|
+
disabled: !selected.length,
|
|
320
|
+
onClick: () => {
|
|
321
|
+
if (props.multiple) props.onChange([]);
|
|
322
|
+
else props.onChange("");
|
|
323
|
+
},
|
|
324
|
+
children: "\u6E05\u7A7A"
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
props.multiple && /* @__PURE__ */ jsx(Button, { size: "small", onClick: close, children: "\u5B8C\u6210" })
|
|
328
|
+
] })
|
|
329
|
+
] })
|
|
330
|
+
]
|
|
331
|
+
}
|
|
332
|
+
)
|
|
333
|
+
] });
|
|
334
|
+
}
|
|
335
|
+
export {
|
|
336
|
+
TreeSelect
|
|
337
|
+
};
|