@starasia/input 4.1.0 → 4.2.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,5 +1,5 @@
1
1
  import { InputSize, InputStatus } from "./types";
2
- export declare const renderIconSize: (size: InputSize | undefined) => 18 | 16;
2
+ export declare const renderIconSize: (size: InputSize | undefined) => 18 | 14 | 16;
3
3
  export declare const renderIconColor: (status: InputStatus, disabled?: boolean) => string;
4
4
  export declare const renderColorLeftIcon: (status: InputStatus, disabled?: boolean) => string;
5
5
  export declare const renderColorRightIcon: (status: InputStatus, disabled?: boolean) => string;
package/dist/input.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx as s, jsxs as o, Fragment as Sn } from "react/jsx-runtime";
1
+ import { jsx as a, jsxs as o, Fragment as Sn } from "react/jsx-runtime";
2
2
  import Z, { forwardRef as mn, useState as I, useRef as R, useEffect as D, useImperativeHandle as En, useLayoutEffect as pn } from "react";
3
3
  const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
4
 
@@ -90,6 +90,8 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
90
90
  line-height: normal;
91
91
  margin: 0;
92
92
  }
93
+ .sa-tf-size-xs .sa-tf-label,
94
+ .sa-tf-size-xs .sa-tf-label-inside-text,
93
95
  .sa-tf-size-sm .sa-tf-label,
94
96
  .sa-tf-size-sm .sa-tf-label-inside-text {
95
97
  font-size: 12px;
@@ -127,6 +129,9 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
127
129
  .sa-tf-error {
128
130
  color: var(--sa-input-text-error);
129
131
  }
132
+ .sa-tf-size-xs .sa-tf-desc-top,
133
+ .sa-tf-size-xs .sa-tf-helper,
134
+ .sa-tf-size-xs .sa-tf-error,
130
135
  .sa-tf-size-sm .sa-tf-desc-top,
131
136
  .sa-tf-size-sm .sa-tf-helper,
132
137
  .sa-tf-size-sm .sa-tf-error {
@@ -157,6 +162,12 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
157
162
  }
158
163
 
159
164
  /* sizes */
165
+ .sa-tf-size-xs .sa-tf-box {
166
+ min-height: 28px;
167
+ }
168
+ .sa-tf-size-xs .sa-tf-box-content {
169
+ padding-block: 4px;
170
+ }
160
171
  .sa-tf-size-sm .sa-tf-box {
161
172
  min-height: 32px;
162
173
  }
@@ -357,6 +368,7 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
357
368
  .sa-tf-addon-right {
358
369
  border-left: 1px solid var(--sa-input-border-subtle);
359
370
  }
371
+ .sa-tf-size-xs .sa-tf-addon,
360
372
  .sa-tf-size-sm .sa-tf-addon {
361
373
  font-size: 12px;
362
374
  line-height: 18px;
@@ -383,6 +395,7 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
383
395
  line-height: 21px;
384
396
  color: var(--sa-input-text-primary);
385
397
  }
398
+ .sa-tf-size-xs .sa-tf-input,
386
399
  .sa-tf-size-sm .sa-tf-input {
387
400
  font-size: 12px;
388
401
  line-height: 18px;
@@ -436,6 +449,7 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
436
449
  overflow: hidden;
437
450
  text-overflow: ellipsis;
438
451
  }
452
+ .sa-tf-size-xs .sa-tf-placeholder,
439
453
  .sa-tf-size-sm .sa-tf-placeholder {
440
454
  font-size: 12px;
441
455
  line-height: 18px;
@@ -493,6 +507,7 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
493
507
  .sa-tf-label-inside.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
494
508
  transform: translateY(11px);
495
509
  }
510
+ .sa-tf-label-inside.sa-tf-size-xs.sa-tf-floating .sa-tf-box-content > .sa-tf-icon,
496
511
  .sa-tf-label-inside.sa-tf-size-sm.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
497
512
  transform: translateY(9px);
498
513
  }
@@ -521,6 +536,7 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
521
536
  .sa-tf-label-inside .sa-tf-inside-label-row label {
522
537
  pointer-events: auto;
523
538
  }
539
+ .sa-tf-label-inside.sa-tf-size-xs .sa-tf-inside-label-row,
524
540
  .sa-tf-label-inside.sa-tf-size-sm .sa-tf-inside-label-row {
525
541
  font-size: 12px;
526
542
  line-height: 18px;
@@ -593,12 +609,12 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
593
609
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
594
610
  min-height: 80px;
595
611
  }
596
- `, z = (n) => n === "lg" || n === "xl" ? 18 : 16, J = {
612
+ `, z = (n) => n === "lg" || n === "xl" ? 18 : n === "xs" ? 14 : 16, J = {
597
613
  default: "var(--sa-color-gray-800, #505258)",
598
614
  error: "var(--sa-text-error, #a4133c)",
599
615
  success: "var(--sa-text-success, #208958)",
600
616
  disable: "var(--sa-icon-disable, #181a198f)"
601
- }, gn = (n, e) => e ? J.disable : J[n] ?? J.default;
617
+ }, xn = (n, e) => e ? J.disable : J[n] ?? J.default;
602
618
  function Fn(n) {
603
619
  return Number(n.replace(/\./g, ""));
604
620
  }
@@ -616,27 +632,27 @@ function Dn(n, e) {
616
632
  return n.length;
617
633
  }
