@sia.soul/sia-react-ui 0.1.6 → 0.1.8
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/dist/{Select-GiTHMScg.d.cts → Select-CVvF4mcy.d.cts} +14 -0
- package/dist/{Select-rtDktLYY.d.ts → Select-Ce2Irbpt.d.ts} +14 -0
- package/dist/{chunk-PX6BOFTW.js → chunk-F3VH6LJH.js} +2 -4
- package/dist/chunk-FVQON65A.js +1331 -0
- package/dist/{chunk-EJ23MVR6.js → chunk-JJVD2ITI.js} +592 -1
- package/dist/chunk-JMVCKK34.js +1494 -0
- package/dist/{chunk-MJUTLEEE.js → chunk-PXQUIG6V.js} +2 -2
- package/dist/{core-D8BSMfHD.d.ts → core-ByQQ3hq2.d.ts} +1 -1
- package/dist/{core-CBtbeAms.d.cts → core-Dwc_30PN.d.cts} +1 -1
- package/dist/core.cjs +1094 -715
- package/dist/core.css +142 -11
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +7 -9
- package/dist/index.cjs +4123 -3971
- package/dist/index.css +142 -11
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +76 -230
- package/dist/rich-text-editor.cjs +11 -2
- package/dist/rich-text-editor.js +2 -3
- package/dist/{select-date-range-CQ1vmze_.d.ts → select-date-range-D-JMfpwD.d.ts} +1 -1
- package/dist/{select-date-range-DRmGaEzP.d.cts → select-date-range-l-xgB959.d.cts} +1 -1
- package/dist/select-date-range.cjs +1092 -77
- package/dist/select-date-range.d.cts +2 -2
- package/dist/select-date-range.d.ts +2 -2
- package/dist/select-date-range.js +4 -3
- package/package.json +1 -1
- package/dist/chunk-IHTODT53.js +0 -586
- package/dist/chunk-R7BVDN3Q.js +0 -366
- package/dist/chunk-S2JAJCLN.js +0 -2154
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-
|
|
1
|
+
export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-l-xgB959.cjs';
|
|
2
2
|
import 'react';
|
|
3
3
|
import './shared-DAYZvZVu.cjs';
|
|
4
|
-
import './Select-
|
|
4
|
+
import './Select-CVvF4mcy.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-
|
|
1
|
+
export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-D-JMfpwD.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import './shared-DAYZvZVu.js';
|
|
4
|
-
import './Select-
|
|
4
|
+
import './Select-Ce2Irbpt.js';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SelectDateRange
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-PXQUIG6V.js";
|
|
4
|
+
import "./chunk-JMVCKK34.js";
|
|
5
|
+
import "./chunk-JJVD2ITI.js";
|
|
6
|
+
import "./chunk-MBS2HXLZ.js";
|
|
6
7
|
import "./chunk-EJDPRAU2.js";
|
|
7
8
|
export {
|
|
8
9
|
SelectDateRange
|
package/package.json
CHANGED
package/dist/chunk-IHTODT53.js
DELETED
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Button
|
|
3
|
-
} from "./chunk-MBS2HXLZ.js";
|
|
4
|
-
import {
|
|
5
|
-
Icon,
|
|
6
|
-
PopupPortal
|
|
7
|
-
} from "./chunk-EJ23MVR6.js";
|
|
8
|
-
import {
|
|
9
|
-
useControllableState,
|
|
10
|
-
usePlaceholderMode
|
|
11
|
-
} from "./chunk-EJDPRAU2.js";
|
|
12
|
-
|
|
13
|
-
// src/components/Navigation.tsx
|
|
14
|
-
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
15
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
-
function MenuPopup({
|
|
17
|
-
anchorRef,
|
|
18
|
-
open,
|
|
19
|
-
placement,
|
|
20
|
-
menuId,
|
|
21
|
-
theme,
|
|
22
|
-
children,
|
|
23
|
-
onMouseEnter,
|
|
24
|
-
onMouseLeave
|
|
25
|
-
}) {
|
|
26
|
-
const [mounted, setMounted] = useState(open);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (open) {
|
|
29
|
-
setMounted(true);
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
const timer = window.setTimeout(() => setMounted(false), 160);
|
|
33
|
-
return () => window.clearTimeout(timer);
|
|
34
|
-
}, [open]);
|
|
35
|
-
return /* @__PURE__ */ jsx(
|
|
36
|
-
PopupPortal,
|
|
37
|
-
{
|
|
38
|
-
anchorRef,
|
|
39
|
-
open: mounted,
|
|
40
|
-
placement,
|
|
41
|
-
offset: 4,
|
|
42
|
-
className: `sia-menu__popup sia-menu--${theme}${open ? " is-open" : " is-closing"}`,
|
|
43
|
-
"data-sia-menu-owner": menuId,
|
|
44
|
-
onMouseEnter,
|
|
45
|
-
onMouseLeave,
|
|
46
|
-
children: /* @__PURE__ */ jsx("ul", { className: "sia-menu__popup-list", role: "menu", children })
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
function MenuEntry({
|
|
51
|
-
item,
|
|
52
|
-
level,
|
|
53
|
-
parents,
|
|
54
|
-
props
|
|
55
|
-
}) {
|
|
56
|
-
const anchorRef = useRef(null);
|
|
57
|
-
const closeTimerRef = useRef(void 0);
|
|
58
|
-
const hasChildren = Boolean(item.children?.length);
|
|
59
|
-
const isOpen = props.open.includes(item.key);
|
|
60
|
-
const isSelected = props.selected.includes(item.key);
|
|
61
|
-
const path = [item.key, ...parents];
|
|
62
|
-
const collapsed = props.inlineCollapsed && level === 0;
|
|
63
|
-
const inlineSubmenu = props.mode === "inline" && !collapsed;
|
|
64
|
-
useEffect(() => () => {
|
|
65
|
-
if (closeTimerRef.current !== void 0) window.clearTimeout(closeTimerRef.current);
|
|
66
|
-
}, []);
|
|
67
|
-
function cancelClose() {
|
|
68
|
-
if (closeTimerRef.current !== void 0) {
|
|
69
|
-
window.clearTimeout(closeTimerRef.current);
|
|
70
|
-
closeTimerRef.current = void 0;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function scheduleClose() {
|
|
74
|
-
cancelClose();
|
|
75
|
-
closeTimerRef.current = window.setTimeout(() => props.toggle(item.key, false), 100);
|
|
76
|
-
}
|
|
77
|
-
const hover = props.triggerSubMenuAction === "hover" && hasChildren && !inlineSubmenu;
|
|
78
|
-
const submenu = hasChildren ? /* @__PURE__ */ jsx(MenuLevel, { items: item.children ?? [], level: level + 1, parents: [item.key, ...parents], props }) : null;
|
|
79
|
-
const popupPlacement = props.mode === "horizontal" && level === 0 ? "bottom-start" : "right-start";
|
|
80
|
-
return /* @__PURE__ */ jsxs(
|
|
81
|
-
"li",
|
|
82
|
-
{
|
|
83
|
-
className: `sia-menu__entry${isOpen ? " is-open" : ""}${isSelected ? " is-selected" : ""}${item.disabled ? " is-disabled" : ""}${item.danger ? " is-danger" : ""}`,
|
|
84
|
-
onMouseEnter: hover ? () => {
|
|
85
|
-
cancelClose();
|
|
86
|
-
props.toggle(item.key, true);
|
|
87
|
-
} : void 0,
|
|
88
|
-
onMouseLeave: hover ? scheduleClose : void 0,
|
|
89
|
-
children: [
|
|
90
|
-
/* @__PURE__ */ jsxs(
|
|
91
|
-
"button",
|
|
92
|
-
{
|
|
93
|
-
ref: anchorRef,
|
|
94
|
-
type: "button",
|
|
95
|
-
className: "sia-menu__item",
|
|
96
|
-
style: { paddingInlineStart: collapsed ? void 0 : 12 + level * props.inlineIndent },
|
|
97
|
-
title: collapsed ? item.title ?? (typeof item.label === "string" ? item.label : void 0) : item.title,
|
|
98
|
-
disabled: item.disabled,
|
|
99
|
-
"aria-current": isSelected ? "page" : void 0,
|
|
100
|
-
"aria-expanded": hasChildren ? isOpen : void 0,
|
|
101
|
-
onClick: (event) => hasChildren ? props.toggle(item.key) : props.select(item, path, event),
|
|
102
|
-
children: [
|
|
103
|
-
item.icon ? /* @__PURE__ */ jsx("span", { className: "sia-menu__icon", children: item.icon }) : null,
|
|
104
|
-
!collapsed ? /* @__PURE__ */ jsx("span", { className: "sia-menu__label", children: item.label }) : null,
|
|
105
|
-
!collapsed && item.extra ? /* @__PURE__ */ jsx("span", { className: "sia-menu__extra", children: item.extra }) : null,
|
|
106
|
-
!collapsed && hasChildren ? /* @__PURE__ */ jsx(Icon, { className: "sia-menu__expand-icon", name: "chevron-down", size: 13 }) : null
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
),
|
|
110
|
-
hasChildren ? inlineSubmenu ? /* @__PURE__ */ jsx("ul", { className: "sia-menu__submenu", role: "menu", "aria-hidden": !isOpen, children: submenu }) : /* @__PURE__ */ jsx(
|
|
111
|
-
MenuPopup,
|
|
112
|
-
{
|
|
113
|
-
anchorRef,
|
|
114
|
-
open: isOpen,
|
|
115
|
-
placement: popupPlacement,
|
|
116
|
-
menuId: props.menuId,
|
|
117
|
-
theme: props.theme,
|
|
118
|
-
onMouseEnter: hover ? cancelClose : void 0,
|
|
119
|
-
onMouseLeave: hover ? scheduleClose : void 0,
|
|
120
|
-
children: submenu
|
|
121
|
-
}
|
|
122
|
-
) : null
|
|
123
|
-
]
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
function MenuLevel({
|
|
128
|
-
items,
|
|
129
|
-
level,
|
|
130
|
-
parents,
|
|
131
|
-
props
|
|
132
|
-
}) {
|
|
133
|
-
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, index) => {
|
|
134
|
-
if (item.type === "divider") return /* @__PURE__ */ jsx("li", { className: "sia-menu__divider", role: "separator" }, item.key || `divider-${index}`);
|
|
135
|
-
if (item.type === "group") return /* @__PURE__ */ jsxs("li", { className: "sia-menu__group", children: [
|
|
136
|
-
/* @__PURE__ */ jsx("div", { className: "sia-menu__group-title", children: item.label }),
|
|
137
|
-
/* @__PURE__ */ jsx("ul", { role: "group", children: /* @__PURE__ */ jsx(MenuLevel, { items: item.children ?? [], level: level + 1, parents: [...parents, item.key], props }) })
|
|
138
|
-
] }, item.key);
|
|
139
|
-
return /* @__PURE__ */ jsx(MenuEntry, { item, level, parents, props }, item.key);
|
|
140
|
-
}) });
|
|
141
|
-
}
|
|
142
|
-
function Menu({
|
|
143
|
-
items,
|
|
144
|
-
mode = "vertical",
|
|
145
|
-
theme = "light",
|
|
146
|
-
selectedKeys,
|
|
147
|
-
defaultSelectedKeys = [],
|
|
148
|
-
openKeys,
|
|
149
|
-
defaultOpenKeys = [],
|
|
150
|
-
multiple = false,
|
|
151
|
-
selectable = true,
|
|
152
|
-
inlineCollapsed = false,
|
|
153
|
-
inlineIndent = 20,
|
|
154
|
-
triggerSubMenuAction = "click",
|
|
155
|
-
onClick,
|
|
156
|
-
onSelect,
|
|
157
|
-
onDeselect,
|
|
158
|
-
onOpenChange,
|
|
159
|
-
className = "",
|
|
160
|
-
...rest
|
|
161
|
-
}) {
|
|
162
|
-
const menuId = useId();
|
|
163
|
-
const rootRef = useRef(null);
|
|
164
|
-
const [selected, setSelected] = useControllableState({ value: selectedKeys, defaultValue: defaultSelectedKeys });
|
|
165
|
-
const [open, setOpen] = useControllableState({ value: openKeys, defaultValue: defaultOpenKeys, onChange: (next) => onOpenChange?.([...next]) });
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
if (mode === "inline" || !open.length) return void 0;
|
|
168
|
-
const closeOutside = (event) => {
|
|
169
|
-
const target = event.target;
|
|
170
|
-
if (rootRef.current?.contains(target)) return;
|
|
171
|
-
const owner = target instanceof Element ? target.closest("[data-sia-menu-owner]")?.getAttribute("data-sia-menu-owner") : null;
|
|
172
|
-
if (owner !== menuId) setOpen([]);
|
|
173
|
-
};
|
|
174
|
-
document.addEventListener("pointerdown", closeOutside);
|
|
175
|
-
return () => document.removeEventListener("pointerdown", closeOutside);
|
|
176
|
-
}, [menuId, mode, open.length, setOpen]);
|
|
177
|
-
function toggle(key, force) {
|
|
178
|
-
const shouldOpen = force ?? !open.includes(key);
|
|
179
|
-
setOpen(shouldOpen ? open.includes(key) ? open : [...open, key] : open.filter((item) => item !== key));
|
|
180
|
-
}
|
|
181
|
-
function select(item, keyPath, domEvent) {
|
|
182
|
-
const info = { key: item.key, keyPath, domEvent, item };
|
|
183
|
-
onClick?.(info);
|
|
184
|
-
if (!selectable) return;
|
|
185
|
-
const exists = selected.includes(item.key);
|
|
186
|
-
const next = multiple ? exists ? selected.filter((key) => key !== item.key) : [...selected, item.key] : [item.key];
|
|
187
|
-
setSelected(next);
|
|
188
|
-
if (exists && multiple) onDeselect?.({ ...info, selectedKeys: [...next] });
|
|
189
|
-
else onSelect?.({ ...info, selectedKeys: [...next] });
|
|
190
|
-
if (mode !== "inline") setOpen([]);
|
|
191
|
-
}
|
|
192
|
-
return /* @__PURE__ */ jsx("ul", { ref: rootRef, className: `sia-menu sia-menu--${mode} sia-menu--${theme}${inlineCollapsed ? " sia-menu--collapsed" : ""} ${className}`.trim(), role: "menu", ...rest, "data-sia-menu-owner": menuId, children: /* @__PURE__ */ jsx(MenuLevel, { items, level: 0, parents: [], props: { menuId, mode, theme, multiple, selectable, inlineCollapsed, inlineIndent, triggerSubMenuAction, selected, open, select, toggle } }) });
|
|
193
|
-
}
|
|
194
|
-
function Steps({ items, current = 0, initial = 0, direction = "horizontal", type = "default", size = "default", status = "process", progressDot = false, onChange, className = "", ...props }) {
|
|
195
|
-
return /* @__PURE__ */ jsx("div", { className: `sia-steps sia-steps--${direction} sia-steps--${type} sia-steps--${size} ${className}`.trim(), ...props, children: items.map((item, rawIndex) => {
|
|
196
|
-
const index = rawIndex + initial;
|
|
197
|
-
const itemStatus = item.status ?? (index < current ? "finish" : index === current ? status : "wait");
|
|
198
|
-
const dot = /* @__PURE__ */ jsx("span", { className: "sia-steps__dot" });
|
|
199
|
-
const icon = progressDot ? typeof progressDot === "function" ? progressDot(dot, { index, status: itemStatus, title: item.title, description: item.description }) : dot : item.icon ?? (itemStatus === "finish" ? /* @__PURE__ */ jsx(Icon, { name: "check", size: 15 }) : itemStatus === "error" ? /* @__PURE__ */ jsx(Icon, { name: "close", size: 14 }) : index + 1);
|
|
200
|
-
return /* @__PURE__ */ jsxs("button", { type: "button", className: `sia-steps__item sia-steps__item--${itemStatus}`, disabled: item.disabled || !onChange, onClick: () => onChange?.(index), children: [
|
|
201
|
-
/* @__PURE__ */ jsxs("span", { className: "sia-steps__head", children: [
|
|
202
|
-
/* @__PURE__ */ jsx("span", { className: "sia-steps__icon", children: icon }),
|
|
203
|
-
/* @__PURE__ */ jsx("span", { className: "sia-steps__tail" })
|
|
204
|
-
] }),
|
|
205
|
-
/* @__PURE__ */ jsxs("span", { className: "sia-steps__content", children: [
|
|
206
|
-
/* @__PURE__ */ jsxs("span", { className: "sia-steps__title", children: [
|
|
207
|
-
item.title,
|
|
208
|
-
item.subTitle ? /* @__PURE__ */ jsx("small", { children: item.subTitle }) : null
|
|
209
|
-
] }),
|
|
210
|
-
item.description ? /* @__PURE__ */ jsx("span", { className: "sia-steps__description", children: item.description }) : null
|
|
211
|
-
] })
|
|
212
|
-
] }, index);
|
|
213
|
-
}) });
|
|
214
|
-
}
|
|
215
|
-
function Segmented({ options, value, defaultValue, size = "medium", block = false, vertical = false, disabled = false, onChange, className = "", onKeyDown, ...props }) {
|
|
216
|
-
const normalized = useMemo(() => options.map((option) => typeof option === "object" ? option : { label: option, value: option }), [options]);
|
|
217
|
-
const [current, setCurrent] = useControllableState({ value, defaultValue: defaultValue ?? normalized[0]?.value, onChange: (next) => next !== void 0 && onChange?.(next) });
|
|
218
|
-
function keyboard(event) {
|
|
219
|
-
onKeyDown?.(event);
|
|
220
|
-
if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) return;
|
|
221
|
-
event.preventDefault();
|
|
222
|
-
const enabled = normalized.filter((option) => !option.disabled);
|
|
223
|
-
const index = enabled.findIndex((option) => option.value === current);
|
|
224
|
-
const next = event.key === "ArrowRight" || event.key === "ArrowDown" ? enabled[(index + 1) % enabled.length] : enabled[(index - 1 + enabled.length) % enabled.length];
|
|
225
|
-
if (next) setCurrent(next.value);
|
|
226
|
-
}
|
|
227
|
-
return /* @__PURE__ */ jsx("div", { className: `sia-segmented sia-segmented--${size}${block ? " sia-segmented--block" : ""}${vertical ? " sia-segmented--vertical" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), role: "radiogroup", onKeyDown: keyboard, ...props, children: normalized.map((option) => /* @__PURE__ */ jsxs("button", { type: "button", role: "radio", "aria-checked": option.value === current, title: option.title, className: option.value === current ? "is-selected" : "", disabled: disabled || option.disabled, onClick: () => setCurrent(option.value), children: [
|
|
228
|
-
option.icon,
|
|
229
|
-
/* @__PURE__ */ jsx("span", { children: option.label ?? option.value })
|
|
230
|
-
] }, option.value)) });
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// src/components/Dropdown.tsx
|
|
234
|
-
import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
235
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
236
|
-
var placementMap = {
|
|
237
|
-
bottomLeft: "bottom-start",
|
|
238
|
-
bottomRight: "bottom-end",
|
|
239
|
-
topLeft: "top-start",
|
|
240
|
-
topRight: "top-end"
|
|
241
|
-
};
|
|
242
|
-
function DropdownRoot({
|
|
243
|
-
menu,
|
|
244
|
-
children,
|
|
245
|
-
trigger = ["hover"],
|
|
246
|
-
placement = "bottomLeft",
|
|
247
|
-
open,
|
|
248
|
-
defaultOpen = false,
|
|
249
|
-
disabled = false,
|
|
250
|
-
arrow = false,
|
|
251
|
-
autoFocus = false,
|
|
252
|
-
openDelay = 80,
|
|
253
|
-
closeDelay = 120,
|
|
254
|
-
popupClassName = "",
|
|
255
|
-
popupStyle,
|
|
256
|
-
popupRender,
|
|
257
|
-
onOpenChange,
|
|
258
|
-
className = "",
|
|
259
|
-
onClick,
|
|
260
|
-
onMouseEnter,
|
|
261
|
-
onMouseLeave,
|
|
262
|
-
onContextMenu,
|
|
263
|
-
onKeyDown,
|
|
264
|
-
...props
|
|
265
|
-
}) {
|
|
266
|
-
const rootRef = useRef2(null);
|
|
267
|
-
const contextAnchorRef = useRef2(null);
|
|
268
|
-
const popupRef = useRef2(null);
|
|
269
|
-
const openTimerRef = useRef2(void 0);
|
|
270
|
-
const closeTimerRef = useRef2(void 0);
|
|
271
|
-
const [internalOpen, setInternalOpen] = useState2(defaultOpen);
|
|
272
|
-
const [mounted, setMounted] = useState2(open ?? defaultOpen);
|
|
273
|
-
const [contextPoint, setContextPoint] = useState2();
|
|
274
|
-
const visible = open ?? internalOpen;
|
|
275
|
-
const triggerSet = new Set(trigger);
|
|
276
|
-
const pointAtCenter = typeof arrow === "object" && arrow.pointAtCenter;
|
|
277
|
-
function clearTimer(ref) {
|
|
278
|
-
if (ref.current === void 0) return;
|
|
279
|
-
window.clearTimeout(ref.current);
|
|
280
|
-
ref.current = void 0;
|
|
281
|
-
}
|
|
282
|
-
function clearTimers() {
|
|
283
|
-
clearTimer(openTimerRef);
|
|
284
|
-
clearTimer(closeTimerRef);
|
|
285
|
-
}
|
|
286
|
-
function updateOpen(next, source) {
|
|
287
|
-
clearTimers();
|
|
288
|
-
if (next === visible) return;
|
|
289
|
-
if (open === void 0) setInternalOpen(next);
|
|
290
|
-
onOpenChange?.(next, { source });
|
|
291
|
-
}
|
|
292
|
-
function scheduleOpen() {
|
|
293
|
-
clearTimer(closeTimerRef);
|
|
294
|
-
clearTimer(openTimerRef);
|
|
295
|
-
openTimerRef.current = window.setTimeout(() => updateOpen(true, "trigger"), Math.max(0, openDelay));
|
|
296
|
-
}
|
|
297
|
-
function scheduleClose() {
|
|
298
|
-
clearTimer(openTimerRef);
|
|
299
|
-
clearTimer(closeTimerRef);
|
|
300
|
-
closeTimerRef.current = window.setTimeout(() => updateOpen(false, "trigger"), Math.max(0, closeDelay));
|
|
301
|
-
}
|
|
302
|
-
useEffect2(() => {
|
|
303
|
-
if (visible) {
|
|
304
|
-
setMounted(true);
|
|
305
|
-
return void 0;
|
|
306
|
-
}
|
|
307
|
-
const timer = window.setTimeout(() => setMounted(false), 160);
|
|
308
|
-
return () => window.clearTimeout(timer);
|
|
309
|
-
}, [visible]);
|
|
310
|
-
useEffect2(() => {
|
|
311
|
-
if (!visible && !mounted) setContextPoint(void 0);
|
|
312
|
-
}, [mounted, visible]);
|
|
313
|
-
useEffect2(() => () => clearTimers(), []);
|
|
314
|
-
useEffect2(() => {
|
|
315
|
-
if (!visible) return void 0;
|
|
316
|
-
const contextMenuTrigger = triggerSet.has("contextMenu");
|
|
317
|
-
const closeOutside = (event) => {
|
|
318
|
-
const target = event.target;
|
|
319
|
-
if (popupRef.current?.contains(target)) return;
|
|
320
|
-
if (!contextMenuTrigger && rootRef.current?.contains(target)) return;
|
|
321
|
-
const targetOwner = target instanceof Element ? target.closest("[data-sia-menu-owner]")?.getAttribute("data-sia-menu-owner") : null;
|
|
322
|
-
const menuOwner = popupRef.current?.querySelector("[data-sia-menu-owner]")?.getAttribute("data-sia-menu-owner");
|
|
323
|
-
if (menuOwner && targetOwner === menuOwner) return;
|
|
324
|
-
updateOpen(false, "trigger");
|
|
325
|
-
};
|
|
326
|
-
const closeWithEscape = (event) => {
|
|
327
|
-
if (event.key !== "Escape") return;
|
|
328
|
-
updateOpen(false, "trigger");
|
|
329
|
-
rootRef.current?.querySelector("button, a, [tabindex]:not([tabindex='-1'])")?.focus();
|
|
330
|
-
};
|
|
331
|
-
const keepOpenOverNestedMenu = (event) => {
|
|
332
|
-
const target = event.target;
|
|
333
|
-
if (target instanceof Element && target.closest(".sia-menu__popup")) clearTimer(closeTimerRef);
|
|
334
|
-
};
|
|
335
|
-
document.addEventListener("pointerdown", closeOutside);
|
|
336
|
-
document.addEventListener("keydown", closeWithEscape);
|
|
337
|
-
document.addEventListener("pointerover", keepOpenOverNestedMenu);
|
|
338
|
-
return () => {
|
|
339
|
-
document.removeEventListener("pointerdown", closeOutside);
|
|
340
|
-
document.removeEventListener("keydown", closeWithEscape);
|
|
341
|
-
document.removeEventListener("pointerover", keepOpenOverNestedMenu);
|
|
342
|
-
};
|
|
343
|
-
}, [visible]);
|
|
344
|
-
useEffect2(() => {
|
|
345
|
-
if (!visible || !mounted || !autoFocus) return void 0;
|
|
346
|
-
const frame = window.requestAnimationFrame(() => {
|
|
347
|
-
popupRef.current?.querySelector(
|
|
348
|
-
"[data-sia-dropdown-autofocus], input:not(:disabled), textarea:not(:disabled), .sia-menu__item:not(:disabled)"
|
|
349
|
-
)?.focus();
|
|
350
|
-
});
|
|
351
|
-
return () => window.cancelAnimationFrame(frame);
|
|
352
|
-
}, [autoFocus, mounted, visible]);
|
|
353
|
-
function handleMenuClick(info) {
|
|
354
|
-
info.domEvent.stopPropagation();
|
|
355
|
-
menu.onClick?.(info);
|
|
356
|
-
updateOpen(false, "menu");
|
|
357
|
-
}
|
|
358
|
-
function handleClick(event) {
|
|
359
|
-
onClick?.(event);
|
|
360
|
-
if (disabled || !triggerSet.has("click") || event.defaultPrevented) return;
|
|
361
|
-
setContextPoint(void 0);
|
|
362
|
-
updateOpen(!visible, "trigger");
|
|
363
|
-
}
|
|
364
|
-
function handleMouseEnter(event) {
|
|
365
|
-
onMouseEnter?.(event);
|
|
366
|
-
if (!disabled && triggerSet.has("hover")) scheduleOpen();
|
|
367
|
-
}
|
|
368
|
-
function handleMouseLeave(event) {
|
|
369
|
-
onMouseLeave?.(event);
|
|
370
|
-
if (!disabled && triggerSet.has("hover")) scheduleClose();
|
|
371
|
-
}
|
|
372
|
-
function handleContextMenu(event) {
|
|
373
|
-
onContextMenu?.(event);
|
|
374
|
-
if (disabled || !triggerSet.has("contextMenu") || event.defaultPrevented) return;
|
|
375
|
-
event.preventDefault();
|
|
376
|
-
event.stopPropagation();
|
|
377
|
-
setContextPoint({ x: event.clientX, y: event.clientY });
|
|
378
|
-
updateOpen(true, "trigger");
|
|
379
|
-
}
|
|
380
|
-
function handleKeyDown(event) {
|
|
381
|
-
onKeyDown?.(event);
|
|
382
|
-
if (disabled || event.defaultPrevented) return;
|
|
383
|
-
if (event.key === "ArrowDown" && (triggerSet.has("click") || triggerSet.has("hover"))) {
|
|
384
|
-
event.preventDefault();
|
|
385
|
-
setContextPoint(void 0);
|
|
386
|
-
updateOpen(true, "trigger");
|
|
387
|
-
} else if (triggerSet.has("contextMenu") && (event.key === "ContextMenu" || event.shiftKey && event.key === "F10")) {
|
|
388
|
-
event.preventDefault();
|
|
389
|
-
setContextPoint(void 0);
|
|
390
|
-
updateOpen(true, "trigger");
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
const menuNode = /* @__PURE__ */ jsx2(
|
|
394
|
-
Menu,
|
|
395
|
-
{
|
|
396
|
-
mode: "vertical",
|
|
397
|
-
theme: menu.theme,
|
|
398
|
-
items: menu.items,
|
|
399
|
-
multiple: menu.multiple,
|
|
400
|
-
selectable: menu.selectable,
|
|
401
|
-
selectedKeys: menu.selectedKeys,
|
|
402
|
-
defaultSelectedKeys: menu.defaultSelectedKeys,
|
|
403
|
-
triggerSubMenuAction: "hover",
|
|
404
|
-
onClick: handleMenuClick,
|
|
405
|
-
onSelect: menu.onSelect,
|
|
406
|
-
onDeselect: menu.onDeselect,
|
|
407
|
-
className: "sia-dropdown__menu"
|
|
408
|
-
}
|
|
409
|
-
);
|
|
410
|
-
return /* @__PURE__ */ jsxs2(
|
|
411
|
-
"span",
|
|
412
|
-
{
|
|
413
|
-
ref: rootRef,
|
|
414
|
-
className: `sia-dropdown${visible ? " is-open" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(),
|
|
415
|
-
"aria-expanded": visible,
|
|
416
|
-
"aria-haspopup": "menu",
|
|
417
|
-
tabIndex: triggerSet.has("contextMenu") ? 0 : void 0,
|
|
418
|
-
onClick: handleClick,
|
|
419
|
-
onMouseEnter: handleMouseEnter,
|
|
420
|
-
onMouseLeave: handleMouseLeave,
|
|
421
|
-
onContextMenu: handleContextMenu,
|
|
422
|
-
onKeyDown: handleKeyDown,
|
|
423
|
-
...props,
|
|
424
|
-
children: [
|
|
425
|
-
children,
|
|
426
|
-
/* @__PURE__ */ jsx2(
|
|
427
|
-
"span",
|
|
428
|
-
{
|
|
429
|
-
ref: contextAnchorRef,
|
|
430
|
-
className: "sia-dropdown__context-anchor",
|
|
431
|
-
style: contextPoint ? { left: contextPoint.x, top: contextPoint.y } : void 0,
|
|
432
|
-
"aria-hidden": "true"
|
|
433
|
-
}
|
|
434
|
-
),
|
|
435
|
-
/* @__PURE__ */ jsx2(
|
|
436
|
-
PopupPortal,
|
|
437
|
-
{
|
|
438
|
-
ref: popupRef,
|
|
439
|
-
anchorRef: contextPoint ? contextAnchorRef : rootRef,
|
|
440
|
-
open: mounted,
|
|
441
|
-
placement: contextPoint ? "bottom-start" : placementMap[placement],
|
|
442
|
-
offset: contextPoint ? 2 : 6,
|
|
443
|
-
className: `sia-dropdown__popup${visible ? " is-open" : " is-closing"}${arrow ? " sia-dropdown__popup--arrow" : ""}${pointAtCenter ? " sia-dropdown__popup--arrow-center" : ""} ${popupClassName}`.trim(),
|
|
444
|
-
style: popupStyle,
|
|
445
|
-
onMouseEnter: () => {
|
|
446
|
-
clearTimer(closeTimerRef);
|
|
447
|
-
if (!disabled && triggerSet.has("hover")) clearTimer(openTimerRef);
|
|
448
|
-
},
|
|
449
|
-
onMouseLeave: () => {
|
|
450
|
-
if (!disabled && triggerSet.has("hover")) scheduleClose();
|
|
451
|
-
},
|
|
452
|
-
onClick: (event) => event.stopPropagation(),
|
|
453
|
-
children: popupRender ? popupRender(menuNode) : menuNode
|
|
454
|
-
},
|
|
455
|
-
contextPoint ? `context-${contextPoint.x}-${contextPoint.y}` : "trigger"
|
|
456
|
-
)
|
|
457
|
-
]
|
|
458
|
-
}
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
function DropdownButton({
|
|
462
|
-
children,
|
|
463
|
-
className = "",
|
|
464
|
-
buttonProps,
|
|
465
|
-
onClick,
|
|
466
|
-
disabled,
|
|
467
|
-
trigger = ["click"],
|
|
468
|
-
...dropdownProps
|
|
469
|
-
}) {
|
|
470
|
-
return /* @__PURE__ */ jsxs2("span", { className: `sia-dropdown-button ${className}`.trim(), children: [
|
|
471
|
-
/* @__PURE__ */ jsx2(Button, { ...buttonProps, disabled, onClick, children }),
|
|
472
|
-
/* @__PURE__ */ jsx2(DropdownRoot, { ...dropdownProps, disabled, trigger, children: /* @__PURE__ */ jsx2(
|
|
473
|
-
Button,
|
|
474
|
-
{
|
|
475
|
-
...buttonProps,
|
|
476
|
-
className: `sia-dropdown-button__arrow ${buttonProps?.className ?? ""}`.trim(),
|
|
477
|
-
disabled,
|
|
478
|
-
icon: /* @__PURE__ */ jsx2(Icon, { name: "chevron-down", size: 14 }),
|
|
479
|
-
"aria-label": "\u5C55\u5F00\u4E0B\u62C9\u83DC\u5355"
|
|
480
|
-
}
|
|
481
|
-
) })
|
|
482
|
-
] });
|
|
483
|
-
}
|
|
484
|
-
var Dropdown = Object.assign(DropdownRoot, { Button: DropdownButton });
|
|
485
|
-
|
|
486
|
-
// src/components/Input.tsx
|
|
487
|
-
import { forwardRef, useId as useId2, useRef as useRef3, useState as useState3 } from "react";
|
|
488
|
-
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
489
|
-
var Input = forwardRef(function Input2({
|
|
490
|
-
label,
|
|
491
|
-
hint,
|
|
492
|
-
status = "default",
|
|
493
|
-
size = "medium",
|
|
494
|
-
prefix,
|
|
495
|
-
suffix,
|
|
496
|
-
allowClear = false,
|
|
497
|
-
onClear,
|
|
498
|
-
showCount = false,
|
|
499
|
-
placeholderMode,
|
|
500
|
-
placeholder,
|
|
501
|
-
className = "",
|
|
502
|
-
id,
|
|
503
|
-
disabled,
|
|
504
|
-
value,
|
|
505
|
-
defaultValue,
|
|
506
|
-
maxLength,
|
|
507
|
-
onChange,
|
|
508
|
-
...props
|
|
509
|
-
}, forwardedRef) {
|
|
510
|
-
const fallbackId = useId2();
|
|
511
|
-
const inputId = id ?? fallbackId;
|
|
512
|
-
const localRef = useRef3(null);
|
|
513
|
-
const [uncontrolledValue, setUncontrolledValue] = useState3(() => defaultValue === void 0 ? "" : String(defaultValue));
|
|
514
|
-
const currentText = value !== void 0 ? String(value) : uncontrolledValue;
|
|
515
|
-
const hasValue = currentText.length > 0;
|
|
516
|
-
const floatingPlaceholder = usePlaceholderMode(placeholderMode) === "floating" && Boolean(placeholder);
|
|
517
|
-
const hintId = `${inputId}-hint`;
|
|
518
|
-
const describedBy = [props["aria-describedby"], hint ? hintId : null].filter(Boolean).join(" ") || void 0;
|
|
519
|
-
function setRef(node) {
|
|
520
|
-
localRef.current = node;
|
|
521
|
-
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
522
|
-
else if (forwardedRef) forwardedRef.current = node;
|
|
523
|
-
}
|
|
524
|
-
function handleChange(event) {
|
|
525
|
-
if (maxLength !== void 0 && maxLength >= 0 && event.target.value.length > maxLength) {
|
|
526
|
-
const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
|
|
527
|
-
valueSetter?.call(event.target, event.target.value.slice(0, maxLength));
|
|
528
|
-
}
|
|
529
|
-
setUncontrolledValue(event.target.value);
|
|
530
|
-
onChange?.(event);
|
|
531
|
-
}
|
|
532
|
-
function clearValue() {
|
|
533
|
-
const input2 = localRef.current;
|
|
534
|
-
if (!input2 || disabled) return;
|
|
535
|
-
const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
|
|
536
|
-
valueSetter?.call(input2, "");
|
|
537
|
-
input2.dispatchEvent(new Event("input", { bubbles: true }));
|
|
538
|
-
setUncontrolledValue("");
|
|
539
|
-
input2.focus();
|
|
540
|
-
onClear?.();
|
|
541
|
-
}
|
|
542
|
-
const input = /* @__PURE__ */ jsx3(
|
|
543
|
-
"input",
|
|
544
|
-
{
|
|
545
|
-
...props,
|
|
546
|
-
ref: setRef,
|
|
547
|
-
id: inputId,
|
|
548
|
-
className: "sia-input",
|
|
549
|
-
disabled,
|
|
550
|
-
value,
|
|
551
|
-
defaultValue,
|
|
552
|
-
maxLength,
|
|
553
|
-
placeholder,
|
|
554
|
-
"aria-describedby": describedBy,
|
|
555
|
-
"aria-invalid": status === "error" || void 0,
|
|
556
|
-
onChange: handleChange
|
|
557
|
-
}
|
|
558
|
-
);
|
|
559
|
-
const control = /* @__PURE__ */ jsxs3("span", { className: `sia-input-control sia-input-control--${size} sia-input-control--${status}${floatingPlaceholder ? " sia-input-control--floating" : ""}${floatingPlaceholder && hasValue ? " is-filled" : ""}${disabled ? " is-disabled" : ""}`, children: [
|
|
560
|
-
prefix ? /* @__PURE__ */ jsx3("span", { className: "sia-input-control__affix", children: prefix }) : null,
|
|
561
|
-
floatingPlaceholder ? /* @__PURE__ */ jsxs3("span", { className: "sia-input-control__input-wrap", children: [
|
|
562
|
-
input,
|
|
563
|
-
/* @__PURE__ */ jsx3("span", { className: "sia-input-control__floating-placeholder", "aria-hidden": "true", children: placeholder })
|
|
564
|
-
] }) : input,
|
|
565
|
-
allowClear && hasValue && !disabled ? /* @__PURE__ */ jsx3("button", { className: "sia-input-control__clear", type: "button", "aria-label": "\u6E05\u7A7A\u8F93\u5165", onClick: clearValue, children: /* @__PURE__ */ jsx3(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null,
|
|
566
|
-
suffix ? /* @__PURE__ */ jsx3("span", { className: "sia-input-control__affix", children: suffix }) : null,
|
|
567
|
-
showCount ? /* @__PURE__ */ jsxs3("span", { className: `sia-input-control__count${maxLength !== void 0 && currentText.length >= maxLength ? " is-limit" : ""}`, "aria-live": "polite", children: [
|
|
568
|
-
currentText.length,
|
|
569
|
-
maxLength !== void 0 ? `/${maxLength}` : null
|
|
570
|
-
] }) : null
|
|
571
|
-
] });
|
|
572
|
-
if (!label && !hint) return /* @__PURE__ */ jsx3("span", { className: `sia-field ${className}`.trim(), children: control });
|
|
573
|
-
return /* @__PURE__ */ jsxs3("span", { className: `sia-field ${className}`.trim(), children: [
|
|
574
|
-
label ? /* @__PURE__ */ jsx3("label", { className: "sia-field__label", htmlFor: inputId, children: label }) : null,
|
|
575
|
-
control,
|
|
576
|
-
hint ? /* @__PURE__ */ jsx3("span", { id: hintId, className: `sia-field__hint sia-field__hint--${status}`, children: hint }) : null
|
|
577
|
-
] });
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
export {
|
|
581
|
-
Menu,
|
|
582
|
-
Steps,
|
|
583
|
-
Segmented,
|
|
584
|
-
Dropdown,
|
|
585
|
-
Input
|
|
586
|
-
};
|