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