618
634
  const Tn = mn(
619
- ({ options: n, value: e, setValue: r, isComponentVisible: l, onOptionChange: d }, c) => {
620
- const [x, T] = I([]), f = R(null), u = () => {
621
- if (c != null && c.current && f.current) {
622
- const g = window.innerHeight, b = c == null ? void 0 : c.current.getBoundingClientRect(), m = f.current.getBoundingClientRect(), v = b.bottom + m.height;
623
- f.current.style.left = `${b.left}px`, f.current.style.width = `${b.width}px`, v >= g - 10 ? f.current.style.top = `${b.top - m.height - 5}px` : f.current.style.top = `${b.top + b.height}px`;
635
+ ({ options: n, value: e, setValue: r, isComponentVisible: l, onOptionChange: d }, f) => {
636
+ const [h, T] = I([]), c = R(null), u = () => {
637
+ if (f != null && f.current && c.current) {
638
+ const x = window.innerHeight, b = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(), v = b.bottom + m.height;
639
+ c.current.style.left = `${b.left}px`, c.current.style.width = `${b.width}px`, v >= x - 10 ? c.current.style.top = `${b.top - m.height - 5}px` : c.current.style.top = `${b.top + b.height}px`;
624
640
  }
625
641
  };
626
642
  return D(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
627
643
  window.removeEventListener("scroll", u), window.removeEventListener("resize", u);
628
- }), [c, f]), D(() => {
644
+ }), [f, c]), D(() => {
629
645
  u();
630
646
  }, [l]), D(() => {
631
647
  T(
632
648
  (n == null ? void 0 : n.filter(
633
- (g) => g.toLowerCase().startsWith(e.toLowerCase())
649
+ (x) => x.toLowerCase().startsWith(e.toLowerCase())
634
650
  )) || []
635
651
  );
636
- }, [e, n]), /* @__PURE__ */ s(
652
+ }, [e, n]), /* @__PURE__ */ a(
637
653
  "div",
638
654
  {
639
- ref: f,
655
+ ref: c,
640
656
  style: {
641
657
  position: "fixed",
642
658
  padding: "8px",
@@ -647,8 +663,8 @@ const Tn = mn(
647
663
  overflow: "auto",
648
664
  zIndex: 5e4
649
665
  },
650
- children: x == null ? void 0 : x.map(
651
- (g) => Vn(g, e, r, d)
666
+ children: h == null ? void 0 : h.map(
667
+ (x) => Vn(x, e, r, d)
652
668
  )
653
669
  }
654
670
  );
@@ -670,24 +686,24 @@ const Tn = mn(
670
686
  },
671
687
  children: [
672
688
  n.slice(0, d),
673
- /* @__PURE__ */ s("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + e.length) }),
689
+ /* @__PURE__ */ a("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + e.length) }),
674
690
  n.slice(d + e.length)
675
691
  ]
676
692
  }
677
693
  );
678
694
  };
679
695
  function On(n) {
680
- const [e, r] = I(n), l = R(null), d = (c) => {
681
- l.current && !l.current.contains(c.target) && r(!1);
696
+ const [e, r] = I(n), l = R(null), d = (f) => {
697
+ l.current && !l.current.contains(f.target) && r(!1);
682
698
  };
683
699
  return D(() => (document.addEventListener("click", d, !0), () => {
684
700
  document.removeEventListener("click", d, !0);
685
701
  }), []), { ref: l, isComponentVisible: e, setIsComponentVisible: r };
686
702
  }
687
- const hn = "sa-input-styles", jn = (n) => {
688
- if (!(typeof document > "u") && !document.getElementById(hn)) {
703
+ const gn = "sa-input-styles", jn = (n) => {
704
+ if (!(typeof document > "u") && !document.getElementById(gn)) {
689
705
  const e = document.createElement("style");
690
- e.id = hn, e.textContent = n, document.head.appendChild(e);
706
+ e.id = gn, e.textContent = n, document.head.appendChild(e);
691
707
  }
692
708
  };
693
709
  jn($n);
@@ -699,8 +715,8 @@ const Yn = (n) => /* @__PURE__ */ o(
699
715
  xmlns: "http://www.w3.org/2000/svg",
700
716
  ...n,
701
717
  children: [
702
- /* @__PURE__ */ s("circle", { cx: "8", cy: "8", r: "6.5", stroke: "currentColor", strokeWidth: "1.2" }),
703
- /* @__PURE__ */ s(
718
+ /* @__PURE__ */ a("circle", { cx: "8", cy: "8", r: "6.5", stroke: "currentColor", strokeWidth: "1.2" }),
719
+ /* @__PURE__ */ a(
704
720
  "path",
705
721
  {
706
722
  d: "M5.2 8.2l1.8 1.8 3.8-4.2",
@@ -720,8 +736,8 @@ const Yn = (n) => /* @__PURE__ */ o(
720
736
  xmlns: "http://www.w3.org/2000/svg",
721
737
  ...n,
722
738
  children: [
723
- /* @__PURE__ */ s("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
724
- /* @__PURE__ */ s(
739
+ /* @__PURE__ */ a("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
740
+ /* @__PURE__ */ a(
725
741
  "path",
726
742
  {
727
743
  d: "M5.5 5.5l5 5M10.5 5.5l-5 5",
@@ -735,15 +751,15 @@ const Yn = (n) => /* @__PURE__ */ o(
735
751
  ), Wn = mn(
736
752
  (n, e) => {
737
753
  const {
738
- size: r = "md",
754
+ size: r = "sm",
739
755
  variant: l = "outline",
740
756
  status: d = "default",
741
- label: c,
742
- labelPosition: x = "outside-top",
757
+ label: f,
758
+ labelPosition: h = "outside-top",
743
759
  required: T,
744
- optional: f,
760
+ optional: c,
745
761
  description: u,
746
- helperText: g,
762
+ helperText: x,
747
763
  errorText: b,
748
764
  leftIcon: m,
749
765
  rightIcon: v,
@@ -758,14 +774,14 @@ const Yn = (n) => /* @__PURE__ */ o(
758
774
  onOptionChange: j,
759
775
  clearable: wn = !0,
760
776
  onClear: Y,
761
- ...a
762
- } = n, A = a.value !== void 0, [W, y] = I(() => {
763
- const t = a.value !== void 0 ? String(a.value ?? "") : String(a.defaultValue ?? "");
777
+ ...s
778
+ } = n, A = s.value !== void 0, [W, y] = I(() => {
779
+ const t = s.value !== void 0 ? String(s.value ?? "") : String(s.defaultValue ?? "");
764
780
  return S ? Q(t) : t;
765
- }), [tn, en] = I(!1), [yn, an] = I(""), k = R(null), C = R(null);
781
+ }), [tn, en] = I(!1), [yn, sn] = I(""), k = R(null), C = R(null);
766
782
  En(e, () => C.current);
767
- const sn = R(
768
- a.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
783
+ const an = R(
784
+ s.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
769
785
  ), {
770
786
  isComponentVisible: rn,
771
787
  ref: _,
@@ -774,9 +790,9 @@ const Yn = (n) => /* @__PURE__ */ o(
774
790
  pn(() => {
775
791
  if (!A)
776
792
  return;
777
- const t = a.value === void 0 || a.value === null ? "" : String(a.value), i = S ? Q(t) : t;
793
+ const t = s.value === void 0 || s.value === null ? "" : String(s.value), i = S ? Q(t) : t;
778
794
  y((p) => p === i ? p : i);
779
- }, [a.value, S, A]), pn(() => {
795
+ }, [s.value, S, A]), pn(() => {
780
796
  if (k.current === null)
781
797
  return;
782
798
  const t = C.current, i = k.current;
@@ -786,16 +802,16 @@ const Yn = (n) => /* @__PURE__ */ o(
786
802
  } catch {
787
803
  }
788
804
  }, [W]);
789
- const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || a.disabled, M = w ? "disable" : d, P = x === "inside", zn = P && ($ || tn), H = [
805
+ const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || s.disabled, M = w ? "disable" : d, P = h === "inside", zn = P && ($ || tn), H = [
790
806
  "sa-tf",
791
807
  `sa-tf-variant-${l}`,
792
808
  `sa-tf-size-${r}`,
793
809
  `sa-tf-status-${M}`,
794
- `sa-tf-label-${x}`,
810
+ `sa-tf-label-${h}`,
795
811
  tn ? "sa-tf-focused" : "",
796
812
  w ? "sa-tf-disabled" : "",
797
813
  zn ? "sa-tf-floating" : "",
798
- c ? "" : "sa-tf-no-label",
814
+ f ? "" : "sa-tf-no-label",
799
815
  vn ? "sa-tf-fullwidth" : ""
800
816
  ].filter(Boolean).join(" "), Cn = () => {
801
817
  var t;
@@ -804,39 +820,39 @@ const Yn = (n) => /* @__PURE__ */ o(
804
820
  var un, bn;
805
821
  if (!S) {
806
822
  const F = t.target.selectionStart;
807
- F !== null && (k.current = F), y(t.target.value), (un = a.onChange) == null || un.call(a, t);
823
+ F !== null && (k.current = F), y(t.target.value), (un = s.onChange) == null || un.call(s, t);
808
824
  return;
809
825
  }
810
826
  const i = t.target.value;
811
- let p = i, h = t.target.selectionStart ?? i.length;
827
+ let p = i, g = t.target.selectionStart ?? i.length;
812
828
  if (yn === "Backspace") {
813
829
  const F = W.replace(/\D/g, ""), Ln = i.replace(/\D/g, "");
814
- F.length === Ln.length && h > 0 && (p = i.slice(0, h - 1) + i.slice(h), h -= 1);
830
+ F.length === Ln.length && g > 0 && (p = i.slice(0, g - 1) + i.slice(g), g -= 1);
815
831
  }
816
- const G = Q(p), Rn = p.slice(0, h).replace(/\D/g, "").length, Bn = Dn(G, Rn);
817
- k.current = Bn, y(G), (bn = a.onChange) == null || bn.call(a, {
832
+ const G = Q(p), Rn = p.slice(0, g).replace(/\D/g, "").length, Bn = Dn(G, Rn);
833
+ k.current = Bn, y(G), (bn = s.onChange) == null || bn.call(s, {
818
834
  ...t,
819
835
  target: {
820
836
  ...t.target,
821
837
  value: String(Fn(G)),
822
838
  name: t.target.name
823
839
  }
824
- }), an("");
825
- }, q = (t) => c ? /* @__PURE__ */ o("div", { className: t, children: [
826
- /* @__PURE__ */ s(
840
+ }), sn("");
841
+ }, q = (t) => f ? /* @__PURE__ */ o("div", { className: t, children: [
842
+ /* @__PURE__ */ a(
827
843
  "label",
828
844
  {
829
- htmlFor: sn.current,
845
+ htmlFor: an.current,
830
846
  style: { cursor: w ? "not-allowed" : "pointer" },
831
- children: c
847
+ children: f
832
848
  }
833
849
  ),
834
- f ? /* @__PURE__ */ s("span", { className: "sa-tf-optional", children: "Optional" }) : null,
835
- T ? /* @__PURE__ */ s("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
850
+ c ? /* @__PURE__ */ a("span", { className: "sa-tf-optional", children: "Optional" }) : null,
851
+ T ? /* @__PURE__ */ a("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
836
852
  ] }) : null, K = /* @__PURE__ */ o(Sn, { children: [
837
- g ? /* @__PURE__ */ s("p", { className: "sa-tf-helper", children: g }) : null,
838
- b && d === "error" ? /* @__PURE__ */ s("p", { className: "sa-tf-error", children: b }) : null
839
- ] }), U = (t, i) => /* @__PURE__ */ s(
853
+ x ? /* @__PURE__ */ a("p", { className: "sa-tf-helper", children: x }) : null,
854
+ b && d === "error" ? /* @__PURE__ */ a("p", { className: "sa-tf-error", children: b }) : null
855
+ ] }), U = (t, i) => /* @__PURE__ */ a(
840
856
  "span",
841
857
  {
842
858
  className: `sa-tf-icon${i ? " sa-tf-icon-clickable" : ""}`,
@@ -844,13 +860,13 @@ const Yn = (n) => /* @__PURE__ */ o(
844
860
  children: Z.cloneElement(t, {
845
861
  width: z(r),
846
862
  height: z(r),
847
- color: gn(M, w),
848
- style: { color: gn(M, w) }
863
+ color: xn(M, w),
864
+ style: { color: xn(M, w) }
849
865
  })
850
866
  }
851
867
  ), on = () => {
852
868
  var i;
853
- return v == null ? null : !Z.isValidElement(v) || ((i = v.type) == null ? void 0 : i.__saRaw) === !0 ? /* @__PURE__ */ s(
869
+ return v == null ? null : !Z.isValidElement(v) || ((i = v.type) == null ? void 0 : i.__saRaw) === !0 ? /* @__PURE__ */ a(
854
870
  "span",
855
871
  {
856
872
  className: `sa-tf-icon${V ? " sa-tf-icon-clickable" : ""}`,
@@ -858,13 +874,13 @@ const Yn = (n) => /* @__PURE__ */ o(
858
874
  children: v
859
875
  }
860
876
  ) : U(v, V);
861
- }, ln = d === "success" ? /* @__PURE__ */ s("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ s(
877
+ }, ln = d === "success" ? /* @__PURE__ */ a("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ a(
862
878
  Yn,
863
879
  {
864
880
  width: z(r),
865
881
  height: z(r)
866
882
  }
867
- ) }) : null, dn = wn && !w ? /* @__PURE__ */ s(
883
+ ) }) : null, dn = wn && !w ? /* @__PURE__ */ a(
868
884
  "button",
869
885
  {
870
886
  type: "button",
@@ -876,16 +892,16 @@ const Yn = (n) => /* @__PURE__ */ o(
876
892
  var p;
877
893
  t.stopPropagation(), A || y("");
878
894
  const i = {
879
- target: { value: "", name: a.name },
880
- currentTarget: { value: "", name: a.name }
895
+ target: { value: "", name: s.name },
896
+ currentTarget: { value: "", name: s.name }
881
897
  };
882
- (p = a.onChange) == null || p.call(a, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
883
- var h;
884
- return (h = C.current) == null ? void 0 : h.focus();
898
+ (p = s.onChange) == null || p.call(s, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
899
+ var g;
900
+ return (g = C.current) == null ? void 0 : g.focus();
885
901
  });
886
902
  },
887
903
  onMouseDown: (t) => t.preventDefault(),
888
- children: /* @__PURE__ */ s(
904
+ children: /* @__PURE__ */ a(
889
905
  An,
890
906
  {
891
907
  width: z(r),
@@ -893,34 +909,34 @@ const Yn = (n) => /* @__PURE__ */ o(
893
909
  }
894
910
  )
895
911
  }
896
- ) : null, In = !$ && !!a.placeholder && !!O, cn = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
897
- /* @__PURE__ */ s(
912
+ ) : null, In = !$ && !!s.placeholder && !!O, fn = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
913
+ /* @__PURE__ */ a(
898
914
  "input",
899
915
  {
900
- ...a,
901
- id: sn.current,
916
+ ...s,
917
+ id: an.current,
902
918
  ref: C,
903
919
  className: "sa-tf-input",
904
920
  disabled: w,
905
- placeholder: O ? "" : a.placeholder,
921
+ placeholder: O ? "" : s.placeholder,
906
922
  value: N,
907
923
  onFocus: (t) => {
908
924
  var i;
909
- en(!0), kn(!0), (i = a.onFocus) == null || i.call(a, t);
925
+ en(!0), kn(!0), (i = s.onFocus) == null || i.call(s, t);
910
926
  },
911
927
  onBlur: (t) => {
912
928
  var i;
913
- en(!1), (i = a.onBlur) == null || i.call(a, t);
929
+ en(!1), (i = s.onBlur) == null || i.call(s, t);
914
930
  },
915
931
  onKeyDown: (t) => {
916
932
  var i;
917
- t.key === "Backspace" && an(t.key), (i = a.onKeyDown) == null || i.call(a, t);
933
+ t.key === "Backspace" && sn(t.key), (i = s.onKeyDown) == null || i.call(s, t);
918
934
  },
919
935
  onChange: Nn
920
936
  }
921
937
  ),
922
- In ? _n(a.placeholder, O) : null
923
- ] }), fn = N && rn && (E != null && E.length) ? /* @__PURE__ */ s(
938
+ In ? _n(s.placeholder, O) : null
939
+ ] }), cn = N && rn && (E != null && E.length) ? /* @__PURE__ */ a(
924
940
  Tn,
925
941
  {
926
942
  options: E,
@@ -939,37 +955,37 @@ const Yn = (n) => /* @__PURE__ */ o(
939
955
  ref: _,
940
956
  onClick: Cn,
941
957
  children: [
942
- B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
958
+ B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
943
959
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
944
960
  m ? U(m, nn) : null,
945
961
  /* @__PURE__ */ o("div", { className: "sa-tf-inside-stack", children: [
946
962
  q("sa-tf-inside-label-row"),
947
- /* @__PURE__ */ s("div", { className: "sa-tf-inside-row", children: cn })
963
+ /* @__PURE__ */ a("div", { className: "sa-tf-inside-row", children: fn })
948
964
  ] }),
949
965
  dn,
950
966
  ln,
951
967
  on()
952
968
  ] }),
953
- L ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
954
- fn
969
+ L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
970
+ cn
955
971
  ]
956
972
  }
957
973
  ) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: _, children: [
958
- B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
974
+ B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
959
975
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
960
976
  m ? U(m, nn) : null,
961
- cn,
977
+ fn,
962
978
  dn,
963
979
  ln,
964
980
  on()
965
981
  ] }),
966
- L ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
967
- fn
982
+ L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
983
+ cn
968
984
  ] });
969
- return x === "outside-left" ? /* @__PURE__ */ o("div", { className: H, children: [
985
+ return h === "outside-left" ? /* @__PURE__ */ o("div", { className: H, children: [
970
986
  /* @__PURE__ */ o("div", { className: "sa-tf-label-col", children: [
971
987
  q("sa-tf-label"),
972
- u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null
988
+ u ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: u }) : null
973
989
  ] }),
974
990
  /* @__PURE__ */ o("div", { className: "sa-tf-input-col", children: [
975
991
  X,
@@ -980,7 +996,7 @@ const Yn = (n) => /* @__PURE__ */ o(
980
996
  K
981
997
  ] }) : /* @__PURE__ */ o("div", { className: H, children: [
982
998
  q("sa-tf-label"),
983
- u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null,
999
+ u ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: u }) : null,
984
1000
  X,
985
1001
  K
986
1002
  ] });
@@ -989,11 +1005,11 @@ const Yn = (n) => /* @__PURE__ */ o(
989
1005
  if (!n)
990
1006
  return null;
991
1007
  if (!e)
992
- return /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n });
1008
+ return /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n });
993
1009
  const r = n.toLowerCase().indexOf(e.toLowerCase());
994
- return r === -1 ? /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ o("p", { className: "sa-tf-placeholder", children: [
1010
+ return r === -1 ? /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ o("p", { className: "sa-tf-placeholder", children: [
995
1011
  n.slice(0, r),
996
- /* @__PURE__ */ s("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + e.length) }),
1012
+ /* @__PURE__ */ a("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + e.length) }),
997
1013
  n.slice(r + e.length)
998
1014
  ] });
999
1015
  };
@@ -1029,18 +1045,18 @@ const Mn = `.sa-kbd {
1029
1045
  font-size: var(--sa-font-size-sm, 12px);
1030
1046
  user-select: none;
1031
1047
  }
1032
- `, xn = "sa-kbd-styles", Pn = (n) => {
1033
- if (!(typeof document > "u") && !document.getElementById(xn)) {
1048
+ `, hn = "sa-kbd-styles", Pn = (n) => {
1049
+ if (!(typeof document > "u") && !document.getElementById(hn)) {
1034
1050
  const e = document.createElement("style");
1035
- e.id = xn, e.textContent = n, document.head.appendChild(e);
1051
+ e.id = hn, e.textContent = n, document.head.appendChild(e);
1036
1052
  }
1037
1053
  };
1038
1054
  Pn(Mn);
1039
1055
  function Hn({ keys: n, separator: e, className: r, ...l }) {
1040
- return /* @__PURE__ */ s("span", { className: `sa-kbd${r ? ` ${r}` : ""}`, ...l, children: n.map((d, c) => /* @__PURE__ */ o(Z.Fragment, { children: [
1041
- c > 0 && e != null ? /* @__PURE__ */ s("span", { className: "sa-kbd-sep", "aria-hidden": "true", children: e }) : null,
1042
- /* @__PURE__ */ s("kbd", { className: "sa-kbd-key", children: d })
1043
- ] }, c)) });
1056
+ return /* @__PURE__ */ a("span", { className: `sa-kbd${r ? ` ${r}` : ""}`, ...l, children: n.map((d, f) => /* @__PURE__ */ o(Z.Fragment, { children: [
1057
+ f > 0 && e != null ? /* @__PURE__ */ a("span", { className: "sa-kbd-sep", "aria-hidden": "true", children: e }) : null,
1058
+ /* @__PURE__ */ a("kbd", { className: "sa-kbd-key", children: d })
1059
+ ] }, f)) });
1044
1060
  }
1045
1061
  Hn.__saRaw = !0;
1046
1062
  export {
package/dist/input.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(b,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):(b=typeof globalThis<"u"?globalThis:b||self,n(b.Input={},b.jsxRuntime,b.React))})(this,function(b,n,o){"use strict";const gn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ (function(b,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):(b=typeof globalThis<"u"?globalThis:b||self,n(b.Input={},b.jsxRuntime,b.React))})(this,function(b,n,o){"use strict";const hn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
2
2
 
3
3
  :root {
4
4
  /* Layer 3 — references Layer 2 semantic tokens */
@@ -88,6 +88,8 @@
88
88
  line-height: normal;
89
89
  margin: 0;
90
90
  }
91
+ .sa-tf-size-xs .sa-tf-label,
92
+ .sa-tf-size-xs .sa-tf-label-inside-text,
91
93
  .sa-tf-size-sm .sa-tf-label,
92
94
  .sa-tf-size-sm .sa-tf-label-inside-text {
93
95
  font-size: 12px;
@@ -125,6 +127,9 @@
125
127
  .sa-tf-error {
126
128
  color: var(--sa-input-text-error);
127
129
  }
130
+ .sa-tf-size-xs .sa-tf-desc-top,
131
+ .sa-tf-size-xs .sa-tf-helper,
132
+ .sa-tf-size-xs .sa-tf-error,
128
133
  .sa-tf-size-sm .sa-tf-desc-top,
129
134
  .sa-tf-size-sm .sa-tf-helper,
130
135
  .sa-tf-size-sm .sa-tf-error {
@@ -155,6 +160,12 @@
155
160
  }
156
161
 
157
162
  /* sizes */
163
+ .sa-tf-size-xs .sa-tf-box {
164
+ min-height: 28px;
165
+ }
166
+ .sa-tf-size-xs .sa-tf-box-content {
167
+ padding-block: 4px;
168
+ }
158
169
  .sa-tf-size-sm .sa-tf-box {
159
170
  min-height: 32px;
160
171
  }
@@ -355,6 +366,7 @@
355
366
  .sa-tf-addon-right {
356
367
  border-left: 1px solid var(--sa-input-border-subtle);
357
368
  }
369
+ .sa-tf-size-xs .sa-tf-addon,
358
370
  .sa-tf-size-sm .sa-tf-addon {
359
371
  font-size: 12px;
360
372
  line-height: 18px;
@@ -381,6 +393,7 @@
381
393
  line-height: 21px;
382
394
  color: var(--sa-input-text-primary);
383
395
  }
396
+ .sa-tf-size-xs .sa-tf-input,
384
397
  .sa-tf-size-sm .sa-tf-input {
385
398
  font-size: 12px;
386
399
  line-height: 18px;
@@ -434,6 +447,7 @@
434
447
  overflow: hidden;
435
448
  text-overflow: ellipsis;
436
449
  }
450
+ .sa-tf-size-xs .sa-tf-placeholder,
437
451
  .sa-tf-size-sm .sa-tf-placeholder {
438
452
  font-size: 12px;
439
453
  line-height: 18px;
@@ -491,6 +505,7 @@
491
505
  .sa-tf-label-inside.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
492
506
  transform: translateY(11px);
493
507
  }
508
+ .sa-tf-label-inside.sa-tf-size-xs.sa-tf-floating .sa-tf-box-content > .sa-tf-icon,
494
509
  .sa-tf-label-inside.sa-tf-size-sm.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
495
510
  transform: translateY(9px);
496
511
  }
@@ -519,6 +534,7 @@
519
534
  .sa-tf-label-inside .sa-tf-inside-label-row label {
520
535
  pointer-events: auto;
521
536
  }
537
+ .sa-tf-label-inside.sa-tf-size-xs .sa-tf-inside-label-row,
522
538
  .sa-tf-label-inside.sa-tf-size-sm .sa-tf-inside-label-row {
523
539
  font-size: 12px;
524
540
  line-height: 18px;
@@ -591,7 +607,7 @@
591
607
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
592
608
  min-height: 80px;
593
609
  }
594
- `,k=t=>t==="lg"||t==="xl"?18:16,F={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"var(--sa-icon-disable, #181a198f)"},Q=(t,s)=>s?F.disable:F[t]??F.default;function xn(t){return Number(t.replace(/\./g,""))}function T(t){let s=t.replace(/[^\d]/g,"");return s=s.replace(/^0+(?=\d)/,""),s.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function vn(t,s){if(s<=0)return 0;let i=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(i+=1,i===s))return l+1;return t.length}const mn=o.forwardRef(({options:t,value:s,setValue:i,isComponentVisible:l,onOptionChange:d},f)=>{const[v,D]=o.useState([]),c=o.useRef(null),u=()=>{if(f!=null&&f.current&&c.current){const g=window.innerHeight,p=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),w=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,w>=g-10?c.current.style.top=`${p.top-m.height-5}px`:c.current.style.top=`${p.top+p.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",u),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u),window.removeEventListener("resize",u)}),[f,c]),o.useEffect(()=>{u()},[l]),o.useEffect(()=>{D((t==null?void 0:t.filter(g=>g.toLowerCase().startsWith(s.toLowerCase())))||[])},[s,t]),n.jsx("div",{ref:c,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",borderRadius:"8px",background:"white",overflow:"auto",zIndex:5e4},children:v==null?void 0:v.map(g=>wn(g,s,i,d))})}),wn=(t,s,i,l)=>{const d=t.toLowerCase().indexOf(s.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{i(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+s.length)}),t.slice(d+s.length)]})};function yn(t){const[s,i]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&i(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:s,setIsComponentVisible:i}}const Z="sa-input-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(Z)){const s=document.createElement("style");s.id=Z,s.textContent=t,document.head.appendChild(s)}})(gn);const kn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.5",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.2 8.2l1.8 1.8 3.8-4.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),zn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),R=o.forwardRef((t,s)=>{const{size:i="md",variant:l="outline",status:d="default",label:f,labelPosition:v="outside-top",required:D,optional:c,description:u,helperText:g,errorText:p,leftIcon:m,rightIcon:w,leftAddons:S,rightAddons:E,onClickLeftIcon:en,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:L,options:B,onOptionChange:Y,clearable:Sn=!0,onClear:A,...a}=t,M=a.value!==void 0,[P,z]=o.useState(()=>{const e=a.value!==void 0?String(a.value??""):String(a.defaultValue??"");return L?T(e):e}),[sn,an]=o.useState(!1),[En,rn]=o.useState(""),C=o.useRef(null),N=o.useRef(null);o.useImperativeHandle(s,()=>N.current);const on=o.useRef(a.id??`sa-input-${Math.random().toString(36).slice(2,9)}`),{isComponentVisible:ln,ref:W,setIsComponentVisible:Ln}=yn(!1);o.useLayoutEffect(()=>{if(!M)return;const e=a.value===void 0||a.value===null?"":String(a.value),r=L?T(e):e;z(h=>h===r?h:r)},[a.value,L,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const e=N.current,r=C.current;if(C.current=null,!!e)try{e.setSelectionRange(r,r)}catch{}},[P]);const I=P,$=I!==""&&I!==void 0,y=d==="disable"||a.disabled,_=y?"disable":d,q=v==="inside",Bn=q&&($||sn),H=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${i}`,`sa-tf-status-${_}`,`sa-tf-label-${v}`,sn?"sa-tf-focused":"",y?"sa-tf-disabled":"",Bn?"sa-tf-floating":"",f?"":"sa-tf-no-label",In?"sa-tf-fullwidth":""].filter(Boolean).join(" "),$n=()=>{var e;return(e=N.current)==null?void 0:e.focus()},jn=e=>{var pn,hn;if(!L){const j=e.target.selectionStart;j!==null&&(C.current=j),z(e.target.value),(pn=a.onChange)==null||pn.call(a,e);return}const r=e.target.value;let h=r,x=e.target.selectionStart??r.length;if(En==="Backspace"){const j=P.replace(/\D/g,""),Vn=r.replace(/\D/g,"");j.length===Vn.length&&x>0&&(h=r.slice(0,x-1)+r.slice(x),x-=1)}const J=T(h),Dn=h.slice(0,x).replace(/\D/g,"").length,On=vn(J,Dn);C.current=On,z(J),(hn=a.onChange)==null||hn.call(a,{...e,target:{...e.target,value:String(xn(J)),name:e.target.name}}),rn("")},K=e=>f?n.jsxs("div",{className:e,children:[n.jsx("label",{htmlFor:on.current,style:{cursor:y?"not-allowed":"pointer"},children:f}),c?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,D?n.jsx("span",{className:"sa-tf-required","aria-hidden":"true",children:"*"}):null]}):null,U=n.jsxs(n.Fragment,{children:[g?n.jsx("p",{className:"sa-tf-helper",children:g}):null,p&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:p}):null]}),X=(e,r)=>n.jsx("span",{className:`sa-tf-icon${r?" sa-tf-icon-clickable":""}`,onClick:r,children:o.cloneElement(e,{width:k(i),height:k(i),color:Q(_,y),style:{color:Q(_,y)}})}),dn=()=>{var r;return w==null?null:!o.isValidElement(w)||((r=w.type)==null?void 0:r.__saRaw)===!0?n.jsx("span",{className:`sa-tf-icon${O?" sa-tf-icon-clickable":""}`,onClick:O,children:w}):X(w,O)},fn=d==="success"?n.jsx("span",{className:"sa-tf-icon sa-tf-success-mark","aria-hidden":"true",children:n.jsx(kn,{width:k(i),height:k(i)})}):null,Fn=e=>{var h;e.stopPropagation(),M||z("");const r={target:{value:"",name:a.name},currentTarget:{value:"",name:a.name}};(h=a.onChange)==null||h.call(a,r),A==null||A(),C.current=0,requestAnimationFrame(()=>{var x;return(x=N.current)==null?void 0:x.focus()})},cn=Sn&&!y?n.jsx("button",{type:"button",className:`sa-tf-icon sa-tf-clear${$?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!$,tabIndex:-1,onClick:Fn,onMouseDown:e=>e.preventDefault(),children:n.jsx(zn,{width:k(i),height:k(i)})}):null,Tn=!$&&!!a.placeholder&&!!V,un=n.jsxs("div",{className:"sa-tf-field-wrap",children:[n.jsx("input",{...a,id:on.current,ref:N,className:"sa-tf-input",disabled:y,placeholder:V?"":a.placeholder,value:I,onFocus:e=>{var r;an(!0),Ln(!0),(r=a.onFocus)==null||r.call(a,e)},onBlur:e=>{var r;an(!1),(r=a.onBlur)==null||r.call(a,e)},onKeyDown:e=>{var r;e.key==="Backspace"&&rn(e.key),(r=a.onKeyDown)==null||r.call(a,e)},onChange:jn}),Tn?Cn(a.placeholder,V):null]}),bn=I&&ln&&(B!=null&&B.length)?n.jsx(mn,{options:B,value:I,setValue:z,ref:W,isComponentVisible:ln,onOptionChange:e=>{Y==null||Y(e),z(e)}}):null,G=q?n.jsxs("div",{className:"sa-tf-box",ref:W,onClick:$n,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,en):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[K("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:un})]}),cn,fn,dn()]}),E?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:E}):null,bn]}):n.jsxs("div",{className:"sa-tf-box",ref:W,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,en):null,un,cn,fn,dn()]}),E?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:E}):null,bn]});return v==="outside-left"?n.jsxs("div",{className:H,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[K("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[G,U]})]}):q?n.jsxs("div",{className:H,children:[G,U]}):n.jsxs("div",{className:H,children:[K("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null,G,U]})}),Cn=(t,s)=>{if(!t)return null;if(!s)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const i=t.toLowerCase().indexOf(s.toLowerCase());return i===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,i),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(i,i+s.length)}),t.slice(i+s.length)]})};R.displayName="Input";const Nn=`.sa-kbd {
610
+ `,k=t=>t==="lg"||t==="xl"?18:t==="xs"?14:16,F={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"var(--sa-icon-disable, #181a198f)"},Q=(t,e)=>e?F.disable:F[t]??F.default;function gn(t){return Number(t.replace(/\./g,""))}function T(t){let e=t.replace(/[^\d]/g,"");return e=e.replace(/^0+(?=\d)/,""),e.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function vn(t,e){if(e<=0)return 0;let i=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(i+=1,i===e))return l+1;return t.length}const mn=o.forwardRef(({options:t,value:e,setValue:i,isComponentVisible:l,onOptionChange:d},f)=>{const[v,D]=o.useState([]),c=o.useRef(null),u=()=>{if(f!=null&&f.current&&c.current){const h=window.innerHeight,p=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),w=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,w>=h-10?c.current.style.top=`${p.top-m.height-5}px`:c.current.style.top=`${p.top+p.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",u),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u),window.removeEventListener("resize",u)}),[f,c]),o.useEffect(()=>{u()},[l]),o.useEffect(()=>{D((t==null?void 0:t.filter(h=>h.toLowerCase().startsWith(e.toLowerCase())))||[])},[e,t]),n.jsx("div",{ref:c,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",borderRadius:"8px",background:"white",overflow:"auto",zIndex:5e4},children:v==null?void 0:v.map(h=>wn(h,e,i,d))})}),wn=(t,e,i,l)=>{const d=t.toLowerCase().indexOf(e.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{i(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+e.length)}),t.slice(d+e.length)]})};function yn(t){const[e,i]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&i(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:i}}const Z="sa-input-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(Z)){const e=document.createElement("style");e.id=Z,e.textContent=t,document.head.appendChild(e)}})(hn);const kn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.5",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.2 8.2l1.8 1.8 3.8-4.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),zn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),R=o.forwardRef((t,e)=>{const{size:i="sm",variant:l="outline",status:d="default",label:f,labelPosition:v="outside-top",required:D,optional:c,description:u,helperText:h,errorText:p,leftIcon:m,rightIcon:w,leftAddons:S,rightAddons:E,onClickLeftIcon:sn,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:L,options:B,onOptionChange:Y,clearable:Sn=!0,onClear:A,...a}=t,M=a.value!==void 0,[P,z]=o.useState(()=>{const s=a.value!==void 0?String(a.value??""):String(a.defaultValue??"");return L?T(s):s}),[en,an]=o.useState(!1),[En,rn]=o.useState(""),C=o.useRef(null),N=o.useRef(null);o.useImperativeHandle(e,()=>N.current);const on=o.useRef(a.id??`sa-input-${Math.random().toString(36).slice(2,9)}`),{isComponentVisible:ln,ref:W,setIsComponentVisible:Ln}=yn(!1);o.useLayoutEffect(()=>{if(!M)return;const s=a.value===void 0||a.value===null?"":String(a.value),r=L?T(s):s;z(x=>x===r?x:r)},[a.value,L,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const s=N.current,r=C.current;if(C.current=null,!!s)try{s.setSelectionRange(r,r)}catch{}},[P]);const I=P,$=I!==""&&I!==void 0,y=d==="disable"||a.disabled,_=y?"disable":d,q=v==="inside",Bn=q&&($||en),H=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${i}`,`sa-tf-status-${_}`,`sa-tf-label-${v}`,en?"sa-tf-focused":"",y?"sa-tf-disabled":"",Bn?"sa-tf-floating":"",f?"":"sa-tf-no-label",In?"sa-tf-fullwidth":""].filter(Boolean).join(" "),$n=()=>{var s;return(s=N.current)==null?void 0:s.focus()},jn=s=>{var pn,xn;if(!L){const j=s.target.selectionStart;j!==null&&(C.current=j),z(s.target.value),(pn=a.onChange)==null||pn.call(a,s);return}const r=s.target.value;let x=r,g=s.target.selectionStart??r.length;if(En==="Backspace"){const j=P.replace(/\D/g,""),Vn=r.replace(/\D/g,"");j.length===Vn.length&&g>0&&(x=r.slice(0,g-1)+r.slice(g),g-=1)}const J=T(x),Dn=x.slice(0,g).replace(/\D/g,"").length,On=vn(J,Dn);C.current=On,z(J),(xn=a.onChange)==null||xn.call(a,{...s,target:{...s.target,value:String(gn(J)),name:s.target.name}}),rn("")},K=s=>f?n.jsxs("div",{className:s,children:[n.jsx("label",{htmlFor:on.current,style:{cursor:y?"not-allowed":"pointer"},children:f}),c?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,D?n.jsx("span",{className:"sa-tf-required","aria-hidden":"true",children:"*"}):null]}):null,U=n.jsxs(n.Fragment,{children:[h?n.jsx("p",{className:"sa-tf-helper",children:h}):null,p&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:p}):null]}),X=(s,r)=>n.jsx("span",{className:`sa-tf-icon${r?" sa-tf-icon-clickable":""}`,onClick:r,children:o.cloneElement(s,{width:k(i),height:k(i),color:Q(_,y),style:{color:Q(_,y)}})}),dn=()=>{var r;return w==null?null:!o.isValidElement(w)||((r=w.type)==null?void 0:r.__saRaw)===!0?n.jsx("span",{className:`sa-tf-icon${O?" sa-tf-icon-clickable":""}`,onClick:O,children:w}):X(w,O)},fn=d==="success"?n.jsx("span",{className:"sa-tf-icon sa-tf-success-mark","aria-hidden":"true",children:n.jsx(kn,{width:k(i),height:k(i)})}):null,Fn=s=>{var x;s.stopPropagation(),M||z("");const r={target:{value:"",name:a.name},currentTarget:{value:"",name:a.name}};(x=a.onChange)==null||x.call(a,r),A==null||A(),C.current=0,requestAnimationFrame(()=>{var g;return(g=N.current)==null?void 0:g.focus()})},cn=Sn&&!y?n.jsx("button",{type:"button",className:`sa-tf-icon sa-tf-clear${$?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!$,tabIndex:-1,onClick:Fn,onMouseDown:s=>s.preventDefault(),children:n.jsx(zn,{width:k(i),height:k(i)})}):null,Tn=!$&&!!a.placeholder&&!!V,un=n.jsxs("div",{className:"sa-tf-field-wrap",children:[n.jsx("input",{...a,id:on.current,ref:N,className:"sa-tf-input",disabled:y,placeholder:V?"":a.placeholder,value:I,onFocus:s=>{var r;an(!0),Ln(!0),(r=a.onFocus)==null||r.call(a,s)},onBlur:s=>{var r;an(!1),(r=a.onBlur)==null||r.call(a,s)},onKeyDown:s=>{var r;s.key==="Backspace"&&rn(s.key),(r=a.onKeyDown)==null||r.call(a,s)},onChange:jn}),Tn?Cn(a.placeholder,V):null]}),bn=I&&ln&&(B!=null&&B.length)?n.jsx(mn,{options:B,value:I,setValue:z,ref:W,isComponentVisible:ln,onOptionChange:s=>{Y==null||Y(s),z(s)}}):null,G=q?n.jsxs("div",{className:"sa-tf-box",ref:W,onClick:$n,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,sn):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[K("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:un})]}),cn,fn,dn()]}),E?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:E}):null,bn]}):n.jsxs("div",{className:"sa-tf-box",ref:W,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,sn):null,un,cn,fn,dn()]}),E?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:E}):null,bn]});return v==="outside-left"?n.jsxs("div",{className:H,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[K("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[G,U]})]}):q?n.jsxs("div",{className:H,children:[G,U]}):n.jsxs("div",{className:H,children:[K("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null,G,U]})}),Cn=(t,e)=>{if(!t)return null;if(!e)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const i=t.toLowerCase().indexOf(e.toLowerCase());return i===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,i),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(i,i+e.length)}),t.slice(i+e.length)]})};R.displayName="Input";const Nn=`.sa-kbd {
595
611
  display: inline-flex;
596
612
  align-items: center;
597
613
  gap: var(--sa-spacing-4, 4px);
@@ -622,4 +638,4 @@
622
638
  font-size: var(--sa-font-size-sm, 12px);
623
639
  user-select: none;
624
640
  }
625
- `,nn="sa-kbd-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(nn)){const s=document.createElement("style");s.id=nn,s.textContent=t,document.head.appendChild(s)}})(Nn);function tn({keys:t,separator:s,className:i,...l}){return n.jsx("span",{className:`sa-kbd${i?` ${i}`:""}`,...l,children:t.map((d,f)=>n.jsxs(o.Fragment,{children:[f>0&&s!=null?n.jsx("span",{className:"sa-kbd-sep","aria-hidden":"true",children:s}):null,n.jsx("kbd",{className:"sa-kbd-key",children:d})]},f))})}tn.__saRaw=!0,b.Input=R,b.Kbd=tn,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
641
+ `,nn="sa-kbd-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(nn)){const e=document.createElement("style");e.id=nn,e.textContent=t,document.head.appendChild(e)}})(Nn);function tn({keys:t,separator:e,className:i,...l}){return n.jsx("span",{className:`sa-kbd${i?` ${i}`:""}`,...l,children:t.map((d,f)=>n.jsxs(o.Fragment,{children:[f>0&&e!=null?n.jsx("span",{className:"sa-kbd-sep","aria-hidden":"true",children:e}):null,n.jsx("kbd",{className:"sa-kbd-key",children:d})]},f))})}tn.__saRaw=!0,b.Input=R,b.Kbd=tn,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ReactElement, ReactNode } from "react";
2
2
  export interface IconInputProps extends React.SVGProps<SVGSVGElement> {
3
3
  }
4
- export type InputSize = "sm" | "md" | "lg" | "xl";
4
+ export type InputSize = "xs" | "sm" | "md" | "lg" | "xl";
5
5
  export type InputVariant = "standard" | "outline" | "flushed" | "borderless";
6
6
  export type InputStatus = "default" | "error" | "success" | "disable";
7
7
  export type InputLabelPosition = "outside-top" | "outside-left" | "inside";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/input",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "input component for starasia UI",
5
5
  "author": "Rizki Izzul Haq",
6
6
  "main": "dist/input.umd.js",