@starasia/dropdown 3.5.1 → 4.0.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 +147 -139
- package/dist/dropdown.umd.js +7 -3
- package/dist/interface.d.ts +1 -0
- package/package.json +1 -1
package/dist/dropdown.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsxs as l, jsx as n, Fragment as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsxs as l, jsx as n, Fragment as sn } from "react/jsx-runtime";
|
|
2
|
+
import T, { useState as P, useRef as B, useEffect as g, forwardRef as ln } from "react";
|
|
3
|
+
const pn = `@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;
|
|
@@ -116,6 +116,7 @@ const sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
116
116
|
background-color: transparent;
|
|
117
117
|
border: 0.8px solid var(--sa-dropdown-border-subtle);
|
|
118
118
|
border-radius: var(--borderRadius);
|
|
119
|
+
outline: none;
|
|
119
120
|
}
|
|
120
121
|
.sa-input-dropdown-container.outline.active {
|
|
121
122
|
border: 1.2px solid var(--sa-dropdown-border-active);
|
|
@@ -365,9 +366,12 @@ const sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
365
366
|
display: flex;
|
|
366
367
|
flex-direction: column;
|
|
367
368
|
gap: 6px;
|
|
368
|
-
width:
|
|
369
|
+
width: max-content;
|
|
369
370
|
font-family: "Poppins", sans-serif;
|
|
370
371
|
}
|
|
372
|
+
.sa-select-field-fullwidth {
|
|
373
|
+
width: 100%;
|
|
374
|
+
}
|
|
371
375
|
.sa-select-field-left {
|
|
372
376
|
flex-direction: row;
|
|
373
377
|
align-items: flex-start;
|
|
@@ -447,15 +451,15 @@ const sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
447
451
|
}
|
|
448
452
|
|
|
449
453
|
`;
|
|
450
|
-
function
|
|
451
|
-
const [p, d] =
|
|
454
|
+
function cn(e) {
|
|
455
|
+
const [p, d] = P(e), s = B(null), r = (o) => {
|
|
452
456
|
s.current && !s.current.contains(o.target) && d(!1);
|
|
453
457
|
};
|
|
454
458
|
return g(() => (document.addEventListener("click", r, !0), () => {
|
|
455
459
|
document.removeEventListener("click", r, !0);
|
|
456
460
|
}), []), { ref: s, isComponentVisible: p, setIsComponentVisible: d };
|
|
457
461
|
}
|
|
458
|
-
const
|
|
462
|
+
const un = ({ ...e }) => /* @__PURE__ */ l(
|
|
459
463
|
"svg",
|
|
460
464
|
{
|
|
461
465
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -487,7 +491,7 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
|
|
|
487
491
|
)
|
|
488
492
|
]
|
|
489
493
|
}
|
|
490
|
-
),
|
|
494
|
+
), wn = ({ width: e = 16 }) => /* @__PURE__ */ n(
|
|
491
495
|
"svg",
|
|
492
496
|
{
|
|
493
497
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -506,7 +510,7 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
|
|
|
506
510
|
}
|
|
507
511
|
)
|
|
508
512
|
}
|
|
509
|
-
),
|
|
513
|
+
), hn = ln(
|
|
510
514
|
({
|
|
511
515
|
positionDropdown: e,
|
|
512
516
|
dropdownLists: p,
|
|
@@ -514,78 +518,78 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
|
|
|
514
518
|
searchAble: s,
|
|
515
519
|
onSearch: r,
|
|
516
520
|
value: o,
|
|
517
|
-
handleChangeValue:
|
|
521
|
+
handleChangeValue: N,
|
|
518
522
|
multiSelect: u,
|
|
519
|
-
searchValue:
|
|
523
|
+
searchValue: F,
|
|
520
524
|
highlightedIndex: m,
|
|
521
|
-
footer:
|
|
522
|
-
groupLabel:
|
|
523
|
-
onSelectAll:
|
|
524
|
-
},
|
|
525
|
-
const
|
|
525
|
+
footer: I,
|
|
526
|
+
groupLabel: j,
|
|
527
|
+
onSelectAll: A
|
|
528
|
+
}, H) => {
|
|
529
|
+
const R = B([]);
|
|
526
530
|
g(() => {
|
|
527
531
|
var a;
|
|
528
|
-
m >= 0 &&
|
|
532
|
+
m >= 0 && R.current[m] && ((a = R.current[m]) == null || a.scrollIntoView({ block: "nearest" }));
|
|
529
533
|
}, [m]);
|
|
530
|
-
const
|
|
531
|
-
/* @__PURE__ */ n(
|
|
534
|
+
const D = s ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
|
|
535
|
+
/* @__PURE__ */ n(un, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
|
|
532
536
|
/* @__PURE__ */ n(
|
|
533
537
|
"input",
|
|
534
538
|
{
|
|
535
539
|
onChange: (a) => {
|
|
536
540
|
r && r(a.target.value);
|
|
537
541
|
},
|
|
538
|
-
value:
|
|
542
|
+
value: F,
|
|
539
543
|
autoFocus: !0,
|
|
540
544
|
placeholder: "Search..."
|
|
541
545
|
}
|
|
542
546
|
)
|
|
543
547
|
] }) : null;
|
|
544
|
-
return /* @__PURE__ */ n(
|
|
548
|
+
return /* @__PURE__ */ n(sn, { children: d ? /* @__PURE__ */ l(
|
|
545
549
|
"div",
|
|
546
550
|
{
|
|
547
551
|
className: "sa-input-dropdown-lists-container",
|
|
548
552
|
onClick: (a) => a.stopPropagation(),
|
|
549
|
-
ref:
|
|
553
|
+
ref: H,
|
|
550
554
|
children: [
|
|
551
|
-
e !== "top" &&
|
|
555
|
+
e !== "top" && D,
|
|
552
556
|
/* @__PURE__ */ l(
|
|
553
557
|
"div",
|
|
554
558
|
{
|
|
555
559
|
className: `sa-input-dropdwon-item-container ${u ? "multi" : ""}`,
|
|
556
560
|
children: [
|
|
557
|
-
|
|
558
|
-
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children:
|
|
559
|
-
u &&
|
|
561
|
+
j && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
|
|
562
|
+
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: j }),
|
|
563
|
+
u && A && /* @__PURE__ */ n(
|
|
560
564
|
"button",
|
|
561
565
|
{
|
|
562
566
|
className: "sa-input-dropdown-section-select-all",
|
|
563
567
|
onClick: (a) => {
|
|
564
|
-
a.stopPropagation(),
|
|
568
|
+
a.stopPropagation(), A();
|
|
565
569
|
},
|
|
566
570
|
children: "Select all"
|
|
567
571
|
}
|
|
568
572
|
)
|
|
569
573
|
] }),
|
|
570
|
-
p.map((a,
|
|
571
|
-
const
|
|
574
|
+
p.map((a, z) => {
|
|
575
|
+
const O = !!(o != null && o.find((k) => k.value === a.value)), M = !!a.description;
|
|
572
576
|
return /* @__PURE__ */ l(
|
|
573
577
|
"div",
|
|
574
578
|
{
|
|
575
579
|
className: [
|
|
576
580
|
"sa-input-dropdwon-item",
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
581
|
+
M ? "has-description" : "",
|
|
582
|
+
O ? "active" : "",
|
|
583
|
+
z === m ? "highlight" : "",
|
|
580
584
|
a.disable ? "sa-input-dropdwon-item-disable" : ""
|
|
581
585
|
].filter(Boolean).join(" "),
|
|
582
|
-
ref: (
|
|
583
|
-
|
|
586
|
+
ref: (k) => {
|
|
587
|
+
R.current[z] = k;
|
|
584
588
|
},
|
|
585
|
-
onClick: () =>
|
|
589
|
+
onClick: () => N(a.label, a.value),
|
|
586
590
|
children: [
|
|
587
|
-
u && /* @__PURE__ */ n("div", { className: "sa-input-dropdwon-item-check", children:
|
|
588
|
-
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children:
|
|
591
|
+
u && /* @__PURE__ */ n("div", { className: "sa-input-dropdwon-item-check", children: O && /* @__PURE__ */ n(wn, { width: 16 }) }),
|
|
592
|
+
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: T.cloneElement(a.icon, { width: 16 }) }),
|
|
589
593
|
/* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, children: [
|
|
590
594
|
/* @__PURE__ */ n(
|
|
591
595
|
"p",
|
|
@@ -610,25 +614,25 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
|
|
|
610
614
|
] })
|
|
611
615
|
]
|
|
612
616
|
},
|
|
613
|
-
|
|
617
|
+
z
|
|
614
618
|
);
|
|
615
619
|
})
|
|
616
620
|
]
|
|
617
621
|
}
|
|
618
622
|
),
|
|
619
|
-
e === "top" &&
|
|
620
|
-
|
|
623
|
+
e === "top" && D,
|
|
624
|
+
I && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: I })
|
|
621
625
|
]
|
|
622
626
|
}
|
|
623
627
|
) : null });
|
|
624
628
|
}
|
|
625
|
-
),
|
|
629
|
+
), fn = ({
|
|
626
630
|
children: e,
|
|
627
631
|
handleChangePosition: p
|
|
628
632
|
}) => {
|
|
629
|
-
const d =
|
|
633
|
+
const d = B(null);
|
|
630
634
|
g(() => {
|
|
631
|
-
var
|
|
635
|
+
var N;
|
|
632
636
|
const r = () => {
|
|
633
637
|
if (d.current) {
|
|
634
638
|
let u = d.current.parentElement;
|
|
@@ -637,7 +641,7 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
|
|
|
637
641
|
u && p();
|
|
638
642
|
}
|
|
639
643
|
};
|
|
640
|
-
let o = (
|
|
644
|
+
let o = (N = d.current) == null ? void 0 : N.parentElement;
|
|
641
645
|
for (; o && !s(o); )
|
|
642
646
|
o = o.parentElement;
|
|
643
647
|
return o && o.addEventListener("scroll", r), r(), () => {
|
|
@@ -646,203 +650,207 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
|
|
|
646
650
|
}, []);
|
|
647
651
|
const s = (r) => r && (r.scrollHeight > r.clientHeight || r.scrollWidth > r.clientWidth);
|
|
648
652
|
return /* @__PURE__ */ n("div", { ref: d, children: e });
|
|
649
|
-
},
|
|
650
|
-
if (!document.getElementById(
|
|
653
|
+
}, Y = "sa-input-dropdown-styles", bn = (e) => {
|
|
654
|
+
if (!document.getElementById(Y)) {
|
|
651
655
|
const p = document.createElement("style");
|
|
652
|
-
p.id =
|
|
656
|
+
p.id = Y, p.textContent = e, document.head.appendChild(p);
|
|
653
657
|
}
|
|
654
658
|
};
|
|
655
|
-
|
|
656
|
-
const
|
|
659
|
+
bn(pn);
|
|
660
|
+
const yn = ({
|
|
657
661
|
dropdownLists: e,
|
|
658
662
|
onChange: p,
|
|
659
663
|
defaultValue: d,
|
|
660
664
|
value: s,
|
|
661
665
|
size: r = "md",
|
|
662
666
|
multiSelect: o,
|
|
663
|
-
searchAble:
|
|
667
|
+
searchAble: N,
|
|
664
668
|
iconLeft: u,
|
|
665
|
-
placeholder:
|
|
669
|
+
placeholder: F,
|
|
666
670
|
onSearch: m,
|
|
667
|
-
error:
|
|
668
|
-
onBlur:
|
|
669
|
-
onFocus:
|
|
670
|
-
disable:
|
|
671
|
-
searchValue:
|
|
672
|
-
variant:
|
|
671
|
+
error: I,
|
|
672
|
+
onBlur: j,
|
|
673
|
+
onFocus: A,
|
|
674
|
+
disable: H,
|
|
675
|
+
searchValue: R,
|
|
676
|
+
variant: D = "outline",
|
|
673
677
|
footer: a,
|
|
674
|
-
groupLabel:
|
|
675
|
-
onSelectAll:
|
|
678
|
+
groupLabel: z,
|
|
679
|
+
onSelectAll: O,
|
|
680
|
+
fullWidth: M = !1,
|
|
676
681
|
/* field wrapper */
|
|
677
|
-
label:
|
|
678
|
-
labelPosition:
|
|
679
|
-
required:
|
|
680
|
-
optional:
|
|
681
|
-
description:
|
|
682
|
-
helperText:
|
|
682
|
+
label: k,
|
|
683
|
+
labelPosition: nn = "outside-top",
|
|
684
|
+
required: Z,
|
|
685
|
+
optional: Q,
|
|
686
|
+
description: E,
|
|
687
|
+
helperText: C,
|
|
683
688
|
errorText: w
|
|
684
689
|
}) => {
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
+
const $ = [
|
|
691
|
+
"sa-select-field",
|
|
692
|
+
M ? "sa-select-field-fullwidth" : ""
|
|
693
|
+
].filter(Boolean).join(" "), L = s !== void 0, V = B(), en = I || !!w, [c, S] = P(
|
|
694
|
+
L ? s || [] : d || []
|
|
695
|
+
), [on, X] = P(""), [x, q] = P(-1), h = B(null), { isComponentVisible: f, ref: G, setIsComponentVisible: W } = cn(!1), rn = () => {
|
|
696
|
+
W((t) => !t);
|
|
697
|
+
}, J = (t, i) => {
|
|
690
698
|
if (o)
|
|
691
699
|
if (c == null ? void 0 : c.find((b) => b.value === i)) {
|
|
692
|
-
const b = c.filter((
|
|
693
|
-
|
|
700
|
+
const b = c.filter((dn) => dn.value !== i);
|
|
701
|
+
L || S(b), p(b);
|
|
694
702
|
} else {
|
|
695
703
|
const b = [...c, { label: t, value: i }];
|
|
696
|
-
|
|
704
|
+
L || S(b), p(b);
|
|
697
705
|
}
|
|
698
706
|
else {
|
|
699
707
|
const v = [{ label: t, value: i }];
|
|
700
|
-
|
|
708
|
+
L || S(v), p(v), W(!1);
|
|
701
709
|
}
|
|
702
710
|
};
|
|
703
711
|
g(() => {
|
|
704
|
-
|
|
712
|
+
L && S(s || []);
|
|
705
713
|
}, [s]), g(() => {
|
|
706
|
-
|
|
714
|
+
L || JSON.stringify(V.current) === JSON.stringify(d) || (V.current = d, S(V.current || []));
|
|
707
715
|
}, [d]);
|
|
708
|
-
const
|
|
716
|
+
const an = () => c.length ? o ? c == null ? void 0 : c.map((t, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
709
717
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: t == null ? void 0 : t.label }),
|
|
710
718
|
/* @__PURE__ */ n(
|
|
711
|
-
|
|
719
|
+
gn,
|
|
712
720
|
{
|
|
713
721
|
onClick: (v) => {
|
|
714
|
-
v.stopPropagation(),
|
|
722
|
+
v.stopPropagation(), J(t.label, t.value);
|
|
715
723
|
}
|
|
716
724
|
}
|
|
717
725
|
)
|
|
718
|
-
] }, i)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children:
|
|
719
|
-
if (
|
|
720
|
-
const t = window.innerHeight, i =
|
|
721
|
-
h.current.style.left = `${i.left}px`, h.current.style.width = `${i.width}px`, b >= t - 10 ? (h.current.style.top = `${i.top - v.height - 5}px`,
|
|
726
|
+
] }, i)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: F }), y = () => {
|
|
727
|
+
if (G.current && h.current) {
|
|
728
|
+
const t = window.innerHeight, i = G.current.getBoundingClientRect(), v = h.current.getBoundingClientRect(), b = i.bottom + v.height;
|
|
729
|
+
h.current.style.left = `${i.left}px`, h.current.style.width = `${i.width}px`, b >= t - 10 ? (h.current.style.top = `${i.top - v.height - 5}px`, X("top")) : (h.current.style.top = `${i.top + i.height + 4}px`, X("bottom"));
|
|
722
730
|
}
|
|
723
731
|
};
|
|
724
|
-
g(() => (window.addEventListener("scroll",
|
|
725
|
-
window.removeEventListener("scroll",
|
|
732
|
+
g(() => (window.addEventListener("scroll", y), window.addEventListener("resize", y), () => {
|
|
733
|
+
window.removeEventListener("scroll", y), window.removeEventListener("resize", y);
|
|
726
734
|
}), []), g(() => {
|
|
727
|
-
|
|
735
|
+
y();
|
|
728
736
|
}, [f]), g(() => {
|
|
729
737
|
if (!f || !h.current)
|
|
730
738
|
return;
|
|
731
739
|
const t = new ResizeObserver(() => {
|
|
732
|
-
|
|
740
|
+
y();
|
|
733
741
|
});
|
|
734
742
|
return t.observe(h.current), () => t.disconnect();
|
|
735
743
|
}, [f]), g(() => {
|
|
736
|
-
f ||
|
|
744
|
+
f || q(-1);
|
|
737
745
|
}, [f]);
|
|
738
|
-
const
|
|
746
|
+
const tn = (t) => {
|
|
739
747
|
if (!f) {
|
|
740
|
-
(t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(),
|
|
748
|
+
(t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), W(!0));
|
|
741
749
|
return;
|
|
742
750
|
}
|
|
743
751
|
switch (t.key) {
|
|
744
752
|
case "ArrowDown": {
|
|
745
753
|
t.preventDefault();
|
|
746
|
-
const i =
|
|
747
|
-
i !== -1 &&
|
|
754
|
+
const i = _(e, x, 1);
|
|
755
|
+
i !== -1 && q(i);
|
|
748
756
|
break;
|
|
749
757
|
}
|
|
750
758
|
case "ArrowUp": {
|
|
751
759
|
t.preventDefault();
|
|
752
|
-
const i =
|
|
753
|
-
i !== -1 &&
|
|
760
|
+
const i = _(e, x, -1);
|
|
761
|
+
i !== -1 && q(i);
|
|
754
762
|
break;
|
|
755
763
|
}
|
|
756
764
|
case "Enter": {
|
|
757
|
-
t.preventDefault(), x >= 0 && e[x] && !e[x].disable &&
|
|
765
|
+
t.preventDefault(), x >= 0 && e[x] && !e[x].disable && J(
|
|
758
766
|
e[x].label,
|
|
759
767
|
e[x].value
|
|
760
768
|
);
|
|
761
769
|
break;
|
|
762
770
|
}
|
|
763
771
|
case "Escape":
|
|
764
|
-
|
|
772
|
+
W(!1);
|
|
765
773
|
break;
|
|
766
774
|
}
|
|
767
|
-
},
|
|
775
|
+
}, K = r === "lg" || r === "xl" ? 20 : 16, U = /* @__PURE__ */ n(fn, { handleChangePosition: y, children: /* @__PURE__ */ l(
|
|
768
776
|
"div",
|
|
769
777
|
{
|
|
770
778
|
className: [
|
|
771
779
|
"sa-input-dropdown-container",
|
|
772
|
-
|
|
780
|
+
D,
|
|
773
781
|
`sa-input-dropdown-size-${r}`,
|
|
774
782
|
f ? "active" : "",
|
|
775
|
-
|
|
776
|
-
|
|
783
|
+
en ? "error" : "",
|
|
784
|
+
H ? "disable" : ""
|
|
777
785
|
].filter(Boolean).join(" "),
|
|
778
|
-
ref:
|
|
779
|
-
onClick:
|
|
780
|
-
onKeyDown:
|
|
786
|
+
ref: G,
|
|
787
|
+
onClick: rn,
|
|
788
|
+
onKeyDown: tn,
|
|
781
789
|
tabIndex: 0,
|
|
782
|
-
onBlur:
|
|
783
|
-
onFocus:
|
|
790
|
+
onBlur: j,
|
|
791
|
+
onFocus: A,
|
|
784
792
|
children: [
|
|
785
793
|
/* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
|
|
786
|
-
u ?
|
|
787
|
-
width:
|
|
794
|
+
u ? T.cloneElement(u, {
|
|
795
|
+
width: K,
|
|
788
796
|
style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
|
|
789
797
|
}) : null,
|
|
790
|
-
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children:
|
|
791
|
-
f ? /* @__PURE__ */ n(
|
|
798
|
+
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: an() }),
|
|
799
|
+
f ? /* @__PURE__ */ n(vn, { width: K }) : /* @__PURE__ */ n(xn, { width: K })
|
|
792
800
|
] }),
|
|
793
801
|
/* @__PURE__ */ n(
|
|
794
|
-
|
|
802
|
+
hn,
|
|
795
803
|
{
|
|
796
804
|
dropdownLists: e,
|
|
797
|
-
handleChangeValue:
|
|
805
|
+
handleChangeValue: J,
|
|
798
806
|
isComponentVisible: f,
|
|
799
|
-
positionDropdown:
|
|
800
|
-
searchAble: !!
|
|
807
|
+
positionDropdown: on,
|
|
808
|
+
searchAble: !!N,
|
|
801
809
|
value: c,
|
|
802
810
|
onSearch: m,
|
|
803
811
|
ref: h,
|
|
804
812
|
multiSelect: o,
|
|
805
|
-
searchValue:
|
|
813
|
+
searchValue: R,
|
|
806
814
|
highlightedIndex: x,
|
|
807
815
|
footer: a,
|
|
808
|
-
groupLabel:
|
|
809
|
-
onSelectAll:
|
|
816
|
+
groupLabel: z,
|
|
817
|
+
onSelectAll: O
|
|
810
818
|
}
|
|
811
819
|
)
|
|
812
820
|
]
|
|
813
821
|
}
|
|
814
822
|
) });
|
|
815
|
-
return
|
|
823
|
+
return k ? nn === "outside-left" ? /* @__PURE__ */ l("div", { className: `${$} sa-select-field-left`, children: [
|
|
816
824
|
/* @__PURE__ */ l("div", { className: "sa-select-field-left-label", children: [
|
|
817
825
|
/* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
|
|
818
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
819
|
-
|
|
820
|
-
|
|
826
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: k }),
|
|
827
|
+
Q && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
828
|
+
Z && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
821
829
|
] }),
|
|
822
|
-
|
|
830
|
+
E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E })
|
|
823
831
|
] }),
|
|
824
832
|
/* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
|
|
825
|
-
|
|
826
|
-
|
|
833
|
+
U,
|
|
834
|
+
C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
|
|
827
835
|
w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
|
|
828
836
|
] })
|
|
829
|
-
] }) : /* @__PURE__ */ l("div", { className:
|
|
837
|
+
] }) : /* @__PURE__ */ l("div", { className: $, children: [
|
|
830
838
|
/* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
|
|
831
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
832
|
-
|
|
833
|
-
|
|
839
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: k }),
|
|
840
|
+
Q && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
841
|
+
Z && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
834
842
|
] }),
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
843
|
+
E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
|
|
844
|
+
U,
|
|
845
|
+
C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
|
|
838
846
|
w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
|
|
839
|
-
] }) : /* @__PURE__ */ l("div", { className:
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
847
|
+
] }) : /* @__PURE__ */ l("div", { className: $, children: [
|
|
848
|
+
E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
|
|
849
|
+
U,
|
|
850
|
+
C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
|
|
843
851
|
w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
|
|
844
852
|
] });
|
|
845
|
-
},
|
|
853
|
+
}, _ = (e, p, d) => {
|
|
846
854
|
const s = e.length;
|
|
847
855
|
let r = p + d;
|
|
848
856
|
for (; r >= 0 && r < s; ) {
|
|
@@ -859,7 +867,7 @@ const mn = ({
|
|
|
859
867
|
if (!e[o].disable)
|
|
860
868
|
return o;
|
|
861
869
|
return -1;
|
|
862
|
-
},
|
|
870
|
+
}, gn = (e) => /* @__PURE__ */ n(
|
|
863
871
|
"svg",
|
|
864
872
|
{
|
|
865
873
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -880,7 +888,7 @@ const mn = ({
|
|
|
880
888
|
}
|
|
881
889
|
)
|
|
882
890
|
}
|
|
883
|
-
),
|
|
891
|
+
), xn = ({ width: e = 16 }) => /* @__PURE__ */ n(
|
|
884
892
|
"svg",
|
|
885
893
|
{
|
|
886
894
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -900,7 +908,7 @@ const mn = ({
|
|
|
900
908
|
}
|
|
901
909
|
)
|
|
902
910
|
}
|
|
903
|
-
),
|
|
911
|
+
), vn = ({ width: e = 16 }) => /* @__PURE__ */ n(
|
|
904
912
|
"svg",
|
|
905
913
|
{
|
|
906
914
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -922,5 +930,5 @@ const mn = ({
|
|
|
922
930
|
}
|
|
923
931
|
);
|
|
924
932
|
export {
|
|
925
|
-
|
|
933
|
+
yn as Dropdown
|
|
926
934
|
};
|
package/dist/dropdown.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(g,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):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,d){"use strict";const
|
|
1
|
+
(function(g,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):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,d){"use strict";const Y=`@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;
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
background-color: transparent;
|
|
115
115
|
border: 0.8px solid var(--sa-dropdown-border-subtle);
|
|
116
116
|
border-radius: var(--borderRadius);
|
|
117
|
+
outline: none;
|
|
117
118
|
}
|
|
118
119
|
.sa-input-dropdown-container.outline.active {
|
|
119
120
|
border: 1.2px solid var(--sa-dropdown-border-active);
|
|
@@ -363,9 +364,12 @@
|
|
|
363
364
|
display: flex;
|
|
364
365
|
flex-direction: column;
|
|
365
366
|
gap: 6px;
|
|
366
|
-
width:
|
|
367
|
+
width: max-content;
|
|
367
368
|
font-family: "Poppins", sans-serif;
|
|
368
369
|
}
|
|
370
|
+
.sa-select-field-fullwidth {
|
|
371
|
+
width: 100%;
|
|
372
|
+
}
|
|
369
373
|
.sa-select-field-left {
|
|
370
374
|
flex-direction: row;
|
|
371
375
|
align-items: flex-start;
|
|
@@ -444,4 +448,4 @@
|
|
|
444
448
|
margin: 0;
|
|
445
449
|
}
|
|
446
450
|
|
|
447
|
-
`;function
|
|
451
|
+
`;function _(e){const[p,i]=d.useState(e),l=d.useRef(null),r=o=>{l.current&&!l.current.contains(o.target)&&i(!1)};return d.useEffect(()=>(document.addEventListener("click",r,!0),()=>{document.removeEventListener("click",r,!0)}),[]),{ref:l,isComponentVisible:p,setIsComponentVisible:i}}const R=({...e})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...e,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"})]}),nn=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),en=d.forwardRef(({positionDropdown:e,dropdownLists:p,isComponentVisible:i,searchAble:l,onSearch:r,value:o,handleChangeValue:E,multiSelect:f,searchValue:W,highlightedIndex:k,footer:j,groupLabel:I,onSelectAll:D},F)=>{const L=d.useRef([]);d.useEffect(()=>{var a;k>=0&&L.current[k]&&((a=L.current[k])==null||a.scrollIntoView({block:"nearest"}))},[k]);const A=l?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(R,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{r&&r(a.target.value)},value:W,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:i?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:a=>a.stopPropagation(),ref:F,children:[e!=="top"&&A,n.jsxs("div",{className:`sa-input-dropdwon-item-container ${f?"multi":""}`,children:[I&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:I}),f&&D&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),D()},children:"Select all"})]}),p.map((a,z)=>{const O=!!(o!=null&&o.find(m=>m.value===a.value)),H=!!a.description;return n.jsxs("div",{className:["sa-input-dropdwon-item",H?"has-description":"",O?"active":"",z===k?"highlight":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),ref:m=>{L.current[z]=m},onClick:()=>E(a.label,a.value),children:[f&&n.jsx("div",{className:"sa-input-dropdwon-item-check",children:O&&n.jsx(nn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:d.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdwon-item-text",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdwon-item-text-description",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},z)})]}),e==="top"&&A,j&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:j})]}):null})}),on=({children:e,handleChangePosition:p})=>{const i=d.useRef(null);d.useEffect(()=>{var E;const r=()=>{if(i.current){let f=i.current.parentElement;for(;f&&!l(f);)f=f.parentElement;f&&p()}};let o=(E=i.current)==null?void 0:E.parentElement;for(;o&&!l(o);)o=o.parentElement;return o&&o.addEventListener("scroll",r),r(),()=>{o&&o.removeEventListener("scroll",r)}},[]);const l=r=>r&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth);return n.jsx("div",{ref:i,children:e})},U="sa-input-dropdown-styles";(e=>{if(!document.getElementById(U)){const p=document.createElement("style");p.id=U,p.textContent=e,document.head.appendChild(p)}})(Y);const rn=({dropdownLists:e,onChange:p,defaultValue:i,value:l,size:r="md",multiSelect:o,searchAble:E,iconLeft:f,placeholder:W,onSearch:k,error:j,onBlur:I,onFocus:D,disable:F,searchValue:L,variant:A="outline",footer:a,groupLabel:z,onSelectAll:O,fullWidth:H=!1,label:m,labelPosition:tn="outside-top",required:Z,optional:Q,description:N,helperText:C,errorText:w})=>{const M=["sa-select-field",H?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),S=l!==void 0,$=d.useRef(),ln=j||!!w,[c,B]=d.useState(S?l||[]:i||[]),[pn,X]=d.useState(""),[x,q]=d.useState(-1),h=d.useRef(null),{isComponentVisible:u,ref:V,setIsComponentVisible:P}=_(!1),cn=()=>{P(s=>!s)},G=(s,t)=>{if(o)if(c==null?void 0:c.find(b=>b.value===t)){const b=c.filter(hn=>hn.value!==t);S||B(b),p(b)}else{const b=[...c,{label:s,value:t}];S||B(b),p(b)}else{const v=[{label:s,value:t}];S||B(v),p(v),P(!1)}};d.useEffect(()=>{S&&B(l||[])},[l]),d.useEffect(()=>{S||JSON.stringify($.current)===JSON.stringify(i)||($.current=i,B($.current||[]))},[i]);const fn=()=>c.length?o?c==null?void 0:c.map((s,t)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:s==null?void 0:s.label}),n.jsx(an,{onClick:v=>{v.stopPropagation(),G(s.label,s.value)}})]},t)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:W}),y=()=>{if(V.current&&h.current){const s=window.innerHeight,t=V.current.getBoundingClientRect(),v=h.current.getBoundingClientRect(),b=t.bottom+v.height;h.current.style.left=`${t.left}px`,h.current.style.width=`${t.width}px`,b>=s-10?(h.current.style.top=`${t.top-v.height-5}px`,X("top")):(h.current.style.top=`${t.top+t.height+4}px`,X("bottom"))}};d.useEffect(()=>(window.addEventListener("scroll",y),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y),window.removeEventListener("resize",y)}),[]),d.useEffect(()=>{y()},[u]),d.useEffect(()=>{if(!u||!h.current)return;const s=new ResizeObserver(()=>{y()});return s.observe(h.current),()=>s.disconnect()},[u]),d.useEffect(()=>{u||q(-1)},[u]);const wn=s=>{if(!u){(s.key==="ArrowDown"||s.key==="Enter")&&(s.preventDefault(),P(!0));return}switch(s.key){case"ArrowDown":{s.preventDefault();const t=T(e,x,1);t!==-1&&q(t);break}case"ArrowUp":{s.preventDefault();const t=T(e,x,-1);t!==-1&&q(t);break}case"Enter":{s.preventDefault(),x>=0&&e[x]&&!e[x].disable&&G(e[x].label,e[x].value);break}case"Escape":P(!1);break}},J=r==="lg"||r==="xl"?20:16,K=n.jsx(on,{handleChangePosition:y,children:n.jsxs("div",{className:["sa-input-dropdown-container",A,`sa-input-dropdown-size-${r}`,u?"active":"",ln?"error":"",F?"disable":""].filter(Boolean).join(" "),ref:V,onClick:cn,onKeyDown:wn,tabIndex:0,onBlur:I,onFocus:D,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[f?d.cloneElement(f,{width:J,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:fn()}),u?n.jsx(dn,{width:J}):n.jsx(sn,{width:J})]}),n.jsx(en,{dropdownLists:e,handleChangeValue:G,isComponentVisible:u,positionDropdown:pn,searchAble:!!E,value:c,onSearch:k,ref:h,multiSelect:o,searchValue:L,highlightedIndex:x,footer:a,groupLabel:z,onSelectAll:O})]})});return m?tn==="outside-left"?n.jsxs("div",{className:`${M} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:m}),Q&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),Z&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[K,C&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:C}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]})]}):n.jsxs("div",{className:M,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:m}),Q&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),Z&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N}),K,C&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:C}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]}):n.jsxs("div",{className:M,children:[N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N}),K,C&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:C}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]})},T=(e,p,i)=>{const l=e.length;let r=p+i;for(;r>=0&&r<l;){if(!e[r].disable)return r;r+=i}if(i===1){for(let o=0;o<l;o++)if(!e[o].disable)return o}else for(let o=l-1;o>=0;o--)if(!e[o].disable)return o;return-1},an=e=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...e,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),sn=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),dn=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});g.Dropdown=rn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interface.d.ts
CHANGED