@starasia/dropdown 1.0.5 → 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.
@@ -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;
@@ -1,6 +1,6 @@
1
- import { jsx as r, jsxs as l, Fragment as q } from "react/jsx-runtime";
2
- import F, { useState as y, useRef as k, useEffect as b, forwardRef as M } from "react";
3
- const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
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;
@@ -10,67 +10,77 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
10
10
  :root {
11
11
  /* color */
12
12
  /* brand */
13
- --starasia-ui-dropdown-color-primary-blue: var(--starasia-ui-brand-primary-default);
14
- --starasia-ui-dropdown-color-secondary-blue: var(--starasia-ui-brand-primary-default);
15
- --starasia-ui-dropdown-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary);
16
- --starasia-ui-dropdown-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary);
17
- --starasia-ui-dropdown-color-quinary-blue: var(--starasia-ui-brand-primary-tertiary);
13
+ --starasia-ui-dropdown-color-primary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
14
+ --starasia-ui-dropdown-color-secondary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
15
+ --starasia-ui-dropdown-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary, rgba(144, 176, 218, 1));
16
+ --starasia-ui-dropdown-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary, rgba(227, 237, 248, 1));
17
+ --starasia-ui-dropdown-color-quinary-blue: var(--starasia-ui-brand-primary-tertiary, rgba(227, 237, 248, 1));
18
18
  /* gray */
19
19
  --starasia-ui-dropdown-color-primary-gray: var(
20
20
  --starasia-ui-color-gray-700,
21
- #374151
21
+ rgba(55, 65, 81, 1)
22
22
  );
23
23
  --starasia-ui-dropdown-color-secondary-gray: var(
24
24
  --starasia-ui-color-gray-500,
25
- #6b7280
25
+ rgba(107, 114, 128, 1)
26
26
  );
27
27
  --starasia-ui-dropdown-color-tertiary-gray: var(
28
28
  --starasia-ui-color-gray-300,
29
- #d1d5db
29
+ rgba(209, 213, 219, 1)
30
30
  );
31
31
  --starasia-ui-dropdown-color-quaternary-gray: var(
32
32
  --starasia-ui-color-gray-100,
33
- #f3f4f6
33
+ rgba(243, 244, 246, 1)
34
34
  );
35
35
  --starasia-ui-dropdown-color-quinary-gray: var(
36
36
  --starasia-ui-color-gray-50,
37
- #f9fafb
37
+ rgba(249, 250, 251, 1)
38
38
  );
39
39
  /* bg color */
40
40
  --starasia-ui-dropdown-background-color-primary: var(
41
41
  --starasia-ui-dropdown-color-secondary-blue,
42
- #3b82f6
42
+ rgba(59, 130, 246, 1)
43
43
  );
44
44
  --starasia-ui-dropdown-background-color-secondary: var(
45
45
  --starasia-ui-dropdown-color-quinary-blue,
46
- #eff6ff
46
+ rgba(239, 246, 255, 1)
47
47
  );
48
48
 
49
49
  /* disalble color */
50
50
  --starasia-ui-dropdown-color-disable: var(
51
51
  --starasia-ui-dropdown-color-tertiary-gray,
52
- #d1d5db
52
+ rgba(209, 213, 219, 1)
53
53
  );
54
54
 
55
55
  /* border color */
56
- --starasia-ui-dropdown-border-color-primary: var(--starasia-ui-brand-primary-default);
56
+ --starasia-ui-dropdown-border-color-primary: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
57
57
  --starasia-ui-dropdown-border-color-secondary: var(
58
58
  --starasia-ui-color-gray-300,
59
- #d1d5db
59
+ rgba(209, 213, 219, 1)
60
60
  );
61
61
  --starasia-ui-dropdown-border-color-tertiary: rgba(120, 134, 127, 0.2);
62
62
 
63
63
  --starasia-ui-dropdown-color-secondary-red: var(
64
64
  --starasia-ui-color-red-500,
65
- #ef4444
65
+ rgba(239, 68, 68, 1)
66
66
  );
67
67
 
68
68
  /* plachoder color */
69
69
  --starasia-ui-dropdown-placholder-color: var(
70
70
  --starasia-ui-color-gray-200,
71
- #c9cecc
71
+ rgba(201, 206, 204, 1)
72
72
  );
73
73
 
74
+ /* white */
75
+ --starasia-ui-dropdown-color-white: var(--starasia-ui-color-gray-50, rgba(255, 254, 255, 1));
76
+ /* disabled bg */
77
+ --starasia-ui-dropdown-color-disabled-bg: rgba(242, 243, 242, 1);
78
+ /* text colors */
79
+ --starasia-ui-dropdown-color-text-primary: rgba(24, 26, 25, 1);
80
+ --starasia-ui-dropdown-color-text-secondary: rgba(120, 134, 127, 1);
81
+ /* shadow */
82
+ --starasia-ui-dropdown-box-shadow-list: rgba(0, 0, 0, 0.08);
83
+
74
84
  /* border width */
75
85
  --starasia-ui-dropdown-border-width: var(--starasia-ui-border, 1px);
76
86
 
@@ -79,7 +89,7 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
79
89
  --starasia-ui-dropdown-spacing-sm: var(--starasia-ui-spacing-sm, 8px);
80
90
 
81
91
  /* shadow */
82
- --starasia-ui-dropdown-box-shadow: 0px 0px 0px 2px rgba(var(--starasia-ui-raw-color-brand-secondary), 0.2);
92
+ --starasia-ui-dropdown-box-shadow: 0px 0px 0px 2px rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.2);
83
93
 
84
94
  /* below is for size,above is */
