@starasia/dropdown 1.0.6 → 1.0.7
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/DropdownList.d.ts +1 -0
- package/dist/dropdown.es.js +216 -158
- package/dist/dropdown.umd.js +7 -2
- package/package.json +6 -6
package/dist/DropdownList.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface IProps {
|
|
|
13
13
|
handleChangeValue: (label: string, values: string) => void;
|
|
14
14
|
multiSelect: boolean | undefined;
|
|
15
15
|
searchValue?: string;
|
|
16
|
+
highlightedIndex: number;
|
|
16
17
|
}
|
|
17
18
|
declare const DropdownList: React.ForwardRefExoticComponent<IProps & React.RefAttributes<HTMLDivElement>>;
|
|
18
19
|
export default DropdownList;
|
package/dist/dropdown.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsx as a, jsxs as p, Fragment as H } from "react/jsx-runtime";
|
|
2
|
+
import O, { useState as R, useRef as z, useEffect as b, forwardRef as K } from "react";
|
|
3
|
+
const U = `@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;
|
|
@@ -266,6 +266,11 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
|
|
|
266
266
|
/* background: var(--starasia-ui-dropdown-background-color-secondary); */
|
|
267
267
|
/* box-shadow: 0px 0px 0px -1px #f0f0f0; */
|
|
268
268
|
}
|
|
269
|
+
.starasia-input-dropdwon-item.highlight {
|
|
270
|
+
background-color: rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.35);
|
|
271
|
+
outline: 2px solid rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.4);
|
|
272
|
+
outline-offset: -2px;
|
|
273
|
+
}
|
|
269
274
|
|
|
270
275
|
.starasia-input-dropdwon-item-disable {
|
|
271
276
|
color: var(--starasia-ui-dropdown-color-disable) !important;
|
|
@@ -397,23 +402,23 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
|
|
|
397
402
|
width: 100%;
|
|
398
403
|
}
|
|
399
404
|
`;
|
|
400
|
-
function
|
|
401
|
-
const [
|
|
402
|
-
|
|
405
|
+
function G(n) {
|
|
406
|
+
const [c, s] = R(n), d = z(null), i = (o) => {
|
|
407
|
+
d.current && !d.current.contains(o.target) && s(!1);
|
|
403
408
|
};
|
|
404
|
-
return b(() => (document.addEventListener("click",
|
|
405
|
-
document.removeEventListener("click",
|
|
406
|
-
}), []), { ref:
|
|
409
|
+
return b(() => (document.addEventListener("click", i, !0), () => {
|
|
410
|
+
document.removeEventListener("click", i, !0);
|
|
411
|
+
}), []), { ref: d, isComponentVisible: c, setIsComponentVisible: s };
|
|
407
412
|
}
|
|
408
|
-
const
|
|
413
|
+
const Q = ({ ...n }) => /* @__PURE__ */ a(
|
|
409
414
|
"svg",
|
|
410
415
|
{
|
|
411
416
|
xmlns: "http://www.w3.org/2000/svg",
|
|
412
|
-
...
|
|
417
|
+
...n,
|
|
413
418
|
viewBox: "0 0 24 24",
|
|
414
419
|
fill: "none",
|
|
415
420
|
color: "#939E99",
|
|
416
|
-
children: /* @__PURE__ */
|
|
421
|
+
children: /* @__PURE__ */ a(
|
|
417
422
|
"path",
|
|
418
423
|
{
|
|
419
424
|
d: "M4 9L12 17L20 9",
|
|
@@ -424,15 +429,15 @@ const J = ({ ...a }) => /* @__PURE__ */ n(
|
|
|
424
429
|
}
|
|
425
430
|
)
|
|
426
431
|
}
|
|
427
|
-
),
|
|
432
|
+
), T = ({ ...n }) => /* @__PURE__ */ p(
|
|
428
433
|
"svg",
|
|
429
434
|
{
|
|
430
435
|
xmlns: "http://www.w3.org/2000/svg",
|
|
431
|
-
...
|
|
436
|
+
...n,
|
|
432
437
|
viewBox: "0 0 20 20",
|
|
433
438
|
fill: "none",
|
|
434
439
|
children: [
|
|
435
|
-
/* @__PURE__ */
|
|
440
|
+
/* @__PURE__ */ a(
|
|
436
441
|
"circle",
|
|
437
442
|
{
|
|
438
443
|
cx: "9.80547",
|
|
@@ -444,7 +449,7 @@ const J = ({ ...a }) => /* @__PURE__ */ n(
|
|
|
444
449
|
strokeLinejoin: "round"
|
|
445
450
|
}
|
|
446
451
|
),
|
|
447
|
-
/* @__PURE__ */
|
|
452
|
+
/* @__PURE__ */ a(
|
|
448
453
|
"path",
|
|
449
454
|
{
|
|
450
455
|
d: "M15.0153 15.4043L17.9519 18.3333",
|
|
@@ -456,19 +461,19 @@ const J = ({ ...a }) => /* @__PURE__ */ n(
|
|
|
456
461
|
)
|
|
457
462
|
]
|
|
458
463
|
}
|
|
459
|
-
),
|
|
464
|
+
), X = ({ isChecked: n }) => /* @__PURE__ */ p("div", { className: "checkbox-wrapper-30", children: [
|
|
460
465
|
/* @__PURE__ */ p("span", { className: "checkbox", children: [
|
|
461
|
-
/* @__PURE__ */
|
|
466
|
+
/* @__PURE__ */ a(
|
|
462
467
|
"input",
|
|
463
468
|
{
|
|
464
469
|
type: "checkbox",
|
|
465
470
|
style: { pointerEvents: "none" },
|
|
466
|
-
checked:
|
|
471
|
+
checked: n
|
|
467
472
|
}
|
|
468
473
|
),
|
|
469
|
-
/* @__PURE__ */
|
|
474
|
+
/* @__PURE__ */ a("svg", { children: /* @__PURE__ */ a("use", { xlinkHref: "#checkbox-30", className: "checkbox" }) })
|
|
470
475
|
] }),
|
|
471
|
-
/* @__PURE__ */
|
|
476
|
+
/* @__PURE__ */ a("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, children: /* @__PURE__ */ a("symbol", { id: "checkbox-30", viewBox: "0 0 22 22", children: /* @__PURE__ */ a(
|
|
472
477
|
"path",
|
|
473
478
|
{
|
|
474
479
|
fill: "none",
|
|
@@ -476,58 +481,55 @@ const J = ({ ...a }) => /* @__PURE__ */ n(
|
|
|
476
481
|
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"
|
|
477
482
|
}
|
|
478
483
|
) }) })
|
|
479
|
-
] }),
|
|
484
|
+
] }), Y = K(
|
|
480
485
|
({
|
|
481
|
-
positionDropdown:
|
|
482
|
-
dropdownLists:
|
|
483
|
-
isComponentVisible:
|
|
484
|
-
searchAble:
|
|
485
|
-
onSearch:
|
|
486
|
-
value:
|
|
487
|
-
handleChangeValue:
|
|
486
|
+
positionDropdown: n,
|
|
487
|
+
dropdownLists: c,
|
|
488
|
+
isComponentVisible: s,
|
|
489
|
+
searchAble: d,
|
|
490
|
+
onSearch: i,
|
|
491
|
+
value: o,
|
|
492
|
+
handleChangeValue: g,
|
|
488
493
|
multiSelect: l,
|
|
489
|
-
searchValue:
|
|
490
|
-
|
|
491
|
-
|
|
494
|
+
searchValue: $,
|
|
495
|
+
highlightedIndex: v
|
|
496
|
+
}, N) => {
|
|
497
|
+
const [I, W] = R(0), f = z(null), x = z([]);
|
|
492
498
|
return b(() => {
|
|
493
|
-
if (
|
|
494
|
-
const r =
|
|
495
|
-
|
|
499
|
+
if (f.current) {
|
|
500
|
+
const r = f.current.getBoundingClientRect();
|
|
501
|
+
W(r.width);
|
|
496
502
|
}
|
|
497
|
-
}, [
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
}) : z(void 0);
|
|
504
|
-
}, [v, i]), /* @__PURE__ */ n(q, { children: t ? /* @__PURE__ */ p(
|
|
503
|
+
}, [f, s]), b(() => {
|
|
504
|
+
var r;
|
|
505
|
+
v >= 0 && x.current[v] && ((r = x.current[v]) == null || r.scrollIntoView({ block: "nearest" }));
|
|
506
|
+
}, [v]), /* @__PURE__ */ a(H, { children: s ? /* @__PURE__ */ p(
|
|
505
507
|
"div",
|
|
506
508
|
{
|
|
507
509
|
className: "starasia-input-dropdown-lists-container",
|
|
508
510
|
onClick: (r) => r.stopPropagation(),
|
|
509
|
-
ref:
|
|
511
|
+
ref: N,
|
|
510
512
|
children: [
|
|
511
|
-
|
|
513
|
+
d ? /* @__PURE__ */ p(
|
|
512
514
|
"div",
|
|
513
515
|
{
|
|
514
516
|
className: "starasia-input-dropdown-container-dropdown-search",
|
|
515
517
|
style: {
|
|
516
|
-
order:
|
|
518
|
+
order: n == "bottom" ? 0 : 2,
|
|
517
519
|
position: "sticky",
|
|
518
520
|
top: 0,
|
|
519
521
|
bottom: 0,
|
|
520
522
|
zIndex: 1
|
|
521
523
|
},
|
|
522
524
|
children: [
|
|
523
|
-
/* @__PURE__ */
|
|
524
|
-
/* @__PURE__ */
|
|
525
|
+
/* @__PURE__ */ a("div", { style: { display: "flex" }, children: /* @__PURE__ */ a(T, { strokeWidth: 2, width: 20 }) }),
|
|
526
|
+
/* @__PURE__ */ a(
|
|
525
527
|
"input",
|
|
526
528
|
{
|
|
527
529
|
onChange: (r) => {
|
|
528
|
-
|
|
530
|
+
i && i(r.target.value);
|
|
529
531
|
},
|
|
530
|
-
value:
|
|
532
|
+
value: $,
|
|
531
533
|
autoFocus: !0,
|
|
532
534
|
style: { width: "100%" }
|
|
533
535
|
}
|
|
@@ -535,44 +537,47 @@ const J = ({ ...a }) => /* @__PURE__ */ n(
|
|
|
535
537
|
]
|
|
536
538
|
}
|
|
537
539
|
) : null,
|
|
538
|
-
/* @__PURE__ */
|
|
540
|
+
/* @__PURE__ */ a(
|
|
539
541
|
"div",
|
|
540
542
|
{
|
|
541
543
|
className: `starasia-input-dropdwon-item-container ${l ? "multi" : ""}`,
|
|
542
|
-
ref:
|
|
543
|
-
children:
|
|
544
|
-
const
|
|
544
|
+
ref: f,
|
|
545
|
+
children: c.map((r, w) => {
|
|
546
|
+
const y = !!(o != null && o.find((k) => k.value === r.value));
|
|
545
547
|
return /* @__PURE__ */ p(
|
|
546
548
|
"div",
|
|
547
549
|
{
|
|
548
|
-
className: `starasia-input-dropdwon-item ${
|
|
549
|
-
|
|
550
|
+
className: `starasia-input-dropdwon-item ${y ? "active" : ""} ${w === v ? "highlight" : ""} ${r.disable ? "starasia-input-dropdwon-item-disable" : ""}`,
|
|
551
|
+
ref: (k) => {
|
|
552
|
+
x.current[w] = k;
|
|
553
|
+
},
|
|
554
|
+
onClick: () => g(r.label, r.value),
|
|
550
555
|
children: [
|
|
551
|
-
l ? /* @__PURE__ */
|
|
552
|
-
r.icon ? /* @__PURE__ */
|
|
556
|
+
l ? /* @__PURE__ */ a("div", { style: { marginRight: "8px" }, children: /* @__PURE__ */ a(X, { isChecked: y }) }) : null,
|
|
557
|
+
r.icon ? /* @__PURE__ */ a("div", { children: O.cloneElement(r.icon, {
|
|
553
558
|
width: 16
|
|
554
559
|
}) }) : null,
|
|
555
560
|
/* @__PURE__ */ p("div", { children: [
|
|
556
|
-
/* @__PURE__ */
|
|
561
|
+
/* @__PURE__ */ a(
|
|
557
562
|
"p",
|
|
558
563
|
{
|
|
559
|
-
className: `starasia-input-dropdwon-item-text ${
|
|
564
|
+
className: `starasia-input-dropdwon-item-text ${y ? "active" : null} ${r.disable ? "starasia-input-dropdwon-item-disable" : null}`,
|
|
560
565
|
style: {
|
|
561
566
|
textWrap: "nowrap",
|
|
562
|
-
width: `${
|
|
567
|
+
width: `${I - 12}px`,
|
|
563
568
|
overflow: "hidden",
|
|
564
569
|
textOverflow: "ellipsis"
|
|
565
570
|
},
|
|
566
571
|
children: r.label
|
|
567
572
|
}
|
|
568
573
|
),
|
|
569
|
-
r.description ? /* @__PURE__ */
|
|
574
|
+
r.description ? /* @__PURE__ */ a(
|
|
570
575
|
"p",
|
|
571
576
|
{
|
|
572
|
-
className: `starasia-input-dropdwon-item-text-description ${
|
|
577
|
+
className: `starasia-input-dropdwon-item-text-description ${y ? "active" : null} ${r.disable ? "starasia-input-dropdwon-item-disable" : null}`,
|
|
573
578
|
style: {
|
|
574
579
|
textWrap: "nowrap",
|
|
575
|
-
width: `${
|
|
580
|
+
width: `${I - 12}px`,
|
|
576
581
|
overflow: "hidden",
|
|
577
582
|
textOverflow: "ellipsis"
|
|
578
583
|
},
|
|
@@ -582,7 +587,7 @@ const J = ({ ...a }) => /* @__PURE__ */ n(
|
|
|
582
587
|
] })
|
|
583
588
|
]
|
|
584
589
|
},
|
|
585
|
-
|
|
590
|
+
w
|
|
586
591
|
);
|
|
587
592
|
})
|
|
588
593
|
}
|
|
@@ -591,149 +596,202 @@ const J = ({ ...a }) => /* @__PURE__ */ n(
|
|
|
591
596
|
}
|
|
592
597
|
) : null });
|
|
593
598
|
}
|
|
594
|
-
),
|
|
595
|
-
children:
|
|
596
|
-
handleChangePosition:
|
|
599
|
+
), Z = ({
|
|
600
|
+
children: n,
|
|
601
|
+
handleChangePosition: c
|
|
597
602
|
}) => {
|
|
598
|
-
const
|
|
603
|
+
const s = z(null);
|
|
599
604
|
b(() => {
|
|
600
|
-
var
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
let l =
|
|
604
|
-
for (; l && !
|
|
605
|
+
var g;
|
|
606
|
+
const i = () => {
|
|
607
|
+
if (s.current) {
|
|
608
|
+
let l = s.current.parentElement;
|
|
609
|
+
for (; l && !d(l); )
|
|
605
610
|
l = l.parentElement;
|
|
606
|
-
l &&
|
|
611
|
+
l && c();
|
|
607
612
|
}
|
|
608
613
|
};
|
|
609
|
-
let
|
|
610
|
-
for (;
|
|
611
|
-
|
|
612
|
-
return
|
|
613
|
-
|
|
614
|
+
let o = (g = s.current) == null ? void 0 : g.parentElement;
|
|
615
|
+
for (; o && !d(o); )
|
|
616
|
+
o = o.parentElement;
|
|
617
|
+
return o && o.addEventListener("scroll", i), i(), () => {
|
|
618
|
+
o && o.removeEventListener("scroll", i);
|
|
614
619
|
};
|
|
615
620
|
}, []);
|
|
616
|
-
const
|
|
617
|
-
return /* @__PURE__ */
|
|
618
|
-
},
|
|
619
|
-
if (!document.getElementById(
|
|
620
|
-
const
|
|
621
|
-
|
|
621
|
+
const d = (i) => i && (i.scrollHeight > i.clientHeight || i.scrollWidth > i.clientWidth);
|
|
622
|
+
return /* @__PURE__ */ a("div", { ref: s, children: n });
|
|
623
|
+
}, S = "starasia-input-dropdown-styles", _ = (n) => {
|
|
624
|
+
if (!document.getElementById(S)) {
|
|
625
|
+
const c = document.createElement("style");
|
|
626
|
+
c.id = S, c.textContent = n, document.head.appendChild(c);
|
|
622
627
|
}
|
|
623
628
|
};
|
|
624
|
-
U
|
|
625
|
-
const
|
|
626
|
-
dropdownLists:
|
|
627
|
-
onChange:
|
|
628
|
-
defaultValue:
|
|
629
|
-
size:
|
|
630
|
-
multiSelect:
|
|
631
|
-
searchAble:
|
|
632
|
-
iconLeft:
|
|
629
|
+
_(U);
|
|
630
|
+
const or = ({
|
|
631
|
+
dropdownLists: n,
|
|
632
|
+
onChange: c,
|
|
633
|
+
defaultValue: s,
|
|
634
|
+
size: d = "md",
|
|
635
|
+
multiSelect: i,
|
|
636
|
+
searchAble: o,
|
|
637
|
+
iconLeft: g,
|
|
633
638
|
placeholder: l,
|
|
634
|
-
onSearch:
|
|
635
|
-
error:
|
|
636
|
-
onBlur:
|
|
637
|
-
onFocus:
|
|
638
|
-
disable:
|
|
639
|
-
searchValue:
|
|
639
|
+
onSearch: $,
|
|
640
|
+
error: v,
|
|
641
|
+
onBlur: N,
|
|
642
|
+
onFocus: I,
|
|
643
|
+
disable: W,
|
|
644
|
+
searchValue: f
|
|
640
645
|
}) => {
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
},
|
|
644
|
-
if (!
|
|
645
|
-
|
|
646
|
-
else if (r == null ? void 0 : r.find((u) => u.value ===
|
|
646
|
+
const x = z(), [r, w] = R([]), [y, k] = R(""), [h, L] = R(-1), m = z(null), { isComponentVisible: C, ref: D, setIsComponentVisible: B } = G(!1), V = () => {
|
|
647
|
+
B((e) => !e);
|
|
648
|
+
}, A = (e, t) => {
|
|
649
|
+
if (!i)
|
|
650
|
+
w([{ label: e, value: t }]), c([{ label: e, value: t }]), B(!1);
|
|
651
|
+
else if (r == null ? void 0 : r.find((u) => u.value === t)) {
|
|
647
652
|
const u = [
|
|
648
|
-
...r ? r.filter((
|
|
653
|
+
...r ? r.filter((J) => J.value !== t) : []
|
|
649
654
|
];
|
|
650
|
-
|
|
655
|
+
w(u), c(u);
|
|
651
656
|
} else {
|
|
652
|
-
const u = [...r || [], { label:
|
|
653
|
-
|
|
657
|
+
const u = [...r || [], { label: e, value: t }];
|
|
658
|
+
w(u), c(u);
|
|
654
659
|
}
|
|
655
660
|
};
|
|
656
661
|
b(() => {
|
|
657
|
-
JSON.stringify(
|
|
658
|
-
}, [
|
|
659
|
-
const
|
|
660
|
-
/* @__PURE__ */
|
|
661
|
-
/* @__PURE__ */
|
|
662
|
-
|
|
662
|
+
JSON.stringify(x.current) === JSON.stringify(s) || (x.current = s, w(x.current || []));
|
|
663
|
+
}, [s]);
|
|
664
|
+
const M = () => r.length ? i ? r == null ? void 0 : r.map((e, t) => /* @__PURE__ */ p("div", { className: "starasia-input-dropdown-preview-item", children: [
|
|
665
|
+
/* @__PURE__ */ a("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }, t),
|
|
666
|
+
/* @__PURE__ */ a(
|
|
667
|
+
rr,
|
|
663
668
|
{
|
|
664
|
-
onClick: () =>
|
|
669
|
+
onClick: () => A(e.label, e.value)
|
|
665
670
|
}
|
|
666
671
|
)
|
|
667
|
-
] })) : /* @__PURE__ */
|
|
668
|
-
if (
|
|
669
|
-
const
|
|
670
|
-
|
|
672
|
+
] })) : /* @__PURE__ */ a("p", { style: { minWidth: "max-content" }, children: r == null ? void 0 : r[0].label }) : /* @__PURE__ */ a("p", { className: "starasia-input-dropdown-placeholder", children: l }), E = () => {
|
|
673
|
+
if (D.current && m.current) {
|
|
674
|
+
const e = window.innerHeight, t = D.current.getBoundingClientRect(), j = m.current.getBoundingClientRect(), u = t.bottom + j.height;
|
|
675
|
+
m.current.style.left = `${t.left}px`, m.current.style.width = `${t.width}px`, u >= e - 10 ? (m.current.style.top = `${t.top - j.height - 5}px`, k("top")) : (m.current.style.top = `${t.top + t.height}px`, k("bottom"));
|
|
671
676
|
}
|
|
672
677
|
};
|
|
673
|
-
|
|
674
|
-
window.removeEventListener("scroll",
|
|
678
|
+
b(() => (window.addEventListener("scroll", E), window.addEventListener("resize", E), () => {
|
|
679
|
+
window.removeEventListener("scroll", E), window.removeEventListener("resize", E);
|
|
675
680
|
}), []), b(() => {
|
|
676
|
-
|
|
677
|
-
}, [
|
|
681
|
+
E();
|
|
682
|
+
}, [C]), b(() => {
|
|
683
|
+
C || L(-1);
|
|
684
|
+
}, [C]);
|
|
685
|
+
const P = (e) => {
|
|
686
|
+
if (!C) {
|
|
687
|
+
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), B(!0));
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
switch (e.key) {
|
|
691
|
+
case "ArrowDown": {
|
|
692
|
+
e.preventDefault();
|
|
693
|
+
const t = q(n, h, 1);
|
|
694
|
+
t !== -1 && L(t);
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
case "ArrowUp": {
|
|
698
|
+
e.preventDefault();
|
|
699
|
+
const t = q(n, h, -1);
|
|
700
|
+
t !== -1 && L(t);
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
case "Enter": {
|
|
704
|
+
e.preventDefault(), h >= 0 && n[h] && !n[h].disable && A(
|
|
705
|
+
n[h].label,
|
|
706
|
+
n[h].value
|
|
707
|
+
);
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
case "Escape": {
|
|
711
|
+
B(!1);
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
return /* @__PURE__ */ a(Z, { handleChangePosition: E, children: /* @__PURE__ */ p(
|
|
678
717
|
"div",
|
|
679
718
|
{
|
|
680
|
-
className: `starasia-input-dropdown-container ${
|
|
681
|
-
ref:
|
|
682
|
-
onClick:
|
|
719
|
+
className: `starasia-input-dropdown-container ${W ? "disable" : ""} starasia-input-dropdown-size-${d} ${C ? "active" : ""} ${v ? "error" : ""}`,
|
|
720
|
+
ref: D,
|
|
721
|
+
onClick: V,
|
|
722
|
+
onKeyDown: P,
|
|
723
|
+
tabIndex: 0,
|
|
724
|
+
onBlur: N,
|
|
725
|
+
onFocus: I,
|
|
683
726
|
children: [
|
|
684
727
|
/* @__PURE__ */ p("div", { className: "starasia-input-dropdown-preview-container", children: [
|
|
685
|
-
|
|
686
|
-
width:
|
|
728
|
+
g ? /* @__PURE__ */ a(H, { children: O.cloneElement(g, {
|
|
729
|
+
width: F(d),
|
|
687
730
|
color: "#939E99",
|
|
688
731
|
style: {
|
|
689
732
|
color: "#939E99"
|
|
690
733
|
}
|
|
691
734
|
}) }) : null,
|
|
692
|
-
/* @__PURE__ */
|
|
735
|
+
/* @__PURE__ */ a(
|
|
693
736
|
"div",
|
|
694
737
|
{
|
|
695
738
|
className: "starasia-input-dropdown-container-preview-item",
|
|
696
|
-
|
|
697
|
-
onBlur: C,
|
|
698
|
-
onFocus: R,
|
|
699
|
-
children: O()
|
|
739
|
+
children: M()
|
|
700
740
|
}
|
|
701
741
|
),
|
|
702
|
-
/* @__PURE__ */
|
|
703
|
-
|
|
742
|
+
/* @__PURE__ */ a(
|
|
743
|
+
Q,
|
|
704
744
|
{
|
|
705
745
|
strokeWidth: 2,
|
|
706
|
-
width:
|
|
746
|
+
width: F(d),
|
|
707
747
|
style: { color: "#939E99" }
|
|
708
748
|
}
|
|
709
749
|
)
|
|
710
750
|
] }),
|
|
711
|
-
/* @__PURE__ */
|
|
712
|
-
|
|
751
|
+
/* @__PURE__ */ a(
|
|
752
|
+
Y,
|
|
713
753
|
{
|
|
714
|
-
dropdownLists:
|
|
715
|
-
handleChangeValue:
|
|
716
|
-
isComponentVisible:
|
|
717
|
-
positionDropdown:
|
|
718
|
-
searchAble: !!
|
|
754
|
+
dropdownLists: n,
|
|
755
|
+
handleChangeValue: A,
|
|
756
|
+
isComponentVisible: C,
|
|
757
|
+
positionDropdown: y,
|
|
758
|
+
searchAble: !!o,
|
|
719
759
|
value: r,
|
|
720
|
-
onSearch:
|
|
721
|
-
ref:
|
|
722
|
-
multiSelect:
|
|
723
|
-
searchValue:
|
|
760
|
+
onSearch: $,
|
|
761
|
+
ref: m,
|
|
762
|
+
multiSelect: i,
|
|
763
|
+
searchValue: f,
|
|
764
|
+
highlightedIndex: h
|
|
724
765
|
}
|
|
725
766
|
)
|
|
726
767
|
]
|
|
727
768
|
}
|
|
728
769
|
) });
|
|
729
|
-
},
|
|
730
|
-
|
|
770
|
+
}, q = (n, c, s) => {
|
|
771
|
+
const d = n.length;
|
|
772
|
+
let i = c + s;
|
|
773
|
+
for (; i >= 0 && i < d; ) {
|
|
774
|
+
if (!n[i].disable)
|
|
775
|
+
return i;
|
|
776
|
+
i += s;
|
|
777
|
+
}
|
|
778
|
+
if (s === 1) {
|
|
779
|
+
for (let o = 0; o < d; o++)
|
|
780
|
+
if (!n[o].disable)
|
|
781
|
+
return o;
|
|
782
|
+
} else
|
|
783
|
+
for (let o = d - 1; o >= 0; o--)
|
|
784
|
+
if (!n[o].disable)
|
|
785
|
+
return o;
|
|
786
|
+
return -1;
|
|
787
|
+
}, F = (n) => {
|
|
788
|
+
if (n === "sm")
|
|
731
789
|
return 16;
|
|
732
|
-
if (
|
|
790
|
+
if (n === "md")
|
|
733
791
|
return 16;
|
|
734
|
-
if (
|
|
792
|
+
if (n === "lg")
|
|
735
793
|
return 20;
|
|
736
|
-
},
|
|
794
|
+
}, rr = (n) => /* @__PURE__ */ a(
|
|
737
795
|
"svg",
|
|
738
796
|
{
|
|
739
797
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -741,8 +799,8 @@ const _ = ({
|
|
|
741
799
|
height: "18",
|
|
742
800
|
viewBox: "0 0 18 18",
|
|
743
801
|
fill: "none",
|
|
744
|
-
...
|
|
745
|
-
children: /* @__PURE__ */
|
|
802
|
+
...n,
|
|
803
|
+
children: /* @__PURE__ */ a(
|
|
746
804
|
"path",
|
|
747
805
|
{
|
|
748
806
|
d: "M12 6L6 12M6.00001 6L12 12",
|
|
@@ -755,5 +813,5 @@ const _ = ({
|
|
|
755
813
|
}
|
|
756
814
|
);
|
|
757
815
|
export {
|
|
758
|
-
|
|
816
|
+
or as Dropdown
|
|
759
817
|
};
|
package/dist/dropdown.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(w,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],r):(w=typeof globalThis<"u"?globalThis:w||self,r(w.Dropdown={},w.jsxRuntime,w.React))})(this,function(w,r,
|
|
1
|
+
(function(w,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],r):(w=typeof globalThis<"u"?globalThis:w||self,r(w.Dropdown={},w.jsxRuntime,w.React))})(this,function(w,r,e){"use strict";const F=`@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;
|
|
@@ -264,6 +264,11 @@
|
|
|
264
264
|
/* background: var(--starasia-ui-dropdown-background-color-secondary); */
|
|
265
265
|
/* box-shadow: 0px 0px 0px -1px #f0f0f0; */
|
|
266
266
|
}
|
|
267
|
+
.starasia-input-dropdwon-item.highlight {
|
|
268
|
+
background-color: rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.35);
|
|
269
|
+
outline: 2px solid rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.4);
|
|
270
|
+
outline-offset: -2px;
|
|
271
|
+
}
|
|
267
272
|
|
|
268
273
|
.starasia-input-dropdwon-item-disable {
|
|
269
274
|
color: var(--starasia-ui-dropdown-color-disable) !important;
|
|
@@ -394,4 +399,4 @@
|
|
|
394
399
|
height: 100%;
|
|
395
400
|
width: 100%;
|
|
396
401
|
}
|
|
397
|
-
`;function
|
|
402
|
+
`;function O(a){const[l,d]=e.useState(a),c=e.useRef(null),i=o=>{c.current&&!c.current.contains(o.target)&&d(!1)};return e.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:c,isComponentVisible:l,setIsComponentVisible:d}}const H=({...a})=>r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",...a,viewBox:"0 0 24 24",fill:"none",color:"#939E99",children:r.jsx("path",{d:"M4 9L12 17L20 9",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5})}),V=({...a})=>r.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...a,viewBox:"0 0 20 20",fill:"none",children:[r.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),M=({isChecked:a})=>r.jsxs("div",{className:"checkbox-wrapper-30",children:[r.jsxs("span",{className:"checkbox",children:[r.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:a}),r.jsx("svg",{children:r.jsx("use",{xlinkHref:"#checkbox-30",className:"checkbox"})})]}),r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",style:{display:"none"},children:r.jsx("symbol",{id:"checkbox-30",viewBox:"0 0 22 22",children:r.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"})})})]}),P=e.forwardRef(({positionDropdown:a,dropdownLists:l,isComponentVisible:d,searchAble:c,onSearch:i,value:o,handleChangeValue:g,multiSelect:p,searchValue:B,highlightedIndex:v},$)=>{const[z,N]=e.useState(0),y=e.useRef(null),f=e.useRef([]);return e.useEffect(()=>{if(y.current){const n=y.current.getBoundingClientRect();N(n.width)}},[y,d]),e.useEffect(()=>{var n;v>=0&&f.current[v]&&((n=f.current[v])==null||n.scrollIntoView({block:"nearest"}))},[v]),r.jsx(r.Fragment,{children:d?r.jsxs("div",{className:"starasia-input-dropdown-lists-container",onClick:n=>n.stopPropagation(),ref:$,children:[c?r.jsxs("div",{className:"starasia-input-dropdown-container-dropdown-search",style:{order:a=="bottom"?0:2,position:"sticky",top:0,bottom:0,zIndex:1},children:[r.jsx("div",{style:{display:"flex"},children:r.jsx(V,{strokeWidth:2,width:20})}),r.jsx("input",{onChange:n=>{i&&i(n.target.value)},value:B,autoFocus:!0,style:{width:"100%"}})]}):null,r.jsx("div",{className:`starasia-input-dropdwon-item-container ${p?"multi":""}`,ref:y,children:l.map((n,h)=>{const m=!!(o!=null&&o.find(k=>k.value===n.value));return r.jsxs("div",{className:`starasia-input-dropdwon-item ${m?"active":""} ${h===v?"highlight":""} ${n.disable?"starasia-input-dropdwon-item-disable":""}`,ref:k=>{f.current[h]=k},onClick:()=>g(n.label,n.value),children:[p?r.jsx("div",{style:{marginRight:"8px"},children:r.jsx(M,{isChecked:m})}):null,n.icon?r.jsx("div",{children:e.cloneElement(n.icon,{width:16})}):null,r.jsxs("div",{children:[r.jsx("p",{className:`starasia-input-dropdwon-item-text ${m?"active":null} ${n.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${z-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:n.label}),n.description?r.jsx("p",{className:`starasia-input-dropdwon-item-text-description ${m?"active":null} ${n.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${z-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:n.description}):null]})]},h)})})]}):null})}),T=({children:a,handleChangePosition:l})=>{const d=e.useRef(null);e.useEffect(()=>{var g;const i=()=>{if(d.current){let p=d.current.parentElement;for(;p&&!c(p);)p=p.parentElement;p&&l()}};let o=(g=d.current)==null?void 0:g.parentElement;for(;o&&!c(o);)o=o.parentElement;return o&&o.addEventListener("scroll",i),i(),()=>{o&&o.removeEventListener("scroll",i)}},[]);const c=i=>i&&(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth);return r.jsx("div",{ref:d,children:a})},j="starasia-input-dropdown-styles";(a=>{if(!document.getElementById(j)){const l=document.createElement("style");l.id=j,l.textContent=a,document.head.appendChild(l)}})(F);const J=({dropdownLists:a,onChange:l,defaultValue:d,size:c="md",multiSelect:i,searchAble:o,iconLeft:g,placeholder:p,onSearch:B,error:v,onBlur:$,onFocus:z,disable:N,searchValue:y})=>{const f=e.useRef(),[n,h]=e.useState([]),[m,k]=e.useState(""),[b,W]=e.useState(-1),x=e.useRef(null),{isComponentVisible:E,ref:D,setIsComponentVisible:I}=O(!1),U=()=>{I(s=>!s)},L=(s,t)=>{if(!i)h([{label:s,value:t}]),l([{label:s,value:t}]),I(!1);else if(n==null?void 0:n.find(u=>u.value===t)){const u=[...n?n.filter(X=>X.value!==t):[]];h(u),l(u)}else{const u=[...n||[],{label:s,value:t}];h(u),l(u)}};e.useEffect(()=>{JSON.stringify(f.current)===JSON.stringify(d)||(f.current=d,h(f.current||[]))},[d]);const G=()=>n.length?i?n==null?void 0:n.map((s,t)=>r.jsxs("div",{className:"starasia-input-dropdown-preview-item",children:[r.jsx("p",{style:{minWidth:"max-content"},children:s==null?void 0:s.label},t),r.jsx(K,{onClick:()=>L(s.label,s.value)})]})):r.jsx("p",{style:{minWidth:"max-content"},children:n==null?void 0:n[0].label}):r.jsx("p",{className:"starasia-input-dropdown-placeholder",children:p}),C=()=>{if(D.current&&x.current){const s=window.innerHeight,t=D.current.getBoundingClientRect(),S=x.current.getBoundingClientRect(),u=t.bottom+S.height;x.current.style.left=`${t.left}px`,x.current.style.width=`${t.width}px`,u>=s-10?(x.current.style.top=`${t.top-S.height-5}px`,k("top")):(x.current.style.top=`${t.top+t.height}px`,k("bottom"))}};e.useEffect(()=>(window.addEventListener("scroll",C),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C),window.removeEventListener("resize",C)}),[]),e.useEffect(()=>{C()},[E]),e.useEffect(()=>{E||W(-1)},[E]);const Q=s=>{if(!E){(s.key==="ArrowDown"||s.key==="Enter")&&(s.preventDefault(),I(!0));return}switch(s.key){case"ArrowDown":{s.preventDefault();const t=A(a,b,1);t!==-1&&W(t);break}case"ArrowUp":{s.preventDefault();const t=A(a,b,-1);t!==-1&&W(t);break}case"Enter":{s.preventDefault(),b>=0&&a[b]&&!a[b].disable&&L(a[b].label,a[b].value);break}case"Escape":{I(!1);break}}};return r.jsx(T,{handleChangePosition:C,children:r.jsxs("div",{className:`starasia-input-dropdown-container ${N?"disable":""} starasia-input-dropdown-size-${c} ${E?"active":""} ${v?"error":""}`,ref:D,onClick:U,onKeyDown:Q,tabIndex:0,onBlur:$,onFocus:z,children:[r.jsxs("div",{className:"starasia-input-dropdown-preview-container",children:[g?r.jsx(r.Fragment,{children:e.cloneElement(g,{width:q(c),color:"#939E99",style:{color:"#939E99"}})}):null,r.jsx("div",{className:"starasia-input-dropdown-container-preview-item",children:G()}),r.jsx(H,{strokeWidth:2,width:q(c),style:{color:"#939E99"}})]}),r.jsx(P,{dropdownLists:a,handleChangeValue:L,isComponentVisible:E,positionDropdown:m,searchAble:!!o,value:n,onSearch:B,ref:x,multiSelect:i,searchValue:y,highlightedIndex:b})]})})},A=(a,l,d)=>{const c=a.length;let i=l+d;for(;i>=0&&i<c;){if(!a[i].disable)return i;i+=d}if(d===1){for(let o=0;o<c;o++)if(!a[o].disable)return o}else for(let o=c-1;o>=0;o--)if(!a[o].disable)return o;return-1},q=a=>{if(a==="sm")return 16;if(a==="md")return 16;if(a==="lg")return 20},K=a=>r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",...a,children:r.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})});w.Dropdown=J,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starasia/dropdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "dropdown component for starasia UI",
|
|
5
5
|
"author": "Prawito Hudoro",
|
|
6
6
|
"main": "dist/dropdown.umd.js",
|
|
@@ -12,10 +12,6 @@
|
|
|
12
12
|
"dist/*.map",
|
|
13
13
|
"dist/*.css"
|
|
14
14
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"dev": "vite --config vite.config.ts --port 3000",
|
|
17
|
-
"build": "vite build --config vite.config.ts"
|
|
18
|
-
},
|
|
19
15
|
"keywords": [],
|
|
20
16
|
"license": "ISC",
|
|
21
17
|
"type": "module",
|
|
@@ -37,5 +33,9 @@
|
|
|
37
33
|
"react-dom": "^18.2.0",
|
|
38
34
|
"@types/react": "^18.2.55",
|
|
39
35
|
"@types/react-dom": "^18.2.19"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "vite --config vite.config.ts --port 3000",
|
|
39
|
+
"build": "vite build --config vite.config.ts"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|