@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,318 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Icon,
|
|
3
|
+
PopupPortal,
|
|
4
|
+
useControllableState
|
|
5
|
+
} from "./chunk-YCVXUMGP.js";
|
|
6
|
+
|
|
7
|
+
// src/components/Select.tsx
|
|
8
|
+
import { forwardRef, useDeferredValue, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
function defaultFilterOption(query, option) {
|
|
11
|
+
return String(option.label).toLowerCase().includes(query.toLowerCase());
|
|
12
|
+
}
|
|
13
|
+
var Select = forwardRef(function Select2({
|
|
14
|
+
options,
|
|
15
|
+
mode = "single",
|
|
16
|
+
value,
|
|
17
|
+
defaultValue,
|
|
18
|
+
onChange,
|
|
19
|
+
placeholder = "\u8BF7\u9009\u62E9",
|
|
20
|
+
size = "medium",
|
|
21
|
+
status = "default",
|
|
22
|
+
allowClear = false,
|
|
23
|
+
loading = false,
|
|
24
|
+
showSearch = false,
|
|
25
|
+
allowInput = false,
|
|
26
|
+
inputMaxLength,
|
|
27
|
+
searchPlaceholder = "\u641C\u7D22\u9009\u9879",
|
|
28
|
+
onSearch,
|
|
29
|
+
filterOption = defaultFilterOption,
|
|
30
|
+
showSelectAll = false,
|
|
31
|
+
maxTagCount = 2,
|
|
32
|
+
virtual = true,
|
|
33
|
+
virtualThreshold = 100,
|
|
34
|
+
listHeight = 256,
|
|
35
|
+
optionHeight = 34,
|
|
36
|
+
disabled,
|
|
37
|
+
className = "",
|
|
38
|
+
id,
|
|
39
|
+
notFoundContent = "\u6682\u65E0\u6570\u636E",
|
|
40
|
+
onKeyDown,
|
|
41
|
+
...props
|
|
42
|
+
}, forwardedRef) {
|
|
43
|
+
const fallbackId = useId();
|
|
44
|
+
const selectId = id ?? fallbackId;
|
|
45
|
+
const listboxId = `${selectId}-listbox`;
|
|
46
|
+
const rootRef = useRef(null);
|
|
47
|
+
const popupRef = useRef(null);
|
|
48
|
+
const searchRef = useRef(null);
|
|
49
|
+
const listRef = useRef(null);
|
|
50
|
+
const [open, setOpen] = useState(false);
|
|
51
|
+
const [query, setQuery] = useState("");
|
|
52
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
53
|
+
const [scrollTop, setScrollTop] = useState(0);
|
|
54
|
+
const deferredQuery = useDeferredValue(query.trim());
|
|
55
|
+
const initialValue = defaultValue === void 0 ? mode === "multiple" ? [] : null : defaultValue;
|
|
56
|
+
const [currentValue, setCurrentValue] = useControllableState({
|
|
57
|
+
value,
|
|
58
|
+
defaultValue: initialValue,
|
|
59
|
+
onChange: (nextValue) => {
|
|
60
|
+
if (Array.isArray(nextValue)) {
|
|
61
|
+
const selectedOptions2 = nextValue.map((selectedValue) => options.find((option) => option.value === selectedValue) ?? (allowInput ? { label: String(selectedValue), value: selectedValue } : void 0)).filter((option) => option !== void 0);
|
|
62
|
+
onChange?.(nextValue, selectedOptions2);
|
|
63
|
+
} else {
|
|
64
|
+
const selectedOption = nextValue === null ? null : options.find((option) => option.value === nextValue) ?? (allowInput ? { label: String(nextValue), value: nextValue } : null);
|
|
65
|
+
onChange?.(nextValue, selectedOption);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const selectedValues = useMemo(() => {
|
|
70
|
+
if (mode === "multiple") return Array.isArray(currentValue) ? currentValue : currentValue === null ? [] : [currentValue];
|
|
71
|
+
return Array.isArray(currentValue) ? currentValue.slice(0, 1) : currentValue === null ? [] : [currentValue];
|
|
72
|
+
}, [currentValue, mode]);
|
|
73
|
+
const selectedValueSet = useMemo(() => new Set(selectedValues), [selectedValues]);
|
|
74
|
+
const availableOptions = useMemo(() => {
|
|
75
|
+
if (!allowInput) return options;
|
|
76
|
+
const optionValueSet = new Set(options.map((option) => option.value));
|
|
77
|
+
const selectedCustomOptions = selectedValues.filter((selectedValue) => !optionValueSet.has(selectedValue)).map((selectedValue) => ({ label: String(selectedValue), value: selectedValue }));
|
|
78
|
+
return selectedCustomOptions.length ? [...selectedCustomOptions, ...options] : options;
|
|
79
|
+
}, [allowInput, options, selectedValues]);
|
|
80
|
+
const selectedOptions = useMemo(() => selectedValues.map((selectedValue) => availableOptions.find((option) => option.value === selectedValue)).filter((option) => option !== void 0), [availableOptions, selectedValues]);
|
|
81
|
+
const filteredOptions = useMemo(() => deferredQuery ? availableOptions.filter((option) => filterOption(deferredQuery, option)) : availableOptions, [availableOptions, deferredQuery, filterOption]);
|
|
82
|
+
const inputValue = query.trim();
|
|
83
|
+
const exactInputOption = inputValue ? availableOptions.find((option) => String(option.value).toLowerCase() === inputValue.toLowerCase() || typeof option.label === "string" && option.label.toLowerCase() === inputValue.toLowerCase()) : void 0;
|
|
84
|
+
const canSubmitInput = allowInput && Boolean(inputValue) && !exactInputOption;
|
|
85
|
+
const multiple = mode === "multiple";
|
|
86
|
+
const hasValue = selectedOptions.length > 0;
|
|
87
|
+
const virtualEnabled = virtual && filteredOptions.length >= virtualThreshold;
|
|
88
|
+
const overscan = 3;
|
|
89
|
+
const visibleCount = Math.ceil(listHeight / optionHeight) + overscan * 2;
|
|
90
|
+
const virtualStart = virtualEnabled ? Math.max(0, Math.floor(scrollTop / optionHeight) - overscan) : 0;
|
|
91
|
+
const virtualEnd = virtualEnabled ? Math.min(filteredOptions.length, virtualStart + visibleCount) : filteredOptions.length;
|
|
92
|
+
const renderedOptions = virtualEnabled ? filteredOptions.slice(virtualStart, virtualEnd) : filteredOptions;
|
|
93
|
+
const enabledFilteredOptions = filteredOptions.filter((option) => !option.disabled);
|
|
94
|
+
const allFilteredSelected = enabledFilteredOptions.length > 0 && enabledFilteredOptions.every((option) => selectedValueSet.has(option.value));
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!open) return void 0;
|
|
97
|
+
function closeFromOutside(event) {
|
|
98
|
+
const target = event.target;
|
|
99
|
+
if (!rootRef.current?.contains(target) && !popupRef.current?.contains(target)) closeDropdown();
|
|
100
|
+
}
|
|
101
|
+
document.addEventListener("mousedown", closeFromOutside);
|
|
102
|
+
return () => document.removeEventListener("mousedown", closeFromOutside);
|
|
103
|
+
}, [open]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (open && (showSearch || allowInput)) searchRef.current?.focus();
|
|
106
|
+
}, [allowInput, open, showSearch]);
|
|
107
|
+
function firstEnabledIndex() {
|
|
108
|
+
return filteredOptions.findIndex((option) => !option.disabled);
|
|
109
|
+
}
|
|
110
|
+
function closeDropdown() {
|
|
111
|
+
setOpen(false);
|
|
112
|
+
setQuery("");
|
|
113
|
+
setScrollTop(0);
|
|
114
|
+
}
|
|
115
|
+
function openDropdown() {
|
|
116
|
+
if (disabled || loading) return;
|
|
117
|
+
const selectedIndex = filteredOptions.findIndex((option) => selectedValueSet.has(option.value) && !option.disabled);
|
|
118
|
+
setActiveIndex(selectedIndex >= 0 ? selectedIndex : firstEnabledIndex());
|
|
119
|
+
setOpen(true);
|
|
120
|
+
}
|
|
121
|
+
function keepActiveVisible(index) {
|
|
122
|
+
if (!virtualEnabled || !listRef.current) return;
|
|
123
|
+
const optionTop = index * optionHeight;
|
|
124
|
+
const optionBottom = optionTop + optionHeight;
|
|
125
|
+
const viewportTop = listRef.current.scrollTop;
|
|
126
|
+
const viewportBottom = viewportTop + listHeight;
|
|
127
|
+
const nextScrollTop = optionTop < viewportTop ? optionTop : optionBottom > viewportBottom ? optionBottom - listHeight : viewportTop;
|
|
128
|
+
if (nextScrollTop !== viewportTop) {
|
|
129
|
+
listRef.current.scrollTop = nextScrollTop;
|
|
130
|
+
setScrollTop(nextScrollTop);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function moveActive(direction) {
|
|
134
|
+
if (filteredOptions.length === 0) return;
|
|
135
|
+
let nextIndex = activeIndex;
|
|
136
|
+
for (let index = 0; index < filteredOptions.length; index += 1) {
|
|
137
|
+
nextIndex = (nextIndex + direction + filteredOptions.length) % filteredOptions.length;
|
|
138
|
+
if (!filteredOptions[nextIndex]?.disabled) {
|
|
139
|
+
setActiveIndex(nextIndex);
|
|
140
|
+
keepActiveVisible(nextIndex);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function selectOption(option) {
|
|
146
|
+
if (option.disabled) return;
|
|
147
|
+
if (multiple) {
|
|
148
|
+
const nextValues = selectedValueSet.has(option.value) ? selectedValues.filter((item) => item !== option.value) : [...selectedValues, option.value];
|
|
149
|
+
setCurrentValue(nextValues);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
setCurrentValue(option.value);
|
|
153
|
+
closeDropdown();
|
|
154
|
+
}
|
|
155
|
+
function selectAllFiltered() {
|
|
156
|
+
if (allFilteredSelected) return;
|
|
157
|
+
const nextValues = [...selectedValues];
|
|
158
|
+
const nextValueSet = new Set(nextValues);
|
|
159
|
+
enabledFilteredOptions.forEach((option) => {
|
|
160
|
+
if (!nextValueSet.has(option.value)) nextValues.push(option.value);
|
|
161
|
+
});
|
|
162
|
+
setCurrentValue(nextValues);
|
|
163
|
+
}
|
|
164
|
+
function submitInputValue() {
|
|
165
|
+
if (!allowInput || !inputValue) return;
|
|
166
|
+
selectOption(exactInputOption ?? { label: inputValue, value: inputValue });
|
|
167
|
+
if (multiple) {
|
|
168
|
+
setQuery("");
|
|
169
|
+
setActiveIndex(-1);
|
|
170
|
+
setScrollTop(0);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function clearSelection() {
|
|
174
|
+
setCurrentValue(multiple ? [] : null);
|
|
175
|
+
}
|
|
176
|
+
function handleInteractionKeyDown(event, fromSearch = false) {
|
|
177
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
if (!open) openDropdown();
|
|
180
|
+
else moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
181
|
+
} else if (event.key === "Enter" || event.key === " " && !fromSearch) {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
if (!open) openDropdown();
|
|
184
|
+
else if (activeIndex >= 0 && filteredOptions[activeIndex]) selectOption(filteredOptions[activeIndex]);
|
|
185
|
+
else if (fromSearch && allowInput) submitInputValue();
|
|
186
|
+
} else if (event.key === "Escape") {
|
|
187
|
+
closeDropdown();
|
|
188
|
+
} else if (event.key === "Home" && open && !fromSearch) {
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
const firstIndex = firstEnabledIndex();
|
|
191
|
+
setActiveIndex(firstIndex);
|
|
192
|
+
keepActiveVisible(firstIndex);
|
|
193
|
+
} else if (event.key === "End" && open && !fromSearch) {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
const reversedIndex = [...filteredOptions].reverse().findIndex((option) => !option.disabled);
|
|
196
|
+
const lastIndex = reversedIndex < 0 ? -1 : filteredOptions.length - 1 - reversedIndex;
|
|
197
|
+
setActiveIndex(lastIndex);
|
|
198
|
+
keepActiveVisible(lastIndex);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function handleTriggerKeyDown(event) {
|
|
202
|
+
handleInteractionKeyDown(event);
|
|
203
|
+
onKeyDown?.(event);
|
|
204
|
+
}
|
|
205
|
+
function handleSearchChange(event) {
|
|
206
|
+
const nextQuery = event.target.value;
|
|
207
|
+
setQuery(nextQuery);
|
|
208
|
+
setActiveIndex(-1);
|
|
209
|
+
setScrollTop(0);
|
|
210
|
+
if (listRef.current) listRef.current.scrollTop = 0;
|
|
211
|
+
onSearch?.(nextQuery);
|
|
212
|
+
}
|
|
213
|
+
function clearValue(event) {
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
clearSelection();
|
|
216
|
+
}
|
|
217
|
+
function handleListScroll(event) {
|
|
218
|
+
if (virtualEnabled) setScrollTop(event.currentTarget.scrollTop);
|
|
219
|
+
}
|
|
220
|
+
function renderOption(option, renderedIndex) {
|
|
221
|
+
const optionIndex = virtualEnabled ? virtualStart + renderedIndex : renderedIndex;
|
|
222
|
+
const selected = selectedValueSet.has(option.value);
|
|
223
|
+
return /* @__PURE__ */ jsxs(
|
|
224
|
+
"div",
|
|
225
|
+
{
|
|
226
|
+
id: `${listboxId}-${optionIndex}`,
|
|
227
|
+
className: `sia-select__option${selected ? " is-selected" : ""}${optionIndex === activeIndex ? " is-active" : ""}${option.disabled ? " is-disabled" : ""}`,
|
|
228
|
+
role: "option",
|
|
229
|
+
"aria-selected": selected,
|
|
230
|
+
"aria-disabled": option.disabled || void 0,
|
|
231
|
+
style: virtualEnabled ? { position: "absolute", top: optionIndex * optionHeight, right: 0, left: 0, height: optionHeight } : void 0,
|
|
232
|
+
onMouseEnter: () => !option.disabled && setActiveIndex(optionIndex),
|
|
233
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
234
|
+
onClick: () => selectOption(option),
|
|
235
|
+
children: [
|
|
236
|
+
/* @__PURE__ */ jsx("span", { children: option.label }),
|
|
237
|
+
selected ? /* @__PURE__ */ jsx(Icon, { name: "check", size: 15 }) : null
|
|
238
|
+
]
|
|
239
|
+
},
|
|
240
|
+
`${typeof option.value}-${option.value}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const visibleTags = selectedOptions.slice(0, Math.max(0, maxTagCount));
|
|
244
|
+
const hiddenTagCount = selectedOptions.length - visibleTags.length;
|
|
245
|
+
return /* @__PURE__ */ jsxs("div", { ref: rootRef, className: `sia-select sia-select--${size} sia-select--${status}${open ? " is-open" : ""}${disabled ? " is-disabled" : ""}${multiple ? " sia-select--multiple" : ""} ${className}`.trim(), children: [
|
|
246
|
+
/* @__PURE__ */ jsxs(
|
|
247
|
+
"button",
|
|
248
|
+
{
|
|
249
|
+
...props,
|
|
250
|
+
ref: forwardedRef,
|
|
251
|
+
className: "sia-select__trigger",
|
|
252
|
+
id: selectId,
|
|
253
|
+
type: "button",
|
|
254
|
+
role: "combobox",
|
|
255
|
+
"aria-controls": listboxId,
|
|
256
|
+
"aria-expanded": open,
|
|
257
|
+
"aria-haspopup": "listbox",
|
|
258
|
+
"aria-activedescendant": open && activeIndex >= 0 ? `${listboxId}-${activeIndex}` : void 0,
|
|
259
|
+
"aria-invalid": status === "error" || void 0,
|
|
260
|
+
disabled,
|
|
261
|
+
onClick: () => open ? closeDropdown() : openDropdown(),
|
|
262
|
+
onKeyDown: handleTriggerKeyDown,
|
|
263
|
+
children: [
|
|
264
|
+
multiple && hasValue ? /* @__PURE__ */ jsxs("span", { className: "sia-select__tags", children: [
|
|
265
|
+
visibleTags.map((option) => /* @__PURE__ */ jsx("span", { className: "sia-select__tag", children: option.label }, `${typeof option.value}-${option.value}`)),
|
|
266
|
+
hiddenTagCount > 0 ? /* @__PURE__ */ jsxs("span", { className: "sia-select__tag sia-select__tag--rest", children: [
|
|
267
|
+
"+",
|
|
268
|
+
hiddenTagCount
|
|
269
|
+
] }) : null
|
|
270
|
+
] }) : /* @__PURE__ */ jsx("span", { className: `sia-select__value${hasValue ? "" : " is-placeholder"}`, children: selectedOptions[0]?.label ?? placeholder }),
|
|
271
|
+
loading ? /* @__PURE__ */ jsx("span", { className: "sia-select__spinner", "aria-hidden": "true" }) : null,
|
|
272
|
+
/* @__PURE__ */ jsx(Icon, { className: "sia-select__arrow", name: "chevron-down", size: 15 })
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
),
|
|
276
|
+
allowClear && hasValue && !disabled && !loading ? /* @__PURE__ */ jsx("button", { className: "sia-select__clear", type: "button", "aria-label": "\u6E05\u7A7A\u9009\u62E9", onClick: clearValue, children: /* @__PURE__ */ jsx(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null,
|
|
277
|
+
/* @__PURE__ */ jsxs(PopupPortal, { ref: popupRef, anchorRef: rootRef, open, className: "sia-select__dropdown", children: [
|
|
278
|
+
showSearch || allowInput ? /* @__PURE__ */ jsxs("label", { className: "sia-select__search", children: [
|
|
279
|
+
/* @__PURE__ */ jsx(Icon, { name: "search", size: 15 }),
|
|
280
|
+
/* @__PURE__ */ jsx("input", { ref: searchRef, value: query, maxLength: inputMaxLength, onChange: handleSearchChange, onKeyDown: (event) => handleInteractionKeyDown(event, true), placeholder: searchPlaceholder, "aria-label": searchPlaceholder })
|
|
281
|
+
] }) : null,
|
|
282
|
+
canSubmitInput ? /* @__PURE__ */ jsxs("button", { type: "button", className: "sia-select__input-option", onMouseDown: (event) => event.preventDefault(), onClick: submitInputValue, children: [
|
|
283
|
+
/* @__PURE__ */ jsx(Icon, { name: "plus", size: 14 }),
|
|
284
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
285
|
+
"\u4F7F\u7528\u201C",
|
|
286
|
+
inputValue,
|
|
287
|
+
"\u201D"
|
|
288
|
+
] })
|
|
289
|
+
] }) : null,
|
|
290
|
+
multiple && showSelectAll ? /* @__PURE__ */ jsxs("div", { className: "sia-select__actions", children: [
|
|
291
|
+
/* @__PURE__ */ jsx("button", { type: "button", disabled: allFilteredSelected || enabledFilteredOptions.length === 0, onClick: selectAllFiltered, children: "\u5168\u9009" }),
|
|
292
|
+
/* @__PURE__ */ jsx("button", { type: "button", disabled: !hasValue, onClick: clearSelection, children: "\u6E05\u9664" }),
|
|
293
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
294
|
+
selectedValues.length,
|
|
295
|
+
" \u9879\u5DF2\u9009"
|
|
296
|
+
] })
|
|
297
|
+
] }) : null,
|
|
298
|
+
/* @__PURE__ */ jsx(
|
|
299
|
+
"div",
|
|
300
|
+
{
|
|
301
|
+
ref: listRef,
|
|
302
|
+
id: listboxId,
|
|
303
|
+
className: "sia-select__list",
|
|
304
|
+
role: "listbox",
|
|
305
|
+
"aria-labelledby": selectId,
|
|
306
|
+
"aria-multiselectable": multiple || void 0,
|
|
307
|
+
style: { maxHeight: listHeight },
|
|
308
|
+
onScroll: handleListScroll,
|
|
309
|
+
children: filteredOptions.length > 0 ? virtualEnabled ? /* @__PURE__ */ jsx("div", { className: "sia-select__virtual-space", style: { height: filteredOptions.length * optionHeight }, children: renderedOptions.map(renderOption) }) : renderedOptions.map(renderOption) : canSubmitInput ? null : /* @__PURE__ */ jsx("div", { className: "sia-select__empty", children: notFoundContent })
|
|
310
|
+
}
|
|
311
|
+
)
|
|
312
|
+
] })
|
|
313
|
+
] });
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
export {
|
|
317
|
+
Select
|
|
318
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/components/Button.tsx
|
|
2
|
+
import { forwardRef, useRef } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
var Button = forwardRef(function Button2({
|
|
5
|
+
variant = "default",
|
|
6
|
+
size = "medium",
|
|
7
|
+
loading = false,
|
|
8
|
+
block = false,
|
|
9
|
+
danger = false,
|
|
10
|
+
icon,
|
|
11
|
+
iconPosition = "start",
|
|
12
|
+
className = "",
|
|
13
|
+
children,
|
|
14
|
+
disabled,
|
|
15
|
+
onClick,
|
|
16
|
+
style,
|
|
17
|
+
...props
|
|
18
|
+
}, forwardedRef) {
|
|
19
|
+
const localRef = useRef(null);
|
|
20
|
+
function setRef(node) {
|
|
21
|
+
localRef.current = node;
|
|
22
|
+
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
23
|
+
else if (forwardedRef) forwardedRef.current = node;
|
|
24
|
+
}
|
|
25
|
+
function handleClick(event) {
|
|
26
|
+
const button = localRef.current;
|
|
27
|
+
if (button && variant === "primary") {
|
|
28
|
+
const rect = button.getBoundingClientRect();
|
|
29
|
+
button.style.setProperty("--sia-wave-x", `${event.clientX - rect.left}px`);
|
|
30
|
+
button.style.setProperty("--sia-wave-y", `${event.clientY - rect.top}px`);
|
|
31
|
+
button.dataset.wave = "active";
|
|
32
|
+
window.setTimeout(() => delete button.dataset.wave, 360);
|
|
33
|
+
}
|
|
34
|
+
onClick?.(event);
|
|
35
|
+
}
|
|
36
|
+
const mergedStyle = block ? { ...style, width: "100%" } : style ?? {};
|
|
37
|
+
return /* @__PURE__ */ jsxs(
|
|
38
|
+
"button",
|
|
39
|
+
{
|
|
40
|
+
ref: setRef,
|
|
41
|
+
type: "button",
|
|
42
|
+
className: `sia-button sia-button--${variant} sia-button--${size}${danger ? " sia-button--danger" : ""} ${className}`.trim(),
|
|
43
|
+
"aria-busy": loading || void 0,
|
|
44
|
+
disabled: disabled || loading,
|
|
45
|
+
onClick: handleClick,
|
|
46
|
+
style: mergedStyle,
|
|
47
|
+
...props,
|
|
48
|
+
children: [
|
|
49
|
+
loading ? /* @__PURE__ */ jsx("span", { className: "sia-button__spinner", "aria-hidden": "true" }) : icon && iconPosition === "start" ? /* @__PURE__ */ jsx("span", { className: "sia-button__icon", children: icon }) : null,
|
|
50
|
+
children !== void 0 && children !== null ? /* @__PURE__ */ jsx("span", { children }) : null,
|
|
51
|
+
!loading && icon && iconPosition === "end" ? /* @__PURE__ */ jsx("span", { className: "sia-button__icon", children: icon }) : null
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
Button
|
|
59
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/components/TextArea.tsx
|
|
2
|
+
import { forwardRef, useId, useState } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
var TextArea = forwardRef(function TextArea2({
|
|
5
|
+
label,
|
|
6
|
+
hint,
|
|
7
|
+
status = "default",
|
|
8
|
+
showCount = false,
|
|
9
|
+
className = "",
|
|
10
|
+
id,
|
|
11
|
+
disabled,
|
|
12
|
+
value,
|
|
13
|
+
defaultValue,
|
|
14
|
+
maxLength,
|
|
15
|
+
onChange,
|
|
16
|
+
...props
|
|
17
|
+
}, ref) {
|
|
18
|
+
const fallbackId = useId();
|
|
19
|
+
const textAreaId = id ?? fallbackId;
|
|
20
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(() => defaultValue === void 0 ? "" : String(defaultValue));
|
|
21
|
+
const currentText = value !== void 0 ? String(value) : uncontrolledValue;
|
|
22
|
+
const hintId = `${textAreaId}-hint`;
|
|
23
|
+
const describedBy = [props["aria-describedby"], hint ? hintId : null].filter(Boolean).join(" ") || void 0;
|
|
24
|
+
function handleChange(event) {
|
|
25
|
+
setUncontrolledValue(event.target.value);
|
|
26
|
+
onChange?.(event);
|
|
27
|
+
}
|
|
28
|
+
const control = /* @__PURE__ */ jsxs("span", { className: `sia-textarea-control sia-textarea-control--${status}${disabled ? " is-disabled" : ""}`, children: [
|
|
29
|
+
/* @__PURE__ */ jsx(
|
|
30
|
+
"textarea",
|
|
31
|
+
{
|
|
32
|
+
...props,
|
|
33
|
+
ref,
|
|
34
|
+
id: textAreaId,
|
|
35
|
+
className: "sia-textarea",
|
|
36
|
+
disabled,
|
|
37
|
+
value,
|
|
38
|
+
defaultValue,
|
|
39
|
+
maxLength,
|
|
40
|
+
"aria-describedby": describedBy,
|
|
41
|
+
"aria-invalid": status === "error" || void 0,
|
|
42
|
+
onChange: handleChange
|
|
43
|
+
}
|
|
44
|
+
),
|
|
45
|
+
showCount ? /* @__PURE__ */ jsxs("span", { className: `sia-textarea-control__count${maxLength !== void 0 && currentText.length >= maxLength ? " is-limit" : ""}`, "aria-live": "polite", children: [
|
|
46
|
+
currentText.length,
|
|
47
|
+
maxLength !== void 0 ? `/${maxLength}` : null
|
|
48
|
+
] }) : null
|
|
49
|
+
] });
|
|
50
|
+
if (!label && !hint) return /* @__PURE__ */ jsx("span", { className: `sia-field ${className}`.trim(), children: control });
|
|
51
|
+
return /* @__PURE__ */ jsxs("span", { className: `sia-field ${className}`.trim(), children: [
|
|
52
|
+
label ? /* @__PURE__ */ jsx("label", { className: "sia-field__label", htmlFor: textAreaId, children: label }) : null,
|
|
53
|
+
control,
|
|
54
|
+
hint ? /* @__PURE__ */ jsx("span", { id: hintId, className: `sia-field__hint sia-field__hint--${status}`, children: hint }) : null
|
|
55
|
+
] });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
TextArea
|
|
60
|
+
};
|