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