@sito/dashboard 0.0.82 → 0.0.83

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 CHANGED
@@ -91,6 +91,7 @@ export function UsersTable() {
91
91
  ## Form Input Notes
92
92
 
93
93
  - `SelectInput` expects `Option` items with an `id` (plus optional `value`/`name`).
94
+ - `AutocompleteInput` supports `autoSelectOnBlur` (`true` by default). In single-select mode, blur selects the matching option when the typed text exactly matches an option label, ignoring case and surrounding spaces.
94
95
  - `CheckInput` is controlled with `checked` (not `value`).
95
96
  - `FileInput` `onChange` receives the native input event; read files from `e.currentTarget.files`.
96
97
  - `FileInput` supports `unstyled` (and alias `hiddenContainer`) to render only the native file input when you provide a custom upload UI.
package/dist/Form.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./SelectInput-BrKnfhB0.cjs"),t=require("./FileInput-MZRpXGKC.cjs");exports.AutocompleteInput=e.AutocompleteInput;exports.CheckInput=e.CheckInput;exports.SelectInput=e.SelectInput;exports.State=e.State;exports.TextInput=e.TextInput;exports.helperTextStateClassName=e.helperTextStateClassName;exports.inputStateClassName=e.inputStateClassName;exports.labelStateClassName=e.labelStateClassName;exports.FileInput=t.FileInput;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./SelectInput-ckBfPXet.cjs"),t=require("./FileInput-MZRpXGKC.cjs");exports.AutocompleteInput=e.AutocompleteInput;exports.CheckInput=e.CheckInput;exports.SelectInput=e.SelectInput;exports.State=e.State;exports.TextInput=e.TextInput;exports.helperTextStateClassName=e.helperTextStateClassName;exports.inputStateClassName=e.inputStateClassName;exports.labelStateClassName=e.labelStateClassName;exports.FileInput=t.FileInput;
package/dist/Form.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as e, C as s, S as l, a as p, T as u, h as m, i as n, l as o } from "./SelectInput-D09muy0T.js";
1
+ import { A as e, C as s, S as l, a as p, T as u, h as m, i as n, l as o } from "./SelectInput-DwiR4IIb.js";
2
2
  import { F as r } from "./FileInput-9ARA_AWC.js";
