@starasia/dropdown 2.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { jsx as e, jsxs as p, Fragment as V } from "react/jsx-runtime";
2
- import M, { 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");
1
+ import { jsx as r, jsxs as w, Fragment as M } from "react/jsx-runtime";
2
+ import P, { useState as B, useRef as z, useEffect as v, forwardRef as G } from "react";
3
+ const Q = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
4
  * {
5
5
  margin: 0;
6
6
  padding: 0;
@@ -28,28 +28,28 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
28
28
  --sa-dropdown-radius-lg: var(--sa-radii-lg, 0.75rem);
29
29
  }
30
30
 
31
- .starasia-input-dropdown-size-sm {
31
+ .sa-input-dropdown-size-sm {
32
32
  --baseFont: var(--sa-font-size-sm, 12px);
33
33
  --height: var(--sa-h-8, 32px);
34
34
  --borderRadius: var(--sa-dropdown-radius);
35
35
  --paddingInline: var(--sa-spacing-sm, 8px);
36
36
  }
37
37
 
38
- .starasia-input-dropdown-size-md {
38
+ .sa-input-dropdown-size-md {
39
39
  --baseFont: var(--sa-font-size-md, 14px);
40
40
  --height: 38px;
41
41
  --borderRadius: var(--sa-dropdown-radius);
42
42
  --paddingInline: var(--sa-spacing-3, 12px);
43
43
  }
44
44
 
45
- .starasia-input-dropdown-size-lg {
45
+ .sa-input-dropdown-size-lg {
46
46
  --baseFont: var(--sa-font-size-lg, 16px);
47
47
  --height: var(--sa-h-12, 48px);
48
48
  --borderRadius: var(--sa-dropdown-radius-lg);
49
49
  --paddingInline: var(--sa-spacing-3, 12px);
50
50
  }
51
51
 
52
- .starasia-input-dropdown-container {
52
+ .sa-input-dropdown-container {
53
53
  position: relative;
54
54
  min-height: var(--height);
55
55
  padding-inline: var(--paddingInline);
@@ -61,22 +61,22 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
61
61
  font-size: var(--baseFont);
62
62
  cursor: pointer;
63
63
  }
64
- .starasia-input-dropdown-container.disable {
64
+ .sa-input-dropdown-container.disable {
65
65
  background-color: var(--sa-dropdown-bg-disabled);
66
66
  cursor: not-allowed;
67
67
  pointer-events: none;
68
68
  }
69
69
 
70
- .starasia-input-dropdown-container.error {
70
+ .sa-input-dropdown-container.error {
71
71
  border-color: var(--sa-dropdown-border-error) !important;
72
72
  }
73
- .starasia-input-dropdown-container.active {
73
+ .sa-input-dropdown-container.active {
74
74
  border-color: var(--sa-dropdown-border-active);
75
75
  box-shadow: var(--sa-dropdown-shadow-focus);
76
76
  background-color: var(--sa-dropdown-bg);
77
77
  }
78
78
 
79
- .starasia-input-dropdown-preview-container {
79
+ .sa-input-dropdown-preview-container {
80
80
  display: flex;
81
81
  flex-direction: row;
82
82
  gap: var(--sa-spacing-sm, 8px);
@@ -86,7 +86,7 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
86
86
  overflow-y: hidden;
87
87
  }
88
88
 
89
- .starasia-input-dropdown-lists-container {
89
+ .sa-input-dropdown-lists-container {
90
90
  /* position: absolute; */
91
91
  position: fixed;
92
92
  /* left: 0; */
@@ -109,16 +109,16 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
109
109
  white-space: nowrap; */
110
110
  }
111
111
 
112
- .starasia-input-dropdown-lists-container-bottom {
112
+ .sa-input-dropdown-lists-container-bottom {
113
113
  top: 100%;
114
114
  margin-top: var(--sa-spacing-xs, 4px);
115
115
  }
116
- .starasia-input-dropdown-lists-container-top {
116
+ .sa-input-dropdown-lists-container-top {
117
117
  bottom: 100%;
118
118
  margin-bottom: var(--sa-spacing-xs, 4px);
119
119
  }
120
120
 
121
- .starasia-input-dropdown-container-dropdown-search {
121
+ .sa-input-dropdown-container-dropdown-search {
122
122
  display: flex;
123
123
  align-items: center;
124
124
  height: var(--height);
@@ -138,14 +138,14 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
138
138
  }
139
139
  }
140
140
 
141
- .starasia-input-dropdwon-item-container {
141
+ .sa-input-dropdwon-item-container {
142
142
  display: flex;
143
143
  flex-direction: column;
144
144
  /* overflow: hidden; */
145
145
 
146
146
  /* gap: var(--sa-spacing-xs, 0.25rem); */
147
147
  }
148
- .starasia-input-dropdwon-item-container.multi {
148
+ .sa-input-dropdwon-item-container.multi {
149
149
  display: flex;
150
150
  flex-direction: column;
151
151
  gap: 8px;
@@ -154,7 +154,7 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
154
154
  /* gap: var(--sa-spacing-xs, 0.25rem); */
155
155
  }
156
156
 
157
- .starasia-input-dropdwon-item {
157
+ .sa-input-dropdwon-item {
158
158
  /* max-height: var(--height); */
159
159
  max-height: 58px;
160
160
  box-sizing: border-box;
@@ -169,28 +169,28 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
169
169
  overflow: hidden;
170
170
  }
171
171
 
172
- .starasia-input-dropdwon-item:hover {
172
+ .sa-input-dropdwon-item:hover {
173
173
  background-color: color-mix(in srgb, var(--sa-dropdown-brand-secondary) 21%, transparent);
174
174
  }
175
- .starasia-input-dropdwon-item.active {
175
+ .sa-input-dropdwon-item.active {
176
176
  /* color: var(--sa-dropdown-brand); */
177
177
  /* border-radius: var(--borderRadius); */
178
178
  background-color: color-mix(in srgb, var(--sa-dropdown-brand-secondary) 21%, transparent);
179
179
  /* background: var(--sa-dropdown-brand-subtle); */
180
180
  /* box-shadow: 0px 0px 0px -1px #f0f0f0; */
181
181
  }
182
- .starasia-input-dropdwon-item.highlight {
182
+ .sa-input-dropdwon-item.highlight {
183
183
  background-color: color-mix(in srgb, var(--sa-dropdown-brand-secondary) 35%, transparent);
184
184
  outline: 2px solid color-mix(in srgb, var(--sa-dropdown-brand-secondary) 40%, transparent);
185
185
  outline-offset: -2px;
186
186
  }
187
187
 
188
- .starasia-input-dropdwon-item-disable {
188
+ .sa-input-dropdwon-item-disable {
189
189
  color: var(--sa-dropdown-color-disable) !important;
190
190
  pointer-events: none;
191
191
  }
192
192
 
193
- .starasia-input-dropdown-container-preview-item {
193
+ .sa-input-dropdown-container-preview-item {
194
194
  flex: 1;
195
195
  display: flex;
196
196
  gap: var(--sa-spacing-xs, 4px);
@@ -200,7 +200,7 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
200
200
  padding-block: 4px;
201
201
  }
202
202
 
203
- .starasia-input-dropdown-preview-item {
203
+ .sa-input-dropdown-preview-item {
204
204
  border: var(--sa-dropdown-border) solid var(--sa-dropdown-border-active);
205
205
  padding-inline: var(--paddingInline);
206
206
  border-radius: var(--borderRadius);
@@ -212,28 +212,28 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
212
212
  align-items: center;
213
213
  gap: 2;
214
214
  }
215
- .starasia-input-dropdown-placeholder {
215
+ .sa-input-dropdown-placeholder {
216
216
  color: var(--sa-dropdown-placeholder);
217
217
  font-weight: var(--sa-font-weight-normal, 300);
218
218
  }
219
219
 
220
- .starasia-input-dropdwon-item-text {
220
+ .sa-input-dropdwon-item-text {
221
221
  color: var(--sa-dropdown-text-primary);
222
222
  /* font-size: 14px; */
223
223
  font-size: inherit;
224
224
  font-weight: 500;
225
225
  }
226
- .starasia-input-dropdwon-item-text.active {
226
+ .sa-input-dropdwon-item-text.active {
227
227
  color: var(--sa-dropdown-brand);
228
228
  }
229
229
 
230
- .starasia-input-dropdwon-item-text-description {
230
+ .sa-input-dropdwon-item-text-description {
231
231
  color: var(--sa-dropdown-text-secondary);
232
232
  /* font-size: 14px; */
233
233
  font-size: inherit;
234
234
  font-weight: 400;
235
235
  }
236
- .starasia-input-dropdwon-item-text-description.active {
236
+ .sa-input-dropdwon-item-text-description.active {
237
237
  color: var(--sa-dropdown-brand);
238
238
  }
239
239
 
@@ -314,23 +314,23 @@ const U = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
314
314
  width: 100%;
315
315
  }
316
316
  `;
317
- function G(r) {
318
- const [c, s] = R(r), d = z(null), a = (o) => {
319
- d.current && !d.current.contains(o.target) && s(!1);
317
+ function T(n) {
318
+ const [l, i] = B(n), c = z(null), a = (o) => {
319
+ c.current && !c.current.contains(o.target) && i(!1);
320
320
  };
321
- return b(() => (document.addEventListener("click", a, !0), () => {
321
+ return v(() => (document.addEventListener("click", a, !0), () => {
322
322
  document.removeEventListener("click", a, !0);
323
- }), []), { ref: d, isComponentVisible: c, setIsComponentVisible: s };
323
+ }), []), { ref: c, isComponentVisible: l, setIsComponentVisible: i };
324
324
  }
325
- const Q = ({ ...r }) => /* @__PURE__ */ e(
325
+ const X = ({ ...n }) => /* @__PURE__ */ r(
326
326
  "svg",
327
327
  {
328
328
  xmlns: "http://www.w3.org/2000/svg",
329
- ...r,
329
+ ...n,
330
330
  viewBox: "0 0 24 24",
331
331
  fill: "none",
332
332
  color: "var(--sa-color-gray-500, #8c8f97)",
333
- children: /* @__PURE__ */ e(
333
+ children: /* @__PURE__ */ r(
334
334
  "path",
335
335
  {
336
336
  d: "M4 9L12 17L20 9",
@@ -341,15 +341,15 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
341
341
  }
342
342
  )
343
343
  }
344
- ), T = ({ ...r }) => /* @__PURE__ */ p(
344
+ ), Y = ({ ...n }) => /* @__PURE__ */ w(
345
345
  "svg",
346
346
  {
347
347
  xmlns: "http://www.w3.org/2000/svg",
348
- ...r,
348
+ ...n,
349
349
  viewBox: "0 0 20 20",
350
350
  fill: "none",
351
351
  children: [
352
- /* @__PURE__ */ e(
352
+ /* @__PURE__ */ r(
353
353
  "circle",
354
354
  {
355
355
  cx: "9.80547",
@@ -361,7 +361,7 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
361
361
  strokeLinejoin: "round"
362
362
  }
363
363
  ),
364
- /* @__PURE__ */ e(
364
+ /* @__PURE__ */ r(
365
365
  "path",
366
366
  {
367
367
  d: "M15.0153 15.4043L17.9519 18.3333",
@@ -373,19 +373,19 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
373
373
  )
374
374
  ]
375
375
  }
376
- ), X = ({ isChecked: r }) => /* @__PURE__ */ p("div", { className: "checkbox-wrapper-30", children: [
377
- /* @__PURE__ */ p("span", { className: "checkbox", children: [
378
- /* @__PURE__ */ e(
376
+ ), Z = ({ isChecked: n }) => /* @__PURE__ */ w("div", { className: "checkbox-wrapper-30", children: [
377
+ /* @__PURE__ */ w("span", { className: "checkbox", children: [
378
+ /* @__PURE__ */ r(
379
379
  "input",
380
380
  {
381
381
  type: "checkbox",
382
382
  style: { pointerEvents: "none" },
383
- checked: r
383
+ checked: n
384
384
  }
385
385
  ),
386
- /* @__PURE__ */ e("svg", { children: /* @__PURE__ */ e("use", { xlinkHref: "#checkbox-30", className: "checkbox" }) })
386
+ /* @__PURE__ */ r("svg", { children: /* @__PURE__ */ r("use", { xlinkHref: "#checkbox-30", className: "checkbox" }) })
387
387
  ] }),
388
- /* @__PURE__ */ e("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, children: /* @__PURE__ */ e("symbol", { id: "checkbox-30", viewBox: "0 0 22 22", children: /* @__PURE__ */ e(
388
+ /* @__PURE__ */ r("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, children: /* @__PURE__ */ r("symbol", { id: "checkbox-30", viewBox: "0 0 22 22", children: /* @__PURE__ */ r(
389
389
  "path",
390
390
  {
391
391
  fill: "none",
@@ -393,55 +393,55 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
393
393
  d: "M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"
394
394
  }
395
395
  ) }) })
396
- ] }), Y = K(
396
+ ] }), _ = G(
397
397
  ({
398
- positionDropdown: r,
399
- dropdownLists: c,
400
- isComponentVisible: s,
401
- searchAble: d,
398
+ positionDropdown: n,
399
+ dropdownLists: l,
400
+ isComponentVisible: i,
401
+ searchAble: c,
402
402
  onSearch: a,
403
403
  value: o,
404
- handleChangeValue: v,
405
- multiSelect: l,
406
- searchValue: $,
404
+ handleChangeValue: m,
405
+ multiSelect: p,
406
+ searchValue: I,
407
407
  highlightedIndex: g
408
- }, N) => {
409
- const [I, L] = R(0), m = z(null), x = z([]);
410
- return b(() => {
411
- if (m.current) {
412
- const n = m.current.getBoundingClientRect();
413
- L(n.width);
408
+ }, L) => {
409
+ const [$, D] = B(0), k = z(null), R = z([]);
410
+ return v(() => {
411
+ if (k.current) {
412
+ const e = k.current.getBoundingClientRect();
413
+ D(e.width);
414
414
  }
415
- }, [m, s]), b(() => {
416
- var n;
417
- g >= 0 && x.current[g] && ((n = x.current[g]) == null || n.scrollIntoView({ block: "nearest" }));
418
- }, [g]), /* @__PURE__ */ e(V, { children: s ? /* @__PURE__ */ p(
415
+ }, [k, i]), v(() => {
416
+ var e;
417
+ g >= 0 && R.current[g] && ((e = R.current[g]) == null || e.scrollIntoView({ block: "nearest" }));
418
+ }, [g]), /* @__PURE__ */ r(M, { children: i ? /* @__PURE__ */ w(
419
419
  "div",
420
420
  {
421
- className: "starasia-input-dropdown-lists-container",
422
- onClick: (n) => n.stopPropagation(),
423
- ref: N,
421
+ className: "sa-input-dropdown-lists-container",
422
+ onClick: (e) => e.stopPropagation(),
423
+ ref: L,
424
424
  children: [
425
- d ? /* @__PURE__ */ p(
425
+ c ? /* @__PURE__ */ w(
426
426
  "div",
427
427
  {
428
- className: "starasia-input-dropdown-container-dropdown-search",
428
+ className: "sa-input-dropdown-container-dropdown-search",
429
429
  style: {
430
- order: r == "bottom" ? 0 : 2,
430
+ order: n == "bottom" ? 0 : 2,
431
431
  position: "sticky",
432
432
  top: 0,
433
433
  bottom: 0,
434
434
  zIndex: 1
435
435
  },
436
436
  children: [
437
- /* @__PURE__ */ e("div", { style: { display: "flex" }, children: /* @__PURE__ */ e(T, { strokeWidth: 2, width: 20 }) }),
438
- /* @__PURE__ */ e(
437
+ /* @__PURE__ */ r("div", { style: { display: "flex" }, children: /* @__PURE__ */ r(Y, { strokeWidth: 2, width: 20 }) }),
438
+ /* @__PURE__ */ r(
439
439
  "input",
440
440
  {
441
- onChange: (n) => {
442
- a && a(n.target.value);
441
+ onChange: (e) => {
442
+ a && a(e.target.value);
443
443
  },
444
- value: $,
444
+ value: I,
445
445
  autoFocus: !0,
446
446
  style: { width: "100%" }
447
447
  }
@@ -449,57 +449,57 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
449
449
  ]
450
450
  }
451
451
  ) : null,
452
- /* @__PURE__ */ e(
452
+ /* @__PURE__ */ r(
453
453
  "div",
454
454
  {
455
- className: `starasia-input-dropdwon-item-container ${l ? "multi" : ""}`,
456
- ref: m,
457
- children: c.map((n, h) => {
458
- const k = !!(o != null && o.find((y) => y.value === n.value));
459
- return /* @__PURE__ */ p(
455
+ className: `sa-input-dropdwon-item-container ${p ? "multi" : ""}`,
456
+ ref: k,
457
+ children: l.map((e, f) => {
458
+ const s = !!(o != null && o.find((h) => h.value === e.value));
459
+ return /* @__PURE__ */ w(
460
460
  "div",
461
461
  {
462
- className: `starasia-input-dropdwon-item ${k ? "active" : ""} ${h === g ? "highlight" : ""} ${n.disable ? "starasia-input-dropdwon-item-disable" : ""}`,
463
- ref: (y) => {
464
- x.current[h] = y;
462
+ className: `sa-input-dropdwon-item ${s ? "active" : ""} ${f === g ? "highlight" : ""} ${e.disable ? "sa-input-dropdwon-item-disable" : ""}`,
463
+ ref: (h) => {
464
+ R.current[f] = h;
465
465
  },
466
- onClick: () => v(n.label, n.value),
466
+ onClick: () => m(e.label, e.value),
467
467
  children: [
468
- l ? /* @__PURE__ */ e("div", { style: { marginRight: "8px" }, children: /* @__PURE__ */ e(X, { isChecked: k }) }) : null,
469
- n.icon ? /* @__PURE__ */ e("div", { children: M.cloneElement(n.icon, {
468
+ p ? /* @__PURE__ */ r("div", { style: { marginRight: "8px" }, children: /* @__PURE__ */ r(Z, { isChecked: s }) }) : null,
469
+ e.icon ? /* @__PURE__ */ r("div", { children: P.cloneElement(e.icon, {
470
470
  width: 16
471
471
  }) }) : null,
472
- /* @__PURE__ */ p("div", { children: [
473
- /* @__PURE__ */ e(
472
+ /* @__PURE__ */ w("div", { children: [
473
+ /* @__PURE__ */ r(
474
474
  "p",
475
475
  {
476
- className: `starasia-input-dropdwon-item-text ${k ? "active" : null} ${n.disable ? "starasia-input-dropdwon-item-disable" : null}`,
476
+ className: `sa-input-dropdwon-item-text ${s ? "active" : null} ${e.disable ? "sa-input-dropdwon-item-disable" : null}`,
477
477
  style: {
478
478
  textWrap: "nowrap",
479
- width: `${I - 12}px`,
479
+ width: `${$ - 12}px`,
480
480
  overflow: "hidden",
481
481
  textOverflow: "ellipsis"
482
482
  },
483
- children: n.label
483
+ children: e.label
484
484
  }
485
485
  ),
486
- n.description ? /* @__PURE__ */ e(
486
+ e.description ? /* @__PURE__ */ r(
487
487
  "p",
488
488
  {
489
- className: `starasia-input-dropdwon-item-text-description ${k ? "active" : null} ${n.disable ? "starasia-input-dropdwon-item-disable" : null}`,
489
+ className: `sa-input-dropdwon-item-text-description ${s ? "active" : null} ${e.disable ? "sa-input-dropdwon-item-disable" : null}`,
490
490
  style: {
491
491
  textWrap: "nowrap",
492
- width: `${I - 12}px`,
492
+ width: `${$ - 12}px`,
493
493
  overflow: "hidden",
494
494
  textOverflow: "ellipsis"
495
495
  },
496
- children: n.description
496
+ children: e.description
497
497
  }
498
498
  ) : null
499
499
  ] })
500
500
  ]
501
501
  },
502
- h
502
+ f
503
503
  );
504
504
  })
505
505
  }
@@ -508,202 +508,208 @@ const Q = ({ ...r }) => /* @__PURE__ */ e(
508
508
  }
509
509
  ) : null });
510
510
  }
511
- ), Z = ({
512
- children: r,
513
- handleChangePosition: c
511
+ ), nn = ({
512
+ children: n,
513
+ handleChangePosition: l
514
514
  }) => {
515
- const s = z(null);
516
- b(() => {
517
- var v;
515
+ const i = z(null);
516
+ v(() => {
517
+ var m;
518
518
  const a = () => {
519
- if (s.current) {
520
- let l = s.current.parentElement;
521
- for (; l && !d(l); )
522
- l = l.parentElement;
523
- l && c();
519
+ if (i.current) {
520
+ let p = i.current.parentElement;
521
+ for (; p && !c(p); )
522
+ p = p.parentElement;
523
+ p && l();
524
524
  }
525
525
  };
526
- let o = (v = s.current) == null ? void 0 : v.parentElement;
527
- for (; o && !d(o); )
526
+ let o = (m = i.current) == null ? void 0 : m.parentElement;
527
+ for (; o && !c(o); )
528
528
  o = o.parentElement;
529
529
  return o && o.addEventListener("scroll", a), a(), () => {
530
530
  o && o.removeEventListener("scroll", a);
531
531
  };
532
532
  }, []);
533
- const d = (a) => a && (a.scrollHeight > a.clientHeight || a.scrollWidth > a.clientWidth);
534
- return /* @__PURE__ */ e("div", { ref: s, children: r });
535
- }, F = "starasia-input-dropdown-styles", _ = (r) => {
536
- if (!document.getElementById(F)) {
537
- const c = document.createElement("style");
538
- c.id = F, c.textContent = r, document.head.appendChild(c);
533
+ const c = (a) => a && (a.scrollHeight > a.clientHeight || a.scrollWidth > a.clientWidth);
534
+ return /* @__PURE__ */ r("div", { ref: i, children: n });
535
+ }, H = "sa-input-dropdown-styles", rn = (n) => {
536
+ if (!document.getElementById(H)) {
537
+ const l = document.createElement("style");
538
+ l.id = H, l.textContent = n, document.head.appendChild(l);
539
539
  }
540
540
  };
541
- _(U);
542
- const on = ({
543
- dropdownLists: r,
544
- onChange: c,
545
- defaultValue: s,
546
- size: d = "md",
547
- multiSelect: a,
548
- searchAble: o,
549
- iconLeft: v,
550
- placeholder: l,
551
- onSearch: $,
552
- error: g,
553
- onBlur: N,
554
- onFocus: I,
555
- disable: L,
556
- searchValue: m
541
+ rn(Q);
542
+ const tn = ({
543
+ dropdownLists: n,
544
+ onChange: l,
545
+ defaultValue: i,
546
+ value: c,
547
+ size: a = "md",
548
+ multiSelect: o,
549
+ searchAble: m,
550
+ iconLeft: p,
551
+ placeholder: I,
552
+ onSearch: g,
553
+ error: L,
554
+ onBlur: $,
555
+ onFocus: D,
556
+ disable: k,
557
+ searchValue: R
557
558
  }) => {
558
- const x = z(), [n, h] = R([]), [k, y] = R(""), [u, D] = R(-1), f = z(null), { isComponentVisible: C, ref: W, setIsComponentVisible: B } = G(!1), P = () => {
559
- B((t) => !t);
560
- }, A = (t, i) => {
561
- if (!a)
562
- h([{ label: t, value: i }]), c([{ label: t, value: i }]), B(!1);
563
- else if (n == null ? void 0 : n.find((w) => w.value === i)) {
564
- const w = [
565
- ...n ? n.filter((J) => J.value !== i) : []
566
- ];
567
- h(w), c(w);
568
- } else {
569
- const w = [...n || [], { label: t, value: i }];
570
- h(w), c(w);
559
+ const e = c !== void 0, f = z(), [s, h] = B(
560
+ e ? c || [] : i || []
561
+ ), [V, F] = B(""), [b, W] = B(-1), x = z(null), { isComponentVisible: y, ref: A, setIsComponentVisible: N } = T(!1), q = () => {
562
+ N((t) => !t);
563
+ }, j = (t, d) => {
564
+ if (o)
565
+ if (s == null ? void 0 : s.find((u) => u.value === d)) {
566
+ const u = s.filter((U) => U.value !== d);
567
+ e || h(u), l(u);
568
+ } else {
569
+ const u = [...s, { label: t, value: d }];
570
+ e || h(u), l(u);
571
+ }
572
+ else {
573
+ const E = [{ label: t, value: d }];
574
+ e || h(E), l(E), N(!1);
571
575
  }
572
576
  };
573
- b(() => {
574
- JSON.stringify(x.current) === JSON.stringify(s) || (x.current = s, h(x.current || []));
575
- }, [s]);
576
- const S = () => n.length ? a ? n == null ? void 0 : n.map((t, i) => /* @__PURE__ */ p("div", { className: "starasia-input-dropdown-preview-item", children: [
577
- /* @__PURE__ */ e("p", { style: { minWidth: "max-content" }, children: t == null ? void 0 : t.label }, i),
578
- /* @__PURE__ */ e(
579
- nn,
577
+ v(() => {
578
+ e && h(c || []);
579
+ }, [c]), v(() => {
580
+ e || JSON.stringify(f.current) === JSON.stringify(i) || (f.current = i, h(f.current || []));
581
+ }, [i]);
582
+ const J = () => s.length ? o ? s == null ? void 0 : s.map((t, d) => /* @__PURE__ */ w("div", { className: "sa-input-dropdown-preview-item", children: [
583
+ /* @__PURE__ */ r("p", { style: { minWidth: "max-content" }, children: t == null ? void 0 : t.label }, d),
584
+ /* @__PURE__ */ r(
585
+ on,
580
586
  {
581
- onClick: () => A(t.label, t.value)
587
+ onClick: () => j(t.label, t.value)
582
588
  }
583
589
  )
584
- ] })) : /* @__PURE__ */ e("p", { style: { minWidth: "max-content" }, children: n == null ? void 0 : n[0].label }) : /* @__PURE__ */ e("p", { className: "starasia-input-dropdown-placeholder", children: l }), E = () => {
585
- if (W.current && f.current) {
586
- const t = window.innerHeight, i = W.current.getBoundingClientRect(), j = f.current.getBoundingClientRect(), w = i.bottom + j.height;
587
- f.current.style.left = `${i.left}px`, f.current.style.width = `${i.width}px`, w >= t - 10 ? (f.current.style.top = `${i.top - j.height - 5}px`, y("top")) : (f.current.style.top = `${i.top + i.height}px`, y("bottom"));
590
+ ] })) : /* @__PURE__ */ r("p", { style: { minWidth: "max-content" }, children: s == null ? void 0 : s[0].label }) : /* @__PURE__ */ r("p", { className: "sa-input-dropdown-placeholder", children: I }), C = () => {
591
+ if (A.current && x.current) {
592
+ const t = window.innerHeight, d = A.current.getBoundingClientRect(), E = x.current.getBoundingClientRect(), u = d.bottom + E.height;
593
+ x.current.style.left = `${d.left}px`, x.current.style.width = `${d.width}px`, u >= t - 10 ? (x.current.style.top = `${d.top - E.height - 5}px`, F("top")) : (x.current.style.top = `${d.top + d.height}px`, F("bottom"));
588
594
  }
589
595
  };
590
- b(() => (window.addEventListener("scroll", E), window.addEventListener("resize", E), () => {
591
- window.removeEventListener("scroll", E), window.removeEventListener("resize", E);
592
- }), []), b(() => {
593
- E();
594
- }, [C]), b(() => {
595
- C || D(-1);
596
- }, [C]);
597
- const q = (t) => {
598
- if (!C) {
599
- (t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), B(!0));
596
+ v(() => (window.addEventListener("scroll", C), window.addEventListener("resize", C), () => {
597
+ window.removeEventListener("scroll", C), window.removeEventListener("resize", C);
598
+ }), []), v(() => {
599
+ C();
600
+ }, [y]), v(() => {
601
+ y || W(-1);
602
+ }, [y]);
603
+ const K = (t) => {
604
+ if (!y) {
605
+ (t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), N(!0));
600
606
  return;
601
607
  }
602
608
  switch (t.key) {
603
609
  case "ArrowDown": {
604
610
  t.preventDefault();
605
- const i = H(r, u, 1);
606
- i !== -1 && D(i);
611
+ const d = O(n, b, 1);
612
+ d !== -1 && W(d);
607
613
  break;
608
614
  }
609
615
  case "ArrowUp": {
610
616
  t.preventDefault();
611
- const i = H(r, u, -1);
612
- i !== -1 && D(i);
617
+ const d = O(n, b, -1);
618
+ d !== -1 && W(d);
613
619
  break;
614
620
  }
615
621
  case "Enter": {
616
- t.preventDefault(), u >= 0 && r[u] && !r[u].disable && A(
617
- r[u].label,
618
- r[u].value
622
+ t.preventDefault(), b >= 0 && n[b] && !n[b].disable && j(
623
+ n[b].label,
624
+ n[b].value
619
625
  );
620
626
  break;
621
627
  }
622
628
  case "Escape": {
623
- B(!1);
629
+ N(!1);
624
630
  break;
625
631
  }
626
632
  }
627
633
  };
628
- return /* @__PURE__ */ e(Z, { handleChangePosition: E, children: /* @__PURE__ */ p(
634
+ return /* @__PURE__ */ r(nn, { handleChangePosition: C, children: /* @__PURE__ */ w(
629
635
  "div",
630
636
  {
631
- className: `starasia-input-dropdown-container ${L ? "disable" : ""} starasia-input-dropdown-size-${d} ${C ? "active" : ""} ${g ? "error" : ""}`,
632
- ref: W,
633
- onClick: P,
634
- onKeyDown: q,
637
+ className: `sa-input-dropdown-container ${k ? "disable" : ""} sa-input-dropdown-size-${a} ${y ? "active" : ""} ${L ? "error" : ""}`,
638
+ ref: A,
639
+ onClick: q,
640
+ onKeyDown: K,
635
641
  tabIndex: 0,
636
- onBlur: N,
637
- onFocus: I,
642
+ onBlur: $,
643
+ onFocus: D,
638
644
  children: [
639
- /* @__PURE__ */ p("div", { className: "starasia-input-dropdown-preview-container", children: [
640
- v ? /* @__PURE__ */ e(V, { children: M.cloneElement(v, {
641
- width: O(d),
645
+ /* @__PURE__ */ w("div", { className: "sa-input-dropdown-preview-container", children: [
646
+ p ? /* @__PURE__ */ r(M, { children: P.cloneElement(p, {
647
+ width: S(a),
642
648
  color: "var(--sa-color-gray-500, #8c8f97)",
643
649
  style: {
644
650
  color: "var(--sa-color-gray-500, #8c8f97)"
645
651
  }
646
652
  }) }) : null,
647
- /* @__PURE__ */ e(
653
+ /* @__PURE__ */ r(
648
654
  "div",
649
655
  {
650
- className: "starasia-input-dropdown-container-preview-item",
651
- children: S()
656
+ className: "sa-input-dropdown-container-preview-item",
657
+ children: J()
652
658
  }
653
659
  ),
654
- /* @__PURE__ */ e(
655
- Q,
660
+ /* @__PURE__ */ r(
661
+ X,
656
662
  {
657
663
  strokeWidth: 2,
658
- width: O(d),
664
+ width: S(a),
659
665
  style: { color: "var(--sa-color-gray-500, #8c8f97)" }
660
666
  }
661
667
  )
662
668
  ] }),
663
- /* @__PURE__ */ e(
664
- Y,
669
+ /* @__PURE__ */ r(
670
+ _,
665
671
  {
666
- dropdownLists: r,
667
- handleChangeValue: A,
668
- isComponentVisible: C,
669
- positionDropdown: k,
670
- searchAble: !!o,
671
- value: n,
672
- onSearch: $,
673
- ref: f,
674
- multiSelect: a,
675
- searchValue: m,
676
- highlightedIndex: u
672
+ dropdownLists: n,
673
+ handleChangeValue: j,
674
+ isComponentVisible: y,
675
+ positionDropdown: V,
676
+ searchAble: !!m,
677
+ value: s,
678
+ onSearch: g,
679
+ ref: x,
680
+ multiSelect: o,
681
+ searchValue: R,
682
+ highlightedIndex: b
677
683
  }
678
684
  )
679
685
  ]
680
686
  }
681
687
  ) });
682
- }, H = (r, c, s) => {
683
- const d = r.length;
684
- let a = c + s;
685
- for (; a >= 0 && a < d; ) {
686
- if (!r[a].disable)
688
+ }, O = (n, l, i) => {
689
+ const c = n.length;
690
+ let a = l + i;
691
+ for (; a >= 0 && a < c; ) {
692
+ if (!n[a].disable)
687
693
  return a;
688
- a += s;
694
+ a += i;
689
695
  }
690
- if (s === 1) {
691
- for (let o = 0; o < d; o++)
692
- if (!r[o].disable)
696
+ if (i === 1) {
697
+ for (let o = 0; o < c; o++)
698
+ if (!n[o].disable)
693
699
  return o;
694
700
  } else
695
- for (let o = d - 1; o >= 0; o--)
696
- if (!r[o].disable)
701
+ for (let o = c - 1; o >= 0; o--)
702
+ if (!n[o].disable)
697
703
  return o;
698
704
  return -1;
699
- }, O = (r) => {
700
- if (r === "sm")
705
+ }, S = (n) => {
706
+ if (n === "sm")
701
707
  return 16;
702
- if (r === "md")
708
+ if (n === "md")
703
709
  return 16;
704
- if (r === "lg")
710
+ if (n === "lg")
705
711
  return 20;
706
- }, nn = (r) => /* @__PURE__ */ e(
712
+ }, on = (n) => /* @__PURE__ */ r(
707
713
  "svg",
708
714
  {
709
715
  xmlns: "http://www.w3.org/2000/svg",
@@ -711,8 +717,8 @@ const on = ({
711
717
  height: "18",
712
718
  viewBox: "0 0 18 18",
713
719
  fill: "none",
714
- ...r,
715
- children: /* @__PURE__ */ e(
720
+ ...n,
721
+ children: /* @__PURE__ */ r(
716
722
  "path",
717
723
  {
718
724
  d: "M12 6L6 12M6.00001 6L12 12",
@@ -725,5 +731,5 @@ const on = ({
725
731
  }
726
732
  );
727
733
  export {
728
- on as Dropdown
734
+ tn as Dropdown
729
735
  };
@@ -1,4 +1,4 @@
1
- (function(h,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):(h=typeof globalThis<"u"?globalThis:h||self,n(h.Dropdown={},h.jsxRuntime,h.React))})(this,function(h,n,t){"use strict";const O=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ (function(u,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(u=typeof globalThis<"u"?globalThis:u||self,n(u.Dropdown={},u.jsxRuntime,u.React))})(this,function(u,n,d){"use strict";const H=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
2
2
  * {
3
3
  margin: 0;
4
4
  padding: 0;
@@ -26,28 +26,28 @@
26
26
  --sa-dropdown-radius-lg: var(--sa-radii-lg, 0.75rem);
27
27
  }
28
28
 
29
- .starasia-input-dropdown-size-sm {
29
+ .sa-input-dropdown-size-sm {
30
30
  --baseFont: var(--sa-font-size-sm, 12px);
31
31
  --height: var(--sa-h-8, 32px);
32
32
  --borderRadius: var(--sa-dropdown-radius);
33
33
  --paddingInline: var(--sa-spacing-sm, 8px);
34
34
  }
35
35
 
36
- .starasia-input-dropdown-size-md {
36
+ .sa-input-dropdown-size-md {
37
37
  --baseFont: var(--sa-font-size-md, 14px);
38
38
  --height: 38px;
39
39
  --borderRadius: var(--sa-dropdown-radius);
40
40
  --paddingInline: var(--sa-spacing-3, 12px);
41
41
  }
42
42
 
43
- .starasia-input-dropdown-size-lg {
43
+ .sa-input-dropdown-size-lg {
44
44
  --baseFont: var(--sa-font-size-lg, 16px);
45
45
  --height: var(--sa-h-12, 48px);
46
46
  --borderRadius: var(--sa-dropdown-radius-lg);
47
47
  --paddingInline: var(--sa-spacing-3, 12px);
48
48
  }
49
49
 
50
- .starasia-input-dropdown-container {
50
+ .sa-input-dropdown-container {
51
51
  position: relative;
52
52
  min-height: var(--height);
53
53
  padding-inline: var(--paddingInline);
@@ -59,22 +59,22 @@
59
59
  font-size: var(--baseFont);
60
60
  cursor: pointer;
61
61
  }
62
- .starasia-input-dropdown-container.disable {
62
+ .sa-input-dropdown-container.disable {
63
63
  background-color: var(--sa-dropdown-bg-disabled);
64
64
  cursor: not-allowed;
65
65
  pointer-events: none;
66
66
  }
67
67
 
68
- .starasia-input-dropdown-container.error {
68
+ .sa-input-dropdown-container.error {
69
69
  border-color: var(--sa-dropdown-border-error) !important;
70
70
  }
71
- .starasia-input-dropdown-container.active {
71
+ .sa-input-dropdown-container.active {
72
72
  border-color: var(--sa-dropdown-border-active);
73
73
  box-shadow: var(--sa-dropdown-shadow-focus);
74
74
  background-color: var(--sa-dropdown-bg);
75
75
  }
76
76
 
77
- .starasia-input-dropdown-preview-container {
77
+ .sa-input-dropdown-preview-container {
78
78
  display: flex;
79
79
  flex-direction: row;
80
80
  gap: var(--sa-spacing-sm, 8px);
@@ -84,7 +84,7 @@
84
84
  overflow-y: hidden;
85
85
  }
86
86
 
87
- .starasia-input-dropdown-lists-container {
87
+ .sa-input-dropdown-lists-container {
88
88
  /* position: absolute; */
89
89
  position: fixed;
90
90
  /* left: 0; */
@@ -107,16 +107,16 @@
107
107
  white-space: nowrap; */
108
108
  }
109
109
 
110
- .starasia-input-dropdown-lists-container-bottom {
110
+ .sa-input-dropdown-lists-container-bottom {
111
111
  top: 100%;
112
112
  margin-top: var(--sa-spacing-xs, 4px);
113
113
  }
114
- .starasia-input-dropdown-lists-container-top {
114
+ .sa-input-dropdown-lists-container-top {
115
115
  bottom: 100%;
116
116
  margin-bottom: var(--sa-spacing-xs, 4px);
117
117
  }
118
118
 
119
- .starasia-input-dropdown-container-dropdown-search {
119
+ .sa-input-dropdown-container-dropdown-search {
120
120
  display: flex;
121
121
  align-items: center;
122
122
  height: var(--height);
@@ -136,14 +136,14 @@
136
136
  }
137
137
  }
138
138
 
139
- .starasia-input-dropdwon-item-container {
139
+ .sa-input-dropdwon-item-container {
140
140
  display: flex;
141
141
  flex-direction: column;
142
142
  /* overflow: hidden; */
143
143
 
144
144
  /* gap: var(--sa-spacing-xs, 0.25rem); */
145
145
  }
146
- .starasia-input-dropdwon-item-container.multi {
146
+ .sa-input-dropdwon-item-container.multi {
147
147
  display: flex;
148
148
  flex-direction: column;
149
149
  gap: 8px;
@@ -152,7 +152,7 @@
152
152
  /* gap: var(--sa-spacing-xs, 0.25rem); */
153
153
  }
154
154
 
155
- .starasia-input-dropdwon-item {
155
+ .sa-input-dropdwon-item {
156
156
  /* max-height: var(--height); */
157
157
  max-height: 58px;
158
158
  box-sizing: border-box;
@@ -167,28 +167,28 @@
167
167
  overflow: hidden;
168
168
  }
169
169
 
170
- .starasia-input-dropdwon-item:hover {
170
+ .sa-input-dropdwon-item:hover {
171
171
  background-color: color-mix(in srgb, var(--sa-dropdown-brand-secondary) 21%, transparent);
172
172
  }
173
- .starasia-input-dropdwon-item.active {
173
+ .sa-input-dropdwon-item.active {
174
174
  /* color: var(--sa-dropdown-brand); */
175
175
  /* border-radius: var(--borderRadius); */
176
176
  background-color: color-mix(in srgb, var(--sa-dropdown-brand-secondary) 21%, transparent);
177
177
  /* background: var(--sa-dropdown-brand-subtle); */
178
178
  /* box-shadow: 0px 0px 0px -1px #f0f0f0; */
179
179
  }
180
- .starasia-input-dropdwon-item.highlight {
180
+ .sa-input-dropdwon-item.highlight {
181
181
  background-color: color-mix(in srgb, var(--sa-dropdown-brand-secondary) 35%, transparent);
182
182
  outline: 2px solid color-mix(in srgb, var(--sa-dropdown-brand-secondary) 40%, transparent);
183
183
  outline-offset: -2px;
184
184
  }
185
185
 
186
- .starasia-input-dropdwon-item-disable {
186
+ .sa-input-dropdwon-item-disable {
187
187
  color: var(--sa-dropdown-color-disable) !important;
188
188
  pointer-events: none;
189
189
  }
190
190
 
191
- .starasia-input-dropdown-container-preview-item {
191
+ .sa-input-dropdown-container-preview-item {
192
192
  flex: 1;
193
193
  display: flex;
194
194
  gap: var(--sa-spacing-xs, 4px);
@@ -198,7 +198,7 @@
198
198
  padding-block: 4px;
199
199
  }
200
200
 
201
- .starasia-input-dropdown-preview-item {
201
+ .sa-input-dropdown-preview-item {
202
202
  border: var(--sa-dropdown-border) solid var(--sa-dropdown-border-active);
203
203
  padding-inline: var(--paddingInline);
204
204
  border-radius: var(--borderRadius);
@@ -210,28 +210,28 @@
210
210
  align-items: center;
211
211
  gap: 2;
212
212
  }
213
- .starasia-input-dropdown-placeholder {
213
+ .sa-input-dropdown-placeholder {
214
214
  color: var(--sa-dropdown-placeholder);
215
215
  font-weight: var(--sa-font-weight-normal, 300);
216
216
  }
217
217
 
218
- .starasia-input-dropdwon-item-text {
218
+ .sa-input-dropdwon-item-text {
219
219
  color: var(--sa-dropdown-text-primary);
220
220
  /* font-size: 14px; */
221
221
  font-size: inherit;
222
222
  font-weight: 500;
223
223
  }
224
- .starasia-input-dropdwon-item-text.active {
224
+ .sa-input-dropdwon-item-text.active {
225
225
  color: var(--sa-dropdown-brand);
226
226
  }
227
227
 
228
- .starasia-input-dropdwon-item-text-description {
228
+ .sa-input-dropdwon-item-text-description {
229
229
  color: var(--sa-dropdown-text-secondary);
230
230
  /* font-size: 14px; */
231
231
  font-size: inherit;
232
232
  font-weight: 400;
233
233
  }
234
- .starasia-input-dropdwon-item-text-description.active {
234
+ .sa-input-dropdwon-item-text-description.active {
235
235
  color: var(--sa-dropdown-brand);
236
236
  }
237
237
 
@@ -311,4 +311,4 @@
311
311
  height: 100%;
312
312
  width: 100%;
313
313
  }
314
- `;function H(e){const[l,d]=t.useState(e),c=t.useRef(null),a=o=>{c.current&&!c.current.contains(o.target)&&d(!1)};return t.useEffect(()=>(document.addEventListener("click",a,!0),()=>{document.removeEventListener("click",a,!0)}),[]),{ref:c,isComponentVisible:l,setIsComponentVisible:d}}const V=({...e})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",...e,viewBox:"0 0 24 24",fill:"none",color:"var(--sa-color-gray-500, #8c8f97)",children:n.jsx("path",{d:"M4 9L12 17L20 9",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5})}),M=({...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"})]}),P=({isChecked:e})=>n.jsxs("div",{className:"checkbox-wrapper-30",children:[n.jsxs("span",{className:"checkbox",children:[n.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:e}),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"})})})]}),q=t.forwardRef(({positionDropdown:e,dropdownLists:l,isComponentVisible:d,searchAble:c,onSearch:a,value:o,handleChangeValue:u,multiSelect:p,searchValue:B,highlightedIndex:f},$)=>{const[z,N]=t.useState(0),k=t.useRef(null),g=t.useRef([]);return t.useEffect(()=>{if(k.current){const r=k.current.getBoundingClientRect();N(r.width)}},[k,d]),t.useEffect(()=>{var r;f>=0&&g.current[f]&&((r=g.current[f])==null||r.scrollIntoView({block:"nearest"}))},[f]),n.jsx(n.Fragment,{children:d?n.jsxs("div",{className:"starasia-input-dropdown-lists-container",onClick:r=>r.stopPropagation(),ref:$,children:[c?n.jsxs("div",{className:"starasia-input-dropdown-container-dropdown-search",style:{order:e=="bottom"?0:2,position:"sticky",top:0,bottom:0,zIndex:1},children:[n.jsx("div",{style:{display:"flex"},children:n.jsx(M,{strokeWidth:2,width:20})}),n.jsx("input",{onChange:r=>{a&&a(r.target.value)},value:B,autoFocus:!0,style:{width:"100%"}})]}):null,n.jsx("div",{className:`starasia-input-dropdwon-item-container ${p?"multi":""}`,ref:k,children:l.map((r,b)=>{const y=!!(o!=null&&o.find(m=>m.value===r.value));return n.jsxs("div",{className:`starasia-input-dropdwon-item ${y?"active":""} ${b===f?"highlight":""} ${r.disable?"starasia-input-dropdwon-item-disable":""}`,ref:m=>{g.current[b]=m},onClick:()=>u(r.label,r.value),children:[p?n.jsx("div",{style:{marginRight:"8px"},children:n.jsx(P,{isChecked:y})}):null,r.icon?n.jsx("div",{children:t.cloneElement(r.icon,{width:16})}):null,n.jsxs("div",{children:[n.jsx("p",{className:`starasia-input-dropdwon-item-text ${y?"active":null} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${z-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:r.label}),r.description?n.jsx("p",{className:`starasia-input-dropdwon-item-text-description ${y?"active":null} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${z-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:r.description}):null]})]},b)})})]}):null})}),T=({children:e,handleChangePosition:l})=>{const d=t.useRef(null);t.useEffect(()=>{var u;const a=()=>{if(d.current){let p=d.current.parentElement;for(;p&&!c(p);)p=p.parentElement;p&&l()}};let o=(u=d.current)==null?void 0:u.parentElement;for(;o&&!c(o);)o=o.parentElement;return o&&o.addEventListener("scroll",a),a(),()=>{o&&o.removeEventListener("scroll",a)}},[]);const c=a=>a&&(a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth);return n.jsx("div",{ref:d,children:e})},S="starasia-input-dropdown-styles";(e=>{if(!document.getElementById(S)){const l=document.createElement("style");l.id=S,l.textContent=e,document.head.appendChild(l)}})(O);const J=({dropdownLists:e,onChange:l,defaultValue:d,size:c="md",multiSelect:a,searchAble:o,iconLeft:u,placeholder:p,onSearch:B,error:f,onBlur:$,onFocus:z,disable:N,searchValue:k})=>{const g=t.useRef(),[r,b]=t.useState([]),[y,m]=t.useState(""),[v,D]=t.useState(-1),x=t.useRef(null),{isComponentVisible:C,ref:L,setIsComponentVisible:I}=H(!1),U=()=>{I(s=>!s)},W=(s,i)=>{if(!a)b([{label:s,value:i}]),l([{label:s,value:i}]),I(!1);else if(r==null?void 0:r.find(w=>w.value===i)){const w=[...r?r.filter(X=>X.value!==i):[]];b(w),l(w)}else{const w=[...r||[],{label:s,value:i}];b(w),l(w)}};t.useEffect(()=>{JSON.stringify(g.current)===JSON.stringify(d)||(g.current=d,b(g.current||[]))},[d]);const G=()=>r.length?a?r==null?void 0:r.map((s,i)=>n.jsxs("div",{className:"starasia-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:s==null?void 0:s.label},i),n.jsx(K,{onClick:()=>W(s.label,s.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:p}),E=()=>{if(L.current&&x.current){const s=window.innerHeight,i=L.current.getBoundingClientRect(),j=x.current.getBoundingClientRect(),w=i.bottom+j.height;x.current.style.left=`${i.left}px`,x.current.style.width=`${i.width}px`,w>=s-10?(x.current.style.top=`${i.top-j.height-5}px`,m("top")):(x.current.style.top=`${i.top+i.height}px`,m("bottom"))}};t.useEffect(()=>(window.addEventListener("scroll",E),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E),window.removeEventListener("resize",E)}),[]),t.useEffect(()=>{E()},[C]),t.useEffect(()=>{C||D(-1)},[C]);const Q=s=>{if(!C){(s.key==="ArrowDown"||s.key==="Enter")&&(s.preventDefault(),I(!0));return}switch(s.key){case"ArrowDown":{s.preventDefault();const i=A(e,v,1);i!==-1&&D(i);break}case"ArrowUp":{s.preventDefault();const i=A(e,v,-1);i!==-1&&D(i);break}case"Enter":{s.preventDefault(),v>=0&&e[v]&&!e[v].disable&&W(e[v].label,e[v].value);break}case"Escape":{I(!1);break}}};return n.jsx(T,{handleChangePosition:E,children:n.jsxs("div",{className:`starasia-input-dropdown-container ${N?"disable":""} starasia-input-dropdown-size-${c} ${C?"active":""} ${f?"error":""}`,ref:L,onClick:U,onKeyDown:Q,tabIndex:0,onBlur:$,onFocus:z,children:[n.jsxs("div",{className:"starasia-input-dropdown-preview-container",children:[u?n.jsx(n.Fragment,{children:t.cloneElement(u,{width:F(c),color:"var(--sa-color-gray-500, #8c8f97)",style:{color:"var(--sa-color-gray-500, #8c8f97)"}})}):null,n.jsx("div",{className:"starasia-input-dropdown-container-preview-item",children:G()}),n.jsx(V,{strokeWidth:2,width:F(c),style:{color:"var(--sa-color-gray-500, #8c8f97)"}})]}),n.jsx(q,{dropdownLists:e,handleChangeValue:W,isComponentVisible:C,positionDropdown:y,searchAble:!!o,value:r,onSearch:B,ref:x,multiSelect:a,searchValue:k,highlightedIndex:v})]})})},A=(e,l,d)=>{const c=e.length;let a=l+d;for(;a>=0&&a<c;){if(!e[a].disable)return a;a+=d}if(d===1){for(let o=0;o<c;o++)if(!e[o].disable)return o}else for(let o=c-1;o>=0;o--)if(!e[o].disable)return o;return-1},F=e=>{if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},K=e=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",...e,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})});h.Dropdown=J,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
314
+ `;function M(r){const[p,s]=d.useState(r),l=d.useRef(null),a=o=>{l.current&&!l.current.contains(o.target)&&s(!1)};return d.useEffect(()=>(document.addEventListener("click",a,!0),()=>{document.removeEventListener("click",a,!0)}),[]),{ref:l,isComponentVisible:p,setIsComponentVisible:s}}const P=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",...r,viewBox:"0 0 24 24",fill:"none",color:"var(--sa-color-gray-500, #8c8f97)",children:n.jsx("path",{d:"M4 9L12 17L20 9",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5})}),q=({...r})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...r,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),T=({isChecked:r})=>n.jsxs("div",{className:"checkbox-wrapper-30",children:[n.jsxs("span",{className:"checkbox",children:[n.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:r}),n.jsx("svg",{children:n.jsx("use",{xlinkHref:"#checkbox-30",className:"checkbox"})})]}),n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",style:{display:"none"},children:n.jsx("symbol",{id:"checkbox-30",viewBox:"0 0 22 22",children:n.jsx("path",{fill:"none",stroke:"currentColor",d:"M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"})})})]}),V=d.forwardRef(({positionDropdown:r,dropdownLists:p,isComponentVisible:s,searchAble:l,onSearch:a,value:o,handleChangeValue:k,multiSelect:w,searchValue:N,highlightedIndex:f},D)=>{const[B,I]=d.useState(0),y=d.useRef(null),z=d.useRef([]);return d.useEffect(()=>{if(y.current){const e=y.current.getBoundingClientRect();I(e.width)}},[y,s]),d.useEffect(()=>{var e;f>=0&&z.current[f]&&((e=z.current[f])==null||e.scrollIntoView({block:"nearest"}))},[f]),n.jsx(n.Fragment,{children:s?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:e=>e.stopPropagation(),ref:D,children:[l?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",style:{order:r=="bottom"?0:2,position:"sticky",top:0,bottom:0,zIndex:1},children:[n.jsx("div",{style:{display:"flex"},children:n.jsx(q,{strokeWidth:2,width:20})}),n.jsx("input",{onChange:e=>{a&&a(e.target.value)},value:N,autoFocus:!0,style:{width:"100%"}})]}):null,n.jsx("div",{className:`sa-input-dropdwon-item-container ${w?"multi":""}`,ref:y,children:p.map((e,g)=>{const c=!!(o!=null&&o.find(h=>h.value===e.value));return n.jsxs("div",{className:`sa-input-dropdwon-item ${c?"active":""} ${g===f?"highlight":""} ${e.disable?"sa-input-dropdwon-item-disable":""}`,ref:h=>{z.current[g]=h},onClick:()=>k(e.label,e.value),children:[w?n.jsx("div",{style:{marginRight:"8px"},children:n.jsx(T,{isChecked:c})}):null,e.icon?n.jsx("div",{children:d.cloneElement(e.icon,{width:16})}):null,n.jsxs("div",{children:[n.jsx("p",{className:`sa-input-dropdwon-item-text ${c?"active":null} ${e.disable?"sa-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${B-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:e.label}),e.description?n.jsx("p",{className:`sa-input-dropdwon-item-text-description ${c?"active":null} ${e.disable?"sa-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${B-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:e.description}):null]})]},g)})})]}):null})}),J=({children:r,handleChangePosition:p})=>{const s=d.useRef(null);d.useEffect(()=>{var k;const a=()=>{if(s.current){let w=s.current.parentElement;for(;w&&!l(w);)w=w.parentElement;w&&p()}};let o=(k=s.current)==null?void 0:k.parentElement;for(;o&&!l(o);)o=o.parentElement;return o&&o.addEventListener("scroll",a),a(),()=>{o&&o.removeEventListener("scroll",a)}},[]);const l=a=>a&&(a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth);return n.jsx("div",{ref:s,children:r})},j="sa-input-dropdown-styles";(r=>{if(!document.getElementById(j)){const p=document.createElement("style");p.id=j,p.textContent=r,document.head.appendChild(p)}})(H);const K=({dropdownLists:r,onChange:p,defaultValue:s,value:l,size:a="md",multiSelect:o,searchAble:k,iconLeft:w,placeholder:N,onSearch:f,error:D,onBlur:B,onFocus:I,disable:y,searchValue:z})=>{const e=l!==void 0,g=d.useRef(),[c,h]=d.useState(e?l||[]:s||[]),[G,O]=d.useState(""),[b,L]=d.useState(-1),x=d.useRef(null),{isComponentVisible:m,ref:W,setIsComponentVisible:$}=M(!1),Q=()=>{$(t=>!t)},S=(t,i)=>{if(o)if(c==null?void 0:c.find(v=>v.value===i)){const v=c.filter(Z=>Z.value!==i);e||h(v),p(v)}else{const v=[...c,{label:t,value:i}];e||h(v),p(v)}else{const E=[{label:t,value:i}];e||h(E),p(E),$(!1)}};d.useEffect(()=>{e&&h(l||[])},[l]),d.useEffect(()=>{e||JSON.stringify(g.current)===JSON.stringify(s)||(g.current=s,h(g.current||[]))},[s]);const X=()=>c.length?o?c==null?void 0:c.map((t,i)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:t==null?void 0:t.label},i),n.jsx(U,{onClick:()=>S(t.label,t.value)})]})):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:N}),C=()=>{if(W.current&&x.current){const t=window.innerHeight,i=W.current.getBoundingClientRect(),E=x.current.getBoundingClientRect(),v=i.bottom+E.height;x.current.style.left=`${i.left}px`,x.current.style.width=`${i.width}px`,v>=t-10?(x.current.style.top=`${i.top-E.height-5}px`,O("top")):(x.current.style.top=`${i.top+i.height}px`,O("bottom"))}};d.useEffect(()=>(window.addEventListener("scroll",C),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C),window.removeEventListener("resize",C)}),[]),d.useEffect(()=>{C()},[m]),d.useEffect(()=>{m||L(-1)},[m]);const Y=t=>{if(!m){(t.key==="ArrowDown"||t.key==="Enter")&&(t.preventDefault(),$(!0));return}switch(t.key){case"ArrowDown":{t.preventDefault();const i=A(r,b,1);i!==-1&&L(i);break}case"ArrowUp":{t.preventDefault();const i=A(r,b,-1);i!==-1&&L(i);break}case"Enter":{t.preventDefault(),b>=0&&r[b]&&!r[b].disable&&S(r[b].label,r[b].value);break}case"Escape":{$(!1);break}}};return n.jsx(J,{handleChangePosition:C,children:n.jsxs("div",{className:`sa-input-dropdown-container ${y?"disable":""} sa-input-dropdown-size-${a} ${m?"active":""} ${D?"error":""}`,ref:W,onClick:Q,onKeyDown:Y,tabIndex:0,onBlur:B,onFocus:I,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[w?n.jsx(n.Fragment,{children:d.cloneElement(w,{width:F(a),color:"var(--sa-color-gray-500, #8c8f97)",style:{color:"var(--sa-color-gray-500, #8c8f97)"}})}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:X()}),n.jsx(P,{strokeWidth:2,width:F(a),style:{color:"var(--sa-color-gray-500, #8c8f97)"}})]}),n.jsx(V,{dropdownLists:r,handleChangeValue:S,isComponentVisible:m,positionDropdown:G,searchAble:!!k,value:c,onSearch:f,ref:x,multiSelect:o,searchValue:z,highlightedIndex:b})]})})},A=(r,p,s)=>{const l=r.length;let a=p+s;for(;a>=0&&a<l;){if(!r[a].disable)return a;a+=s}if(s===1){for(let o=0;o<l;o++)if(!r[o].disable)return o}else for(let o=l-1;o>=0;o--)if(!r[o].disable)return o;return-1},F=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},U=r=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",...r,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})});u.Dropdown=K,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
@@ -16,6 +16,10 @@ export interface IDropdown {
16
16
  label: string;
17
17
  value: string;
18
18
  }[];
19
+ value?: {
20
+ label: string;
21
+ value: string;
22
+ }[];
19
23
  size?: "sm" | "md" | "lg";
20
24
  error?: boolean;
21
25
  multiSelect?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "2.0.2",
3
+ "version": "3.1.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",