85
95
  --starasia-ui-dropdown-fontWeight-normal: var(
@@ -130,14 +140,14 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
130
140
  display: flex;
131
141
  align-items: center;
132
142
  border: var(--starasia-ui-dropdown-border-width) solid
133
- rgba(120, 134, 127, 0.2);
143
+ var(--starasia-ui-dropdown-border-color-tertiary);
134
144
  border-radius: var(--borderRadius);
135
- background-color: white;
145
+ background-color: var(--starasia-ui-dropdown-color-white);
136
146
  font-size: var(--baseFont);
137
147
  cursor: pointer;
138
148
  }
139
149
  .starasia-input-dropdown-container.disable {
140
- background-color: #f2f3f2;
150
+ background-color: var(--starasia-ui-dropdown-color-disabled-bg);
141
151
  cursor: not-allowed;
142
152
  pointer-events: none;
143
153
  }
@@ -148,7 +158,7 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
148
158
  .starasia-input-dropdown-container.active {
149
159
  border-color: var(--starasia-ui-dropdown-border-color-primary);
150
160
  box-shadow: var(--starasia-ui-dropdown-box-shadow);
151
- background-color: white;
161
+ background-color: var(--starasia-ui-dropdown-color-white);
152
162
  }
153
163
 
154
164
  .starasia-input-dropdown-preview-container {
@@ -169,8 +179,8 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
169
179
  border: var(--starasia-ui-dropdown-border-width) solid
170
180
  var(--starasia-ui-dropdown-border-color-tertiary);
171
181
  border-radius: var(--borderRadius);
172
- background-color: #fffeff;
173
- box-shadow: 0px 8px 12px 0px rgba(0, 0, 0, 0.08);
182
+ background-color: var(--starasia-ui-dropdown-color-white);
183
+ box-shadow: 0px 8px 12px 0px var(--starasia-ui-dropdown-box-shadow-list);
174
184
  max-height: 312px;
175
185
  overflow-y: auto;
176
186
  z-index: 999;
@@ -205,7 +215,7 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
205
215
  border-radius: var(--borderRadius);
206
216
  gap: var(--starasia-ui-dropdown-spacing-sm);
207
217
  padding-inline: var(--paddingInline);
208
- background: white;
218
+ background: var(--starasia-ui-dropdown-color-white);
209
219
  & input {
210
220
  flex: 1;
211
221
  outline: none;
@@ -247,15 +257,20 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
247
257
  }
248
258
 
249
259
  .starasia-input-dropdwon-item:hover {
250
- background-color: rgba(var(--starasia-ui-raw-color-brand-secondary), 0.21);
260
+ background-color: rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.21);
251
261
  }
252
262
  .starasia-input-dropdwon-item.active {
253
263
  /* color: var(--starasia-ui-dropdown-background-color-primary); */
254
264
  /* border-radius: var(--borderRadius); */
255
- background-color: rgba(var(--starasia-ui-raw-color-brand-secondary), 0.21);
265
+ background-color: rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.21);
256
266
  /* background: var(--starasia-ui-dropdown-background-color-secondary); */
257
267
  /* box-shadow: 0px 0px 0px -1px #f0f0f0; */
258
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
+ }
259
274
 
260
275
  .starasia-input-dropdwon-item-disable {
261
276
  color: var(--starasia-ui-dropdown-color-disable) !important;
@@ -291,30 +306,30 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
291
306
  }
292
307
 
293
308
  .starasia-input-dropdwon-item-text {
294
- color: #181a19;
309
+ color: var(--starasia-ui-dropdown-color-text-primary);
295
310
  /* font-size: 14px; */
296
311
  font-size: inherit;
297
312
  font-weight: 500;
298
313
  }
299
314
  .starasia-input-dropdwon-item-text.active {
300
- color: var(--starasia-ui-brand-primary-default);
315
+ color: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
301
316
  }
302
317
 
303
318
  .starasia-input-dropdwon-item-text-description {
304
- color: #78867f;
319
+ color: var(--starasia-ui-dropdown-color-text-secondary);
305
320
  /* font-size: 14px; */
306
321
  font-size: inherit;
307
322
  font-weight: 400;
308
323
  }
309
324
  .starasia-input-dropdwon-item-text-description.active {
310
- color: var(--starasia-ui-brand-primary-default);
325
+ color: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
311
326
  }
312
327
 
313
328
  /* for checkbox */
314
329
  .checkbox-wrapper-30 .checkbox {
315
330
  --bg: #fff;
316
331
  --brdr: #d1d6ee;
317
- --brdr-actv: var(--starasia-ui-brand-primary-default);
332
+ --brdr-actv: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
318
333
  --brdr-hovr: #bbc1e1;
319
334
  --dur: calc((var(--size, 2) / 2) * 0.6s);
320
335
  display: inline-block;
@@ -387,23 +402,23 @@ const P = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
387
402
  width: 100%;
388
403
  }