3
3
  export {
4
4
  e as AutocompleteInput,
@@ -0,0 +1,624 @@
1
+ import "./SelectInput.css";
2
+ import { jsxs as S, jsx as l, Fragment as he } from "react/jsx-runtime";
3
+ import { c as u } from "./classNames-DDRjbGA1.js";
4
+ import { forwardRef as $, useState as O, useEffect as _, useCallback as p, useMemo as Y, useRef as j, useLayoutEffect as pe } from "react";
5
+ import { C as J } from "./Chip-6bEZ7uwv.js";
6
+ import { I as me } from "./IconButton-CqPk_OXG.js";
7
+ import { C as fe } from "./Close-rKC9AcNX.js";
8
+ const Ae = $(function(s, f) {
9
+ const {
10
+ state: g,
11
+ value: n,
12
+ onChange: r,
13
+ options: b = [],
14
+ name: D = "",
15
+ id: A = "",
16
+ label: v = "",
17
+ containerClassName: I = "",
18
+ inputContainerClassName: w = "",
19
+ helperText: L = "",
20
+ placeholder: F = "",
21
+ multiple: h = !1,
22
+ autoSelectOnBlur: k = !0,
23
+ required: c = !1,
24
+ "aria-required": T = !1,
25
+ onBlur: P,
26
+ onFocus: H,
27
+ ...M
28
+ } = s, U = T === !0 || String(T).toLowerCase() === "true", E = !!(c || U), m = h && Array.isArray(n) && n.length > 0, C = E && !m, [x, d] = O("");
29
+ _(() => {
30
+ if (!h && n && !Array.isArray(n)) {
31
+ d(String(n.value ?? n.name ?? ""));
32
+ return;
33
+ }
34
+ d("");
35
+ }, [h, n]);
36
+ const [o, y] = O(!1), [B, q] = O(-1), R = p(
37
+ (e) => String(e.value ?? e.name ?? ""),
38
+ []
39
+ ), V = Y(
40
+ () => b.filter((e) => Array.isArray(n) && n.length ? !n.some((a) => a.id === e.id) : n && !Array.isArray(n) ? n.id !== e.id : !0),
41
+ [b, n]
42
+ ), t = Y(
43
+ () => V.filter(
44
+ (e) => R(e).toLowerCase().includes(x.toLowerCase())
45
+ ),
46
+ [V, R, x]
47
+ );
48
+ _(() => {
49
+ if (!o || !t.length) {
50
+ q(-1);
51
+ return;
52
+ }
53
+ q(0);
54
+ }, [o, t]);
55
+ const i = j(null), W = j(null), [Z, G] = O(!1), ee = j(null);
56
+ _(() => {
57
+ const e = (N) => {
58
+ i.current && !i.current.contains(N.target) && y(!1);
59
+ }, a = (N) => {
60
+ N.key === "Escape" && y(!1);
61
+ };
62
+ return document.addEventListener("mousedown", e), document.addEventListener("keydown", a), () => {
63
+ document.removeEventListener("mousedown", e), document.removeEventListener("keydown", a);
64
+ };
65
+ }, []);
66
+ const se = p((e) => {
67
+ d(e.target.value);
68
+ }, []), K = p(
69
+ (e) => {
70
+ e ? h ? (d(""), Array.isArray(n) && n.length ? r([...n, e]) : r([e])) : (d(String(e.name ?? e.value ?? "")), r(e)) : r(null), y(!1);
71
+ },
72
+ [h, r, n]
73
+ ), te = p(
74
+ (e) => {
75
+ const a = e.trim().toLowerCase();
76
+ return a ? V.find(
77
+ (N) => R(N).trim().toLowerCase() === a
78
+ ) ?? null : null;
79
+ },
80
+ [V, R]
81
+ ), ie = p(
82
+ (e) => {
83
+ y(!0), H?.(e);
84
+ },
85
+ [H]
86
+ ), oe = p(
87
+ (e) => {
88
+ if (P?.(e), i.current && e.relatedTarget instanceof Node && i.current.contains(e.relatedTarget))
89
+ return;
90
+ const a = k ? te(e.currentTarget.value) : null;
91
+ if (a) {
92
+ K(a);
93
+ return;
94
+ }
95
+ y(!1);
96
+ },
97
+ [
98
+ k,
99
+ te,
100
+ K,
101
+ P
102
+ ]
103
+ ), ue = p(
104
+ (e) => {
105
+ if (!t.length) {
106
+ e.key === "Escape" && y(!1);
107
+ return;
108
+ }
109
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
110
+ if (e.preventDefault(), !o) {
111
+ y(!0), q(0);
112
+ return;
113
+ }
114
+ q((a) => {
115
+ const N = a >= 0 ? a : 0;
116
+ return e.key === "ArrowDown" ? (N + 1 + t.length) % t.length : (N - 1 + t.length) % t.length;
117
+ });
118
+ return;
119
+ }
120
+ if (e.key === "Enter" && o) {
121
+ e.preventDefault();
122
+ const a = B >= 0 ? B : 0;
123
+ K(t[a]);
124
+ return;
125
+ }
126
+ e.key === "Escape" && o && (e.preventDefault(), y(!1));
127
+ },
128
+ [
129
+ K,
130
+ B,
131
+ o,
132
+ t
133
+ ]
134
+ ), ne = p(
135
+ (e) => {
136
+ if (!Array.isArray(n)) {
137
+ r(null);
138
+ return;
139
+ }
140
+ const a = n.filter((N, de) => de !== e);
141
+ a.length ? r(a) : r(null);
142
+ },
143
+ [r, n]
144
+ ), ce = p(() => {
145
+ Array.isArray(n) && r([n[0]]);
146
+ }, [r, n]);
147
+ return pe(() => {
148
+ const e = ee.current?.offsetWidth ?? 0, a = i.current?.offsetWidth ?? 0;
149
+ G(e > a * 0.4);
150
+ }, [n]), /* @__PURE__ */ S(
151
+ "div",
152
+ {
153
+ className: u("autocomplete-input-container", I),
154
+ ref: i,
155
+ children: [
156
+ /* @__PURE__ */ S("div", { className: "autocomplete-value-input-container", children: [
157
+ /* @__PURE__ */ l(
158
+ le,
159
+ {
160
+ state: g,
161
+ name: D,
162
+ id: A,
163
+ value: x,
164
+ onChange: se,
165
+ placeholder: F,
166
+ helperText: L,
167
+ onFocus: ie,
168
+ onBlur: oe,
169
+ onKeyDown: ue,
170
+ label: v,
171
+ containerClassName: u(
172
+ "autocomplete-text-input",
173
+ w
174
+ ),
175
+ required: C,
176
+ "aria-required": E,
177
+ ref: f ?? W,
178
+ ...M,
179
+ children: !h && n && !Array.isArray(n) && (n.value || n.name) && /* @__PURE__ */ l(
180
+ me,
181
+ {
182
+ icon: /* @__PURE__ */ l(fe, {}),
183
+ className: "autocomplete-delete-button",
184
+ onClick: (e) => {
185
+ K(), e.stopPropagation();
186
+ }
187
+ }
188
+ )
189
+ }
190
+ ),
191
+ h && Array.isArray(n) && n.length ? /* @__PURE__ */ l("ul", { ref: ee, className: "autocomplete-value-container", children: Z ? /* @__PURE__ */ S(he, { children: [
192
+ /* @__PURE__ */ l("li", { children: /* @__PURE__ */ l(
193
+ J,
194
+ {
195
+ text: n[0]?.value ?? n[0]?.name,
196
+ onDelete: (e) => {
197
+ ne(0), e.stopPropagation();
198
+ }
199
+ }
200
+ ) }),
201
+ n.length > 1 && /* @__PURE__ */ l("li", { children: /* @__PURE__ */ l(
202
+ J,
203
+ {
204
+ text: `+${n.length - 1}`,
205
+ onDelete: (e) => {
206
+ ce(), e.stopPropagation();
207
+ }
208
+ }
209
+ ) })
210
+ ] }) : n.map((e, a) => /* @__PURE__ */ l("li", { children: /* @__PURE__ */ l(
211
+ J,
212
+ {
213
+ text: String(e.value ?? e.name),
214
+ onDelete: (N) => {
215
+ ne(a), N.stopPropagation();
216
+ }
217
+ }
218
+ ) }, e.id ?? e.value ?? e.name)) }) : null
219
+ ] }),
220
+ o && /* @__PURE__ */ l(
221
+ "ul",
222
+ {
223
+ className: "autocomplete-suggestions-container",
224
+ style: { width: i.current?.offsetWidth },
225
+ children: t.map((e) => /* @__PURE__ */ l(
226
+ "li",
227
+ {
228
+ className: u(
229
+ "autocomplete-suggestion-item",
230
+ e.id === t[B]?.id ? "highlighted" : ""
231
+ ),
232
+ onMouseEnter: () => q(
233
+ t.findIndex((a) => a.id === e.id)
234
+ ),
235
+ onMouseDown: (a) => a.preventDefault(),
236
+ onClick: (a) => {
237
+ K(e), a.stopPropagation();
238
+ },
239
+ children: e.value ?? e.name
240
+ },
241
+ e.id ?? e.value ?? e.name
242
+ ))
243
+ }
244
+ )
245
+ ]
246
+ }
247
+ );
248
+ });
249
+ var z = /* @__PURE__ */ ((s) => (s.error = "error", s.good = "good", s.default = "default", s))(z || {});
250
+ const Q = (s) => {
251
+ switch (s) {
252
+ case "error":
253
+ return "input-error";
254
+ case "good":
255
+ return "input-good";
256
+ default:
257
+ return "input-normal";
258
+ }
259
+ }, X = (s) => {
260
+ switch (s) {
261
+ case "error":
262
+ return "input-label-error";
263
+ case "good":
264
+ return "input-label-good";
265
+ default:
266
+ return "input-label-normal";
267
+ }
268
+ }, ae = (s) => {
269
+ switch (s) {
270
+ case "error":
271
+ return "input-helper-text-error";
272
+ case "good":
273
+ return "input-helper-text-good";
274
+ default:
275
+ return "input-helper-text-normal";
276
+ }
277
+ }, ke = $(function(s, f) {
278
+ const {
279
+ checked: g,
280
+ onChange: n,
281
+ name: r = "",
282
+ id: b = "",
283
+ label: D = "",
284
+ state: A = z.default,
285
+ containerClassName: v = "",
286
+ inputClassName: I = "",
287
+ labelClassName: w = "",
288
+ ...L
289
+ } = s;
290
+ return /* @__PURE__ */ S("label", { className: u("input-check-container", v), children: [
291
+ /* @__PURE__ */ l(
292
+ "input",
293
+ {
294
+ id: b,
295
+ ref: f,
296
+ name: r,
297
+ type: "checkbox",
298
+ checked: g,
299
+ onChange: n,
300
+ className: u(
301
+ "input-check",
302
+ Q(A),
303
+ I
304
+ ),
305
+ ...L
306
+ }
307
+ ),
308
+ /* @__PURE__ */ l(
309
+ "span",
310
+ {
311
+ className: u(
312
+ "input-check-label",
313
+ X(A),
314
+ w
315
+ ),
316
+ children: D
317
+ }
318
+ )
319
+ ] });
320
+ }), re = (s) => s == null ? !1 : Array.isArray(s) ? s.length > 0 : `${s}`.length > 0, ge = /* @__PURE__ */ new Set([
321
+ "date",
322
+ "datetime-local",
323
+ "time",
324
+ "month",
325
+ "week",
326
+ "range",
327
+ "color",
328
+ "file"
329
+ ]), le = $(function(s, f) {
330
+ const {
331
+ children: g,
332
+ state: n = z.default,
333
+ label: r = "",
334
+ containerClassName: b = "",
335
+ inputClassName: D = "",
336
+ labelClassName: A = "",
337
+ helperText: v = "",
338
+ helperTextClassName: I = "",
339
+ value: w,
340
+ defaultValue: L,
341
+ onChange: F,
342
+ onFocus: h,
343
+ onBlur: k,
344
+ ...c
345
+ } = s, T = w !== void 0, [P, H] = O(
346
+ () => re(L)
347
+ ), M = T ? re(w) : P, U = ge.has(
348
+ c.type ?? ""
349
+ ), E = !!c.placeholder || U, m = c["aria-required"] === !0 || String(c["aria-required"]).toLowerCase() === "true", C = !!(c.required || m), x = (d) => {
350
+ T || H(d.currentTarget.value.length > 0), F?.(d);
351
+ };
352
+ return /* @__PURE__ */ S("div", { className: u("text-input-container", b), children: [
353
+ /* @__PURE__ */ S("div", { className: "text-input-field", children: [
354
+ /* @__PURE__ */ l(
355
+ "input",
356
+ {
357
+ ref: f,
358
+ defaultValue: L,
359
+ onChange: x,
360
+ onFocus: h,
361
+ onBlur: k,
362
+ ...T ? { value: w } : {},
363
+ className: u(
364
+ "text-input",
365
+ Q(n),
366
+ D,
367
+ M ? "has-value" : "",
368
+ c.placeholder ? "has-placeholder" : "",
369
+ E ? "keep-label-up" : ""
370
+ ),
371
+ ...c
372
+ }
373
+ ),
374
+ !!r && /* @__PURE__ */ S(
375
+ "label",
376
+ {
377
+ htmlFor: c.id,
378
+ className: u(
379
+ "text-input-label",
380
+ X(n),
381
+ A
382
+ ),
383
+ children: [
384
+ r,
385
+ C ? " *" : ""
386
+ ]
387
+ }
388
+ ),
389
+ g
390
+ ] }),
391
+ !!v && /* @__PURE__ */ l(
392
+ "p",
393
+ {
394
+ className: u(
395
+ "text-input-helper-text",
396
+ ae(n),
397
+ I
398
+ ),
399
+ children: v
400
+ }
401
+ )
402
+ ] });
403
+ }), Se = $(function(s, f) {
404
+ const {
405
+ value: g,
406
+ onChange: n,
407
+ options: r,
408
+ containerClassName: b = "",
409
+ inputClassName: D = "",
410
+ labelClassName: A = "",
411
+ helperText: v = "",
412
+ helperTextClassName: I = "",
413
+ label: w = "",
414
+ placeholder: L = "",
415
+ name: F = "",
416
+ id: h = "",
417
+ state: k = z.default,
418
+ native: c = !0,
419
+ disabled: T,
420
+ required: P,
421
+ autoFocus: H,
422
+ children: M,
423
+ ...U
424
+ } = s, E = j(null), [m, C] = O(!1), [x, d] = O(-1), o = Y(
425
+ () => r.findIndex(
426
+ (t) => String(t.id) === String(g ?? r[0]?.id ?? "")
427
+ ),
428
+ [r, g]
429
+ ), y = Y(
430
+ () => o >= 0 ? r[o] : void 0,
431
+ [r, o]
432
+ );
433
+ _(() => {
434
+ if (!(c || !m)) {
435
+ if (!r.length) {
436
+ d(-1);
437
+ return;
438
+ }
439
+ d(o >= 0 ? o : 0);
440
+ }
441
+ }, [c, r.length, o, m]), _(() => {
442
+ if (c) return;
443
+ const t = (i) => {
444
+ E.current && !E.current.contains(i.target) && C(!1);
445
+ };
446
+ return document.addEventListener("mousedown", t), () => {
447
+ document.removeEventListener("mousedown", t);
448
+ };
449
+ }, [c]);
450
+ const B = p(
451
+ (t) => {
452
+ f && (typeof f == "function" ? f(t) : f.current = t);
453
+ },
454
+ [f]
455
+ ), q = p(
456
+ (t) => {
457
+ if (!n) return;
458
+ const i = {
459
+ target: { value: String(t) },
460
+ currentTarget: { value: String(t) }
461
+ };
462
+ n(i);
463
+ },
464
+ [n]
465
+ ), R = p(
466
+ (t) => {
467
+ const i = r[t];
468
+ i && (q(i.id), C(!1));
469
+ },
470
+ [q, r]
471
+ ), V = p(
472
+ (t) => {
473
+ if (r.length) {
474
+ if (t.key === "ArrowDown" || t.key === "ArrowUp") {
475
+ if (t.preventDefault(), !m) {
476
+ C(!0);
477
+ const i = o >= 0 ? o : 0;
478
+ d(i);
479
+ return;
480
+ }
481
+ d((i) => {
482
+ const W = i >= 0 ? i : o;
483
+ return t.key === "ArrowDown" ? (W + 1 + r.length) % r.length : (W - 1 + r.length) % r.length;
484
+ });
485
+ return;
486
+ }
487
+ if (t.key === "Enter") {
488
+ if (!m) {
489
+ t.preventDefault(), C(!0), d(o >= 0 ? o : 0);
490
+ return;
491
+ }
492
+ t.preventDefault(), R(x >= 0 ? x : 0);
493
+ return;
494
+ }
495
+ t.key === "Escape" && m && (t.preventDefault(), C(!1));
496
+ }
497
+ },
498
+ [x, r, R, o, m]
499
+ );
500
+ return c ? /* @__PURE__ */ S("div", { className: u("select-input-container", b), children: [
501
+ /* @__PURE__ */ l(
502
+ "select",
503
+ {
504
+ ...U,
505
+ id: h,
506
+ ref: B,
507
+ name: F,
508
+ value: g,
509
+ onChange: n,
510
+ className: u(
511
+ "select-input",
512
+ Q(k),
513
+ "peer",
514
+ D
515
+ ),
516
+ children: r?.map((t) => /* @__PURE__ */ l("option", { value: t.id, children: t.value ?? t.name ?? t.id }, t.id))
517
+ }
518
+ ),
519
+ /* @__PURE__ */ l(
520
+ "label",
521
+ {
522
+ htmlFor: h,
523
+ className: u(
524
+ "select-input-label",
525
+ X(k),
526
+ A
527
+ ),
528
+ children: w
529
+ }
530
+ ),
531
+ M,
532
+ v && /* @__PURE__ */ l(
533
+ "p",
534
+ {
535
+ className: u(
536
+ "select-input-helper-text",
537
+ ae(k),
538
+ I
539
+ ),
540
+ children: v
541
+ }
542
+ )
543
+ ] }) : /* @__PURE__ */ S(
544
+ "div",
545
+ {
546
+ ref: E,
547
+ className: u("select-input-container", b),
548
+ children: [
549
+ /* @__PURE__ */ l(
550
+ "select",
551
+ {
552
+ ...U,
553
+ ref: B,
554
+ name: F,
555
+ id: h,
556
+ value: g,
557
+ onChange: n,
558
+ className: "select-input-native-hidden",
559
+ tabIndex: -1,
560
+ "aria-hidden": !0,
561
+ children: r?.map((t) => /* @__PURE__ */ l("option", { value: t.id, children: t.value ?? t.name ?? t.id }, t.id))
562
+ }
563
+ ),
564
+ /* @__PURE__ */ l(
565
+ le,
566
+ {
567
+ id: h,
568
+ name: F,
569
+ state: k,
570
+ value: String(y?.value ?? y?.name ?? ""),
571
+ readOnly: !0,
572
+ label: w,
573
+ helperText: v,
574
+ containerClassName: "select-input-text-container",
575
+ inputClassName: u("select-input-text", D),
576
+ labelClassName: A,
577
+ helperTextClassName: I,
578
+ placeholder: L,
579
+ disabled: T,
580
+ required: P,
581
+ autoFocus: H,
582
+ onClick: () => C((t) => !t),
583
+ onKeyDown: V,
584
+ onFocus: () => C(!0),
585
+ role: "combobox",
586
+ "aria-expanded": m,
587
+ "aria-haspopup": "listbox",
588
+ children: M
589
+ }
590
+ ),
591
+ m && /* @__PURE__ */ l("ul", { className: "select-input-options-container", role: "listbox", children: r.map((t, i) => {
592
+ const W = String(t.id) === String(g);
593
+ return /* @__PURE__ */ l(
594
+ "li",
595
+ {
596
+ role: "option",
597
+ "aria-selected": W,
598
+ className: u(
599
+ "select-input-option-item",
600
+ i === x ? "highlighted" : ""
601
+ ),
602
+ onMouseEnter: () => d(i),
603
+ onClick: (G) => {
604
+ R(i), G.stopPropagation();
605
+ },
606
+ children: t.value ?? t.name ?? t.id
607
+ },
608
+ t.id
609
+ );
610
+ }) })
611
+ ]
612
+ }
613
+ );
614
+ });
615
+ export {
616
+ Ae as A,
617
+ ke as C,
618
+ Se as S,
619
+ le as T,
620
+ z as a,
621
+ ae as h,
622
+ Q as i,
623
+ X as l
624
+ };
@@ -0,0 +1 @@
1
+ var he=require("./SelectInput.css");const r=require("react/jsx-runtime"),c=require("./classNames-DHAzUjfZ.cjs"),n=require("react"),$=require("./Chip-N4r2Xf9l.cjs"),le=require("./IconButton-DVZCHIHB.cjs"),ie=require("./Close-O9P7wJGf.cjs"),oe=n.forwardRef(function(i,f){const{state:g,value:a,onChange:s,options:w=[],name:j="",id:S="",label:b="",containerClassName:A="",inputContainerClassName:y="",helperText:I="",placeholder:q="",multiple:p=!1,autoSelectOnBlur:v=!0,required:d=!1,"aria-required":D=!1,onBlur:B,onFocus:F,...O}=i,M=D===!0||String(D).toLowerCase()==="true",E=!!(d||M),m=p&&Array.isArray(a)&&a.length>0,x=E&&!m,[k,h]=n.useState("");n.useEffect(()=>{if(!p&&a&&!Array.isArray(a)){h(String(a.value??a.name??""));return}h("")},[p,a]);const[u,C]=n.useState(!1),[R,L]=n.useState(-1),T=n.useCallback(e=>String(e.value??e.name??""),[]),P=n.useMemo(()=>w.filter(e=>Array.isArray(a)&&a.length?!a.some(l=>l.id===e.id):a&&!Array.isArray(a)?a.id!==e.id:!0),[w,a]),t=n.useMemo(()=>P.filter(e=>T(e).toLowerCase().includes(k.toLowerCase())),[P,T,k]);n.useEffect(()=>{if(!u||!t.length){L(-1);return}L(0)},[u,t]);const o=n.useRef(null),U=n.useRef(null),[_,Y]=n.useState(!1),J=n.useRef(null);n.useEffect(()=>{const e=N=>{o.current&&!o.current.contains(N.target)&&C(!1)},l=N=>{N.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",l)}},[]);const ee=n.useCallback(e=>{h(e.target.value)},[]),V=n.useCallback(e=>{e?p?(h(""),Array.isArray(a)&&a.length?s([...a,e]):s([e])):(h(String(e.name??e.value??"")),s(e)):s(null),C(!1)},[p,s,a]),Q=n.useCallback(e=>{const l=e.trim().toLowerCase();return l?P.find(N=>T(N).trim().toLowerCase()===l)??null:null},[P,T]),te=n.useCallback(e=>{C(!0),F?.(e)},[F]),ae=n.useCallback(e=>{if(B?.(e),o.current&&e.relatedTarget instanceof Node&&o.current.contains(e.relatedTarget))return;const l=v?Q(e.currentTarget.value):null;if(l){V(l);return}C(!1)},[v,Q,V,B]),ne=n.useCallback(e=>{if(!t.length){e.key==="Escape"&&C(!1);return}if(e.key==="ArrowDown"||e.key==="ArrowUp"){if(e.preventDefault(),!u){C(!0),L(0);return}L(l=>{const N=l>=0?l:0;return e.key==="ArrowDown"?(N+1+t.length)%t.length:(N-1+t.length)%t.length});return}if(e.key==="Enter"&&u){e.preventDefault();const l=R>=0?R:0;V(t[l]);return}e.key==="Escape"&&u&&(e.preventDefault(),C(!1))},[V,R,u,t]),X=n.useCallback(e=>{if(!Array.isArray(a)){s(null);return}const l=a.filter((N,re)=>re!==e);l.length?s(l):s(null)},[s,a]),se=n.useCallback(()=>{Array.isArray(a)&&s([a[0]])},[s,a]);return n.useLayoutEffect(()=>{const e=J.current?.offsetWidth??0,l=o.current?.offsetWidth??0;Y(e>l*.4)},[a]),r.jsxs("div",{className:c.classNames("autocomplete-input-container",A),ref:o,children:[r.jsxs("div",{className:"autocomplete-value-input-container",children:[r.jsx(G,{state:g,name:j,id:S,value:k,onChange:ee,placeholder:q,helperText:I,onFocus:te,onBlur:ae,onKeyDown:ne,label:b,containerClassName:c.classNames("autocomplete-text-input",y),required:x,"aria-required":E,ref:f??U,...O,children:!p&&a&&!Array.isArray(a)&&(a.value||a.name)&&r.jsx(le.IconButton,{icon:r.jsx(ie.Close,{}),className:"autocomplete-delete-button",onClick:e=>{V(),e.stopPropagation()}})}),p&&Array.isArray(a)&&a.length?r.jsx("ul",{ref:J,className:"autocomplete-value-container",children:_?r.jsxs(r.Fragment,{children:[r.jsx("li",{children:r.jsx($.Chip,{text:a[0]?.value??a[0]?.name,onDelete:e=>{X(0),e.stopPropagation()}})}),a.length>1&&r.jsx("li",{children:r.jsx($.Chip,{text:`+${a.length-1}`,onDelete:e=>{se(),e.stopPropagation()}})})]}):a.map((e,l)=>r.jsx("li",{children:r.jsx($.Chip,{text:String(e.value??e.name),onDelete:N=>{X(l),N.stopPropagation()}})},e.id??e.value??e.name))}):null]}),u&&r.jsx("ul",{className:"autocomplete-suggestions-container",style:{width:o.current?.offsetWidth},children:t.map(e=>r.jsx("li",{className:c.classNames("autocomplete-suggestion-item",e.id===t[R]?.id?"highlighted":""),onMouseEnter:()=>L(t.findIndex(l=>l.id===e.id)),onMouseDown:l=>l.preventDefault(),onClick:l=>{V(e),l.stopPropagation()},children:e.value??e.name},e.id??e.value??e.name))})]})});var W=(i=>(i.error="error",i.good="good",i.default="default",i))(W||{});const H=i=>{switch(i){case"error":return"input-error";case"good":return"input-good";default:return"input-normal"}},K=i=>{switch(i){case"error":return"input-label-error";case"good":return"input-label-good";default:return"input-label-normal"}},z=i=>{switch(i){case"error":return"input-helper-text-error";case"good":return"input-helper-text-good";default:return"input-helper-text-normal"}},ue=n.forwardRef(function(i,f){const{checked:g,onChange:a,name:s="",id:w="",label:j="",state:S=W.default,containerClassName:b="",inputClassName:A="",labelClassName:y="",...I}=i;return r.jsxs("label",{className:c.classNames("input-check-container",b),children:[r.jsx("input",{id:w,ref:f,name:s,type:"checkbox",checked:g,onChange:a,className:c.classNames("input-check",H(S),A),...I}),r.jsx("span",{className:c.classNames("input-check-label",K(S),y),children:j})]})}),Z=i=>i==null?!1:Array.isArray(i)?i.length>0:`${i}`.length>0,ce=new Set(["date","datetime-local","time","month","week","range","color","file"]),G=n.forwardRef(function(i,f){const{children:g,state:a=W.default,label:s="",containerClassName:w="",inputClassName:j="",labelClassName:S="",helperText:b="",helperTextClassName:A="",value:y,defaultValue:I,onChange:q,onFocus:p,onBlur:v,...d}=i,D=y!==void 0,[B,F]=n.useState(()=>Z(I)),O=D?Z(y):B,M=ce.has(d.type??""),E=!!d.placeholder||M,m=d["aria-required"]===!0||String(d["aria-required"]).toLowerCase()==="true",x=!!(d.required||m),k=h=>{D||F(h.currentTarget.value.length>0),q?.(h)};return r.jsxs("div",{className:c.classNames("text-input-container",w),children:[r.jsxs("div",{className:"text-input-field",children:[r.jsx("input",{ref:f,defaultValue:I,onChange:k,onFocus:p,onBlur:v,...D?{value:y}:{},className:c.classNames("text-input",H(a),j,O?"has-value":"",d.placeholder?"has-placeholder":"",E?"keep-label-up":""),...d}),!!s&&r.jsxs("label",{htmlFor:d.id,className:c.classNames("text-input-label",K(a),S),children:[s,x?" *":""]}),g]}),!!b&&r.jsx("p",{className:c.classNames("text-input-helper-text",z(a),A),children:b})]})}),de=n.forwardRef(function(i,f){const{value:g,onChange:a,options:s,containerClassName:w="",inputClassName:j="",labelClassName:S="",helperText:b="",helperTextClassName:A="",label:y="",placeholder:I="",name:q="",id:p="",state:v=W.default,native:d=!0,disabled:D,required:B,autoFocus:F,children:O,...M}=i,E=n.useRef(null),[m,x]=n.useState(!1),[k,h]=n.useState(-1),u=n.useMemo(()=>s.findIndex(t=>String(t.id)===String(g??s[0]?.id??"")),[s,g]),C=n.useMemo(()=>u>=0?s[u]:void 0,[s,u]);n.useEffect(()=>{if(!(d||!m)){if(!s.length){h(-1);return}h(u>=0?u:0)}},[d,s.length,u,m]),n.useEffect(()=>{if(d)return;const t=o=>{E.current&&!E.current.contains(o.target)&&x(!1)};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[d]);const R=n.useCallback(t=>{f&&(typeof f=="function"?f(t):f.current=t)},[f]),L=n.useCallback(t=>{if(!a)return;const o={target:{value:String(t)},currentTarget:{value:String(t)}};a(o)},[a]),T=n.useCallback(t=>{const o=s[t];o&&(L(o.id),x(!1))},[L,s]),P=n.useCallback(t=>{if(s.length){if(t.key==="ArrowDown"||t.key==="ArrowUp"){if(t.preventDefault(),!m){x(!0);const o=u>=0?u:0;h(o);return}h(o=>{const U=o>=0?o:u;return t.key==="ArrowDown"?(U+1+s.length)%s.length:(U-1+s.length)%s.length});return}if(t.key==="Enter"){if(!m){t.preventDefault(),x(!0),h(u>=0?u:0);return}t.preventDefault(),T(k>=0?k:0);return}t.key==="Escape"&&m&&(t.preventDefault(),x(!1))}},[k,s,T,u,m]);return d?r.jsxs("div",{className:c.classNames("select-input-container",w),children:[r.jsx("select",{...M,id:p,ref:R,name:q,value:g,onChange:a,className:c.classNames("select-input",H(v),"peer",j),children:s?.map(t=>r.jsx("option",{value:t.id,children:t.value??t.name??t.id},t.id))}),r.jsx("label",{htmlFor:p,className:c.classNames("select-input-label",K(v),S),children:y}),O,b&&r.jsx("p",{className:c.classNames("select-input-helper-text",z(v),A),children:b})]}):r.jsxs("div",{ref:E,className:c.classNames("select-input-container",w),children:[r.jsx("select",{...M,ref:R,name:q,id:p,value:g,onChange:a,className:"select-input-native-hidden",tabIndex:-1,"aria-hidden":!0,children:s?.map(t=>r.jsx("option",{value:t.id,children:t.value??t.name??t.id},t.id))}),r.jsx(G,{id:p,name:q,state:v,value:String(C?.value??C?.name??""),readOnly:!0,label:y,helperText:b,containerClassName:"select-input-text-container",inputClassName:c.classNames("select-input-text",j),labelClassName:S,helperTextClassName:A,placeholder:I,disabled:D,required:B,autoFocus:F,onClick:()=>x(t=>!t),onKeyDown:P,onFocus:()=>x(!0),role:"combobox","aria-expanded":m,"aria-haspopup":"listbox",children:O}),m&&r.jsx("ul",{className:"select-input-options-container",role:"listbox",children:s.map((t,o)=>{const U=String(t.id)===String(g),_=o===k;return r.jsx("li",{role:"option","aria-selected":U,className:c.classNames("select-input-option-item",_?"highlighted":""),onMouseEnter:()=>h(o),onClick:Y=>{T(o),Y.stopPropagation()},children:t.value??t.name??t.id},t.id)})})]})});exports.AutocompleteInput=oe;exports.CheckInput=ue;exports.SelectInput=de;exports.State=W;exports.TextInput=G;exports.helperTextStateClassName=z;exports.inputStateClassName=H;exports.labelStateClassName=K;