@starasia/dropdown 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dropdown.es.js +201 -195
- package/dist/dropdown.umd.js +2 -2
- package/dist/interface.d.ts +4 -0
- package/package.json +1 -1
package/dist/dropdown.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsx as r, jsxs as w, Fragment as M } from "react/jsx-runtime";
|
|
2
|
+
import P, { useState as B, useRef as z, useEffect as v, forwardRef as G } from "react";
|
|
3
|
+
const Q = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
4
4
|
* {
|
|
5
5
|
margin: 0;
|
|
6
6
|
padding: 0;
|
|
@@ -314,23 +314,23 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
|
|
|
314
314
|
width: 100%;
|
|
315
315
|
}
|
|
316
316
|
`;
|
|
317
|
-
function
|
|
318
|
-
const [
|
|
319
|
-
|
|
317
|
+
function T(n) {
|
|
318
|
+
const [l, i] = B(n), c = z(null), a = (o) => {
|
|
319
|
+
c.current && !c.current.contains(o.target) && i(!1);
|
|
320
320
|
};
|
|
321
|
-
return
|
|
321
|
+
return v(() => (document.addEventListener("click", a, !0), () => {
|
|
322
322
|
document.removeEventListener("click", a, !0);
|
|
323
|
-
}), []), { ref:
|
|
323
|
+
}), []), { ref: c, isComponentVisible: l, setIsComponentVisible: i };
|
|
324
324
|
}
|
|
325
|
-
const
|
|
325
|
+
const X = ({ ...n }) => /* @__PURE__ */ r(
|
|
326
326
|
"svg",
|
|
327
327
|
{
|
|
328
328
|
xmlns: "http://www.w3.org/2000/svg",
|
|
329
|
-
...
|
|
329
|
+
...n,
|
|
330
330
|
viewBox: "0 0 24 24",
|
|
331
331
|
fill: "none",
|
|
332
332
|
color: "var(--sa-color-gray-500, #8c8f97)",
|
|
333
|
-
children: /* @__PURE__ */
|
|
333
|
+
children: /* @__PURE__ */ r(
|
|
334
334
|
"path",
|
|
335
335
|
{
|
|
336
336
|
d: "M4 9L12 17L20 9",
|
|
@@ -341,15 +341,15 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
|
|
|
341
341
|
}
|
|
342
342
|
)
|
|
343
343
|
}
|
|
344
|
-
),
|
|
344
|
+
), Y = ({ ...n }) => /* @__PURE__ */ w(
|
|
345
345
|
"svg",
|
|
346
346
|
{
|
|
347
347
|
xmlns: "http://www.w3.org/2000/svg",
|
|
348
|
-
...
|
|
348
|
+
...n,
|
|
349
349
|
viewBox: "0 0 20 20",
|
|
350
350
|
fill: "none",
|
|
351
351
|
children: [
|
|
352
|
-
/* @__PURE__ */
|
|
352
|
+
/* @__PURE__ */ r(
|
|
353
353
|
"circle",
|
|
354
354
|
{
|
|
355
355
|
cx: "9.80547",
|
|
@@ -361,7 +361,7 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
|
|
|
361
361
|
strokeLinejoin: "round"
|
|
362
362
|
}
|
|
363
363
|
),
|
|
364
|
-
/* @__PURE__ */
|
|
364
|
+
/* @__PURE__ */ r(
|
|
365
365
|
"path",
|
|
366
366
|
{
|
|
367
367
|
d: "M15.0153 15.4043L17.9519 18.3333",
|
|
@@ -373,19 +373,19 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
|
|
|
373
373
|
)
|
|
374
374
|
]
|
|
375
375
|
}
|
|
376
|
-
),
|
|
377
|
-
/* @__PURE__ */
|
|
378
|
-
/* @__PURE__ */
|
|
376
|
+
), Z = ({ isChecked: n }) => /* @__PURE__ */ w("div", { className: "checkbox-wrapper-30", children: [
|
|
377
|
+
/* @__PURE__ */ w("span", { className: "checkbox", children: [
|
|
378
|
+
/* @__PURE__ */ r(
|
|
379
379
|
"input",
|
|
380
380
|
{
|
|
381
381
|
type: "checkbox",
|
|
382
382
|
style: { pointerEvents: "none" },
|
|
383
|
-
checked:
|
|
383
|
+
checked: n
|
|
384
384
|
}
|
|
385
385
|
),
|
|
386
|
-
/* @__PURE__ */
|
|
386
|
+
/* @__PURE__ */ r("svg", { children: /* @__PURE__ */ r("use", { xlinkHref: "#checkbox-30", className: "checkbox" }) })
|
|
387
387
|
] }),
|
|
388
|
-
/* @__PURE__ */
|
|
388
|
+
/* @__PURE__ */ r("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, children: /* @__PURE__ */ r("symbol", { id: "checkbox-30", viewBox: "0 0 22 22", children: /* @__PURE__ */ r(
|
|
389
389
|
"path",
|
|
390
390
|
{
|
|
391
391
|
fill: "none",
|
|
@@ -393,55 +393,55 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
|
|
|
393
393
|
d: "M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"
|
|
394
394
|
}
|
|
395
395
|
) }) })
|
|
396
|
-
] }),
|
|
396
|
+
] }), _ = G(
|
|
397
397
|
({
|
|
398
|
-
positionDropdown:
|
|
399
|
-
dropdownLists:
|
|
400
|
-
isComponentVisible:
|
|
401
|
-
searchAble:
|
|
398
|
+
positionDropdown: n,
|
|
399
|
+
dropdownLists: l,
|
|
400
|
+
isComponentVisible: i,
|
|
401
|
+
searchAble: c,
|
|
402
402
|
onSearch: a,
|
|
403
403
|
value: o,
|
|
404
|
-
handleChangeValue:
|
|
405
|
-
multiSelect:
|
|
406
|
-
searchValue:
|
|
404
|
+
handleChangeValue: m,
|
|
405
|
+
multiSelect: p,
|
|
406
|
+
searchValue: I,
|
|
407
407
|
highlightedIndex: g
|
|
408
|
-
},
|
|
409
|
-
const [
|
|
410
|
-
return
|
|
411
|
-
if (
|
|
412
|
-
const
|
|
413
|
-
|
|
408
|
+
}, L) => {
|
|
409
|
+
const [$, D] = B(0), k = z(null), R = z([]);
|
|
410
|
+
return v(() => {
|
|
411
|
+
if (k.current) {
|
|
412
|
+
const e = k.current.getBoundingClientRect();
|
|
413
|
+
D(e.width);
|
|
414
414
|
}
|
|
415
|
-
}, [
|
|
416
|
-
var
|
|
417
|
-
g >= 0 &&
|
|
418
|
-
}, [g]), /* @__PURE__ */
|
|
415
|
+
}, [k, i]), v(() => {
|
|
416
|
+
var e;
|
|
417
|
+
g >= 0 && R.current[g] && ((e = R.current[g]) == null || e.scrollIntoView({ block: "nearest" }));
|
|
418
|
+
}, [g]), /* @__PURE__ */ r(M, { children: i ? /* @__PURE__ */ w(
|
|
419
419
|
"div",
|
|
420
420
|
{
|
|
421
421
|
className: "sa-input-dropdown-lists-container",
|
|
422
|
-
onClick: (
|
|
423
|
-
ref:
|
|
422
|
+
onClick: (e) => e.stopPropagation(),
|
|
423
|
+
ref: L,
|
|
424
424
|
children: [
|
|
425
|
-
|
|
425
|
+
c ? /* @__PURE__ */ w(
|
|
426
426
|
"div",
|
|
427
427
|
{
|
|
428
428
|
className: "sa-input-dropdown-container-dropdown-search",
|
|
429
429
|
style: {
|
|
430
|
-
order:
|
|
430
|
+
order: n == "bottom" ? 0 : 2,
|
|
431
431
|
position: "sticky",
|
|
432
432
|
top: 0,
|
|
433
433
|
bottom: 0,
|
|
434
434
|
zIndex: 1
|
|
435
435
|
},
|
|
436
436
|
children: [
|
|
437
|
-
/* @__PURE__ */
|
|
438
|
-
/* @__PURE__ */
|
|
437
|
+
/* @__PURE__ */ r("div", { style: { display: "flex" }, children: /* @__PURE__ */ r(Y, { strokeWidth: 2, width: 20 }) }),
|
|
438
|
+
/* @__PURE__ */ r(
|
|
439
439
|
"input",
|
|
440
440
|
{
|
|
441
|
-
onChange: (
|
|
442
|
-
a && a(
|
|
441
|
+
onChange: (e) => {
|
|
442
|
+
a && a(e.target.value);
|
|
443
443
|
},
|
|
444
|
-
value:
|
|
444
|
+
value: I,
|
|
445
445
|
autoFocus: !0,
|
|
446
446
|
style: { width: "100%" }
|
|
447
447
|
}
|
|
@@ -449,57 +449,57 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
|
|
|
449
449
|
]
|
|
450
450
|
}
|
|
451
451
|
) : null,
|
|
452
|
-
/* @__PURE__ */
|
|
452
|
+
/* @__PURE__ */ r(
|
|
453
453
|
"div",
|
|
454
454
|
{
|
|
455
|
-
className: `sa-input-dropdwon-item-container ${
|
|
456
|
-
ref:
|
|
457
|
-
children:
|
|
458
|
-
const
|
|
459
|
-
return /* @__PURE__ */
|
|
455
|
+
className: `sa-input-dropdwon-item-container ${p ? "multi" : ""}`,
|
|
456
|
+
ref: k,
|
|
457
|
+
children: l.map((e, f) => {
|
|
458
|
+
const s = !!(o != null && o.find((h) => h.value === e.value));
|
|
459
|
+
return /* @__PURE__ */ w(
|
|
460
460
|
"div",
|
|
461
461
|
{
|
|
462
|
-
className: `sa-input-dropdwon-item ${
|
|
463
|
-
ref: (
|
|
464
|
-
|
|
462
|
+
className: `sa-input-dropdwon-item ${s ? "active" : ""} ${f === g ? "highlight" : ""} ${e.disable ? "sa-input-dropdwon-item-disable" : ""}`,
|
|
463
|
+
ref: (h) => {
|
|
464
|
+
R.current[f] = h;
|
|
465
465
|
},
|
|
466
|
-
onClick: () =>
|
|
466
|
+
onClick: () => m(e.label, e.value),
|
|
467
467
|
children: [
|
|
468
|
-
|
|
469
|
-
|
|
468
|
+
p ? /* @__PURE__ */ r("div", { style: { marginRight: "8px" }, children: /* @__PURE__ */ r(Z, { isChecked: s }) }) : null,
|
|
469
|
+
e.icon ? /* @__PURE__ */ r("div", { children: P.cloneElement(e.icon, {
|
|
470
470
|
width: 16
|
|
471
471
|
}) }) : null,
|
|
472
|
-
/* @__PURE__ */
|
|
473
|
-
/* @__PURE__ */
|
|
472
|
+
/* @__PURE__ */ w("div", { children: [
|
|
473
|
+
/* @__PURE__ */ r(
|
|
474
474
|
"p",
|
|
475
475
|
{
|
|
476
|
-
className: `sa-input-dropdwon-item-text ${
|
|
476
|
+
className: `sa-input-dropdwon-item-text ${s ? "active" : null} ${e.disable ? "sa-input-dropdwon-item-disable" : null}`,
|
|
477
477
|
style: {
|
|
478
478
|
textWrap: "nowrap",
|
|
479
|
-
width: `${
|
|
479
|
+
width: `${$ - 12}px`,
|
|
480
480
|
overflow: "hidden",
|
|
481
481
|
textOverflow: "ellipsis"
|
|
482
482
|
},
|
|
483
|
-
children:
|
|
483
|
+
children: e.label
|
|
484
484
|
}
|
|
485
485
|
),
|
|
486
|
-
|
|
486
|
+
e.description ? /* @__PURE__ */ r(
|
|
487
487
|
"p",
|
|
488
488
|
{
|
|
489
|
-
className: `sa-input-dropdwon-item-text-description ${
|
|
489
|
+
className: `sa-input-dropdwon-item-text-description ${s ? "active" : null} ${e.disable ? "sa-input-dropdwon-item-disable" : null}`,
|
|
490
490
|
style: {
|
|
491
491
|
textWrap: "nowrap",
|
|
492
|
-
width: `${
|
|
492
|
+
width: `${$ - 12}px`,
|
|
493
493
|
overflow: "hidden",
|
|
494
494
|
textOverflow: "ellipsis"
|
|
495
495
|
},
|
|
496
|
-
children:
|
|
496
|
+
children: e.description
|
|
497
497
|
}
|
|
498
498
|
) : null
|
|
499
499
|
] })
|
|
500
500
|
]
|
|
501
501
|
},
|
|
502
|
-
|
|
502
|
+
f
|
|
503
503
|
);
|
|
504
504
|
})
|
|
505
505
|
}
|
|
@@ -508,202 +508,208 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
|
|
|
508
508
|
}
|
|
509
509
|
) : null });
|
|
510
510
|
}
|
|
511
|
-
),
|
|
512
|
-
children:
|
|
513
|
-
handleChangePosition:
|
|
511
|
+
), nn = ({
|
|
512
|
+
children: n,
|
|
513
|
+
handleChangePosition: l
|
|
514
514
|
}) => {
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
var
|
|
515
|
+
const i = z(null);
|
|
516
|
+
v(() => {
|
|
517
|
+
var m;
|
|
518
518
|
const a = () => {
|
|
519
|
-
if (
|
|
520
|
-
let
|
|
521
|
-
for (;
|
|
522
|
-
|
|
523
|
-
|
|
519
|
+
if (i.current) {
|
|
520
|
+
let p = i.current.parentElement;
|
|
521
|
+
for (; p && !c(p); )
|
|
522
|
+
p = p.parentElement;
|
|
523
|
+
p && l();
|
|
524
524
|
}
|
|
525
525
|
};
|
|
526
|
-
let o = (
|
|
527
|
-
for (; o && !
|
|
526
|
+
let o = (m = i.current) == null ? void 0 : m.parentElement;
|
|
527
|
+
for (; o && !c(o); )
|
|
528
528
|
o = o.parentElement;
|
|
529
529
|
return o && o.addEventListener("scroll", a), a(), () => {
|
|
530
530
|
o && o.removeEventListener("scroll", a);
|
|
531
531
|
};
|
|
532
532
|
}, []);
|
|
533
|
-
const
|
|
534
|
-
return /* @__PURE__ */
|
|
535
|
-
},
|
|
536
|
-
if (!document.getElementById(
|
|
537
|
-
const
|
|
538
|
-
|
|
533
|
+
const c = (a) => a && (a.scrollHeight > a.clientHeight || a.scrollWidth > a.clientWidth);
|
|
534
|
+
return /* @__PURE__ */ r("div", { ref: i, children: n });
|
|
535
|
+
}, H = "sa-input-dropdown-styles", rn = (n) => {
|
|
536
|
+
if (!document.getElementById(H)) {
|
|
537
|
+
const l = document.createElement("style");
|
|
538
|
+
l.id = H, l.textContent = n, document.head.appendChild(l);
|
|
539
539
|
}
|
|
540
540
|
};
|
|
541
|
-
|
|
542
|
-
const
|
|
543
|
-
dropdownLists:
|
|
544
|
-
onChange:
|
|
545
|
-
defaultValue:
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
541
|
+
rn(Q);
|
|
542
|
+
const tn = ({
|
|
543
|
+
dropdownLists: n,
|
|
544
|
+
onChange: l,
|
|
545
|
+
defaultValue: i,
|
|
546
|
+
value: c,
|
|
547
|
+
size: a = "md",
|
|
548
|
+
multiSelect: o,
|
|
549
|
+
searchAble: m,
|
|
550
|
+
iconLeft: p,
|
|
551
|
+
placeholder: I,
|
|
552
|
+
onSearch: g,
|
|
553
|
+
error: L,
|
|
554
|
+
onBlur: $,
|
|
555
|
+
onFocus: D,
|
|
556
|
+
disable: k,
|
|
557
|
+
searchValue: R
|
|
557
558
|
}) => {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
559
|
+
const e = c !== void 0, f = z(), [s, h] = B(
|
|
560
|
+
e ? c || [] : i || []
|
|
561
|
+
), [V, F] = B(""), [b, W] = B(-1), x = z(null), { isComponentVisible: y, ref: A, setIsComponentVisible: N } = T(!1), q = () => {
|
|
562
|
+
N((t) => !t);
|
|
563
|
+
}, j = (t, d) => {
|
|
564
|
+
if (o)
|
|
565
|
+
if (s == null ? void 0 : s.find((u) => u.value === d)) {
|
|
566
|
+
const u = s.filter((U) => U.value !== d);
|
|
567
|
+
e || h(u), l(u);
|
|
568
|
+
} else {
|
|
569
|
+
const u = [...s, { label: t, value: d }];
|
|
570
|
+
e || h(u), l(u);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
const E = [{ label: t, value: d }];
|
|
574
|
+
e || h(E), l(E), N(!1);
|
|
571
575
|
}
|
|
572
576
|
};
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}, [
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
577
|
+
v(() => {
|
|
578
|
+
e && h(c || []);
|
|
579
|
+
}, [c]), v(() => {
|
|
580
|
+
e || JSON.stringify(f.current) === JSON.stringify(i) || (f.current = i, h(f.current || []));
|
|
581
|
+
}, [i]);
|
|
582
|
+
const J = () => s.length ? o ? s == null ? void 0 : s.map((t, d) => /* @__PURE__ */ w("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
583
|
+
/* @__PURE__ */ r("p", { style: { minWidth: "max-content" }, children: t == null ? void 0 : t.label }, d),
|
|
584
|
+
/* @__PURE__ */ r(
|
|
585
|
+
on,
|
|
580
586
|
{
|
|
581
|
-
onClick: () =>
|
|
587
|
+
onClick: () => j(t.label, t.value)
|
|
582
588
|
}
|
|
583
589
|
)
|
|
584
|
-
] })) : /* @__PURE__ */
|
|
585
|
-
if (
|
|
586
|
-
const t = window.innerHeight,
|
|
587
|
-
|
|
590
|
+
] })) : /* @__PURE__ */ r("p", { style: { minWidth: "max-content" }, children: s == null ? void 0 : s[0].label }) : /* @__PURE__ */ r("p", { className: "sa-input-dropdown-placeholder", children: I }), C = () => {
|
|
591
|
+
if (A.current && x.current) {
|
|
592
|
+
const t = window.innerHeight, d = A.current.getBoundingClientRect(), E = x.current.getBoundingClientRect(), u = d.bottom + E.height;
|
|
593
|
+
x.current.style.left = `${d.left}px`, x.current.style.width = `${d.width}px`, u >= t - 10 ? (x.current.style.top = `${d.top - E.height - 5}px`, F("top")) : (x.current.style.top = `${d.top + d.height}px`, F("bottom"));
|
|
588
594
|
}
|
|
589
595
|
};
|
|
590
|
-
|
|
591
|
-
window.removeEventListener("scroll",
|
|
592
|
-
}), []),
|
|
593
|
-
|
|
594
|
-
}, [
|
|
595
|
-
|
|
596
|
-
}, [
|
|
597
|
-
const
|
|
598
|
-
if (!
|
|
599
|
-
(t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(),
|
|
596
|
+
v(() => (window.addEventListener("scroll", C), window.addEventListener("resize", C), () => {
|
|
597
|
+
window.removeEventListener("scroll", C), window.removeEventListener("resize", C);
|
|
598
|
+
}), []), v(() => {
|
|
599
|
+
C();
|
|
600
|
+
}, [y]), v(() => {
|
|
601
|
+
y || W(-1);
|
|
602
|
+
}, [y]);
|
|
603
|
+
const K = (t) => {
|
|
604
|
+
if (!y) {
|
|
605
|
+
(t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), N(!0));
|
|
600
606
|
return;
|
|
601
607
|
}
|
|
602
608
|
switch (t.key) {
|
|
603
609
|
case "ArrowDown": {
|
|
604
610
|
t.preventDefault();
|
|
605
|
-
const
|
|
606
|
-
|
|
611
|
+
const d = O(n, b, 1);
|
|
612
|
+
d !== -1 && W(d);
|
|
607
613
|
break;
|
|
608
614
|
}
|
|
609
615
|
case "ArrowUp": {
|
|
610
616
|
t.preventDefault();
|
|
611
|
-
const
|
|
612
|
-
|
|
617
|
+
const d = O(n, b, -1);
|
|
618
|
+
d !== -1 && W(d);
|
|
613
619
|
break;
|
|
614
620
|
}
|
|
615
621
|
case "Enter": {
|
|
616
|
-
t.preventDefault(),
|
|
617
|
-
|
|
618
|
-
|
|
622
|
+
t.preventDefault(), b >= 0 && n[b] && !n[b].disable && j(
|
|
623
|
+
n[b].label,
|
|
624
|
+
n[b].value
|
|
619
625
|
);
|
|
620
626
|
break;
|
|
621
627
|
}
|
|
622
628
|
case "Escape": {
|
|
623
|
-
|
|
629
|
+
N(!1);
|
|
624
630
|
break;
|
|
625
631
|
}
|
|
626
632
|
}
|
|
627
633
|
};
|
|
628
|
-
return /* @__PURE__ */
|
|
634
|
+
return /* @__PURE__ */ r(nn, { handleChangePosition: C, children: /* @__PURE__ */ w(
|
|
629
635
|
"div",
|
|
630
636
|
{
|
|
631
|
-
className: `sa-input-dropdown-container ${
|
|
632
|
-
ref:
|
|
633
|
-
onClick:
|
|
634
|
-
onKeyDown:
|
|
637
|
+
className: `sa-input-dropdown-container ${k ? "disable" : ""} sa-input-dropdown-size-${a} ${y ? "active" : ""} ${L ? "error" : ""}`,
|
|
638
|
+
ref: A,
|
|
639
|
+
onClick: q,
|
|
640
|
+
onKeyDown: K,
|
|
635
641
|
tabIndex: 0,
|
|
636
|
-
onBlur:
|
|
637
|
-
onFocus:
|
|
642
|
+
onBlur: $,
|
|
643
|
+
onFocus: D,
|
|
638
644
|
children: [
|
|
639
|
-
/* @__PURE__ */
|
|
640
|
-
|
|
641
|
-
width:
|
|
645
|
+
/* @__PURE__ */ w("div", { className: "sa-input-dropdown-preview-container", children: [
|
|
646
|
+
p ? /* @__PURE__ */ r(M, { children: P.cloneElement(p, {
|
|
647
|
+
width: S(a),
|
|
642
648
|
color: "var(--sa-color-gray-500, #8c8f97)",
|
|
643
649
|
style: {
|
|
644
650
|
color: "var(--sa-color-gray-500, #8c8f97)"
|
|
645
651
|
}
|
|
646
652
|
}) }) : null,
|
|
647
|
-
/* @__PURE__ */
|
|
653
|
+
/* @__PURE__ */ r(
|
|
648
654
|
"div",
|
|
649
655
|
{
|
|
650
656
|
className: "sa-input-dropdown-container-preview-item",
|
|
651
|
-
children:
|
|
657
|
+
children: J()
|
|
652
658
|
}
|
|
653
659
|
),
|
|
654
|
-
/* @__PURE__ */
|
|
655
|
-
|
|
660
|
+
/* @__PURE__ */ r(
|
|
661
|
+
X,
|
|
656
662
|
{
|
|
657
663
|
strokeWidth: 2,
|
|
658
|
-
width:
|
|
664
|
+
width: S(a),
|
|
659
665
|
style: { color: "var(--sa-color-gray-500, #8c8f97)" }
|
|
660
666
|
}
|
|
661
667
|
)
|
|
662
668
|
] }),
|
|
663
|
-
/* @__PURE__ */
|
|
664
|
-
|
|
669
|
+
/* @__PURE__ */ r(
|
|
670
|
+
_,
|
|
665
671
|
{
|
|
666
|
-
dropdownLists:
|
|
667
|
-
handleChangeValue:
|
|
668
|
-
isComponentVisible:
|
|
669
|
-
positionDropdown:
|
|
670
|
-
searchAble: !!
|
|
671
|
-
value:
|
|
672
|
-
onSearch:
|
|
673
|
-
ref:
|
|
674
|
-
multiSelect:
|
|
675
|
-
searchValue:
|
|
676
|
-
highlightedIndex:
|
|
672
|
+
dropdownLists: n,
|
|
673
|
+
handleChangeValue: j,
|
|
674
|
+
isComponentVisible: y,
|
|
675
|
+
positionDropdown: V,
|
|
676
|
+
searchAble: !!m,
|
|
677
|
+
value: s,
|
|
678
|
+
onSearch: g,
|
|
679
|
+
ref: x,
|
|
680
|
+
multiSelect: o,
|
|
681
|
+
searchValue: R,
|
|
682
|
+
highlightedIndex: b
|
|
677
683
|
}
|
|
678
684
|
)
|
|
679
685
|
]
|
|
680
686
|
}
|
|
681
687
|
) });
|
|
682
|
-
},
|
|
683
|
-
const
|
|
684
|
-
let a =
|
|
685
|
-
for (; a >= 0 && a <
|
|
686
|
-
if (!
|
|
688
|
+
}, O = (n, l, i) => {
|
|
689
|
+
const c = n.length;
|
|
690
|
+
let a = l + i;
|
|
691
|
+
for (; a >= 0 && a < c; ) {
|
|
692
|
+
if (!n[a].disable)
|
|
687
693
|
return a;
|
|
688
|
-
a +=
|
|
694
|
+
a += i;
|
|
689
695
|
}
|
|
690
|
-
if (
|
|
691
|
-
for (let o = 0; o <
|
|
692
|
-
if (!
|
|
696
|
+
if (i === 1) {
|
|
697
|
+
for (let o = 0; o < c; o++)
|
|
698
|
+
if (!n[o].disable)
|
|
693
699
|
return o;
|
|
694
700
|
} else
|
|
695
|
-
for (let o =
|
|
696
|
-
if (!
|
|
701
|
+
for (let o = c - 1; o >= 0; o--)
|
|
702
|
+
if (!n[o].disable)
|
|
697
703
|
return o;
|
|
698
704
|
return -1;
|
|
699
|
-
},
|
|
700
|
-
if (
|
|
705
|
+
}, S = (n) => {
|
|
706
|
+
if (n === "sm")
|
|
701
707
|
return 16;
|
|
702
|
-
if (
|
|
708
|
+
if (n === "md")
|
|
703
709
|
return 16;
|
|
704
|
-
if (
|
|
710
|
+
if (n === "lg")
|
|
705
711
|
return 20;
|
|
706
|
-
},
|
|
712
|
+
}, on = (n) => /* @__PURE__ */ r(
|
|
707
713
|
"svg",
|
|
708
714
|
{
|
|
709
715
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -711,8 +717,8 @@ const on = ({
|
|
|
711
717
|
height: "18",
|
|
712
718
|
viewBox: "0 0 18 18",
|
|
713
719
|
fill: "none",
|
|
714
|
-
...
|
|
715
|
-
children: /* @__PURE__ */
|
|
720
|
+
...n,
|
|
721
|
+
children: /* @__PURE__ */ r(
|
|
716
722
|
"path",
|
|
717
723
|
{
|
|
718
724
|
d: "M12 6L6 12M6.00001 6L12 12",
|
|
@@ -725,5 +731,5 @@ const on = ({
|
|
|
725
731
|
}
|
|
726
732
|
);
|
|
727
733
|
export {
|
|
728
|
-
|
|
734
|
+
tn as Dropdown
|
|
729
735
|
};
|
package/dist/dropdown.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(u=typeof globalThis<"u"?globalThis:u||self,n(u.Dropdown={},u.jsxRuntime,u.React))})(this,function(u,n,d){"use strict";const H=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
2
2
|
* {
|
|
3
3
|
margin: 0;
|
|
4
4
|
padding: 0;
|
|
@@ -311,4 +311,4 @@
|
|
|
311
311
|
height: 100%;
|
|
312
312
|
width: 100%;
|
|
313
313
|
}
|
|
314
|
-
`;function
|
|
314
|
+
`;function M(r){const[p,s]=d.useState(r),l=d.useRef(null),a=o=>{l.current&&!l.current.contains(o.target)&&s(!1)};return d.useEffect(()=>(document.addEventListener("click",a,!0),()=>{document.removeEventListener("click",a,!0)}),[]),{ref:l,isComponentVisible:p,setIsComponentVisible:s}}const P=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",...r,viewBox:"0 0 24 24",fill:"none",color:"var(--sa-color-gray-500, #8c8f97)",children:n.jsx("path",{d:"M4 9L12 17L20 9",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5})}),q=({...r})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...r,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),T=({isChecked:r})=>n.jsxs("div",{className:"checkbox-wrapper-30",children:[n.jsxs("span",{className:"checkbox",children:[n.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:r}),n.jsx("svg",{children:n.jsx("use",{xlinkHref:"#checkbox-30",className:"checkbox"})})]}),n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",style:{display:"none"},children:n.jsx("symbol",{id:"checkbox-30",viewBox:"0 0 22 22",children:n.jsx("path",{fill:"none",stroke:"currentColor",d:"M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"})})})]}),V=d.forwardRef(({positionDropdown:r,dropdownLists:p,isComponentVisible:s,searchAble:l,onSearch:a,value:o,handleChangeValue:k,multiSelect:w,searchValue:N,highlightedIndex:f},D)=>{const[B,I]=d.useState(0),y=d.useRef(null),z=d.useRef([]);return d.useEffect(()=>{if(y.current){const e=y.current.getBoundingClientRect();I(e.width)}},[y,s]),d.useEffect(()=>{var e;f>=0&&z.current[f]&&((e=z.current[f])==null||e.scrollIntoView({block:"nearest"}))},[f]),n.jsx(n.Fragment,{children:s?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:e=>e.stopPropagation(),ref:D,children:[l?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",style:{order:r=="bottom"?0:2,position:"sticky",top:0,bottom:0,zIndex:1},children:[n.jsx("div",{style:{display:"flex"},children:n.jsx(q,{strokeWidth:2,width:20})}),n.jsx("input",{onChange:e=>{a&&a(e.target.value)},value:N,autoFocus:!0,style:{width:"100%"}})]}):null,n.jsx("div",{className:`sa-input-dropdwon-item-container ${w?"multi":""}`,ref:y,children:p.map((e,g)=>{const c=!!(o!=null&&o.find(h=>h.value===e.value));return n.jsxs("div",{className:`sa-input-dropdwon-item ${c?"active":""} ${g===f?"highlight":""} ${e.disable?"sa-input-dropdwon-item-disable":""}`,ref:h=>{z.current[g]=h},onClick:()=>k(e.label,e.value),children:[w?n.jsx("div",{style:{marginRight:"8px"},children:n.jsx(T,{isChecked:c})}):null,e.icon?n.jsx("div",{children:d.cloneElement(e.icon,{width:16})}):null,n.jsxs("div",{children:[n.jsx("p",{className:`sa-input-dropdwon-item-text ${c?"active":null} ${e.disable?"sa-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${B-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:e.label}),e.description?n.jsx("p",{className:`sa-input-dropdwon-item-text-description ${c?"active":null} ${e.disable?"sa-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${B-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:e.description}):null]})]},g)})})]}):null})}),J=({children:r,handleChangePosition:p})=>{const s=d.useRef(null);d.useEffect(()=>{var k;const a=()=>{if(s.current){let w=s.current.parentElement;for(;w&&!l(w);)w=w.parentElement;w&&p()}};let o=(k=s.current)==null?void 0:k.parentElement;for(;o&&!l(o);)o=o.parentElement;return o&&o.addEventListener("scroll",a),a(),()=>{o&&o.removeEventListener("scroll",a)}},[]);const l=a=>a&&(a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth);return n.jsx("div",{ref:s,children:r})},j="sa-input-dropdown-styles";(r=>{if(!document.getElementById(j)){const p=document.createElement("style");p.id=j,p.textContent=r,document.head.appendChild(p)}})(H);const K=({dropdownLists:r,onChange:p,defaultValue:s,value:l,size:a="md",multiSelect:o,searchAble:k,iconLeft:w,placeholder:N,onSearch:f,error:D,onBlur:B,onFocus:I,disable:y,searchValue:z})=>{const e=l!==void 0,g=d.useRef(),[c,h]=d.useState(e?l||[]:s||[]),[G,O]=d.useState(""),[b,L]=d.useState(-1),x=d.useRef(null),{isComponentVisible:m,ref:W,setIsComponentVisible:$}=M(!1),Q=()=>{$(t=>!t)},S=(t,i)=>{if(o)if(c==null?void 0:c.find(v=>v.value===i)){const v=c.filter(Z=>Z.value!==i);e||h(v),p(v)}else{const v=[...c,{label:t,value:i}];e||h(v),p(v)}else{const E=[{label:t,value:i}];e||h(E),p(E),$(!1)}};d.useEffect(()=>{e&&h(l||[])},[l]),d.useEffect(()=>{e||JSON.stringify(g.current)===JSON.stringify(s)||(g.current=s,h(g.current||[]))},[s]);const X=()=>c.length?o?c==null?void 0:c.map((t,i)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:t==null?void 0:t.label},i),n.jsx(U,{onClick:()=>S(t.label,t.value)})]})):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:N}),C=()=>{if(W.current&&x.current){const t=window.innerHeight,i=W.current.getBoundingClientRect(),E=x.current.getBoundingClientRect(),v=i.bottom+E.height;x.current.style.left=`${i.left}px`,x.current.style.width=`${i.width}px`,v>=t-10?(x.current.style.top=`${i.top-E.height-5}px`,O("top")):(x.current.style.top=`${i.top+i.height}px`,O("bottom"))}};d.useEffect(()=>(window.addEventListener("scroll",C),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C),window.removeEventListener("resize",C)}),[]),d.useEffect(()=>{C()},[m]),d.useEffect(()=>{m||L(-1)},[m]);const Y=t=>{if(!m){(t.key==="ArrowDown"||t.key==="Enter")&&(t.preventDefault(),$(!0));return}switch(t.key){case"ArrowDown":{t.preventDefault();const i=A(r,b,1);i!==-1&&L(i);break}case"ArrowUp":{t.preventDefault();const i=A(r,b,-1);i!==-1&&L(i);break}case"Enter":{t.preventDefault(),b>=0&&r[b]&&!r[b].disable&&S(r[b].label,r[b].value);break}case"Escape":{$(!1);break}}};return n.jsx(J,{handleChangePosition:C,children:n.jsxs("div",{className:`sa-input-dropdown-container ${y?"disable":""} sa-input-dropdown-size-${a} ${m?"active":""} ${D?"error":""}`,ref:W,onClick:Q,onKeyDown:Y,tabIndex:0,onBlur:B,onFocus:I,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[w?n.jsx(n.Fragment,{children:d.cloneElement(w,{width:F(a),color:"var(--sa-color-gray-500, #8c8f97)",style:{color:"var(--sa-color-gray-500, #8c8f97)"}})}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:X()}),n.jsx(P,{strokeWidth:2,width:F(a),style:{color:"var(--sa-color-gray-500, #8c8f97)"}})]}),n.jsx(V,{dropdownLists:r,handleChangeValue:S,isComponentVisible:m,positionDropdown:G,searchAble:!!k,value:c,onSearch:f,ref:x,multiSelect:o,searchValue:z,highlightedIndex:b})]})})},A=(r,p,s)=>{const l=r.length;let a=p+s;for(;a>=0&&a<l;){if(!r[a].disable)return a;a+=s}if(s===1){for(let o=0;o<l;o++)if(!r[o].disable)return o}else for(let o=l-1;o>=0;o--)if(!r[o].disable)return o;return-1},F=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},U=r=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",...r,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})});u.Dropdown=K,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interface.d.ts
CHANGED