corestack-ui 0.1.0 → 0.2.1
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 +297 -8
- package/dist/index.css +20 -0
- package/dist/index.d.mts +241 -24
- package/dist/index.d.ts +241 -24
- package/dist/index.js +938 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +933 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +57 -54
package/dist/index.mjs
CHANGED
|
@@ -1,59 +1,948 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import React2, { forwardRef, useId, useState, useMemo, createContext, useRef, useContext, useCallback, useEffect, useLayoutEffect } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
/* Corestack UI - built with tsup */
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
|
|
8
|
+
// src/utils/cn.ts
|
|
9
|
+
var cn = (...parts) => parts.filter(Boolean).join(" ");
|
|
10
|
+
var getParentBackground = (button) => {
|
|
11
|
+
const computedStyle = getComputedStyle(button);
|
|
12
|
+
let bgColor = computedStyle.backgroundColor;
|
|
13
|
+
const fallback = "rgba(0, 0, 0, 0.1)";
|
|
14
|
+
try {
|
|
15
|
+
const match = bgColor.match(/\d+/g);
|
|
16
|
+
if (match && match.length >= 3) {
|
|
17
|
+
const r = Math.max(0, parseInt(match[0]) - 30);
|
|
18
|
+
const g = Math.max(0, parseInt(match[1]) - 30);
|
|
19
|
+
const b = Math.max(0, parseInt(match[2]) - 30);
|
|
20
|
+
const a = match[3] ? parseFloat(match[3]) : 0.3;
|
|
21
|
+
return {
|
|
22
|
+
bgColor: `rgba(${r}, ${g}, ${b}, 0.3)`
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.warn("Error parsing background color:", err);
|
|
12
27
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
return { bgColor: fallback };
|
|
29
|
+
};
|
|
30
|
+
function createRipple(event) {
|
|
31
|
+
const button = event.currentTarget;
|
|
32
|
+
const rect = button.getBoundingClientRect();
|
|
33
|
+
const circle = document.createElement("span");
|
|
34
|
+
const diameter = Math.max(button.clientWidth, button.clientHeight);
|
|
35
|
+
const radius = diameter / 2;
|
|
36
|
+
circle.style.width = circle.style.height = `${diameter}px`;
|
|
37
|
+
circle.style.left = `${event.clientX - rect.left - radius}px`;
|
|
38
|
+
circle.style.top = `${event.clientY - rect.top - radius}px`;
|
|
39
|
+
circle.classList.add("ripple");
|
|
40
|
+
const { bgColor } = getParentBackground(button);
|
|
41
|
+
circle.style.backgroundColor = bgColor;
|
|
42
|
+
const existingRipple = button.getElementsByClassName("ripple")[0];
|
|
43
|
+
if (existingRipple) existingRipple.remove();
|
|
44
|
+
button.appendChild(circle);
|
|
45
|
+
const timer = setTimeout(() => {
|
|
46
|
+
}, 300);
|
|
47
|
+
return () => clearTimeout(timer);
|
|
48
|
+
}
|
|
49
|
+
function Button({
|
|
50
|
+
children,
|
|
51
|
+
disableRipple,
|
|
52
|
+
isLoading,
|
|
53
|
+
className,
|
|
54
|
+
onClick,
|
|
55
|
+
...props
|
|
56
|
+
}) {
|
|
57
|
+
const handleClick = (e) => {
|
|
58
|
+
if (onClick) onClick(e);
|
|
59
|
+
if (!disableRipple) createRipple(e);
|
|
60
|
+
};
|
|
61
|
+
return /* @__PURE__ */ jsx("button", { ...props, className: cn(className), onClick: handleClick, children: isLoading ? /* @__PURE__ */ jsxs(
|
|
62
|
+
"svg",
|
|
63
|
+
{
|
|
64
|
+
"aria-hidden": "true",
|
|
65
|
+
className: "w-4 h-4 m-auto animate-spin dark:text-gray-500 fill-primary-700 dark:fill-white",
|
|
66
|
+
viewBox: "0 0 100 101",
|
|
67
|
+
fill: "none",
|
|
68
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
69
|
+
children: [
|
|
70
|
+
/* @__PURE__ */ jsx(
|
|
71
|
+
"path",
|
|
72
|
+
{
|
|
73
|
+
d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",
|
|
74
|
+
fill: "currentColor"
|
|
75
|
+
}
|
|
76
|
+
),
|
|
77
|
+
/* @__PURE__ */ jsx(
|
|
78
|
+
"path",
|
|
79
|
+
{
|
|
80
|
+
d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",
|
|
81
|
+
fill: "currentFill"
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
) : children });
|
|
87
|
+
}
|
|
88
|
+
function useAutocomplete(props) {
|
|
89
|
+
const {
|
|
90
|
+
options,
|
|
91
|
+
value,
|
|
92
|
+
defaultValue,
|
|
93
|
+
onChange,
|
|
94
|
+
getOptionLabel,
|
|
95
|
+
isOptionEqualToValue,
|
|
96
|
+
multiple,
|
|
97
|
+
disabled,
|
|
98
|
+
disableCloseOnSelect
|
|
99
|
+
} = props;
|
|
100
|
+
const getLabel = useCallback(
|
|
101
|
+
(option) => {
|
|
102
|
+
if (getOptionLabel) return getOptionLabel(option);
|
|
103
|
+
return String(option);
|
|
104
|
+
},
|
|
105
|
+
[getOptionLabel]
|
|
106
|
+
);
|
|
107
|
+
const isEqual = useCallback(
|
|
108
|
+
(option, v) => isOptionEqualToValue ? isOptionEqualToValue(option, v) : getLabel(option) === getLabel(v),
|
|
109
|
+
[isOptionEqualToValue, getLabel]
|
|
110
|
+
);
|
|
111
|
+
const isControlled = value !== void 0;
|
|
112
|
+
const [internalValue, setInternalValue] = useState(() => {
|
|
113
|
+
if (defaultValue !== void 0) return defaultValue;
|
|
114
|
+
return multiple ? [] : null;
|
|
115
|
+
});
|
|
116
|
+
const currentValue = isControlled ? value : internalValue;
|
|
117
|
+
const [open, setOpen] = useState(false);
|
|
118
|
+
const [inputValue, setInputValue] = useState(() => {
|
|
119
|
+
if (multiple) return "";
|
|
120
|
+
return currentValue && !Array.isArray(currentValue) ? getLabel(currentValue) : "";
|
|
121
|
+
});
|
|
122
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
123
|
+
const rootRef = useRef(null);
|
|
124
|
+
const inputRef = useRef(null);
|
|
125
|
+
const listboxRef = useRef(null);
|
|
126
|
+
const isFocusedRef = useRef(false);
|
|
127
|
+
const blurTimeoutRef = useRef(null);
|
|
128
|
+
const filteredOptions = useMemo(() => {
|
|
129
|
+
const query = inputValue.trim().toLowerCase();
|
|
130
|
+
if (!query) return options;
|
|
131
|
+
return options.filter(
|
|
132
|
+
(option) => getLabel(option).toLowerCase().includes(query)
|
|
133
|
+
);
|
|
134
|
+
}, [options, inputValue, getLabel]);
|
|
135
|
+
const selectedValues = useMemo(() => {
|
|
136
|
+
if (multiple)
|
|
137
|
+
return Array.isArray(currentValue) ? currentValue : [];
|
|
138
|
+
return currentValue && !Array.isArray(currentValue) ? [currentValue] : [];
|
|
139
|
+
}, [currentValue, multiple]);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (multiple) return;
|
|
142
|
+
if (!isFocusedRef.current) {
|
|
143
|
+
const next = currentValue && !Array.isArray(currentValue) ? getLabel(currentValue) : "";
|
|
144
|
+
setInputValue(next);
|
|
145
|
+
}
|
|
146
|
+
}, [currentValue, getLabel, multiple]);
|
|
147
|
+
const updateValue = useCallback(
|
|
148
|
+
(event, nextValue, reason) => {
|
|
149
|
+
if (!isControlled) {
|
|
150
|
+
setInternalValue(nextValue);
|
|
151
|
+
}
|
|
152
|
+
if (onChange) {
|
|
153
|
+
if (multiple) {
|
|
154
|
+
onChange(event, nextValue, reason);
|
|
155
|
+
} else {
|
|
156
|
+
onChange(event, nextValue, reason);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
[isControlled, onChange, multiple]
|
|
161
|
+
);
|
|
162
|
+
const selectOption = useCallback(
|
|
163
|
+
(event, option) => {
|
|
164
|
+
if (blurTimeoutRef.current) {
|
|
165
|
+
clearTimeout(blurTimeoutRef.current);
|
|
166
|
+
blurTimeoutRef.current = null;
|
|
167
|
+
}
|
|
168
|
+
if (multiple) {
|
|
169
|
+
const existing = Array.isArray(currentValue) ? currentValue : [];
|
|
170
|
+
const isSelected = existing.some((item) => isEqual(item, option));
|
|
171
|
+
const next = isSelected ? existing.filter((item) => !isEqual(item, option)) : [...existing, option];
|
|
172
|
+
updateValue(event, next, isSelected ? "removeOption" : "selectOption");
|
|
173
|
+
setInputValue("");
|
|
174
|
+
setActiveIndex(-1);
|
|
175
|
+
if (disableCloseOnSelect) setOpen(true);
|
|
176
|
+
else setOpen(false);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
updateValue(event, option, "selectOption");
|
|
180
|
+
setInputValue(getLabel(option));
|
|
181
|
+
if (!disableCloseOnSelect) {
|
|
182
|
+
setOpen(false);
|
|
183
|
+
}
|
|
184
|
+
setActiveIndex(-1);
|
|
185
|
+
},
|
|
186
|
+
[currentValue, getLabel, isEqual, multiple, updateValue]
|
|
187
|
+
);
|
|
188
|
+
const clearValue = useCallback(
|
|
189
|
+
(event) => {
|
|
190
|
+
updateValue(event, multiple ? [] : null, "clear");
|
|
191
|
+
setInputValue("");
|
|
192
|
+
setActiveIndex(-1);
|
|
193
|
+
},
|
|
194
|
+
[multiple, updateValue]
|
|
195
|
+
);
|
|
196
|
+
const removeOption = useCallback(
|
|
197
|
+
(event, option) => {
|
|
198
|
+
if (!multiple) return;
|
|
199
|
+
const existing = Array.isArray(currentValue) ? currentValue : [];
|
|
200
|
+
const next = existing.filter((item) => !isEqual(item, option));
|
|
201
|
+
updateValue(event, next, "removeOption");
|
|
202
|
+
setActiveIndex(-1);
|
|
203
|
+
},
|
|
204
|
+
[currentValue, isEqual, multiple, updateValue]
|
|
205
|
+
);
|
|
206
|
+
const setInputFocused = useCallback((focused) => {
|
|
207
|
+
isFocusedRef.current = focused;
|
|
208
|
+
}, []);
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
if (!open || activeIndex < 0 || !listboxRef.current) return;
|
|
211
|
+
const activeId = `autocomplete-option-${activeIndex}`;
|
|
212
|
+
const el = listboxRef.current.querySelector(`#${activeId}`);
|
|
213
|
+
if (el) {
|
|
214
|
+
el.scrollIntoView({ block: "nearest" });
|
|
215
|
+
}
|
|
216
|
+
}, [open, activeIndex]);
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
const handleClickOutside = (event) => {
|
|
219
|
+
const root = rootRef.current;
|
|
220
|
+
const list = listboxRef.current;
|
|
221
|
+
if (!root) return;
|
|
222
|
+
if (root.contains(event.target) || (list == null ? void 0 : list.contains(event.target))) return;
|
|
223
|
+
setOpen(false);
|
|
224
|
+
setActiveIndex(-1);
|
|
225
|
+
};
|
|
226
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
227
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
228
|
+
}, []);
|
|
229
|
+
const handleInputChange = useCallback(
|
|
230
|
+
(event) => {
|
|
231
|
+
var _a;
|
|
232
|
+
setInputValue(event.target.value);
|
|
233
|
+
setOpen(true);
|
|
234
|
+
setActiveIndex(0);
|
|
235
|
+
(_a = props.onChange) == null ? void 0 : _a.call(props, event, event.target.value, "selectOption");
|
|
236
|
+
},
|
|
237
|
+
[setInputValue, setOpen, setActiveIndex]
|
|
238
|
+
);
|
|
239
|
+
const handleInputFocus = useCallback(
|
|
240
|
+
(event) => {
|
|
241
|
+
var _a;
|
|
242
|
+
if (!!disabled) return;
|
|
243
|
+
if (blurTimeoutRef.current) {
|
|
244
|
+
clearTimeout(blurTimeoutRef.current);
|
|
245
|
+
blurTimeoutRef.current = null;
|
|
246
|
+
}
|
|
247
|
+
setInputFocused(true);
|
|
248
|
+
setOpen(true);
|
|
249
|
+
if (filteredOptions.length > 0) {
|
|
250
|
+
setActiveIndex(0);
|
|
251
|
+
}
|
|
252
|
+
(_a = props.onFocus) == null ? void 0 : _a.call(props, event);
|
|
253
|
+
},
|
|
254
|
+
[
|
|
255
|
+
!!disabled,
|
|
256
|
+
setInputFocused,
|
|
257
|
+
setOpen,
|
|
258
|
+
filteredOptions.length,
|
|
259
|
+
setActiveIndex
|
|
260
|
+
]
|
|
261
|
+
);
|
|
262
|
+
const handleInputBlur = useCallback(
|
|
263
|
+
(event) => {
|
|
264
|
+
var _a;
|
|
265
|
+
setInputFocused(false);
|
|
266
|
+
if (blurTimeoutRef.current) {
|
|
267
|
+
clearTimeout(blurTimeoutRef.current);
|
|
268
|
+
}
|
|
269
|
+
blurTimeoutRef.current = setTimeout(() => {
|
|
270
|
+
const root = rootRef.current;
|
|
271
|
+
if (!root) return;
|
|
272
|
+
if (root.contains(document.activeElement)) return;
|
|
273
|
+
setOpen(false);
|
|
274
|
+
setActiveIndex(-1);
|
|
275
|
+
blurTimeoutRef.current = null;
|
|
276
|
+
}, 150);
|
|
277
|
+
(_a = props.onBlur) == null ? void 0 : _a.call(props, event);
|
|
278
|
+
},
|
|
279
|
+
[setInputFocused, setOpen, setActiveIndex]
|
|
280
|
+
);
|
|
281
|
+
const handleToggleClick = useCallback(
|
|
282
|
+
(event) => {
|
|
283
|
+
var _a;
|
|
284
|
+
if (!!disabled) return;
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
if (open) {
|
|
287
|
+
setOpen(false);
|
|
288
|
+
setActiveIndex(-1);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
setOpen(true);
|
|
292
|
+
setActiveIndex(0);
|
|
293
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
294
|
+
},
|
|
295
|
+
[!!disabled, open, setActiveIndex, setOpen, inputRef]
|
|
296
|
+
);
|
|
297
|
+
const handleKeyDown = useCallback(
|
|
298
|
+
(event) => {
|
|
299
|
+
if (!!disabled) return;
|
|
300
|
+
if (event.key === "ArrowDown") {
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
setOpen(true);
|
|
303
|
+
setActiveIndex(
|
|
304
|
+
(prev) => Math.min(prev + 1, filteredOptions.length - 1)
|
|
305
|
+
);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (event.key === "ArrowUp") {
|
|
309
|
+
event.preventDefault();
|
|
310
|
+
setOpen(true);
|
|
311
|
+
setActiveIndex((prev) => Math.max(prev - 1, 0));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (event.key === "Enter") {
|
|
315
|
+
if (!open || activeIndex < 0) return;
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
const option = filteredOptions[activeIndex];
|
|
318
|
+
if (option) {
|
|
319
|
+
selectOption(event, option);
|
|
320
|
+
}
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (event.key === "Escape") {
|
|
324
|
+
event.preventDefault();
|
|
325
|
+
setOpen(false);
|
|
326
|
+
setActiveIndex(-1);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
[
|
|
331
|
+
activeIndex,
|
|
332
|
+
filteredOptions,
|
|
333
|
+
!!disabled,
|
|
334
|
+
open,
|
|
335
|
+
selectOption,
|
|
336
|
+
setActiveIndex,
|
|
337
|
+
setOpen
|
|
338
|
+
]
|
|
339
|
+
);
|
|
340
|
+
return {
|
|
341
|
+
rootRef,
|
|
342
|
+
inputRef,
|
|
343
|
+
listboxRef,
|
|
344
|
+
open,
|
|
345
|
+
inputValue,
|
|
346
|
+
activeIndex,
|
|
347
|
+
filteredOptions,
|
|
348
|
+
selectedValues,
|
|
349
|
+
getLabel,
|
|
350
|
+
isEqual,
|
|
351
|
+
selectOption,
|
|
352
|
+
clearValue,
|
|
353
|
+
removeOption,
|
|
354
|
+
disabled: !!disabled,
|
|
355
|
+
handleToggleClick,
|
|
356
|
+
handleInputChange,
|
|
357
|
+
handleInputFocus,
|
|
358
|
+
handleInputBlur,
|
|
359
|
+
setOpen,
|
|
360
|
+
handleKeyDown
|
|
361
|
+
};
|
|
23
362
|
}
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
363
|
+
var MARGIN = 16;
|
|
364
|
+
function useDropdownPosition(anchor, menuRef) {
|
|
365
|
+
const [position, setPosition] = useState(null);
|
|
366
|
+
useLayoutEffect(() => {
|
|
367
|
+
let mounted = true;
|
|
368
|
+
let ro = null;
|
|
369
|
+
let rafId = null;
|
|
370
|
+
let stopPolling = false;
|
|
371
|
+
function getAnchor() {
|
|
372
|
+
if (!anchor) return null;
|
|
373
|
+
return typeof anchor === "function" ? anchor() : anchor != null ? anchor : null;
|
|
374
|
+
}
|
|
375
|
+
function calc(menu, a) {
|
|
376
|
+
const aRect = a.getBoundingClientRect();
|
|
377
|
+
const mRect = menu.getBoundingClientRect();
|
|
378
|
+
const vw = window.innerWidth;
|
|
379
|
+
const vh = window.innerHeight;
|
|
380
|
+
let placement = "bottom";
|
|
381
|
+
let top = Math.round(aRect.bottom);
|
|
382
|
+
if (aRect.bottom + mRect.height + MARGIN > vh) {
|
|
383
|
+
placement = "top";
|
|
384
|
+
top = Math.round(aRect.top - (mRect.height + MARGIN));
|
|
385
|
+
}
|
|
386
|
+
let left = Math.round(aRect.left);
|
|
387
|
+
const width = Math.round(aRect.width);
|
|
388
|
+
if (left + width + MARGIN > vw) {
|
|
389
|
+
left = Math.max(MARGIN, vw - width - MARGIN);
|
|
390
|
+
}
|
|
391
|
+
return { top, left, width, placement };
|
|
392
|
+
}
|
|
393
|
+
function scheduleUpdate(menu, a) {
|
|
394
|
+
if (rafId != null) cancelAnimationFrame(rafId);
|
|
395
|
+
rafId = requestAnimationFrame(() => {
|
|
396
|
+
if (!mounted) return;
|
|
397
|
+
const next = calc(menu, a);
|
|
398
|
+
setPosition((prev) => {
|
|
399
|
+
if (!prev || prev.top !== next.top || prev.left !== next.left || prev.width !== next.width || prev.placement !== next.placement) {
|
|
400
|
+
return next;
|
|
401
|
+
}
|
|
402
|
+
return prev;
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function setupForMenu(menu) {
|
|
407
|
+
const a = getAnchor();
|
|
408
|
+
if (!a) return;
|
|
409
|
+
const initial = calc(menu, a);
|
|
410
|
+
if (mounted)
|
|
411
|
+
setPosition((prev) => {
|
|
412
|
+
if (!prev || prev.top !== initial.top || prev.left !== initial.left || prev.width !== initial.width || prev.placement !== initial.placement) {
|
|
413
|
+
return initial;
|
|
414
|
+
}
|
|
415
|
+
return prev;
|
|
416
|
+
});
|
|
417
|
+
ro = new ResizeObserver(() => scheduleUpdate(menu, a));
|
|
418
|
+
ro.observe(menu);
|
|
419
|
+
}
|
|
420
|
+
let cleanupFn = null;
|
|
421
|
+
(function waitForMenu() {
|
|
422
|
+
const menu = menuRef.current;
|
|
423
|
+
if (menu) {
|
|
424
|
+
setupForMenu(menu);
|
|
425
|
+
const onScroll = () => {
|
|
426
|
+
const a = getAnchor();
|
|
427
|
+
if (!a || !menu) return;
|
|
428
|
+
scheduleUpdate(menu, a);
|
|
429
|
+
};
|
|
430
|
+
const onResize = () => {
|
|
431
|
+
const a = getAnchor();
|
|
432
|
+
if (!a || !menu) return;
|
|
433
|
+
scheduleUpdate(menu, a);
|
|
434
|
+
};
|
|
435
|
+
window.addEventListener("scroll", onScroll, true);
|
|
436
|
+
window.addEventListener("resize", onResize);
|
|
437
|
+
cleanupFn = () => {
|
|
438
|
+
if (ro) {
|
|
439
|
+
ro.disconnect();
|
|
440
|
+
ro = null;
|
|
441
|
+
}
|
|
442
|
+
if (rafId != null) {
|
|
443
|
+
cancelAnimationFrame(rafId);
|
|
444
|
+
rafId = null;
|
|
445
|
+
}
|
|
446
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
447
|
+
window.removeEventListener("resize", onResize);
|
|
448
|
+
};
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (stopPolling) return;
|
|
452
|
+
requestAnimationFrame(waitForMenu);
|
|
453
|
+
})();
|
|
454
|
+
return () => {
|
|
455
|
+
mounted = false;
|
|
456
|
+
stopPolling = true;
|
|
457
|
+
if (cleanupFn) cleanupFn();
|
|
458
|
+
};
|
|
459
|
+
}, [anchor, menuRef]);
|
|
460
|
+
return { position };
|
|
461
|
+
}
|
|
462
|
+
function Autocomplete(props) {
|
|
463
|
+
const {
|
|
464
|
+
renderInput,
|
|
465
|
+
loading,
|
|
466
|
+
disabled,
|
|
467
|
+
multiple,
|
|
468
|
+
placeholder,
|
|
469
|
+
className,
|
|
470
|
+
renderOption
|
|
471
|
+
} = props;
|
|
472
|
+
const {
|
|
473
|
+
rootRef,
|
|
474
|
+
inputRef,
|
|
475
|
+
listboxRef,
|
|
476
|
+
open,
|
|
477
|
+
setOpen,
|
|
478
|
+
inputValue,
|
|
479
|
+
activeIndex,
|
|
480
|
+
filteredOptions,
|
|
481
|
+
selectedValues,
|
|
482
|
+
getLabel,
|
|
483
|
+
isEqual,
|
|
484
|
+
selectOption,
|
|
485
|
+
clearValue,
|
|
486
|
+
removeOption,
|
|
487
|
+
disabled: isDisabled,
|
|
488
|
+
handleToggleClick,
|
|
489
|
+
handleInputChange,
|
|
490
|
+
handleInputFocus,
|
|
491
|
+
handleInputBlur,
|
|
492
|
+
handleKeyDown
|
|
493
|
+
} = useAutocomplete(props);
|
|
494
|
+
const onRemove = React2.useCallback(
|
|
495
|
+
(event, index) => {
|
|
496
|
+
event.stopPropagation();
|
|
497
|
+
const option = selectedValues[index];
|
|
498
|
+
if (!option || !removeOption) return;
|
|
499
|
+
removeOption(event, option);
|
|
500
|
+
},
|
|
501
|
+
[removeOption, selectedValues]
|
|
502
|
+
);
|
|
503
|
+
const listboxId = useMemo(
|
|
504
|
+
() => `autocomplete-listbox-${Math.random().toString(36).slice(2, 9)}`,
|
|
505
|
+
[]
|
|
506
|
+
);
|
|
507
|
+
const startAdornment = useMemo(() => {
|
|
508
|
+
if (!multiple || selectedValues.length === 0) return void 0;
|
|
509
|
+
return /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: selectedValues.map((option, index) => /* @__PURE__ */ jsxs(
|
|
510
|
+
"span",
|
|
33
511
|
{
|
|
34
|
-
className: "
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
512
|
+
className: "inline-flex gap-2 items-center rounded-full bg-slate-100 px-2 py-0.5 text-xs text-slate-700",
|
|
513
|
+
children: [
|
|
514
|
+
getLabel(option),
|
|
515
|
+
/* @__PURE__ */ jsx(Button, { type: "button", className: "w-4", onClick: (event) => onRemove(event, index), children: /* @__PURE__ */ jsx("svg", { focusable: "false", "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx("path", { d: "M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z" }) }) })
|
|
516
|
+
]
|
|
517
|
+
},
|
|
518
|
+
`${getLabel(option)}-${index}`
|
|
519
|
+
)) });
|
|
520
|
+
}, [getLabel, multiple, onRemove, selectedValues]);
|
|
521
|
+
const endAdornment = useMemo(() => {
|
|
522
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center absolute right-3", children: [
|
|
523
|
+
inputValue ? /* @__PURE__ */ jsx(
|
|
524
|
+
Button,
|
|
525
|
+
{
|
|
526
|
+
type: "button",
|
|
527
|
+
className: `text-xs text-slate-500 hover:text-slate-700 transition hover:bg-gray-25 size-5 rounded-full flex items-center justify-center ${disabled ? "hover:bg-transparent" : ""}`,
|
|
528
|
+
onClick: (event) => {
|
|
529
|
+
event.stopPropagation();
|
|
530
|
+
clearValue(event);
|
|
531
|
+
},
|
|
532
|
+
"aria-label": "Clear",
|
|
533
|
+
disabled: isDisabled,
|
|
534
|
+
children: /* @__PURE__ */ jsx(
|
|
535
|
+
"svg",
|
|
536
|
+
{
|
|
537
|
+
focusable: "false",
|
|
538
|
+
"aria-hidden": "true",
|
|
539
|
+
viewBox: "0 0 24 24",
|
|
540
|
+
className: "size-4",
|
|
541
|
+
children: /* @__PURE__ */ jsx("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" })
|
|
542
|
+
}
|
|
543
|
+
)
|
|
544
|
+
}
|
|
545
|
+
) : null,
|
|
546
|
+
/* @__PURE__ */ jsx(
|
|
547
|
+
Button,
|
|
548
|
+
{
|
|
549
|
+
type: "button",
|
|
550
|
+
className: `flex items-center text-slate-500 hover:text-slate-700 transition hover:bg-gray-25 size-5 justify-center rounded-full ${disabled ? "hover:bg-transparent" : ""}`,
|
|
551
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
552
|
+
onClick: handleToggleClick,
|
|
553
|
+
"aria-label": open ? "Close" : "Open",
|
|
554
|
+
disabled: isDisabled,
|
|
555
|
+
children: /* @__PURE__ */ jsx(
|
|
556
|
+
"span",
|
|
557
|
+
{
|
|
558
|
+
className: ` transition-transform ${open ? "rotate-180" : "rotate-0"}`,
|
|
559
|
+
children: /* @__PURE__ */ jsx(
|
|
560
|
+
"svg",
|
|
561
|
+
{
|
|
562
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
563
|
+
viewBox: "0 0 12 12",
|
|
564
|
+
width: "12",
|
|
565
|
+
height: "12",
|
|
566
|
+
fill: "none",
|
|
567
|
+
children: /* @__PURE__ */ jsx(
|
|
568
|
+
"path",
|
|
569
|
+
{
|
|
570
|
+
d: "M1.5 3.5l4.5 4.5 4.5-4.5",
|
|
571
|
+
stroke: "#1E4678",
|
|
572
|
+
"stroke-width": "1.667",
|
|
573
|
+
"stroke-linecap": "round",
|
|
574
|
+
"stroke-linejoin": "round"
|
|
575
|
+
}
|
|
576
|
+
)
|
|
577
|
+
}
|
|
578
|
+
)
|
|
579
|
+
}
|
|
580
|
+
)
|
|
581
|
+
}
|
|
582
|
+
)
|
|
583
|
+
] });
|
|
584
|
+
}, [clearValue, handleToggleClick, inputValue, isDisabled, loading, open]);
|
|
585
|
+
const inputParams = useMemo(
|
|
586
|
+
() => ({
|
|
587
|
+
...props,
|
|
588
|
+
options: void 0,
|
|
589
|
+
getOptionLabel: void 0,
|
|
590
|
+
ref: inputRef,
|
|
591
|
+
role: "combobox",
|
|
592
|
+
"aria-autocomplete": "list",
|
|
593
|
+
"aria-controls": open ? listboxId : void 0,
|
|
594
|
+
"aria-expanded": open,
|
|
595
|
+
"aria-activedescendant": open && activeIndex >= 0 ? `autocomplete-option-${activeIndex}` : void 0,
|
|
596
|
+
autocomplete: "off",
|
|
597
|
+
value: inputValue,
|
|
598
|
+
placeholder,
|
|
599
|
+
onChange: handleInputChange,
|
|
600
|
+
onKeyDown: handleKeyDown,
|
|
601
|
+
onFocus: handleInputFocus,
|
|
602
|
+
onBlur: handleInputBlur,
|
|
603
|
+
disabled: isDisabled,
|
|
604
|
+
InputProps: {
|
|
605
|
+
endAdornment,
|
|
606
|
+
className: "min-h-[40px]"
|
|
607
|
+
}
|
|
608
|
+
}),
|
|
609
|
+
[
|
|
610
|
+
activeIndex,
|
|
611
|
+
endAdornment,
|
|
612
|
+
handleInputBlur,
|
|
613
|
+
handleInputChange,
|
|
614
|
+
handleInputFocus,
|
|
615
|
+
handleKeyDown,
|
|
616
|
+
inputValue,
|
|
617
|
+
isDisabled,
|
|
618
|
+
listboxId,
|
|
619
|
+
open,
|
|
620
|
+
placeholder,
|
|
621
|
+
startAdornment
|
|
622
|
+
]
|
|
623
|
+
);
|
|
624
|
+
if (!renderInput) {
|
|
625
|
+
return /* @__PURE__ */ jsx("p", { children: "Render Input Prop Must be pass " });
|
|
626
|
+
}
|
|
627
|
+
const wrapperRef = useRef(null);
|
|
628
|
+
const { position } = useDropdownPosition(() => rootRef.current, listboxRef);
|
|
629
|
+
return /* @__PURE__ */ jsxs(
|
|
630
|
+
"div",
|
|
631
|
+
{
|
|
632
|
+
ref: rootRef,
|
|
633
|
+
onClick: () => {
|
|
634
|
+
if (!open) {
|
|
635
|
+
setOpen(true);
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
className: `${className} [&_.input-container]:pe-[54px] [&_.input-container]:gap-0`,
|
|
639
|
+
children: [
|
|
640
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
641
|
+
startAdornment,
|
|
642
|
+
renderInput(inputParams)
|
|
643
|
+
] }),
|
|
644
|
+
open || open && loading ? (() => {
|
|
645
|
+
const portalNode = document.body;
|
|
646
|
+
const dropdown = /* @__PURE__ */ jsx(
|
|
647
|
+
"div",
|
|
648
|
+
{
|
|
649
|
+
ref: wrapperRef,
|
|
650
|
+
className: "p-1.5 rounded-md border border-slate-200 bg-white shadow-lg",
|
|
651
|
+
style: {
|
|
652
|
+
position: "fixed",
|
|
653
|
+
top: position ? position.top : 0,
|
|
654
|
+
left: position ? position.left : 0,
|
|
655
|
+
width: position ? position.width : void 0,
|
|
656
|
+
minWidth: position ? position.width : void 0,
|
|
657
|
+
zIndex: 1300,
|
|
658
|
+
visibility: position ? "visible" : "hidden"
|
|
659
|
+
},
|
|
660
|
+
children: /* @__PURE__ */ jsx(
|
|
661
|
+
"ul",
|
|
662
|
+
{
|
|
663
|
+
id: listboxId,
|
|
664
|
+
ref: listboxRef,
|
|
665
|
+
role: "listbox",
|
|
666
|
+
className: "max-h-60 sm:max-h-[325px] w-full overflow-auto ",
|
|
667
|
+
children: loading ? /* @__PURE__ */ jsxs(
|
|
668
|
+
"svg",
|
|
669
|
+
{
|
|
670
|
+
"aria-hidden": "true",
|
|
671
|
+
className: "w-4 h-4 m-auto animate-spin dark:text-gray-500 fill-primary-700 dark:fill-white",
|
|
672
|
+
viewBox: "0 0 100 101",
|
|
673
|
+
fill: "none",
|
|
674
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
675
|
+
children: [
|
|
676
|
+
/* @__PURE__ */ jsx(
|
|
677
|
+
"path",
|
|
678
|
+
{
|
|
679
|
+
d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",
|
|
680
|
+
fill: "currentColor"
|
|
681
|
+
}
|
|
682
|
+
),
|
|
683
|
+
/* @__PURE__ */ jsx(
|
|
684
|
+
"path",
|
|
685
|
+
{
|
|
686
|
+
d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",
|
|
687
|
+
fill: "currentFill"
|
|
688
|
+
}
|
|
689
|
+
)
|
|
690
|
+
]
|
|
691
|
+
}
|
|
692
|
+
) : filteredOptions.length === 0 ? /* @__PURE__ */ jsx("li", { className: "px-3 py-2 text-sm text-slate-500", children: "No Options" }) : filteredOptions.map((option, index) => {
|
|
693
|
+
const selected = selectedValues.some(
|
|
694
|
+
(item) => isEqual(item, option)
|
|
695
|
+
);
|
|
696
|
+
const optionProps = {
|
|
697
|
+
id: `autocomplete-option-${index}`,
|
|
698
|
+
role: "option",
|
|
699
|
+
"aria-selected": selected,
|
|
700
|
+
className: "cursor-pointer px-3 py-2 text-sm text-slate-700 hover:bg-slate-100 " + (index === activeIndex ? "bg-slate-100 " : "") + (selected ? "bg-slate-50 font-medium text-slate-900" : ""),
|
|
701
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
702
|
+
onClick: (event) => selectOption(event, option)
|
|
703
|
+
};
|
|
704
|
+
return renderOption ? renderOption(optionProps, option, { selected, index }) : /* @__PURE__ */ jsx(
|
|
705
|
+
"li",
|
|
706
|
+
{
|
|
707
|
+
...optionProps,
|
|
708
|
+
children: getLabel(option)
|
|
709
|
+
},
|
|
710
|
+
`${getLabel(option)}-${index}`
|
|
711
|
+
);
|
|
712
|
+
})
|
|
713
|
+
}
|
|
714
|
+
)
|
|
715
|
+
}
|
|
716
|
+
);
|
|
717
|
+
return portalNode ? ReactDOM.createPortal(dropdown, portalNode) : dropdown;
|
|
718
|
+
})() : null
|
|
719
|
+
]
|
|
720
|
+
}
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
var TextField = forwardRef(
|
|
724
|
+
({
|
|
725
|
+
value,
|
|
726
|
+
defaultValue,
|
|
727
|
+
onChange,
|
|
728
|
+
onBlur,
|
|
729
|
+
onFocus,
|
|
730
|
+
placeholder,
|
|
731
|
+
label,
|
|
732
|
+
helperText,
|
|
733
|
+
error = false,
|
|
734
|
+
disabled = false,
|
|
735
|
+
required = false,
|
|
736
|
+
multiline = false,
|
|
737
|
+
rows,
|
|
738
|
+
type = "text",
|
|
739
|
+
name,
|
|
740
|
+
id,
|
|
741
|
+
fullWidth = false,
|
|
742
|
+
size = "medium",
|
|
743
|
+
variant = "outlined",
|
|
744
|
+
InputProps,
|
|
745
|
+
className,
|
|
746
|
+
...rest
|
|
747
|
+
}, ref) => {
|
|
748
|
+
var _a;
|
|
749
|
+
const InputComponent = (_a = InputProps == null ? void 0 : InputProps.inputComponent) != null ? _a : multiline ? "textarea" : "input";
|
|
750
|
+
const reactId = useId();
|
|
751
|
+
const inputId = id != null ? id : `textfield-${reactId}`;
|
|
752
|
+
const isControlled = value !== void 0;
|
|
753
|
+
const [focused, setFocused] = useState(false);
|
|
754
|
+
const handleChange = (event) => {
|
|
755
|
+
onChange == null ? void 0 : onChange(event);
|
|
756
|
+
};
|
|
757
|
+
const handleFocus = (event) => {
|
|
758
|
+
setFocused(true);
|
|
759
|
+
onFocus == null ? void 0 : onFocus(event);
|
|
760
|
+
};
|
|
761
|
+
const handleBlur = (event) => {
|
|
762
|
+
setFocused(false);
|
|
763
|
+
onBlur == null ? void 0 : onBlur(event);
|
|
764
|
+
};
|
|
765
|
+
const sizeClasses = useMemo(() => {
|
|
766
|
+
if (size === "small") {
|
|
767
|
+
return {
|
|
768
|
+
container: `${multiline ? "min-h-10" : "h-[45px]"} text-sm`,
|
|
769
|
+
labelRest: "text-base mb-1",
|
|
770
|
+
padding: "py-2.5 px-[14px]",
|
|
771
|
+
gap: "gap-1.5"
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
return {
|
|
775
|
+
container: `${multiline ? "min-h-10" : "h-[45px]"} text-sm`,
|
|
776
|
+
labelRest: "text-base mb-1",
|
|
777
|
+
padding: "py-2.5 px-[14px]",
|
|
778
|
+
gap: "gap-1.5"
|
|
779
|
+
};
|
|
780
|
+
}, [size]);
|
|
781
|
+
const baseLabelColor = disabled ? "text-gray-400" : "text-gray-900";
|
|
782
|
+
const fieldBackground = variant === "filled" ? "bg-gray-50" : "bg-white";
|
|
783
|
+
const helperColor = error ? "text-error-500" : "text-gray-500";
|
|
784
|
+
const withStartAdornment = Boolean(InputProps == null ? void 0 : InputProps.startAdornment);
|
|
785
|
+
const withEndAdornment = Boolean(InputProps == null ? void 0 : InputProps.endAdornment);
|
|
786
|
+
const placeholderText = placeholder;
|
|
787
|
+
const inputValueProps = isControlled ? { value } : { defaultValue };
|
|
788
|
+
const outlinedBorder = cn(
|
|
789
|
+
"border transition-colors duration-200 rounded-lg",
|
|
790
|
+
disabled ? "border-gray-200" : error ? "!border-error-500" : "border-gray-300",
|
|
791
|
+
!disabled && !error && "group-hover:border-gray-400",
|
|
792
|
+
focused && !error && "border-primary-500",
|
|
793
|
+
focused && error && "!border-gray-500"
|
|
794
|
+
);
|
|
795
|
+
const filledBorder = cn(
|
|
796
|
+
"border-b transition-colors duration-200",
|
|
797
|
+
disabled ? "border-gray-200" : error ? "!border-b-error-500" : "border-gray-300",
|
|
798
|
+
!disabled && !error && "group-hover:border-gray-400",
|
|
799
|
+
focused && !error && "border-primary-500 border-b-2",
|
|
800
|
+
focused && error && "!border-b-error-500 border-b-2"
|
|
801
|
+
);
|
|
802
|
+
const rootClasses = cn(
|
|
803
|
+
"flex flex-col",
|
|
804
|
+
fullWidth ? "w-full" : "w-auto",
|
|
805
|
+
className
|
|
806
|
+
);
|
|
807
|
+
const containerClasses = cn(
|
|
808
|
+
"relative w-full group",
|
|
809
|
+
multiline ? "items-start" : "items-center",
|
|
810
|
+
"flex",
|
|
811
|
+
sizeClasses.container,
|
|
812
|
+
sizeClasses.padding,
|
|
813
|
+
sizeClasses.gap,
|
|
814
|
+
fieldBackground,
|
|
815
|
+
disabled && "bg-gray-100",
|
|
816
|
+
variant === "outlined" && outlinedBorder
|
|
817
|
+
);
|
|
818
|
+
const inputClasses = cn(
|
|
819
|
+
"peer w-full bg-transparent outline-none text-gray-900 text-base",
|
|
820
|
+
disabled && "!text-[#00000061] cursor-not-allowed",
|
|
821
|
+
type === "search" && "appearance-none",
|
|
822
|
+
withStartAdornment && "pl-0",
|
|
823
|
+
withEndAdornment && "pr-0",
|
|
824
|
+
multiline && "min-h-[96px] resize-none",
|
|
825
|
+
InputProps == null ? void 0 : InputProps.className
|
|
826
|
+
);
|
|
827
|
+
return /* @__PURE__ */ jsxs("div", { className: rootClasses, children: [
|
|
828
|
+
label && /* @__PURE__ */ jsxs(
|
|
829
|
+
"label",
|
|
830
|
+
{
|
|
831
|
+
htmlFor: inputId,
|
|
832
|
+
className: cn(
|
|
833
|
+
"mb-1 font-medium",
|
|
834
|
+
sizeClasses.labelRest,
|
|
835
|
+
baseLabelColor,
|
|
836
|
+
disabled && "cursor-not-allowed"
|
|
837
|
+
),
|
|
838
|
+
children: [
|
|
839
|
+
label,
|
|
840
|
+
required && /* @__PURE__ */ jsx("span", { className: "text-error-500 font-bold ps-1", children: "*" })
|
|
841
|
+
]
|
|
842
|
+
}
|
|
843
|
+
),
|
|
844
|
+
/* @__PURE__ */ jsxs("div", { className: `${containerClasses} input-container`, children: [
|
|
845
|
+
(InputProps == null ? void 0 : InputProps.startAdornment) && /* @__PURE__ */ jsx("span", { className: "flex items-center text-gray-500", children: InputProps.startAdornment }),
|
|
846
|
+
/* @__PURE__ */ jsx(
|
|
847
|
+
InputComponent,
|
|
848
|
+
{
|
|
849
|
+
ref,
|
|
850
|
+
id: inputId,
|
|
851
|
+
name,
|
|
852
|
+
type: multiline ? void 0 : type,
|
|
853
|
+
rows: multiline ? rows : void 0,
|
|
854
|
+
placeholder: placeholderText,
|
|
855
|
+
disabled,
|
|
856
|
+
required,
|
|
857
|
+
"aria-invalid": error || void 0,
|
|
858
|
+
"aria-required": required || void 0,
|
|
859
|
+
className: inputClasses,
|
|
860
|
+
onChange: handleChange,
|
|
861
|
+
onFocus: handleFocus,
|
|
862
|
+
onBlur: handleBlur,
|
|
863
|
+
...inputValueProps,
|
|
864
|
+
...rest
|
|
865
|
+
}
|
|
866
|
+
),
|
|
867
|
+
(InputProps == null ? void 0 : InputProps.endAdornment) && /* @__PURE__ */ jsx("span", { className: "flex items-center text-gray-500", children: InputProps.endAdornment }),
|
|
868
|
+
variant !== "outlined" && /* @__PURE__ */ jsx(
|
|
869
|
+
"div",
|
|
870
|
+
{
|
|
871
|
+
"aria-hidden": true,
|
|
872
|
+
className: cn("absolute inset-x-0 bottom-0", filledBorder)
|
|
873
|
+
}
|
|
874
|
+
)
|
|
875
|
+
] }),
|
|
876
|
+
helperText && /* @__PURE__ */ jsx("p", { className: cn("mt-1 text-sm", helperColor), children: helperText })
|
|
877
|
+
] });
|
|
878
|
+
}
|
|
879
|
+
);
|
|
880
|
+
TextField.displayName = "TextField";
|
|
49
881
|
|
|
50
882
|
// src/styles/index.ts
|
|
51
883
|
var tokens = {
|
|
52
884
|
colors: {
|
|
53
|
-
primary: "#
|
|
885
|
+
primary: "#1E40AF",
|
|
886
|
+
secondary: "#9333EA",
|
|
887
|
+
success: "#16A34A",
|
|
888
|
+
danger: "#DC2626",
|
|
889
|
+
warning: "#F59E0B",
|
|
890
|
+
background: "#FFFFFF",
|
|
891
|
+
surface: "#F3F4F6",
|
|
892
|
+
border: "#D1D5DB",
|
|
893
|
+
textPrimary: "#111827",
|
|
894
|
+
textSecondary: "#6B7280"
|
|
895
|
+
},
|
|
896
|
+
fonts: {
|
|
897
|
+
body: "Inter, system-ui, sans-serif",
|
|
898
|
+
heading: "Inter, system-ui, sans-serif",
|
|
899
|
+
monospace: "Menlo, monospace",
|
|
900
|
+
size: {
|
|
901
|
+
sm: "12px",
|
|
902
|
+
md: "16px",
|
|
903
|
+
lg: "20px",
|
|
904
|
+
xl: "24px"
|
|
905
|
+
},
|
|
906
|
+
weight: {
|
|
907
|
+
regular: 400,
|
|
908
|
+
medium: 500,
|
|
909
|
+
bold: 700
|
|
910
|
+
}
|
|
911
|
+
},
|
|
912
|
+
spacing: {
|
|
913
|
+
xs: "4px",
|
|
914
|
+
sm: "8px",
|
|
915
|
+
md: "16px",
|
|
916
|
+
lg: "24px",
|
|
917
|
+
xl: "32px"
|
|
54
918
|
}
|
|
55
919
|
};
|
|
920
|
+
var styles_default = tokens;
|
|
921
|
+
var defaultTheme = styles_default;
|
|
922
|
+
var ThemeContext = createContext(defaultTheme);
|
|
923
|
+
var ThemeProvider = ({
|
|
924
|
+
theme,
|
|
925
|
+
children
|
|
926
|
+
}) => {
|
|
927
|
+
const mergedTheme = {
|
|
928
|
+
...defaultTheme,
|
|
929
|
+
...theme,
|
|
930
|
+
colors: {
|
|
931
|
+
...defaultTheme.colors,
|
|
932
|
+
...theme == null ? void 0 : theme.colors
|
|
933
|
+
},
|
|
934
|
+
spacing: {
|
|
935
|
+
...defaultTheme.spacing,
|
|
936
|
+
...theme == null ? void 0 : theme.spacing
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: mergedTheme, children });
|
|
940
|
+
};
|
|
941
|
+
var useTheme = () => useContext(ThemeContext);
|
|
942
|
+
|
|
943
|
+
// src/index.ts
|
|
944
|
+
var cssFile = "./styles.css";
|
|
56
945
|
|
|
57
|
-
export { Autocomplete, Button, cn, tokens,
|
|
946
|
+
export { Autocomplete, Button, TextField, ThemeProvider, cn, cssFile, tokens, useTheme };
|
|
58
947
|
//# sourceMappingURL=index.mjs.map
|
|
59
948
|
//# sourceMappingURL=index.mjs.map
|