@robert-stackflow/oneui 0.6.18 → 0.6.20
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 +4 -0
- package/README.md +1 -0
- package/components/Accordion.d.ts +1 -1
- package/components/Accordion.js +1 -0
- package/components/AccountItem.js +1 -0
- package/components/ActionSheet.js +1 -0
- package/components/Alert.js +1 -0
- package/components/AppShell.js +1 -0
- package/components/AppearanceSettings.js +1 -0
- package/components/AuthLayout.js +1 -0
- package/components/Avatar.js +1 -0
- package/components/AvatarGroup.js +1 -0
- package/components/Badge.js +1 -0
- package/components/Banner.d.ts +3 -3
- package/components/Banner.js +12 -4
- package/components/BarChart.js +1 -0
- package/components/BlockedTab.js +1 -0
- package/components/Breadcrumb.js +1 -0
- package/components/Button.d.ts +4 -2
- package/components/Button.js +24 -0
- package/components/Calendar.js +19 -13
- package/components/Card.d.ts +5 -4
- package/components/Card.js +8 -4
- package/components/Card.module.css +10 -0
- package/components/Cascader.js +1 -0
- package/components/CatalogIcon.js +1 -0
- package/components/CharacterPicker.js +1 -0
- package/components/Checkbox.d.ts +5 -3
- package/components/Checkbox.js +17 -5
- package/components/ColorField.js +1 -0
- package/components/ColorPicker.js +1 -0
- package/components/Combobox.d.ts +4 -2
- package/components/Combobox.js +10 -3
- package/components/CommandPalette.js +1 -0
- package/components/ContextMenu.js +1 -0
- package/components/ContextMenuPanel.js +1 -0
- package/components/ContributionCalendar.js +1 -0
- package/components/ContributionCell.js +1 -0
- package/components/CopyButton.js +1 -0
- package/components/DataTable.js +1 -0
- package/components/DatePicker.js +8 -4
- package/components/DateRangePicker.js +1 -0
- package/components/Descriptions.js +1 -0
- package/components/Dialog.d.ts +9 -3
- package/components/Dialog.js +33 -11
- package/components/DialogVariants.js +1 -0
- package/components/DisclosureChevron.js +1 -0
- package/components/Divider.js +1 -0
- package/components/Drawer.d.ts +5 -2
- package/components/Drawer.js +20 -5
- package/components/EmojiPicker.js +1 -0
- package/components/EmptyState.js +1 -0
- package/components/FieldLabel.d.ts +2 -1
- package/components/FieldLabel.js +1 -0
- package/components/FieldMessages.d.ts +3 -2
- package/components/FieldMessages.js +1 -0
- package/components/FileDropOverlay.js +1 -0
- package/components/FileDropZone.js +1 -0
- package/components/FilePicker.d.ts +3 -2
- package/components/FilePicker.js +21 -5
- package/components/FileSelectionFeedback.js +1 -0
- package/components/FileTree.js +1 -0
- package/components/Form.js +1 -0
- package/components/FormErrorSummary.js +1 -0
- package/components/FormField.js +1 -0
- package/components/FormGroup.js +1 -0
- package/components/FormLayout.js +1 -0
- package/components/IconButton.js +1 -0
- package/components/IconPicker.js +1 -0
- package/components/Indicator.js +1 -0
- package/components/Input.js +1 -0
- package/components/Layout.js +1 -0
- package/components/LoadingOverlay.js +1 -0
- package/components/LoadingState.js +1 -0
- package/components/Markdown.js +1 -0
- package/components/Menu.js +1 -0
- package/components/MenuItem.d.ts +8 -3
- package/components/MenuItem.js +24 -1
- package/components/MenuItemContent.js +1 -0
- package/components/MultiSelect.js +1 -0
- package/components/NavBar.d.ts +2 -1
- package/components/NavBar.js +3 -1
- package/components/NumberInput.js +1 -0
- package/components/Page.d.ts +2 -1
- package/components/Page.js +4 -2
- package/components/Page.module.css +9 -0
- package/components/Pagination.d.ts +4 -1
- package/components/Pagination.js +28 -14
- package/components/PasskeyItem.js +1 -0
- package/components/PasswordField.js +1 -0
- package/components/PinInput.js +1 -0
- package/components/Placeholder.js +1 -0
- package/components/Popconfirm.js +1 -0
- package/components/Popover.d.ts +3 -2
- package/components/Popover.js +9 -2
- package/components/Progress.js +1 -0
- package/components/RadioGroup.js +1 -0
- package/components/RangeSlider.js +1 -0
- package/components/ResizablePanel.js +1 -0
- package/components/ResourceCard.js +1 -0
- package/components/SearchField.js +1 -0
- package/components/Section.js +1 -0
- package/components/Segmented.d.ts +1 -0
- package/components/Segmented.js +32 -20
- package/components/Select.d.ts +3 -1
- package/components/Select.js +12 -2
- package/components/SelectOptionContent.js +1 -0
- package/components/SelectSettingRow.js +1 -0
- package/components/SelectTrigger.js +1 -0
- package/components/SelectionTag.js +1 -0
- package/components/SessionItem.js +1 -0
- package/components/SettingRow.d.ts +3 -2
- package/components/SettingRow.js +9 -2
- package/components/SettingsLayout.js +1 -0
- package/components/ShortcutInput.js +1 -0
- package/components/SideBar.js +1 -0
- package/components/SidebarNavigation.js +1 -0
- package/components/Skeleton.js +1 -0
- package/components/SkeletonRows.js +1 -0
- package/components/SkinTonePicker.js +1 -0
- package/components/Slider.js +1 -0
- package/components/Spinner.js +1 -0
- package/components/SplitButton.js +1 -0
- package/components/Statistic.js +1 -0
- package/components/Steps.js +1 -0
- package/components/Switch.d.ts +5 -0
- package/components/Switch.js +26 -2
- package/components/Switch.module.css +101 -59
- package/components/SwitchSettingRow.js +1 -0
- package/components/SymbolPicker.js +1 -0
- package/components/TabList.js +1 -0
- package/components/Table.js +1 -0
- package/components/TableColumnFilter.js +1 -0
- package/components/TableColumnVisibility.js +1 -0
- package/components/TableMarkup.d.ts +2 -2
- package/components/TableMarkup.js +5 -2
- package/components/TableOfContents.js +1 -0
- package/components/Tabs.js +1 -0
- package/components/TagInput.js +1 -0
- package/components/TextAreaSettingRow.js +1 -0
- package/components/TextSettingRow.js +1 -0
- package/components/Textarea.js +1 -0
- package/components/ThemePicker.js +1 -0
- package/components/ThemeProvider.js +1 -0
- package/components/ThemeStylePicker.js +1 -0
- package/components/TimeColumns.js +8 -1
- package/components/Timeline.js +1 -0
- package/components/Toast.js +4 -1
- package/components/ToastProvider.js +1 -0
- package/components/Tooltip.js +7 -3
- package/components/TreeGuides.js +1 -0
- package/components/TreeSelect.js +1 -0
- package/components/TreeTable.js +1 -0
- package/components/UIProvider.d.ts +1 -0
- package/components/UIProvider.js +2 -0
- package/components/UnderlinedTab.js +1 -0
- package/components/Upload.js +1 -0
- package/components/UploadList.js +1 -0
- package/components/UploadListItem.js +1 -0
- package/components/UptimeChart.js +1 -0
- package/components/VirtualPickerList.js +1 -0
- package/components/appearance.js +1 -0
- package/components/calendarNow.js +1 -0
- package/components/characterCatalog.js +1 -0
- package/components/color.js +1 -0
- package/components/contribution.js +1 -0
- package/components/createToaster.js +1 -0
- package/components/dateConstraints.js +1 -0
- package/components/field.d.ts +7 -7
- package/components/field.js +3 -2
- package/components/fileSelection.js +1 -0
- package/components/hierarchy.js +1 -0
- package/components/iconCatalog.js +1 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +3 -0
- package/components/menuFocus.js +1 -0
- package/components/menuPointer.js +1 -0
- package/components/menuTypes.js +1 -0
- package/components/motion.js +1 -0
- package/components/rangeMath.js +1 -0
- package/components/settingRowControl.js +1 -0
- package/components/surfacePortal.js +1 -0
- package/components/tooltipState.js +1 -0
- package/components/types.js +1 -0
- package/components/uploadTypes.js +1 -0
- package/components/useFormState.js +1 -0
- package/components/useHierarchy.js +1 -0
- package/components/useMenuLayers.js +1 -0
- package/components/useModalFocus.d.ts +1 -1
- package/components/useModalFocus.js +9 -3
- package/components/useModalScrollLock.js +1 -0
- package/components/usePopover.js +1 -0
- package/components/usePortalRoot.d.ts +2 -0
- package/components/usePortalRoot.js +12 -0
- package/components/useTabIndicator.js +1 -0
- package/components/useUIText.d.ts +5 -0
- package/components/useUIText.js +14 -0
- package/components/useUploadQueue.js +1 -0
- package/package.json +1 -1
package/components/DatePicker.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { createElement } from "react";
|
|
3
4
|
import { fieldTriggerProps, useFieldControl } from "./field.js";
|
|
@@ -9,6 +10,7 @@ import { Calendar } from "./Calendar.js";
|
|
|
9
10
|
import { TimeColumns } from "./TimeColumns.js";
|
|
10
11
|
import { Button } from "./Button.js";
|
|
11
12
|
import s from "./DatePicker.module.css";
|
|
13
|
+
import { useUIText } from "./useUIText.js";
|
|
12
14
|
import {
|
|
13
15
|
boundedDate,
|
|
14
16
|
isDateAllowed
|
|
@@ -26,7 +28,7 @@ function SingleDatePicker({
|
|
|
26
28
|
seconds = false,
|
|
27
29
|
timeZone,
|
|
28
30
|
clearable = false,
|
|
29
|
-
placeholder
|
|
31
|
+
placeholder,
|
|
30
32
|
disabled,
|
|
31
33
|
readOnly,
|
|
32
34
|
name,
|
|
@@ -39,6 +41,8 @@ function SingleDatePicker({
|
|
|
39
41
|
disabledDate,
|
|
40
42
|
...aria
|
|
41
43
|
}) {
|
|
44
|
+
const { text } = useUIText();
|
|
45
|
+
placeholder ??= text("\u8BF7\u9009\u62E9", "Select", "\u8ACB\u9078\u64C7");
|
|
42
46
|
const constraints = { minDate, maxDate, disabledDate };
|
|
43
47
|
const field = useFieldControl({
|
|
44
48
|
id: controlId,
|
|
@@ -168,7 +172,7 @@ function SingleDatePicker({
|
|
|
168
172
|
close();
|
|
169
173
|
}
|
|
170
174
|
},
|
|
171
|
-
children: mode === "date" ? "\u4ECA\u5929" : "\u6B64\u523B"
|
|
175
|
+
children: mode === "date" ? text("\u4ECA\u5929", "Today") : text("\u6B64\u523B", "Now")
|
|
172
176
|
}
|
|
173
177
|
),
|
|
174
178
|
(clearable || mode !== "date") && /* @__PURE__ */ jsxs("div", { className: s.rangeActions, children: [
|
|
@@ -182,7 +186,7 @@ function SingleDatePicker({
|
|
|
182
186
|
onChange("");
|
|
183
187
|
close();
|
|
184
188
|
},
|
|
185
|
-
children: "\u6E05\u7A7A"
|
|
189
|
+
children: text("\u6E05\u7A7A", "Clear")
|
|
186
190
|
}
|
|
187
191
|
),
|
|
188
192
|
mode !== "date" && /* @__PURE__ */ jsx(
|
|
@@ -192,7 +196,7 @@ function SingleDatePicker({
|
|
|
192
196
|
size: "small",
|
|
193
197
|
onClick: commit,
|
|
194
198
|
disabled: mode !== "time" && !isDateAllowed(date, constraints),
|
|
195
|
-
children: "\u786E\u5B9A"
|
|
199
|
+
children: text("\u786E\u5B9A", "Apply", "\u78BA\u5B9A")
|
|
196
200
|
}
|
|
197
201
|
)
|
|
198
202
|
] })
|
package/components/Dialog.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ReactNode, type RefObject } from "react";
|
|
2
|
-
export declare function Dialog({ open: requestedOpen, onClose, title, children, footer, wide, size, role, descriptionId, busy, variant, headerIcon, tone, returnFocus, }: {
|
|
2
|
+
export declare function Dialog({ open: requestedOpen, onClose, title, children, footer, wide, size, role, descriptionId, busy, variant, headerIcon, tone, initialFocus, onAfterClose, className, returnFocus, fallbackFocus, portalContainer, closeLabel, }: {
|
|
3
3
|
open: boolean;
|
|
4
4
|
onClose(): void;
|
|
5
|
-
title:
|
|
5
|
+
title: ReactNode;
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
footer?: ReactNode;
|
|
8
8
|
wide?: boolean;
|
|
@@ -14,5 +14,11 @@ export declare function Dialog({ open: requestedOpen, onClose, title, children,
|
|
|
14
14
|
headerIcon?: ReactNode;
|
|
15
15
|
tone?: "neutral" | "info" | "success" | "warning" | "danger";
|
|
16
16
|
/** Trigger to focus after closing, including surfaces opened asynchronously. */
|
|
17
|
+
initialFocus?: RefObject<HTMLElement | null>;
|
|
18
|
+
onAfterClose?(): void;
|
|
19
|
+
className?: string;
|
|
17
20
|
returnFocus?: RefObject<HTMLElement | null>;
|
|
18
|
-
|
|
21
|
+
fallbackFocus?: RefObject<HTMLElement | null>;
|
|
22
|
+
closeLabel?: string;
|
|
23
|
+
portalContainer?: HTMLElement | null;
|
|
24
|
+
}): import("react").ReactPortal | null;
|
package/components/Dialog.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { usePortalRoot } from "./usePortalRoot.js";
|
|
2
4
|
import {
|
|
3
5
|
useId,
|
|
4
6
|
useEffect,
|
|
@@ -33,12 +35,26 @@ function Dialog({
|
|
|
33
35
|
variant = "default",
|
|
34
36
|
headerIcon,
|
|
35
37
|
tone = "neutral",
|
|
36
|
-
|
|
38
|
+
initialFocus,
|
|
39
|
+
onAfterClose,
|
|
40
|
+
className = "",
|
|
41
|
+
returnFocus,
|
|
42
|
+
fallbackFocus,
|
|
43
|
+
portalContainer,
|
|
44
|
+
closeLabel = "\u5173\u95ED\u5F39\u7A97"
|
|
37
45
|
}) {
|
|
46
|
+
const defaultRoot = usePortalRoot();
|
|
47
|
+
const portalRoot = portalContainer ?? defaultRoot;
|
|
38
48
|
const owner = useSurfacePortal(), open = requestedOpen && owner?.active !== false;
|
|
39
49
|
const { ref, host, setRef } = useSurfaceHost();
|
|
40
50
|
const titleId = useId();
|
|
41
|
-
const
|
|
51
|
+
const afterClose = useRef(onAfterClose);
|
|
52
|
+
afterClose.current = onAfterClose;
|
|
53
|
+
const { rememberFocus, restoreFocus } = useModalFocus(
|
|
54
|
+
ref,
|
|
55
|
+
returnFocus,
|
|
56
|
+
fallbackFocus
|
|
57
|
+
);
|
|
42
58
|
const [closing, setClosing] = useState(false);
|
|
43
59
|
useModalScrollLock(open || closing);
|
|
44
60
|
const opened = useRef(open);
|
|
@@ -51,20 +67,24 @@ function Dialog({
|
|
|
51
67
|
}, [requestedOpen, owner?.active, onClose]);
|
|
52
68
|
useEffect(() => {
|
|
53
69
|
const node = ref.current;
|
|
70
|
+
if (!node) return;
|
|
54
71
|
return () => cancelMotion(node);
|
|
55
|
-
}, []);
|
|
72
|
+
}, [portalRoot]);
|
|
56
73
|
useLayoutEffect(() => {
|
|
57
74
|
const element = ref.current;
|
|
75
|
+
if (!element) return;
|
|
58
76
|
if (open) {
|
|
59
77
|
element.inert = false;
|
|
60
78
|
setClosing(false);
|
|
61
79
|
if (!element.open) {
|
|
62
80
|
rememberFocus();
|
|
63
81
|
element.showModal();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
initialFocus?.current?.focus({ preventScroll: true });
|
|
83
|
+
if (!initialFocus?.current)
|
|
84
|
+
element.querySelector(
|
|
85
|
+
"[data-dialog-initial-focus]:not(:disabled)"
|
|
86
|
+
)?.focus({ preventScroll: true });
|
|
87
|
+
if (!initialFocus?.current && !element.querySelector("[data-dialog-initial-focus]:not(:disabled)"))
|
|
68
88
|
element.querySelector(
|
|
69
89
|
'input:not([disabled]):not([readonly]):not([type="hidden"]):not([type="file"]):not([type="checkbox"]):not([type="radio"]),textarea:not([disabled]),[role="combobox"]'
|
|
70
90
|
)?.focus({ preventScroll: true });
|
|
@@ -80,13 +100,15 @@ function Dialog({
|
|
|
80
100
|
element.close();
|
|
81
101
|
restoreFocus();
|
|
82
102
|
setClosing(false);
|
|
103
|
+
afterClose.current?.();
|
|
83
104
|
});
|
|
84
|
-
}, [open, rememberFocus, restoreFocus]);
|
|
105
|
+
}, [open, portalRoot, initialFocus, rememberFocus, restoreFocus]);
|
|
85
106
|
const backdropDown = useRef(false);
|
|
86
107
|
const outside = (event) => {
|
|
87
108
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
88
109
|
return event.target === event.currentTarget && (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom);
|
|
89
110
|
};
|
|
111
|
+
if (!portalRoot) return null;
|
|
90
112
|
return createPortal(
|
|
91
113
|
/* @__PURE__ */ jsx(SurfacePortalContext, { value: { host, active: open }, children: /* @__PURE__ */ jsx(FieldContext, { value: null, children: /* @__PURE__ */ jsxs(
|
|
92
114
|
"dialog",
|
|
@@ -99,7 +121,7 @@ function Dialog({
|
|
|
99
121
|
"data-variant": variant,
|
|
100
122
|
"data-tone": content.tone,
|
|
101
123
|
"data-header-icon": !!content.headerIcon,
|
|
102
|
-
className: `${s.dialog} ${wide || size === "large" ? s.wide : ""} ${size === "small" ? s.small : ""} ${closing ? s.closing : ""}`,
|
|
124
|
+
className: `${s.dialog} ${className} ${wide || size === "large" ? s.wide : ""} ${size === "small" ? s.small : ""} ${closing ? s.closing : ""}`,
|
|
103
125
|
onCancel: (e) => {
|
|
104
126
|
e.preventDefault();
|
|
105
127
|
e.stopPropagation();
|
|
@@ -118,14 +140,14 @@ function Dialog({
|
|
|
118
140
|
content.headerIcon && /* @__PURE__ */ jsx("span", { className: s.dialogIcon, "aria-hidden": "true", children: content.headerIcon }),
|
|
119
141
|
/* @__PURE__ */ jsx("h2", { id: titleId, children: content.title })
|
|
120
142
|
] }),
|
|
121
|
-
/* @__PURE__ */ jsx(IconButton, { label:
|
|
143
|
+
/* @__PURE__ */ jsx(IconButton, { label: closeLabel, onClick: onClose, disabled: busy, children: /* @__PURE__ */ jsx(X, {}) })
|
|
122
144
|
] }),
|
|
123
145
|
/* @__PURE__ */ jsx("div", { className: s.dialogBody, children: content.children }),
|
|
124
146
|
content.footer && /* @__PURE__ */ jsx("footer", { className: s.dialogFooter, children: content.footer })
|
|
125
147
|
]
|
|
126
148
|
}
|
|
127
149
|
) }) }),
|
|
128
|
-
|
|
150
|
+
portalRoot
|
|
129
151
|
);
|
|
130
152
|
}
|
|
131
153
|
export {
|
package/components/Divider.js
CHANGED
package/components/Drawer.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type DrawerProps = {
|
|
|
4
4
|
open: boolean;
|
|
5
5
|
onClose(): void;
|
|
6
6
|
onAfterClose?(): void;
|
|
7
|
-
title:
|
|
7
|
+
title: ReactNode;
|
|
8
8
|
description?: ReactNode;
|
|
9
9
|
children: ReactNode;
|
|
10
10
|
footer?: ReactNode;
|
|
@@ -15,6 +15,9 @@ export type DrawerProps = {
|
|
|
15
15
|
closeOnBackdrop?: boolean;
|
|
16
16
|
initialFocus?: RefObject<HTMLElement | null>;
|
|
17
17
|
returnFocus?: RefObject<HTMLElement | null>;
|
|
18
|
+
fallbackFocus?: RefObject<HTMLElement | null>;
|
|
19
|
+
closeLabel?: string;
|
|
20
|
+
portalContainer?: HTMLElement | null;
|
|
18
21
|
className?: string;
|
|
19
22
|
};
|
|
20
|
-
export declare function Drawer({ open: requestedOpen, onClose, onAfterClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, returnFocus, className, }: DrawerProps): import("react").ReactPortal;
|
|
23
|
+
export declare function Drawer({ open: requestedOpen, onClose, onAfterClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, returnFocus, fallbackFocus, portalContainer, closeLabel, className, }: DrawerProps): import("react").ReactPortal | null;
|
package/components/Drawer.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { usePortalRoot } from "./usePortalRoot.js";
|
|
2
4
|
import {
|
|
3
5
|
useEffect,
|
|
4
6
|
useId,
|
|
@@ -40,11 +42,20 @@ function Drawer({
|
|
|
40
42
|
closeOnBackdrop = true,
|
|
41
43
|
initialFocus,
|
|
42
44
|
returnFocus,
|
|
45
|
+
fallbackFocus,
|
|
46
|
+
portalContainer,
|
|
47
|
+
closeLabel = "\u5173\u95ED\u5F39\u7A97",
|
|
43
48
|
className = ""
|
|
44
49
|
}) {
|
|
50
|
+
const defaultRoot = usePortalRoot();
|
|
51
|
+
const portalRoot = portalContainer ?? defaultRoot;
|
|
45
52
|
const owner = useSurfacePortal(), open = requestedOpen && owner?.active !== false;
|
|
46
53
|
const { ref, host, setRef } = useSurfaceHost();
|
|
47
|
-
const { rememberFocus, restoreFocus } = useModalFocus(
|
|
54
|
+
const { rememberFocus, restoreFocus } = useModalFocus(
|
|
55
|
+
ref,
|
|
56
|
+
returnFocus,
|
|
57
|
+
fallbackFocus
|
|
58
|
+
);
|
|
48
59
|
const opened = useRef(open), backdropDown = useRef(false), titleId = useId(), descriptionId = useId();
|
|
49
60
|
const [closing, setClosing] = useState(false);
|
|
50
61
|
const afterClose = useRef(onAfterClose);
|
|
@@ -56,12 +67,14 @@ function Drawer({
|
|
|
56
67
|
}, [requestedOpen, owner?.active, onClose]);
|
|
57
68
|
useEffect(() => {
|
|
58
69
|
const node = ref.current;
|
|
70
|
+
if (!node) return;
|
|
59
71
|
return () => {
|
|
60
72
|
cancelMotion(node);
|
|
61
73
|
};
|
|
62
|
-
}, []);
|
|
74
|
+
}, [portalRoot]);
|
|
63
75
|
useLayoutEffect(() => {
|
|
64
76
|
const node = ref.current;
|
|
77
|
+
if (!node) return;
|
|
65
78
|
if (open) {
|
|
66
79
|
node.inert = false;
|
|
67
80
|
setClosing(false);
|
|
@@ -92,16 +105,18 @@ function Drawer({
|
|
|
92
105
|
setClosing(false);
|
|
93
106
|
afterClose.current?.();
|
|
94
107
|
});
|
|
95
|
-
}, [open, placement, initialFocus, rememberFocus, restoreFocus]);
|
|
108
|
+
}, [open, portalRoot, placement, initialFocus, rememberFocus, restoreFocus]);
|
|
96
109
|
const outside = (event) => {
|
|
97
110
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
98
111
|
return event.target === event.currentTarget && (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom);
|
|
99
112
|
};
|
|
100
113
|
const length = typeof size === "number" ? `${Number.isFinite(size) ? Math.max(180, size) : 420}px` : size;
|
|
114
|
+
if (!portalRoot) return null;
|
|
101
115
|
return createPortal(
|
|
102
116
|
/* @__PURE__ */ jsx(SurfacePortalContext, { value: { host, active: open }, children: /* @__PURE__ */ jsx(FieldContext, { value: null, children: /* @__PURE__ */ jsxs(
|
|
103
117
|
"dialog",
|
|
104
118
|
{
|
|
119
|
+
role: "dialog",
|
|
105
120
|
ref: setRef,
|
|
106
121
|
tabIndex: -1,
|
|
107
122
|
"aria-labelledby": titleId,
|
|
@@ -131,14 +146,14 @@ function Drawer({
|
|
|
131
146
|
/* @__PURE__ */ jsx("h2", { id: titleId, children: title }),
|
|
132
147
|
description != null && /* @__PURE__ */ jsx("div", { id: descriptionId, className: s.description, children: description })
|
|
133
148
|
] }),
|
|
134
|
-
closable && /* @__PURE__ */ jsx(IconButton, { label:
|
|
149
|
+
closable && /* @__PURE__ */ jsx(IconButton, { label: closeLabel, onClick: onClose, children: /* @__PURE__ */ jsx(X, {}) })
|
|
135
150
|
] }),
|
|
136
151
|
/* @__PURE__ */ jsx("div", { className: s.body, "data-drawer-body": true, children }),
|
|
137
152
|
footer && /* @__PURE__ */ jsx("footer", { className: s.footer, children: footer })
|
|
138
153
|
]
|
|
139
154
|
}
|
|
140
155
|
) }) }),
|
|
141
|
-
|
|
156
|
+
portalRoot
|
|
142
157
|
);
|
|
143
158
|
}
|
|
144
159
|
export {
|
package/components/EmptyState.js
CHANGED
package/components/FieldLabel.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FileConstraints, type FileRejection, type FileSelectionResult } from "./fileSelection";
|
|
2
|
-
|
|
2
|
+
import { type FieldOptions } from "./field";
|
|
3
|
+
export type FilePickerProps = FileConstraints & Pick<FieldOptions, "id" | "disabled" | "aria-describedby" | "aria-invalid"> & {
|
|
3
4
|
onFiles(files: File[]): void;
|
|
4
5
|
onReject?(rejections: FileRejection[]): void;
|
|
5
6
|
onValidation?(result: FileSelectionResult): void;
|
|
@@ -7,4 +8,4 @@ export type FilePickerProps = FileConstraints & {
|
|
|
7
8
|
label?: string;
|
|
8
9
|
showErrors?: boolean;
|
|
9
10
|
};
|
|
10
|
-
export declare function FilePicker({ onFiles, onReject, onValidation, disabled, label, showErrors, ...constraints }: FilePickerProps): import("react").JSX.Element;
|
|
11
|
+
export declare function FilePicker({ onFiles, onReject, onValidation, disabled, id: controlId, "aria-describedby": describedBy, "aria-invalid": invalid, label, showErrors, ...constraints }: FilePickerProps): import("react").JSX.Element;
|
package/components/FilePicker.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { useId, useRef, useState } from "react";
|
|
3
4
|
import { Upload } from "lucide-react";
|
|
@@ -6,15 +7,25 @@ import {
|
|
|
6
7
|
validateFiles
|
|
7
8
|
} from "./fileSelection.js";
|
|
8
9
|
import { FileSelectionFeedback } from "./FileSelectionFeedback.js";
|
|
10
|
+
import { useFieldControl, joinIds } from "./field.js";
|
|
9
11
|
function FilePicker({
|
|
10
12
|
onFiles,
|
|
11
13
|
onReject,
|
|
12
14
|
onValidation,
|
|
13
|
-
disabled
|
|
15
|
+
disabled,
|
|
16
|
+
id: controlId,
|
|
17
|
+
"aria-describedby": describedBy,
|
|
18
|
+
"aria-invalid": invalid,
|
|
14
19
|
label = "\u9009\u62E9\u6587\u4EF6",
|
|
15
20
|
showErrors = true,
|
|
16
21
|
...constraints
|
|
17
22
|
}) {
|
|
23
|
+
const field = useFieldControl({
|
|
24
|
+
id: controlId,
|
|
25
|
+
disabled,
|
|
26
|
+
"aria-describedby": describedBy,
|
|
27
|
+
"aria-invalid": invalid
|
|
28
|
+
});
|
|
18
29
|
const ref = useRef(null), id = useId(), [rejections, setRejections] = useState([]);
|
|
19
30
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
20
31
|
/* @__PURE__ */ jsx(
|
|
@@ -24,11 +35,11 @@ function FilePicker({
|
|
|
24
35
|
type: "file",
|
|
25
36
|
multiple: constraints.multiple !== false,
|
|
26
37
|
accept: constraints.accept,
|
|
27
|
-
disabled,
|
|
38
|
+
disabled: field.disabled,
|
|
28
39
|
hidden: true,
|
|
29
40
|
onChange: (e) => {
|
|
30
41
|
const files = Array.from(e.target.files || []);
|
|
31
|
-
if (files.length && !disabled) {
|
|
42
|
+
if (files.length && !field.disabled && !e.currentTarget.matches(":disabled")) {
|
|
32
43
|
const result = validateFiles(files, constraints);
|
|
33
44
|
setRejections(result.rejected);
|
|
34
45
|
onValidation?.(result);
|
|
@@ -42,8 +53,13 @@ function FilePicker({
|
|
|
42
53
|
/* @__PURE__ */ jsxs(
|
|
43
54
|
Button,
|
|
44
55
|
{
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
id: field.id,
|
|
57
|
+
disabled: field.disabled,
|
|
58
|
+
"aria-invalid": field.invalid,
|
|
59
|
+
"aria-describedby": joinIds(
|
|
60
|
+
field.descriptionId,
|
|
61
|
+
showErrors && rejections.length ? id : void 0
|
|
62
|
+
),
|
|
47
63
|
onClick: () => ref.current?.click(),
|
|
48
64
|
children: [
|
|
49
65
|
/* @__PURE__ */ jsx(Upload, {}),
|
package/components/FileTree.js
CHANGED
package/components/Form.js
CHANGED
package/components/FormField.js
CHANGED
package/components/FormGroup.js
CHANGED
package/components/FormLayout.js
CHANGED
package/components/IconButton.js
CHANGED
package/components/IconPicker.js
CHANGED
package/components/Indicator.js
CHANGED
package/components/Input.js
CHANGED
package/components/Layout.js
CHANGED
package/components/Markdown.js
CHANGED
package/components/Menu.js
CHANGED
package/components/MenuItem.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type MenuItemContentProps } from "./MenuItemContent";
|
|
2
|
-
import type
|
|
2
|
+
import { type HTMLAttributes, type ReactElement, type ReactNode } from "react";
|
|
3
3
|
export type MenuItemProps = Omit<HTMLAttributes<HTMLElement>, "children" | "prefix"> & MenuItemContentProps & {
|
|
4
|
-
as?: "button" | "div";
|
|
4
|
+
as?: "button" | "div" | "a";
|
|
5
|
+
asChild?: boolean;
|
|
6
|
+
children?: ReactElement<HTMLAttributes<HTMLElement>>;
|
|
7
|
+
href?: string;
|
|
8
|
+
target?: string;
|
|
9
|
+
rel?: string;
|
|
5
10
|
prefix?: ReactNode;
|
|
6
11
|
shortcut?: string;
|
|
7
12
|
trailing?: ReactNode;
|
|
@@ -12,4 +17,4 @@ export type MenuItemProps = Omit<HTMLAttributes<HTMLElement>, "children" | "pref
|
|
|
12
17
|
selection?: "check" | "checkbox" | "radio";
|
|
13
18
|
tone?: "default" | "danger";
|
|
14
19
|
};
|
|
15
|
-
export declare function MenuItem({ as, prefix, label, description, icon, reserveIcon, shortcut, trailing, meta, selected, active, disabled, selection, tone, className, ...props }: MenuItemProps): import("react").JSX.Element;
|
|
20
|
+
export declare function MenuItem({ as, asChild, children, prefix, label, description, icon, reserveIcon, shortcut, trailing, meta, selected, active, disabled, selection, tone, className, ...props }: MenuItemProps): import("react").JSX.Element;
|
package/components/MenuItem.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { MenuItemContent } from "./MenuItemContent.js";
|
|
4
|
+
import {
|
|
5
|
+
cloneElement,
|
|
6
|
+
isValidElement
|
|
7
|
+
} from "react";
|
|
3
8
|
import { Check } from "lucide-react";
|
|
4
9
|
import s from "./MenuItem.module.css";
|
|
5
10
|
function MenuItem({
|
|
6
11
|
as = "button",
|
|
12
|
+
asChild = false,
|
|
13
|
+
children,
|
|
7
14
|
prefix,
|
|
8
15
|
label,
|
|
9
16
|
description,
|
|
@@ -44,7 +51,23 @@ function MenuItem({
|
|
|
44
51
|
"data-tone": tone,
|
|
45
52
|
"aria-disabled": disabled || void 0
|
|
46
53
|
};
|
|
47
|
-
|
|
54
|
+
if (asChild && isValidElement(children)) {
|
|
55
|
+
return cloneElement(children, {
|
|
56
|
+
...common,
|
|
57
|
+
className: `${common.className} ${children.props.className ?? ""}`,
|
|
58
|
+
tabIndex: disabled ? -1 : props.tabIndex ?? children.props.tabIndex,
|
|
59
|
+
onClick: (event) => {
|
|
60
|
+
if (disabled) {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
children.props.onClick?.(event);
|
|
65
|
+
if (!event.defaultPrevented) props.onClick?.(event);
|
|
66
|
+
},
|
|
67
|
+
children: content
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return as === "a" ? /* @__PURE__ */ jsx("a", { ...common, tabIndex: disabled ? -1 : props.tabIndex, children: content }) : as === "div" ? /* @__PURE__ */ jsx("div", { ...common, children: content }) : /* @__PURE__ */ jsx("button", { type: "button", ...common, disabled, children: content });
|
|
48
71
|
}
|
|
49
72
|
export {
|
|
50
73
|
MenuItem
|
package/components/NavBar.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type NavBarItem = NavigationItem | {
|
|
|
8
8
|
children: readonly NavigationItem[];
|
|
9
9
|
};
|
|
10
10
|
export type NavBarProps = {
|
|
11
|
+
as?: "header" | "div";
|
|
11
12
|
items: readonly NavBarItem[];
|
|
12
13
|
active: string;
|
|
13
14
|
onNavigate?(path: string): void;
|
|
@@ -17,4 +18,4 @@ export type NavBarProps = {
|
|
|
17
18
|
label?: string;
|
|
18
19
|
className?: string;
|
|
19
20
|
};
|
|
20
|
-
export declare function NavBar({ items, active, onNavigate, brand, homePath, actions, label, className, }: NavBarProps): import("react").JSX.Element;
|
|
21
|
+
export declare function NavBar({ as: Root, items, active, onNavigate, brand, homePath, actions, label, className, }: NavBarProps): import("react").JSX.Element;
|