@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,173 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState
|
|
7
|
+
} from "react";
|
|
8
|
+
import { FormField } from "./FormField.js";
|
|
9
|
+
import { useFieldControl } from "./field.js";
|
|
10
|
+
import s from "./PinInput.module.css";
|
|
11
|
+
function PinInput({
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
onComplete,
|
|
15
|
+
length = 6,
|
|
16
|
+
format = "numeric",
|
|
17
|
+
mask = false,
|
|
18
|
+
groups,
|
|
19
|
+
label,
|
|
20
|
+
error,
|
|
21
|
+
hint,
|
|
22
|
+
ref: forwardedRef,
|
|
23
|
+
...props
|
|
24
|
+
}) {
|
|
25
|
+
const field = useFieldControl({ ...props, label, error, hint }), input = useRef(null), root = useRef(null), lastComplete = useRef(""), pendingCaret = useRef(void 0), [focused, setFocused] = useState(false), [active, setActive] = useState(0), size = Math.max(1, Math.min(16, Math.trunc(length) || 6));
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (value.length < size) lastComplete.current = "";
|
|
28
|
+
}, [value, size]);
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
if (pendingCaret.current === void 0) return;
|
|
31
|
+
const caret = Math.min(pendingCaret.current, value.length);
|
|
32
|
+
input.current?.setSelectionRange(caret, caret);
|
|
33
|
+
pendingCaret.current = void 0;
|
|
34
|
+
}, [value]);
|
|
35
|
+
const clean = (text) => (format === "numeric" ? text.replace(/[^0-9]/g, "") : text.replace(/[^a-z0-9]/gi, "")).slice(0, size);
|
|
36
|
+
const emit = (next, caret) => {
|
|
37
|
+
pendingCaret.current = caret;
|
|
38
|
+
onChange(next);
|
|
39
|
+
setActive(Math.min(caret, size - 1));
|
|
40
|
+
if (next === value) {
|
|
41
|
+
input.current?.setSelectionRange(
|
|
42
|
+
Math.min(caret, value.length),
|
|
43
|
+
Math.min(caret, value.length)
|
|
44
|
+
);
|
|
45
|
+
pendingCaret.current = void 0;
|
|
46
|
+
}
|
|
47
|
+
if (next.length === size && lastComplete.current !== next) {
|
|
48
|
+
lastComplete.current = next;
|
|
49
|
+
onComplete?.(next);
|
|
50
|
+
} else if (next.length < size) lastComplete.current = "";
|
|
51
|
+
};
|
|
52
|
+
const boundaries = /* @__PURE__ */ new Set();
|
|
53
|
+
let offset = 0;
|
|
54
|
+
for (const group of groups || [size]) {
|
|
55
|
+
offset += group;
|
|
56
|
+
boundaries.add(offset);
|
|
57
|
+
}
|
|
58
|
+
const control = /* @__PURE__ */ jsxs(
|
|
59
|
+
"div",
|
|
60
|
+
{
|
|
61
|
+
ref: root,
|
|
62
|
+
className: s.root,
|
|
63
|
+
"data-disabled": field.disabled,
|
|
64
|
+
"data-readonly": field.readOnly || void 0,
|
|
65
|
+
onPointerDown: (event) => {
|
|
66
|
+
if (event.button !== 0 || field.disabled) return;
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
input.current?.focus({ preventScroll: true });
|
|
69
|
+
const slots = [
|
|
70
|
+
...root.current.querySelectorAll("[data-pin-slot]")
|
|
71
|
+
];
|
|
72
|
+
let index = 0, distance = Infinity;
|
|
73
|
+
slots.forEach((slot, i) => {
|
|
74
|
+
const rect = slot.getBoundingClientRect(), d = (event.clientX - rect.left - rect.width / 2) ** 2 + (event.clientY - rect.top - rect.height / 2) ** 2;
|
|
75
|
+
if (d < distance) {
|
|
76
|
+
distance = d;
|
|
77
|
+
index = i;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const caret = Math.min(index < 0 ? size - 1 : index, value.length);
|
|
81
|
+
input.current?.setSelectionRange(
|
|
82
|
+
caret,
|
|
83
|
+
Math.min(caret + 1, value.length)
|
|
84
|
+
);
|
|
85
|
+
setActive(Math.min(caret, size - 1));
|
|
86
|
+
},
|
|
87
|
+
children: [
|
|
88
|
+
Array.from({ length: size }, (_, index) => /* @__PURE__ */ jsxs("span", { className: s.unit, "aria-hidden": "true", children: [
|
|
89
|
+
index > 0 && boundaries.has(index) && /* @__PURE__ */ jsx("span", { className: s.separator, children: "\u2013" }),
|
|
90
|
+
/* @__PURE__ */ jsxs(
|
|
91
|
+
"span",
|
|
92
|
+
{
|
|
93
|
+
"data-pin-slot": true,
|
|
94
|
+
className: s.slot,
|
|
95
|
+
"data-focus": focused && active === index,
|
|
96
|
+
"aria-invalid": field.invalid,
|
|
97
|
+
children: [
|
|
98
|
+
mask && value[index] ? "\u2022" : value[index],
|
|
99
|
+
focused && active === index && !value[index] && /* @__PURE__ */ jsx("i", { className: s.caret })
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
] }, index)),
|
|
104
|
+
/* @__PURE__ */ jsx(
|
|
105
|
+
"input",
|
|
106
|
+
{
|
|
107
|
+
...props,
|
|
108
|
+
ref: (node) => {
|
|
109
|
+
input.current = node;
|
|
110
|
+
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
111
|
+
else if (forwardedRef) forwardedRef.current = node;
|
|
112
|
+
},
|
|
113
|
+
id: field.id,
|
|
114
|
+
name: field.name,
|
|
115
|
+
className: s.input,
|
|
116
|
+
type: "text",
|
|
117
|
+
autoComplete: props.autoComplete || "one-time-code",
|
|
118
|
+
inputMode: format === "numeric" ? "numeric" : "text",
|
|
119
|
+
spellCheck: false,
|
|
120
|
+
required: field.required,
|
|
121
|
+
disabled: field.disabled,
|
|
122
|
+
readOnly: field.readOnly,
|
|
123
|
+
minLength: size,
|
|
124
|
+
maxLength: size,
|
|
125
|
+
pattern: format === "numeric" ? "[0-9]{" + size + "}" : "[a-zA-Z0-9]{" + size + "}",
|
|
126
|
+
value,
|
|
127
|
+
"aria-invalid": field.invalid,
|
|
128
|
+
"aria-describedby": field.descriptionId,
|
|
129
|
+
onFocus: (event) => {
|
|
130
|
+
setFocused(true);
|
|
131
|
+
setActive(
|
|
132
|
+
Math.min(event.currentTarget.selectionStart || 0, size - 1)
|
|
133
|
+
);
|
|
134
|
+
props.onFocus?.(event);
|
|
135
|
+
},
|
|
136
|
+
onBlur: (event) => {
|
|
137
|
+
setFocused(false);
|
|
138
|
+
props.onBlur?.(event);
|
|
139
|
+
},
|
|
140
|
+
onSelect: (event) => {
|
|
141
|
+
setActive(
|
|
142
|
+
Math.min(event.currentTarget.selectionStart || 0, size - 1)
|
|
143
|
+
);
|
|
144
|
+
props.onSelect?.(event);
|
|
145
|
+
},
|
|
146
|
+
onChange: (event) => {
|
|
147
|
+
if (!field.readOnly)
|
|
148
|
+
emit(clean(event.target.value), event.target.selectionStart || 0);
|
|
149
|
+
},
|
|
150
|
+
onPaste: (event) => {
|
|
151
|
+
props.onPaste?.(event);
|
|
152
|
+
if (event.defaultPrevented || field.readOnly) return;
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
const text = clean(
|
|
155
|
+
event.clipboardData.getData("text/plain") || event.clipboardData.getData("text")
|
|
156
|
+
);
|
|
157
|
+
if (!text) return;
|
|
158
|
+
const start = event.currentTarget.selectionStart || 0, end = event.currentTarget.selectionEnd || start;
|
|
159
|
+
emit(
|
|
160
|
+
text.length === size ? text : clean(value.slice(0, start) + text + value.slice(end)),
|
|
161
|
+
text.length === size ? size : start + text.length
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
return field.wrapped ? control : /* @__PURE__ */ jsx(FormField, { ...field, children: control });
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
PinInput
|
|
173
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 7px;
|
|
6
|
+
align-self: flex-start;
|
|
7
|
+
max-width: 100%;
|
|
8
|
+
flex-wrap: wrap;
|
|
9
|
+
}
|
|
10
|
+
.unit {
|
|
11
|
+
display: inline-flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: 10px;
|
|
14
|
+
}
|
|
15
|
+
.slot {
|
|
16
|
+
composes: surface from "./Control.module.css";
|
|
17
|
+
position: relative;
|
|
18
|
+
display: grid;
|
|
19
|
+
place-items: center;
|
|
20
|
+
width: 39px;
|
|
21
|
+
height: 44px;
|
|
22
|
+
font-size: 19px;
|
|
23
|
+
font-variant-numeric: tabular-nums;
|
|
24
|
+
pointer-events: none;
|
|
25
|
+
}
|
|
26
|
+
.separator {
|
|
27
|
+
color: var(--muted);
|
|
28
|
+
padding: 0 2px;
|
|
29
|
+
}
|
|
30
|
+
.input {
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset: 0;
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
padding: 0;
|
|
36
|
+
border: 0;
|
|
37
|
+
outline: 0;
|
|
38
|
+
background: transparent !important;
|
|
39
|
+
color: transparent !important;
|
|
40
|
+
caret-color: transparent !important;
|
|
41
|
+
letter-spacing: 20px;
|
|
42
|
+
font-size: 19px;
|
|
43
|
+
box-shadow: none !important;
|
|
44
|
+
}
|
|
45
|
+
.input::selection {
|
|
46
|
+
background: transparent;
|
|
47
|
+
color: transparent;
|
|
48
|
+
}
|
|
49
|
+
.root[data-disabled="true"] .slot {
|
|
50
|
+
opacity: 0.45;
|
|
51
|
+
}
|
|
52
|
+
.caret {
|
|
53
|
+
position: absolute;
|
|
54
|
+
display: block;
|
|
55
|
+
height: 19px;
|
|
56
|
+
width: 1.5px;
|
|
57
|
+
background: var(--fg);
|
|
58
|
+
animation: pin-caret 1.1s step-end infinite;
|
|
59
|
+
}
|
|
60
|
+
@keyframes pin-caret {
|
|
61
|
+
50% {
|
|
62
|
+
opacity: 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.input:focus,
|
|
67
|
+
.input:focus-visible {
|
|
68
|
+
outline: none !important;
|
|
69
|
+
outline-offset: 0 !important;
|
|
70
|
+
box-shadow: none !important;
|
|
71
|
+
border: 0 !important;
|
|
72
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
declare const presets: {
|
|
3
|
+
empty: {
|
|
4
|
+
icon: import("lucide-react").LucideIcon;
|
|
5
|
+
title: string;
|
|
6
|
+
};
|
|
7
|
+
search: {
|
|
8
|
+
icon: import("lucide-react").LucideIcon;
|
|
9
|
+
title: string;
|
|
10
|
+
};
|
|
11
|
+
error: {
|
|
12
|
+
icon: import("lucide-react").LucideIcon;
|
|
13
|
+
title: string;
|
|
14
|
+
};
|
|
15
|
+
offline: {
|
|
16
|
+
icon: import("lucide-react").LucideIcon;
|
|
17
|
+
title: string;
|
|
18
|
+
};
|
|
19
|
+
folder: {
|
|
20
|
+
icon: import("lucide-react").LucideIcon;
|
|
21
|
+
title: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type PlaceholderVariant = keyof typeof presets;
|
|
25
|
+
export declare function Placeholder({ variant, title, description, children, }: {
|
|
26
|
+
variant?: PlaceholderVariant;
|
|
27
|
+
title?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
children?: ReactNode;
|
|
30
|
+
}): import("react").JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Inbox,
|
|
4
|
+
Search,
|
|
5
|
+
TriangleAlert,
|
|
6
|
+
WifiOff,
|
|
7
|
+
FolderOpen
|
|
8
|
+
} from "lucide-react";
|
|
9
|
+
import { EmptyState } from "./EmptyState.js";
|
|
10
|
+
const presets = {
|
|
11
|
+
empty: { icon: Inbox, title: "\u6682\u65E0\u5185\u5BB9" },
|
|
12
|
+
search: { icon: Search, title: "\u6CA1\u6709\u5339\u914D\u7684\u7ED3\u679C" },
|
|
13
|
+
error: { icon: TriangleAlert, title: "\u5185\u5BB9\u52A0\u8F7D\u5931\u8D25" },
|
|
14
|
+
offline: { icon: WifiOff, title: "\u5F53\u524D\u5904\u4E8E\u79BB\u7EBF\u72B6\u6001" },
|
|
15
|
+
folder: { icon: FolderOpen, title: "\u6587\u4EF6\u5939\u4E3A\u7A7A" }
|
|
16
|
+
};
|
|
17
|
+
function Placeholder({
|
|
18
|
+
variant = "empty",
|
|
19
|
+
title,
|
|
20
|
+
description,
|
|
21
|
+
children
|
|
22
|
+
}) {
|
|
23
|
+
const preset = presets[variant], Icon = preset.icon;
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
EmptyState,
|
|
26
|
+
{
|
|
27
|
+
icon: /* @__PURE__ */ jsx(Icon, {}),
|
|
28
|
+
title: title || preset.title,
|
|
29
|
+
description,
|
|
30
|
+
children
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
Placeholder
|
|
36
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
export type PopconfirmProps = {
|
|
3
|
+
children: ReactElement<ComponentPropsWithRef<"button">>;
|
|
4
|
+
title: string;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
onConfirm(signal: AbortSignal): void | Promise<void>;
|
|
7
|
+
onCancel?(): void;
|
|
8
|
+
open?: boolean;
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
onOpenChange?(open: boolean): void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
confirmText?: string;
|
|
13
|
+
cancelText?: string;
|
|
14
|
+
tone?: "default" | "danger";
|
|
15
|
+
icon?: ReactNode | false;
|
|
16
|
+
};
|
|
17
|
+
export declare function Popconfirm({ children, title, description, onConfirm, onCancel, open: controlled, defaultOpen, onOpenChange, disabled, confirmText, cancelText, tone, icon, }: PopconfirmProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
cloneElement,
|
|
4
|
+
useEffect,
|
|
5
|
+
useId,
|
|
6
|
+
useRef,
|
|
7
|
+
useState
|
|
8
|
+
} from "react";
|
|
9
|
+
import { CircleAlert } from "lucide-react";
|
|
10
|
+
import { Popover } from "./Popover.js";
|
|
11
|
+
import { Button } from "./Button.js";
|
|
12
|
+
import s from "./Popconfirm.module.css";
|
|
13
|
+
function Popconfirm({
|
|
14
|
+
children,
|
|
15
|
+
title,
|
|
16
|
+
description,
|
|
17
|
+
onConfirm,
|
|
18
|
+
onCancel,
|
|
19
|
+
open: controlled,
|
|
20
|
+
defaultOpen = false,
|
|
21
|
+
onOpenChange,
|
|
22
|
+
disabled = false,
|
|
23
|
+
confirmText = "\u786E\u8BA4",
|
|
24
|
+
cancelText = "\u53D6\u6D88",
|
|
25
|
+
tone = "default",
|
|
26
|
+
icon
|
|
27
|
+
}) {
|
|
28
|
+
const [localOpen, setLocalOpen] = useState(defaultOpen), [pending, setPending] = useState(false), [error, setError] = useState(""), anchor = useRef(null), session = useRef(null), alive = useRef(true), id = useId(), confirm = useRef(null);
|
|
29
|
+
const blocked = disabled || !!children.props.disabled, open = (controlled ?? localOpen) && !blocked;
|
|
30
|
+
const change = (next) => {
|
|
31
|
+
if (controlled === void 0) setLocalOpen(next);
|
|
32
|
+
onOpenChange?.(next);
|
|
33
|
+
};
|
|
34
|
+
const abort = () => {
|
|
35
|
+
session.current?.abort();
|
|
36
|
+
session.current = null;
|
|
37
|
+
setPending(false);
|
|
38
|
+
};
|
|
39
|
+
const close = (cancel = true, restoreFocus = true) => {
|
|
40
|
+
abort();
|
|
41
|
+
change(false);
|
|
42
|
+
setError("");
|
|
43
|
+
if (cancel) onCancel?.();
|
|
44
|
+
if (restoreFocus) anchor.current?.focus({ preventScroll: true });
|
|
45
|
+
};
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
alive.current = true;
|
|
48
|
+
return () => {
|
|
49
|
+
alive.current = false;
|
|
50
|
+
session.current?.abort();
|
|
51
|
+
session.current = null;
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!open) {
|
|
56
|
+
session.current?.abort();
|
|
57
|
+
session.current = null;
|
|
58
|
+
setPending(false);
|
|
59
|
+
setError("");
|
|
60
|
+
}
|
|
61
|
+
}, [open]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (error && !pending) confirm.current?.focus({ preventScroll: true });
|
|
64
|
+
}, [error, pending]);
|
|
65
|
+
const submit = async () => {
|
|
66
|
+
if (session.current || !open) return;
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
session.current = controller;
|
|
69
|
+
setPending(true);
|
|
70
|
+
setError("");
|
|
71
|
+
try {
|
|
72
|
+
await onConfirm(controller.signal);
|
|
73
|
+
if (!alive.current || controller.signal.aborted || session.current !== controller)
|
|
74
|
+
return;
|
|
75
|
+
session.current = null;
|
|
76
|
+
setPending(false);
|
|
77
|
+
change(false);
|
|
78
|
+
anchor.current?.focus({ preventScroll: true });
|
|
79
|
+
} catch (reason) {
|
|
80
|
+
if (!alive.current || controller.signal.aborted || session.current !== controller)
|
|
81
|
+
return;
|
|
82
|
+
session.current = null;
|
|
83
|
+
setPending(false);
|
|
84
|
+
setError(reason instanceof Error ? reason.message : "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002");
|
|
85
|
+
confirm.current?.focus({ preventScroll: true });
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const childRef = children.props.ref;
|
|
89
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
90
|
+
cloneElement(children, {
|
|
91
|
+
ref: (node) => {
|
|
92
|
+
anchor.current = node;
|
|
93
|
+
if (typeof childRef === "function") return childRef(node);
|
|
94
|
+
else if (childRef) childRef.current = node;
|
|
95
|
+
},
|
|
96
|
+
disabled: blocked,
|
|
97
|
+
"aria-haspopup": "dialog",
|
|
98
|
+
"aria-expanded": open,
|
|
99
|
+
"aria-controls": id,
|
|
100
|
+
onClick: (event) => {
|
|
101
|
+
children.props.onClick?.(event);
|
|
102
|
+
if (event.defaultPrevented || blocked) return;
|
|
103
|
+
if (open) close();
|
|
104
|
+
else {
|
|
105
|
+
setError("");
|
|
106
|
+
change(true);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}),
|
|
110
|
+
/* @__PURE__ */ jsx(
|
|
111
|
+
Popover,
|
|
112
|
+
{
|
|
113
|
+
anchor,
|
|
114
|
+
open,
|
|
115
|
+
onClose: () => close(true, false),
|
|
116
|
+
label: title,
|
|
117
|
+
role: "alertdialog",
|
|
118
|
+
id,
|
|
119
|
+
descriptionId: description ? id + "-description" : void 0,
|
|
120
|
+
width: 320,
|
|
121
|
+
children: /* @__PURE__ */ jsxs(
|
|
122
|
+
"div",
|
|
123
|
+
{
|
|
124
|
+
className: s.content,
|
|
125
|
+
"data-tone": tone,
|
|
126
|
+
"aria-busy": pending || void 0,
|
|
127
|
+
children: [
|
|
128
|
+
/* @__PURE__ */ jsxs("div", { className: s.copy, children: [
|
|
129
|
+
icon !== false && /* @__PURE__ */ jsx("span", { className: s.icon, "aria-hidden": "true", children: icon || /* @__PURE__ */ jsx(CircleAlert, {}) }),
|
|
130
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
131
|
+
/* @__PURE__ */ jsx("div", { className: s.title, children: title }),
|
|
132
|
+
description && /* @__PURE__ */ jsx("div", { className: s.description, id: id + "-description", children: description })
|
|
133
|
+
] })
|
|
134
|
+
] }),
|
|
135
|
+
error && /* @__PURE__ */ jsx("div", { role: "alert", className: s.error, children: error }),
|
|
136
|
+
/* @__PURE__ */ jsxs("div", { className: s.actions, children: [
|
|
137
|
+
/* @__PURE__ */ jsx(Button, { size: "small", "data-autofocus": true, onClick: () => close(), children: pending ? "\u53D6\u6D88\u64CD\u4F5C" : cancelText }),
|
|
138
|
+
/* @__PURE__ */ jsx(
|
|
139
|
+
Button,
|
|
140
|
+
{
|
|
141
|
+
ref: confirm,
|
|
142
|
+
size: "small",
|
|
143
|
+
variant: tone === "danger" ? "danger" : "primary",
|
|
144
|
+
loading: pending,
|
|
145
|
+
onClick: () => void submit(),
|
|
146
|
+
children: confirmText
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
] })
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
] });
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
Popconfirm
|
|
159
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
.content {
|
|
2
|
+
padding: 12px;
|
|
3
|
+
}
|
|
4
|
+
.copy {
|
|
5
|
+
display: flex;
|
|
6
|
+
gap: 10px;
|
|
7
|
+
align-items: flex-start;
|
|
8
|
+
}
|
|
9
|
+
.copy > div {
|
|
10
|
+
min-width: 0;
|
|
11
|
+
}
|
|
12
|
+
.icon {
|
|
13
|
+
display: flex;
|
|
14
|
+
padding-top: 1px;
|
|
15
|
+
color: var(--warning);
|
|
16
|
+
}
|
|
17
|
+
.icon svg {
|
|
18
|
+
width: 18px;
|
|
19
|
+
height: 18px;
|
|
20
|
+
}
|
|
21
|
+
.content[data-tone="danger"] .icon {
|
|
22
|
+
color: var(--danger);
|
|
23
|
+
}
|
|
24
|
+
.title {
|
|
25
|
+
font-size: 13px;
|
|
26
|
+
font-weight: 600;
|
|
27
|
+
line-height: 20px;
|
|
28
|
+
overflow-wrap: anywhere;
|
|
29
|
+
}
|
|
30
|
+
.description {
|
|
31
|
+
margin-top: 5px;
|
|
32
|
+
font-size: 12px;
|
|
33
|
+
line-height: 1.65;
|
|
34
|
+
color: var(--muted);
|
|
35
|
+
overflow-wrap: anywhere;
|
|
36
|
+
}
|
|
37
|
+
.error {
|
|
38
|
+
margin-top: 10px;
|
|
39
|
+
color: var(--danger);
|
|
40
|
+
font-size: 12px;
|
|
41
|
+
line-height: 1.6;
|
|
42
|
+
overflow-wrap: anywhere;
|
|
43
|
+
}
|
|
44
|
+
.actions {
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: flex-end;
|
|
47
|
+
gap: 8px;
|
|
48
|
+
margin-top: 16px;
|
|
49
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from "react";
|
|
2
|
+
export declare function Popover({ open: requestedOpen, onClose, anchor, children, width, label, role, id, onKeyDown, descriptionId, autoFocus, matchAnchorWidth, className, }: {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onClose(): void;
|
|
5
|
+
anchor: RefObject<HTMLElement | null>;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
width?: number;
|
|
8
|
+
label: string;
|
|
9
|
+
role?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
|
|
12
|
+
descriptionId?: string;
|
|
13
|
+
autoFocus?: boolean;
|
|
14
|
+
matchAnchorWidth?: boolean;
|
|
15
|
+
className?: string;
|
|
16
|
+
}): import("react").ReactPortal;
|