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