389
404
  `;
390
- function V(a) {
391
- const [i, t] = y(a), c = k(null), o = (e) => {
392
- c.current && !c.current.contains(e.target) && t(!1);
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);
393
408
  };
394
- return b(() => (document.addEventListener("click", o, !0), () => {
395
- document.removeEventListener("click", o, !0);
396
- }), []), { ref: c, isComponentVisible: i, setIsComponentVisible: t };
409
+ return b(() => (document.addEventListener("click", i, !0), () => {
410
+ document.removeEventListener("click", i, !0);
411
+ }), []), { ref: d, isComponentVisible: c, setIsComponentVisible: s };
397
412
  }
398
- const J = ({ ...a }) => /* @__PURE__ */ r(
413
+ const Q = ({ ...n }) => /* @__PURE__ */ a(
399
414
  "svg",
400
415
  {
401
416
  xmlns: "http://www.w3.org/2000/svg",
402
- ...a,
417
+ ...n,
403
418
  viewBox: "0 0 24 24",
404
419
  fill: "none",
405
420
  color: "#939E99",
406
- children: /* @__PURE__ */ r(
421
+ children: /* @__PURE__ */ a(
407
422
  "path",
408
423
  {
409
424
  d: "M4 9L12 17L20 9",
@@ -414,15 +429,15 @@ const J = ({ ...a }) => /* @__PURE__ */ r(
414
429
  }
415
430
  )
416
431
  }
417
- ), G = ({ ...a }) => /* @__PURE__ */ l(
432
+ ), T = ({ ...n }) => /* @__PURE__ */ p(
418
433
  "svg",
419
434
  {
420
435
  xmlns: "http://www.w3.org/2000/svg",
421
- ...a,
436
+ ...n,
422
437
  viewBox: "0 0 20 20",
423
438
  fill: "none",
424
439
  children: [
425
- /* @__PURE__ */ r(
440
+ /* @__PURE__ */ a(
426
441
  "circle",
427
442
  {
428
443
  cx: "9.80547",
@@ -434,7 +449,7 @@ const J = ({ ...a }) => /* @__PURE__ */ r(
434
449
  strokeLinejoin: "round"
435
450
  }
436
451
  ),
437
- /* @__PURE__ */ r(
452
+ /* @__PURE__ */ a(
438
453
  "path",
439
454
  {
440
455
  d: "M15.0153 15.4043L17.9519 18.3333",
@@ -446,19 +461,19 @@ const J = ({ ...a }) => /* @__PURE__ */ r(
446
461
  )
447
462
  ]
448
463
  }
449
- ), K = ({ isChecked: a }) => /* @__PURE__ */ l("div", { className: "checkbox-wrapper-30", children: [
450
- /* @__PURE__ */ l("span", { className: "checkbox", children: [
451
- /* @__PURE__ */ r(
464
+ ), X = ({ isChecked: n }) => /* @__PURE__ */ p("div", { className: "checkbox-wrapper-30", children: [
465
+ /* @__PURE__ */ p("span", { className: "checkbox", children: [
466
+ /* @__PURE__ */ a(
452
467
  "input",
453
468
  {
454
469
  type: "checkbox",
455
470
  style: { pointerEvents: "none" },
456
- checked: a
471
+ checked: n
457
472
  }
458
473
  ),
459
- /* @__PURE__ */ r("svg", { children: /* @__PURE__ */ r("use", { xlinkHref: "#checkbox-30", className: "checkbox" }) })
474
+ /* @__PURE__ */ a("svg", { children: /* @__PURE__ */ a("use", { xlinkHref: "#checkbox-30", className: "checkbox" }) })
460
475
  ] }),
461
- /* @__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(
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(
462
477
  "path",
463
478
  {
464
479
  fill: "none",
@@ -466,58 +481,55 @@ const J = ({ ...a }) => /* @__PURE__ */ r(
466
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"
467
482
  }
468
483
  ) }) })
469
- ] }), Q = M(
484
+ ] }), Y = K(
470
485
  ({
471
- positionDropdown: a,
472
- dropdownLists: i,
473
- isComponentVisible: t,
474
- searchAble: c,
475
- onSearch: o,
476
- value: e,
477
- handleChangeValue: h,
478
- multiSelect: p,
479
- searchValue: v
480
- }, I) => {
481
- const [C, R] = y(0), [$, z] = y(), w = k(null);
486
+ positionDropdown: n,
487
+ dropdownLists: c,
488
+ isComponentVisible: s,
489
+ searchAble: d,
490
+ onSearch: i,
491
+ value: o,
492
+ handleChangeValue: g,
493
+ multiSelect: l,
494
+ searchValue: $,
495
+ highlightedIndex: v
496
+ }, N) => {
497
+ const [I, W] = R(0), f = z(null), x = z([]);
482
498
  return b(() => {
483
- if (w.current) {
484
- const n = w.current.getBoundingClientRect();
485
- R(n.width);
499
+ if (f.current) {
500
+ const r = f.current.getBoundingClientRect();
501
+ W(r.width);
486
502
  }
487
- }, [w, t]), b(() => {
488
- i && v ? i.forEach((n) => {
489
- if (n.label.startsWith(v || "")) {
490
- z(n.value);
491
- return;
492
- }
493
- }) : z(void 0);
494
- }, [v, i]), /* @__PURE__ */ r(q, { children: t ? /* @__PURE__ */ l(
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(
495
507
  "div",
496
508
  {
497
509
  className: "starasia-input-dropdown-lists-container",
498
- onClick: (n) => n.stopPropagation(),
499
- ref: I,
510
+ onClick: (r) => r.stopPropagation(),
511
+ ref: N,
500
512
  children: [
501
- c ? /* @__PURE__ */ l(
513
+ d ? /* @__PURE__ */ p(
502
514
  "div",
503
515
  {
504
516
  className: "starasia-input-dropdown-container-dropdown-search",
505
517
  style: {
506
- order: a == "bottom" ? 0 : 2,
518
+ order: n == "bottom" ? 0 : 2,
507
519
  position: "sticky",
508
520
  top: 0,
509
521
  bottom: 0,
510
522
  zIndex: 1
511
523
  },
512
524
  children: [
513
- /* @__PURE__ */ r("div", { style: { display: "flex" }, children: /* @__PURE__ */ r(G, { strokeWidth: 2, width: 20 }) }),
514
- /* @__PURE__ */ r(
525
+ /* @__PURE__ */ a("div", { style: { display: "flex" }, children: /* @__PURE__ */ a(T, { strokeWidth: 2, width: 20 }) }),
526
+ /* @__PURE__ */ a(
515
527
  "input",
516
528
  {
517
- onChange: (n) => {
518
- o && o(n.target.value);
529
+ onChange: (r) => {
530
+ i && i(r.target.value);
519
531
  },
520
- value: v,
532
+ value: $,
521
533
  autoFocus: !0,
522
534
  style: { width: "100%" }
523
535
  }
@@ -525,54 +537,57 @@ const J = ({ ...a }) => /* @__PURE__ */ r(
525
537
  ]
526
538
  }
527
539
  ) : null,
528
- /* @__PURE__ */ r(
540
+ /* @__PURE__ */ a(
529
541
  "div",
530
542
  {
531
- className: `starasia-input-dropdwon-item-container ${p ? "multi" : ""}`,
532
- ref: w,
533
- children: i.map((n, x) => {
534
- const f = !!(e != null && e.find((E) => E.value === n.value));
535
- return /* @__PURE__ */ l(
543
+ className: `starasia-input-dropdwon-item-container ${l ? "multi" : ""}`,
544
+ ref: f,
545
+ children: c.map((r, w) => {
546
+ const y = !!(o != null && o.find((k) => k.value === r.value));
547
+ return /* @__PURE__ */ p(
536
548
  "div",
537
549
  {
538
- className: `starasia-input-dropdwon-item ${f ? "active" : " "} ${n.disable ? "starasia-input-dropdwon-item-disable" : null}`,
539
- onClick: () => h(n.label, n.value),
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),
540
555
  children: [
541
- p ? /* @__PURE__ */ r("div", { style: { marginRight: "8px" }, children: /* @__PURE__ */ r(K, { isChecked: f }) }) : null,
542
- n.icon ? /* @__PURE__ */ r("div", { children: F.cloneElement(n.icon, {
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, {
543
558
  width: 16
544
559
  }) }) : null,
545
- /* @__PURE__ */ l("div", { children: [
546
- /* @__PURE__ */ r(
560
+ /* @__PURE__ */ p("div", { children: [
561
+ /* @__PURE__ */ a(
547
562
  "p",
548
563
  {
549
- className: `starasia-input-dropdwon-item-text ${f ? "active" : null} ${n.disable ? "starasia-input-dropdwon-item-disable" : null}`,
564
+ className: `starasia-input-dropdwon-item-text ${y ? "active" : null} ${r.disable ? "starasia-input-dropdwon-item-disable" : null}`,
550
565
  style: {
551
566
  textWrap: "nowrap",
552
- width: `${C - 12}px`,
567
+ width: `${I - 12}px`,
553
568
  overflow: "hidden",
554
569
  textOverflow: "ellipsis"
555
570
  },
556
- children: n.label
571
+ children: r.label
557
572
  }
558
573
  ),
559
- n.description ? /* @__PURE__ */ r(
574
+ r.description ? /* @__PURE__ */ a(
560
575
  "p",
561
576
  {
562
- className: `starasia-input-dropdwon-item-text-description ${f ? "active" : null} ${n.disable ? "starasia-input-dropdwon-item-disable" : null}`,
577
+ className: `starasia-input-dropdwon-item-text-description ${y ? "active" : null} ${r.disable ? "starasia-input-dropdwon-item-disable" : null}`,
563
578
  style: {
564
579
  textWrap: "nowrap",
565
- width: `${C - 12}px`,
580
+ width: `${I - 12}px`,
566
581
  overflow: "hidden",
567
582
  textOverflow: "ellipsis"
568
583
  },
569
- children: n.description
584
+ children: r.description
570
585
  }
571
586
  ) : null
572
587
  ] })
573
588
  ]
574
589
  },
575
- x
590
+ w
576
591
  );
577
592
  })
578
593
  }
@@ -581,149 +596,202 @@ const J = ({ ...a }) => /* @__PURE__ */ r(
581
596
  }
582
597
  ) : null });
583
598
  }
584
- ), T = ({
585
- children: a,
586
- handleChangePosition: i
599
+ ), Z = ({
600
+ children: n,
601
+ handleChangePosition: c
587
602
  }) => {
588
- const t = k(null);
603
+ const s = z(null);
589
604
  b(() => {
590
- var h;
591
- const o = () => {
592
- if (t.current) {
593
- let p = t.current.parentElement;
594
- for (; p && !c(p); )
595
- p = p.parentElement;
596
- p && i();
605
+ var g;
606
+ const i = () => {
607
+ if (s.current) {
608
+ let l = s.current.parentElement;
609
+ for (; l && !d(l); )
610
+ l = l.parentElement;
611
+ l && c();
597
612
  }
598
613
  };
599
- let e = (h = t.current) == null ? void 0 : h.parentElement;
600
- for (; e && !c(e); )
601
- e = e.parentElement;
602
- return e && e.addEventListener("scroll", o), o(), () => {
603
- e && e.removeEventListener("scroll", o);
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);
604
619
  };
605
620
  }, []);
606
- const c = (o) => o && (o.scrollHeight > o.clientHeight || o.scrollWidth > o.clientWidth);
607
- return /* @__PURE__ */ r("div", { ref: t, children: a });
608
- }, A = "starasia-input-dropdown-styles", U = (a) => {
609
- if (!document.getElementById(A)) {
610
- const i = document.createElement("style");
611
- i.id = A, i.textContent = a, document.head.appendChild(i);
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);
612
627
  }
613
628
  };
614
- U(P);
615
- const _ = ({
616
- dropdownLists: a,
617
- onChange: i,
618
- defaultValue: t,
619
- size: c = "md",
620
- multiSelect: o,
621
- searchAble: e,
622
- iconLeft: h,
623
- placeholder: p,
624
- onSearch: v,
625
- error: I,
626
- onBlur: C,
627
- onFocus: R,
628
- disable: $,
629
- searchValue: z
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,
638
+ placeholder: l,
639
+ onSearch: $,
640
+ error: v,
641
+ onBlur: N,
642
+ onFocus: I,
643
+ disable: W,
644
+ searchValue: f
630
645
  }) => {
631
- const w = k(), [n, x] = y([]), [f, E] = y(""), g = k(null), { isComponentVisible: B, ref: L, setIsComponentVisible: N } = V(!1), H = () => {
632
- N((s) => !s);
633
- }, j = (s, d) => {
634
- if (!o)
635
- x([{ label: s, value: d }]), i([{ label: s, value: d }]), N(!1);
636
- else if (n == null ? void 0 : n.find((u) => u.value === d)) {
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)) {
637
652
  const u = [
638
- ...n ? n.filter((D) => D.value !== d) : []
653
+ ...r ? r.filter((J) => J.value !== t) : []
639
654
  ];
640
- x(u), i(u);
655
+ w(u), c(u);
641
656
  } else {
642
- const u = [...n || [], { label: s, value: d }];
643
- x(u), i(u);
657
+ const u = [...r || [], { label: e, value: t }];
658
+ w(u), c(u);
644
659
  }
645
660
  };
646
661
  b(() => {
647
- JSON.stringify(w.current) === JSON.stringify(t) || (w.current = t, x(w.current || []));
648
- }, [t]);
649
- const O = () => n.length ? o ? n == null ? void 0 : n.map((s, d) => /* @__PURE__ */ l("div", { className: "starasia-input-dropdown-preview-item", children: [
650
- /* @__PURE__ */ r("p", { style: { minWidth: "max-content" }, children: s == null ? void 0 : s.label }, d),
651
- /* @__PURE__ */ r(
652
- X,
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,
653
668
  {
654
- onClick: () => j(s.label, s.value)
669
+ onClick: () => A(e.label, e.value)
655
670
  }
656
671
  )
657
- ] })) : /* @__PURE__ */ r("p", { style: { minWidth: "max-content" }, children: n == null ? void 0 : n[0].label }) : /* @__PURE__ */ r("p", { className: "starasia-input-dropdown-placeholder", children: p }), m = () => {
658
- if (L.current && g.current) {
659
- const s = window.innerHeight, d = L.current.getBoundingClientRect(), W = g.current.getBoundingClientRect(), u = d.bottom + W.height;
660
- g.current.style.left = `${d.left}px`, g.current.style.width = `${d.width}px`, u >= s - 10 ? (g.current.style.top = `${d.top - W.height - 5}px`, E("top")) : (g.current.style.top = `${d.top + d.height}px`, E("bottom"));
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"));
661
676
  }
662
677
  };
663
- return b(() => (window.addEventListener("scroll", m), window.addEventListener("resize", m), () => {
664
- window.removeEventListener("scroll", m), window.removeEventListener("resize", m);
678
+ b(() => (window.addEventListener("scroll", E), window.addEventListener("resize", E), () => {
679
+ window.removeEventListener("scroll", E), window.removeEventListener("resize", E);
665
680
  }), []), b(() => {
666
- m();
667
- }, [B]), /* @__PURE__ */ r(T, { handleChangePosition: m, children: /* @__PURE__ */ l(
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(
668
717
  "div",
669
718
  {
670
- className: `starasia-input-dropdown-container ${$ ? "disable" : ""} starasia-input-dropdown-size-${c} ${B ? "active" : ""} ${I ? "error" : ""}`,
671
- ref: L,
672
- onClick: H,
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,
673
726
  children: [
674
- /* @__PURE__ */ l("div", { className: "starasia-input-dropdown-preview-container", children: [
675
- h ? /* @__PURE__ */ r(q, { children: F.cloneElement(h, {
676
- width: S(c),
727
+ /* @__PURE__ */ p("div", { className: "starasia-input-dropdown-preview-container", children: [
728
+ g ? /* @__PURE__ */ a(H, { children: O.cloneElement(g, {
729
+ width: F(d),
677
730
  color: "#939E99",
678
731
  style: {
679
732
  color: "#939E99"
680
733
  }
681
734
  }) }) : null,
682
- /* @__PURE__ */ r(
735
+ /* @__PURE__ */ a(
683
736
  "div",
684
737
  {
685
738
  className: "starasia-input-dropdown-container-preview-item",
686
- tabIndex: 100,
687
- onBlur: C,
688
- onFocus: R,
689
- children: O()
739
+ children: M()
690
740
  }
691
741
  ),
692
- /* @__PURE__ */ r(
693
- J,
742
+ /* @__PURE__ */ a(
743
+ Q,
694
744
  {
695
745
  strokeWidth: 2,
696
- width: S(c),
746
+ width: F(d),
697
747
  style: { color: "#939E99" }
698
748
  }
699
749
  )
700
750
  ] }),
701
- /* @__PURE__ */ r(
702
- Q,
751
+ /* @__PURE__ */ a(
752
+ Y,
703
753
  {
704
- dropdownLists: a,
705
- handleChangeValue: j,
706
- isComponentVisible: B,
707
- positionDropdown: f,
708
- searchAble: !!e,
709
- value: n,
710
- onSearch: v,
711
- ref: g,
712
- multiSelect: o,
713
- searchValue: z
754
+ dropdownLists: n,
755
+ handleChangeValue: A,
756
+ isComponentVisible: C,
757
+ positionDropdown: y,
758
+ searchAble: !!o,
759
+ value: r,
760
+ onSearch: $,
761
+ ref: m,
762
+ multiSelect: i,
763
+ searchValue: f,
764
+ highlightedIndex: h
714
765
  }
715
766
  )
716
767
  ]
717
768
  }
718
769
  ) });
719
- }, S = (a) => {
720
- if (a === "sm")
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")
721
789
  return 16;
722
- if (a === "md")
790
+ if (n === "md")
723
791
  return 16;
724
- if (a === "lg")
792
+ if (n === "lg")
725
793
  return 20;
726
- }, X = (a) => /* @__PURE__ */ r(
794
+ }, rr = (n) => /* @__PURE__ */ a(
727
795
  "svg",
728
796
  {
729
797
  xmlns: "http://www.w3.org/2000/svg",
@@ -731,8 +799,8 @@ const _ = ({
731
799
  height: "18",
732
800
  viewBox: "0 0 18 18",
733
801
  fill: "none",
734
- ...a,
735
- children: /* @__PURE__ */ r(
802
+ ...n,
803
+ children: /* @__PURE__ */ a(
736
804
  "path",
737
805
  {
738
806
  d: "M12 6L6 12M6.00001 6L12 12",
@@ -745,5 +813,5 @@ const _ = ({
745
813
  }
746
814
  );
747
815
  export {
748
- _ as Dropdown
816
+ or as Dropdown
749
817
  };
@@ -1,4 +1,4 @@
1
- (function(w,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):(w=typeof globalThis<"u"?globalThis:w||self,n(w.Dropdown={},w.jsxRuntime,w.React))})(this,function(w,n,o){"use strict";const q=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
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;
@@ -8,67 +8,77 @@
8
8
  :root {
9
9
  /* color */
10
10
  /* brand */
11
- --starasia-ui-dropdown-color-primary-blue: var(--starasia-ui-brand-primary-default);
12
- --starasia-ui-dropdown-color-secondary-blue: var(--starasia-ui-brand-primary-default);
13
- --starasia-ui-dropdown-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary);
14
- --starasia-ui-dropdown-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary);
15
- --starasia-ui-dropdown-color-quinary-blue: var(--starasia-ui-brand-primary-tertiary);
11
+ --starasia-ui-dropdown-color-primary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
12
+ --starasia-ui-dropdown-color-secondary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
13
+ --starasia-ui-dropdown-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary, rgba(144, 176, 218, 1));
14
+ --starasia-ui-dropdown-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary, rgba(227, 237, 248, 1));
15
+ --starasia-ui-dropdown-color-quinary-blue: var(--starasia-ui-brand-primary-tertiary, rgba(227, 237, 248, 1));
16
16
  /* gray */
17
17
  --starasia-ui-dropdown-color-primary-gray: var(
18
18
  --starasia-ui-color-gray-700,
19
- #374151
19
+ rgba(55, 65, 81, 1)
20
20
  );
21
21
  --starasia-ui-dropdown-color-secondary-gray: var(
22
22
  --starasia-ui-color-gray-500,
23
- #6b7280
23
+ rgba(107, 114, 128, 1)
24
24
  );
25
25
  --starasia-ui-dropdown-color-tertiary-gray: var(
26
26
  --starasia-ui-color-gray-300,
27
- #d1d5db
27
+ rgba(209, 213, 219, 1)
28
28
  );
29
29
  --starasia-ui-dropdown-color-quaternary-gray: var(
30
30
  --starasia-ui-color-gray-100,
31
- #f3f4f6
31
+ rgba(243, 244, 246, 1)
32
32
  );
33
33
  --starasia-ui-dropdown-color-quinary-gray: var(
34
34
  --starasia-ui-color-gray-50,
35
- #f9fafb
35
+ rgba(249, 250, 251, 1)
36
36
  );
37
37
  /* bg color */
38
38
  --starasia-ui-dropdown-background-color-primary: var(
39
39
  --starasia-ui-dropdown-color-secondary-blue,
40
- #3b82f6
40
+ rgba(59, 130, 246, 1)
41
41
  );
42
42
  --starasia-ui-dropdown-background-color-secondary: var(
43
43
  --starasia-ui-dropdown-color-quinary-blue,
44
- #eff6ff
44
+ rgba(239, 246, 255, 1)
45
45
  );
46
46
 
47
47
  /* disalble color */
48
48
  --starasia-ui-dropdown-color-disable: var(
49
49
  --starasia-ui-dropdown-color-tertiary-gray,
50
- #d1d5db
50
+ rgba(209, 213, 219, 1)
51
51
  );
52
52
 
53
53
  /* border color */
54
- --starasia-ui-dropdown-border-color-primary: var(--starasia-ui-brand-primary-default);
54
+ --starasia-ui-dropdown-border-color-primary: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
55
55
  --starasia-ui-dropdown-border-color-secondary: var(
56
56
  --starasia-ui-color-gray-300,
57
- #d1d5db
57
+ rgba(209, 213, 219, 1)
58
58
  );
59
59
  --starasia-ui-dropdown-border-color-tertiary: rgba(120, 134, 127, 0.2);
60
60
 
61
61
  --starasia-ui-dropdown-color-secondary-red: var(
62
62
  --starasia-ui-color-red-500,
63
- #ef4444
63
+ rgba(239, 68, 68, 1)
64
64
  );
65
65
 
66
66
  /* plachoder color */
67
67
  --starasia-ui-dropdown-placholder-color: var(
68
68
  --starasia-ui-color-gray-200,
69
- #c9cecc
69
+ rgba(201, 206, 204, 1)
70
70
  );
71
71
 
72
+ /* white */
73
+ --starasia-ui-dropdown-color-white: var(--starasia-ui-color-gray-50, rgba(255, 254, 255, 1));
74
+ /* disabled bg */
75
+ --starasia-ui-dropdown-color-disabled-bg: rgba(242, 243, 242, 1);
76
+ /* text colors */
77
+ --starasia-ui-dropdown-color-text-primary: rgba(24, 26, 25, 1);
78
+ --starasia-ui-dropdown-color-text-secondary: rgba(120, 134, 127, 1);
79
+ /* shadow */
80
+ --starasia-ui-dropdown-box-shadow-list: rgba(0, 0, 0, 0.08);
81
+
72
82
  /* border width */
73
83
  --starasia-ui-dropdown-border-width: var(--starasia-ui-border, 1px);
74
84
 
@@ -77,7 +87,7 @@
77
87
  --starasia-ui-dropdown-spacing-sm: var(--starasia-ui-spacing-sm, 8px);
78
88
 
79
89
  /* shadow */
80
- --starasia-ui-dropdown-box-shadow: 0px 0px 0px 2px rgba(var(--starasia-ui-raw-color-brand-secondary), 0.2);
90
+ --starasia-ui-dropdown-box-shadow: 0px 0px 0px 2px rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.2);
81
91
 
82
92
  /* below is for size,above is */
83
93
  --starasia-ui-dropdown-fontWeight-normal: var(
@@ -128,14 +138,14 @@
128
138
  display: flex;
129
139
  align-items: center;
130
140
  border: var(--starasia-ui-dropdown-border-width) solid
131
- rgba(120, 134, 127, 0.2);
141
+ var(--starasia-ui-dropdown-border-color-tertiary);
132
142
  border-radius: var(--borderRadius);
133
- background-color: white;
143
+ background-color: var(--starasia-ui-dropdown-color-white);
134
144
  font-size: var(--baseFont);
135
145
  cursor: pointer;
136
146
  }
137
147
  .starasia-input-dropdown-container.disable {
138
- background-color: #f2f3f2;
148
+ background-color: var(--starasia-ui-dropdown-color-disabled-bg);
139
149
  cursor: not-allowed;
140
150
  pointer-events: none;
141
151
  }
@@ -146,7 +156,7 @@
146
156
  .starasia-input-dropdown-container.active {
147
157
  border-color: var(--starasia-ui-dropdown-border-color-primary);
148
158
  box-shadow: var(--starasia-ui-dropdown-box-shadow);
149
- background-color: white;
159
+ background-color: var(--starasia-ui-dropdown-color-white);
150
160
  }
151
161
 
152
162
  .starasia-input-dropdown-preview-container {
@@ -167,8 +177,8 @@
167
177
  border: var(--starasia-ui-dropdown-border-width) solid
168
178
  var(--starasia-ui-dropdown-border-color-tertiary);
169
179
  border-radius: var(--borderRadius);
170
- background-color: #fffeff;
171
- box-shadow: 0px 8px 12px 0px rgba(0, 0, 0, 0.08);
180
+ background-color: var(--starasia-ui-dropdown-color-white);
181
+ box-shadow: 0px 8px 12px 0px var(--starasia-ui-dropdown-box-shadow-list);
172
182
  max-height: 312px;
173
183
  overflow-y: auto;
174
184
  z-index: 999;
@@ -203,7 +213,7 @@
203
213
  border-radius: var(--borderRadius);
204
214
  gap: var(--starasia-ui-dropdown-spacing-sm);
205
215
  padding-inline: var(--paddingInline);
206
- background: white;
216
+ background: var(--starasia-ui-dropdown-color-white);
207
217
  & input {
208
218
  flex: 1;
209
219
  outline: none;
@@ -245,15 +255,20 @@
245
255
  }
246
256
 
247
257
  .starasia-input-dropdwon-item:hover {
248
- background-color: rgba(var(--starasia-ui-raw-color-brand-secondary), 0.21);
258
+ background-color: rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.21);
249
259
  }
250
260
  .starasia-input-dropdwon-item.active {
251
261
  /* color: var(--starasia-ui-dropdown-background-color-primary); */
252
262
  /* border-radius: var(--borderRadius); */
253
- background-color: rgba(var(--starasia-ui-raw-color-brand-secondary), 0.21);
263
+ background-color: rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.21);
254
264
  /* background: var(--starasia-ui-dropdown-background-color-secondary); */
255
265
  /* box-shadow: 0px 0px 0px -1px #f0f0f0; */
256
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
+ }
257
272
 
258
273
  .starasia-input-dropdwon-item-disable {
259
274
  color: var(--starasia-ui-dropdown-color-disable) !important;
@@ -289,30 +304,30 @@
289
304
  }
290
305
 
291
306
  .starasia-input-dropdwon-item-text {
292
- color: #181a19;
307
+ color: var(--starasia-ui-dropdown-color-text-primary);
293
308
  /* font-size: 14px; */
294
309
  font-size: inherit;
295
310
  font-weight: 500;
296
311
  }
297
312
  .starasia-input-dropdwon-item-text.active {
298
- color: var(--starasia-ui-brand-primary-default);
313
+ color: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
299
314
  }
300
315
 
301
316
  .starasia-input-dropdwon-item-text-description {
302
- color: #78867f;
317
+ color: var(--starasia-ui-dropdown-color-text-secondary);
303
318
  /* font-size: 14px; */
304
319
  font-size: inherit;
305
320
  font-weight: 400;
306
321
  }
307
322
  .starasia-input-dropdwon-item-text-description.active {
308
- color: var(--starasia-ui-brand-primary-default);
323
+ color: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
309
324
  }
310
325
 
311
326
  /* for checkbox */
312
327
  .checkbox-wrapper-30 .checkbox {
313
328
  --bg: #fff;
314
329
  --brdr: #d1d6ee;
315
- --brdr-actv: var(--starasia-ui-brand-primary-default);
330
+ --brdr-actv: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
316
331
  --brdr-hovr: #bbc1e1;
317
332
  --dur: calc((var(--size, 2) / 2) * 0.6s);
318
333
  display: inline-block;
@@ -384,4 +399,4 @@
384
399
  height: 100%;
385
400
  width: 100%;
386
401
  }
387
- `;function A(a){const[e,t]=o.useState(a),p=o.useRef(null),i=s=>{p.current&&!p.current.contains(s.target)&&t(!1)};return o.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:p,isComponentVisible:e,setIsComponentVisible:t}}const D=({...a})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",...a,viewBox:"0 0 24 24",fill:"none",color:"#939E99",children:n.jsx("path",{d:"M4 9L12 17L20 9",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5})}),F=({...a})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...a,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"})]}),O=({isChecked:a})=>n.jsxs("div",{className:"checkbox-wrapper-30",children:[n.jsxs("span",{className:"checkbox",children:[n.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:a}),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"})})})]}),H=o.forwardRef(({positionDropdown:a,dropdownLists:e,isComponentVisible:t,searchAble:p,onSearch:i,value:s,handleChangeValue:g,multiSelect:l,searchValue:v},E)=>{const[m,z]=o.useState(0),[N,k]=o.useState(),h=o.useRef(null);return o.useEffect(()=>{if(h.current){const r=h.current.getBoundingClientRect();z(r.width)}},[h,t]),o.useEffect(()=>{e&&v?e.forEach(r=>{if(r.label.startsWith(v||"")){k(r.value);return}}):k(void 0)},[v,e]),n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:"starasia-input-dropdown-lists-container",onClick:r=>r.stopPropagation(),ref:E,children:[p?n.jsxs("div",{className:"starasia-input-dropdown-container-dropdown-search",style:{order:a=="bottom"?0:2,position:"sticky",top:0,bottom:0,zIndex:1},children:[n.jsx("div",{style:{display:"flex"},children:n.jsx(F,{strokeWidth:2,width:20})}),n.jsx("input",{onChange:r=>{i&&i(r.target.value)},value:v,autoFocus:!0,style:{width:"100%"}})]}):null,n.jsx("div",{className:`starasia-input-dropdwon-item-container ${l?"multi":""}`,ref:h,children:e.map((r,f)=>{const x=!!(s!=null&&s.find(C=>C.value===r.value));return n.jsxs("div",{className:`starasia-input-dropdwon-item ${x?"active":" "} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,onClick:()=>g(r.label,r.value),children:[l?n.jsx("div",{style:{marginRight:"8px"},children:n.jsx(O,{isChecked:x})}):null,r.icon?n.jsx("div",{children:o.cloneElement(r.icon,{width:16})}):null,n.jsxs("div",{children:[n.jsx("p",{className:`starasia-input-dropdwon-item-text ${x?"active":null} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${m-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:r.label}),r.description?n.jsx("p",{className:`starasia-input-dropdwon-item-text-description ${x?"active":null} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${m-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:r.description}):null]})]},f)})})]}):null})}),M=({children:a,handleChangePosition:e})=>{const t=o.useRef(null);o.useEffect(()=>{var g;const i=()=>{if(t.current){let l=t.current.parentElement;for(;l&&!p(l);)l=l.parentElement;l&&e()}};let s=(g=t.current)==null?void 0:g.parentElement;for(;s&&!p(s);)s=s.parentElement;return s&&s.addEventListener("scroll",i),i(),()=>{s&&s.removeEventListener("scroll",i)}},[]);const p=i=>i&&(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth);return n.jsx("div",{ref:t,children:a})},W="starasia-input-dropdown-styles";(a=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=a,document.head.appendChild(e)}})(q);const P=({dropdownLists:a,onChange:e,defaultValue:t,size:p="md",multiSelect:i,searchAble:s,iconLeft:g,placeholder:l,onSearch:v,error:E,onBlur:m,onFocus:z,disable:N,searchValue:k})=>{const h=o.useRef(),[r,f]=o.useState([]),[x,C]=o.useState(""),b=o.useRef(null),{isComponentVisible:I,ref:B,setIsComponentVisible:S}=A(!1),V=()=>{S(d=>!d)},j=(d,c)=>{if(!i)f([{label:d,value:c}]),e([{label:d,value:c}]),S(!1);else if(r==null?void 0:r.find(u=>u.value===c)){const u=[...r?r.filter(G=>G.value!==c):[]];f(u),e(u)}else{const u=[...r||[],{label:d,value:c}];f(u),e(u)}};o.useEffect(()=>{JSON.stringify(h.current)===JSON.stringify(t)||(h.current=t,f(h.current||[]))},[t]);const J=()=>r.length?i?r==null?void 0:r.map((d,c)=>n.jsxs("div",{className:"starasia-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:d==null?void 0:d.label},c),n.jsx(T,{onClick:()=>j(d.label,d.value)})]})):n.jsx("p",{style:{minWidth:"max-content"},children:r==null?void 0:r[0].label}):n.jsx("p",{className:"starasia-input-dropdown-placeholder",children:l}),y=()=>{if(B.current&&b.current){const d=window.innerHeight,c=B.current.getBoundingClientRect(),L=b.current.getBoundingClientRect(),u=c.bottom+L.height;b.current.style.left=`${c.left}px`,b.current.style.width=`${c.width}px`,u>=d-10?(b.current.style.top=`${c.top-L.height-5}px`,C("top")):(b.current.style.top=`${c.top+c.height}px`,C("bottom"))}};return o.useEffect(()=>(window.addEventListener("scroll",y),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y),window.removeEventListener("resize",y)}),[]),o.useEffect(()=>{y()},[I]),n.jsx(M,{handleChangePosition:y,children:n.jsxs("div",{className:`starasia-input-dropdown-container ${N?"disable":""} starasia-input-dropdown-size-${p} ${I?"active":""} ${E?"error":""}`,ref:B,onClick:V,children:[n.jsxs("div",{className:"starasia-input-dropdown-preview-container",children:[g?n.jsx(n.Fragment,{children:o.cloneElement(g,{width:$(p),color:"#939E99",style:{color:"#939E99"}})}):null,n.jsx("div",{className:"starasia-input-dropdown-container-preview-item",tabIndex:100,onBlur:m,onFocus:z,children:J()}),n.jsx(D,{strokeWidth:2,width:$(p),style:{color:"#939E99"}})]}),n.jsx(H,{dropdownLists:a,handleChangeValue:j,isComponentVisible:I,positionDropdown:x,searchAble:!!s,value:r,onSearch:v,ref:b,multiSelect:i,searchValue:k})]})})},$=a=>{if(a==="sm")return 16;if(a==="md")return 16;if(a==="lg")return 20},T=a=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",...a,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})});w.Dropdown=P,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
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.5",
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
+ }