@starasia/input 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/input.es.js CHANGED
@@ -1,39 +1,39 @@
1
- import { jsx as a, jsxs as o, Fragment as Bn } from "react/jsx-runtime";
2
- import Ln, { forwardRef as hn, useState as I, useRef as B, useEffect as T, useImperativeHandle as Rn, useLayoutEffect as un } from "react";
1
+ import { jsx as a, jsxs as o, Fragment as Ln } from "react/jsx-runtime";
2
+ import Bn, { forwardRef as hn, useState as I, useRef as L, useEffect as T, useImperativeHandle as Rn, useLayoutEffect as un } from "react";
3
3
  const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
4
 
5
5
  :root {
6
- /* Figma design tokens */
7
- --sa-input-text-primary: #292a2e;
8
- --sa-input-text-subtle: #505258;
9
- --sa-input-text-subtlest: #6b6e76;
10
- --sa-input-text-error: #a4133c;
11
- --sa-input-text-disable: rgba(24, 26, 25, 0.56);
6
+ /* Layer 3 — references Layer 2 semantic tokens */
7
+ --sa-input-text-primary: var(--sa-text-primary, #292a2e);
8
+ --sa-input-text-subtle: var(--sa-text-subtle, #505258);
9
+ --sa-input-text-subtlest: var(--sa-text-subtlest, #6b6e76);
10
+ --sa-input-text-error: var(--sa-text-error, #a4133c);
11
+ --sa-input-text-disable: var(--sa-text-disable, #181a198f);
12
12
 
13
- --sa-input-icon-subtle: #505258;
14
- --sa-input-icon-subtlest: #6b6e76;
15
- --sa-input-icon-success: #208958;
16
- --sa-input-icon-disable: rgba(24, 26, 25, 0.56);
13
+ --sa-input-icon-subtle: var(--sa-icon-subtle, #505258);
14
+ --sa-input-icon-subtlest: var(--sa-icon-subtlest, #6b6e76);
15
+ --sa-input-icon-success: var(--sa-icon-success, #208958);
16
+ --sa-input-icon-disable: var(--sa-icon-disable, #181a198f);
17
17
 
18
- --sa-input-border-subtle: rgba(11, 18, 14, 0.14);
19
- --sa-input-border-brand: #1976d2;
20
- --sa-input-border-brand-subtle: #90caf9;
21
- --sa-input-border-danger: #c9184a;
22
- --sa-input-border-danger-subtle: #ffb3c1;
23
- --sa-input-border-success: #28ac6e;
24
- --sa-input-border-disabled: rgba(24, 26, 25, 0.56);
18
+ --sa-input-border-subtle: var(--sa-border-subtle, #0b120e24);
19
+ --sa-input-border-brand: var(--sa-border-focused, #1a4fa0);
20
+ --sa-input-border-brand-subtle: var(--sa-color-brand-200, #99b3db);
21
+ --sa-input-border-danger: var(--sa-border-danger, #c9184a);
22
+ --sa-input-border-danger-subtle: var(--sa-color-error-200, #ffb3c1);
23
+ --sa-input-border-success: var(--sa-background-success, #28ac6e);
24
+ --sa-input-border-disabled: var(--sa-border-disabled, #181a198f);
25
25
 
26
- --sa-input-bg-neutral: #f0f1f2;
27
- --sa-input-bg-error-subtlest: #fff0f3;
28
- --sa-input-bg-success-subtlest: #ecfff6;
29
- --sa-input-accent-subtle: #f0f1f2;
26
+ --sa-input-bg-neutral: var(--sa-background-neutral, #f0f1f2);
27
+ --sa-input-bg-error-subtlest: var(--sa-background-error-subtlest, #fff0f3);
28
+ --sa-input-bg-success-subtlest: var(--sa-background-success-subtlest, #ecfff6);
29
+ --sa-input-accent-subtle: var(--sa-background-neutral, #f0f1f2);
30
30
 
31
- --sa-input-text-placeholder: rgb(201, 206, 204);
31
+ --sa-input-text-placeholder: var(--sa-text-subtle, #8c8f97);
32
32
 
33
- --sa-input-radius: 6px;
34
- --sa-input-padding-x: 12px;
35
- --sa-input-padding-y: 8px;
36
- --sa-input-gap: 8px;
33
+ --sa-input-radius: var(--sa-radii-sm, 6px);
34
+ --sa-input-padding-x: var(--sa-spacing-md, 12px);
35
+ --sa-input-padding-y: var(--sa-spacing-sm, 8px);
36
+ --sa-input-gap: var(--sa-spacing-sm, 8px);
37
37
  }
38
38
 
39
39
  /* ROOT */
@@ -566,12 +566,12 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
566
566
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
567
567
  min-height: 80px;
568
568
  }
569
- `, k = (n) => n === "lg" || n === "xl" ? 18 : 16, G = {
569
+ `, z = (n) => n === "lg" || n === "xl" ? 18 : 16, G = {
570
570
  default: "var(--sa-color-gray-800, #505258)",
571
571
  error: "var(--sa-text-error, #a4133c)",
572
572
  success: "var(--sa-text-success, #208958)",
573
- disable: "rgba(24, 26, 25, 0.56)"
574
- }, pn = (n, s) => s ? G.disable : G[n] ?? G.default;
573
+ disable: "var(--sa-icon-disable, #181a198f)"
574
+ }, bn = (n, s) => s ? G.disable : G[n] ?? G.default;
575
575
  function En(n) {
576
576
  return Number(n.replace(/\./g, ""));
577
577
  }
@@ -590,10 +590,10 @@ function Dn(n, s) {
590
590
  }
591
591
  const Fn = hn(
592
592
  ({ options: n, value: s, setValue: r, isComponentVisible: l, onOptionChange: d }, f) => {
593
- const [x, V] = I([]), c = B(null), u = () => {
593
+ const [g, V] = I([]), c = L(null), u = () => {
594
594
  if (f != null && f.current && c.current) {
595
- const h = window.innerHeight, p = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(), w = p.bottom + m.height;
596
- 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`;
595
+ const h = window.innerHeight, b = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(), w = b.bottom + m.height;
596
+ c.current.style.left = `${b.left}px`, c.current.style.width = `${b.width}px`, w >= h - 10 ? c.current.style.top = `${b.top - m.height - 5}px` : c.current.style.top = `${b.top + b.height}px`;
597
597
  }
598
598
  };
599
599
  return T(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
@@ -614,13 +614,13 @@ const Fn = hn(
614
614
  position: "fixed",
615
615
  padding: "8px",
616
616
  boxSizing: "border-box",
617
- boxShadow: "0px 8px 12px 0px rgba(0, 0, 0, 0.08)",
617
+ boxShadow: "0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",
618
618
  borderRadius: "8px",
619
619
  background: "white",
620
620
  overflow: "auto",
621
621
  zIndex: 5e4
622
622
  },
623
- children: x == null ? void 0 : x.map(
623
+ children: g == null ? void 0 : g.map(
624
624
  (h) => On(h, s, r, d)
625
625
  )
626
626
  }
@@ -650,17 +650,17 @@ const Fn = hn(
650
650
  );
651
651
  };
652
652
  function Tn(n) {
653
- const [s, r] = I(n), l = B(null), d = (f) => {
653
+ const [s, r] = I(n), l = L(null), d = (f) => {
654
654
  l.current && !l.current.contains(f.target) && r(!1);
655
655
  };
656
656
  return T(() => (document.addEventListener("click", d, !0), () => {
657
657
  document.removeEventListener("click", d, !0);
658
658
  }), []), { ref: l, isComponentVisible: s, setIsComponentVisible: r };
659
659
  }
660
- const bn = "starasia-input-styles", Vn = (n) => {
661
- if (!(typeof document > "u") && !document.getElementById(bn)) {
660
+ const pn = "starasia-input-styles", Vn = (n) => {
661
+ if (!(typeof document > "u") && !document.getElementById(pn)) {
662
662
  const s = document.createElement("style");
663
- s.id = bn, s.textContent = n, document.head.appendChild(s);
663
+ s.id = pn, s.textContent = n, document.head.appendChild(s);
664
664
  }
665
665
  };
666
666
  Vn(Sn);
@@ -712,32 +712,32 @@ const $n = (n) => /* @__PURE__ */ o(
712
712
  variant: l = "outline",
713
713
  status: d = "default",
714
714
  label: f,
715
- labelPosition: x = "outside-top",
715
+ labelPosition: g = "outside-top",
716
716
  required: V,
717
717
  optional: c,
718
718
  description: u,
719
719
  helperText: h,
720
- errorText: p,
720
+ errorText: b,
721
721
  leftIcon: m,
722
722
  rightIcon: w,
723
- leftAddons: L,
723
+ leftAddons: B,
724
724
  rightAddons: R,
725
725
  onClickLeftIcon: Q,
726
726
  onClickRightIcon: Z,
727
- fullWidth: gn = !1,
727
+ fullWidth: xn = !1,
728
728
  highlightPlaceholder: $,
729
729
  currency: S,
730
730
  options: E,
731
731
  onOptionChange: j,
732
- clearable: xn = !0,
732
+ clearable: gn = !0,
733
733
  onClear: Y,
734
734
  ...e
735
735
  } = n, W = e.value !== void 0, [A, y] = I(() => {
736
736
  const t = e.value !== void 0 ? String(e.value ?? "") : String(e.defaultValue ?? "");
737
737
  return S ? J(t) : t;
738
- }), [nn, tn] = I(!1), [mn, en] = I(""), z = B(null), C = B(null);
738
+ }), [nn, tn] = I(!1), [mn, en] = I(""), k = L(null), C = L(null);
739
739
  Rn(s, () => C.current);
740
- const sn = B(
740
+ const sn = L(
741
741
  e.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
742
742
  ), {
743
743
  isComponentVisible: an,
@@ -748,46 +748,46 @@ const $n = (n) => /* @__PURE__ */ o(
748
748
  if (!W)
749
749
  return;
750
750
  const t = e.value === void 0 || e.value === null ? "" : String(e.value), i = S ? J(t) : t;
751
- y((b) => b === i ? b : i);
751
+ y((p) => p === i ? p : i);
752
752
  }, [e.value, S, W]), un(() => {
753
- if (z.current === null)
753
+ if (k.current === null)
754
754
  return;
755
- const t = C.current, i = z.current;
756
- if (z.current = null, !!t)
755
+ const t = C.current, i = k.current;
756
+ if (k.current = null, !!t)
757
757
  try {
758
758
  t.setSelectionRange(i, i);
759
759
  } catch {
760
760
  }
761
761
  }, [A]);
762
- const N = A, D = N !== "" && N !== void 0, v = d === "disable" || e.disabled, P = v ? "disable" : d, H = x === "inside", wn = H && (D || nn), q = [
762
+ const N = A, D = N !== "" && N !== void 0, v = d === "disable" || e.disabled, P = v ? "disable" : d, H = g === "inside", wn = H && (D || nn), q = [
763
763
  "sa-tf",
764
764
  `sa-tf-variant-${l}`,
765
765
  `sa-tf-size-${r}`,
766
766
  `sa-tf-status-${P}`,
767
- `sa-tf-label-${x}`,
767
+ `sa-tf-label-${g}`,
768
768
  nn ? "sa-tf-focused" : "",
769
769
  v ? "sa-tf-disabled" : "",
770
770
  wn ? "sa-tf-floating" : "",
771
771
  f ? "" : "sa-tf-no-label",
772
- gn ? "sa-tf-fullwidth" : ""
772
+ xn ? "sa-tf-fullwidth" : ""
773
773
  ].filter(Boolean).join(" "), yn = () => {
774
774
  var t;
775
775
  return (t = C.current) == null ? void 0 : t.focus();
776
- }, zn = (t) => {
776
+ }, kn = (t) => {
777
777
  var fn, cn;
778
778
  if (!S) {
779
779
  const O = t.target.selectionStart;
780
- O !== null && (z.current = O), y(t.target.value), (fn = e.onChange) == null || fn.call(e, t);
780
+ O !== null && (k.current = O), y(t.target.value), (fn = e.onChange) == null || fn.call(e, t);
781
781
  return;
782
782
  }
783
783
  const i = t.target.value;
784
- let b = i, g = t.target.selectionStart ?? i.length;
784
+ let p = i, x = t.target.selectionStart ?? i.length;
785
785
  if (mn === "Backspace") {
786
786
  const O = A.replace(/\D/g, ""), In = i.replace(/\D/g, "");
787
- O.length === In.length && g > 0 && (b = i.slice(0, g - 1) + i.slice(g), g -= 1);
787
+ O.length === In.length && x > 0 && (p = i.slice(0, x - 1) + i.slice(x), x -= 1);
788
788
  }
789
- const X = J(b), Cn = b.slice(0, g).replace(/\D/g, "").length, Nn = Dn(X, Cn);
790
- z.current = Nn, y(X), (cn = e.onChange) == null || cn.call(e, {
789
+ const X = J(p), Cn = p.slice(0, x).replace(/\D/g, "").length, Nn = Dn(X, Cn);
790
+ k.current = Nn, y(X), (cn = e.onChange) == null || cn.call(e, {
791
791
  ...t,
792
792
  target: {
793
793
  ...t.target,
@@ -806,28 +806,28 @@ const $n = (n) => /* @__PURE__ */ o(
806
806
  ),
807
807
  c ? /* @__PURE__ */ a("span", { className: "sa-tf-optional", children: "Optional" }) : null,
808
808
  V ? /* @__PURE__ */ a("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
809
- ] }) : null, _ = /* @__PURE__ */ o(Bn, { children: [
809
+ ] }) : null, _ = /* @__PURE__ */ o(Ln, { children: [
810
810
  h ? /* @__PURE__ */ a("p", { className: "sa-tf-helper", children: h }) : null,
811
- p && d === "error" ? /* @__PURE__ */ a("p", { className: "sa-tf-error", children: p }) : null
811
+ b && d === "error" ? /* @__PURE__ */ a("p", { className: "sa-tf-error", children: b }) : null
812
812
  ] }), F = (t, i) => /* @__PURE__ */ a(
813
813
  "span",
814
814
  {
815
815
  className: `sa-tf-icon${i ? " sa-tf-icon-clickable" : ""}`,
816
816
  onClick: i,
817
- children: Ln.cloneElement(t, {
818
- width: k(r),
819
- height: k(r),
820
- color: pn(P, v),
821
- style: { color: pn(P, v) }
817
+ children: Bn.cloneElement(t, {
818
+ width: z(r),
819
+ height: z(r),
820
+ color: bn(P, v),
821
+ style: { color: bn(P, v) }
822
822
  })
823
823
  }
824
824
  ), rn = d === "success" ? /* @__PURE__ */ a("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ a(
825
825
  $n,
826
826
  {
827
- width: k(r),
828
- height: k(r)
827
+ width: z(r),
828
+ height: z(r)
829
829
  }
830
- ) }) : null, on = xn && !v ? /* @__PURE__ */ a(
830
+ ) }) : null, on = gn && !v ? /* @__PURE__ */ a(
831
831
  "button",
832
832
  {
833
833
  type: "button",
@@ -836,27 +836,27 @@ const $n = (n) => /* @__PURE__ */ o(
836
836
  "aria-hidden": !D,
837
837
  tabIndex: -1,
838
838
  onClick: (t) => {
839
- var b;
839
+ var p;
840
840
  t.stopPropagation(), W || y("");
841
841
  const i = {
842
842
  target: { value: "", name: e.name },
843
843
  currentTarget: { value: "", name: e.name }
844
844
  };
845
- (b = e.onChange) == null || b.call(e, i), Y == null || Y(), z.current = 0, requestAnimationFrame(() => {
846
- var g;
847
- return (g = C.current) == null ? void 0 : g.focus();
845
+ (p = e.onChange) == null || p.call(e, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
846
+ var x;
847
+ return (x = C.current) == null ? void 0 : x.focus();
848
848
  });
849
849
  },
850
850
  onMouseDown: (t) => t.preventDefault(),
851
851
  children: /* @__PURE__ */ a(
852
852
  jn,
853
853
  {
854
- width: k(r),
855
- height: k(r)
854
+ width: z(r),
855
+ height: z(r)
856
856
  }
857
857
  )
858
858
  }
859
- ) : null, kn = !D && !!e.placeholder && !!$, ln = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
859
+ ) : null, zn = !D && !!e.placeholder && !!$, ln = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
860
860
  /* @__PURE__ */ a(
861
861
  "input",
862
862
  {
@@ -879,10 +879,10 @@ const $n = (n) => /* @__PURE__ */ o(
879
879
  var i;
880
880
  t.key === "Backspace" && en(t.key), (i = e.onKeyDown) == null || i.call(e, t);
881
881
  },
882
- onChange: zn
882
+ onChange: kn
883
883
  }
884
884
  ),
885
- kn ? Wn(e.placeholder, $) : null
885
+ zn ? Wn(e.placeholder, $) : null
886
886
  ] }), dn = N && an && (E != null && E.length) ? /* @__PURE__ */ a(
887
887
  Fn,
888
888
  {
@@ -902,7 +902,7 @@ const $n = (n) => /* @__PURE__ */ o(
902
902
  ref: M,
903
903
  onClick: yn,
904
904
  children: [
905
- L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: L }) : null,
905
+ B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
906
906
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
907
907
  m ? F(m, Q) : null,
908
908
  /* @__PURE__ */ o("div", { className: "sa-tf-inside-stack", children: [
@@ -918,7 +918,7 @@ const $n = (n) => /* @__PURE__ */ o(
918
918
  ]
919
919
  }
920
920
  ) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: M, children: [
921
- L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: L }) : null,
921
+ B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
922
922
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
923
923
  m ? F(m, Q) : null,
924
924
  ln,
@@ -929,7 +929,7 @@ const $n = (n) => /* @__PURE__ */ o(
929
929
  R ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: R }) : null,
930
930
  dn
931
931
  ] });
932
- return x === "outside-left" ? /* @__PURE__ */ o("div", { className: q, children: [
932
+ return g === "outside-left" ? /* @__PURE__ */ o("div", { className: q, children: [
933
933
  /* @__PURE__ */ o("div", { className: "sa-tf-label-col", children: [
934
934
  K("sa-tf-label"),
935
935
  u ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: u }) : null
package/dist/input.umd.js CHANGED
@@ -1,37 +1,37 @@
1
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.Input={},h.jsxRuntime,h.React))})(this,function(h,n,o){"use strict";const pn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
2
2
 
3
3
  :root {
4
- /* Figma design tokens */
5
- --sa-input-text-primary: #292a2e;
6
- --sa-input-text-subtle: #505258;
7
- --sa-input-text-subtlest: #6b6e76;
8
- --sa-input-text-error: #a4133c;
9
- --sa-input-text-disable: rgba(24, 26, 25, 0.56);
4
+ /* Layer 3 — references Layer 2 semantic tokens */
5
+ --sa-input-text-primary: var(--sa-text-primary, #292a2e);
6
+ --sa-input-text-subtle: var(--sa-text-subtle, #505258);
7
+ --sa-input-text-subtlest: var(--sa-text-subtlest, #6b6e76);
8
+ --sa-input-text-error: var(--sa-text-error, #a4133c);
9
+ --sa-input-text-disable: var(--sa-text-disable, #181a198f);
10
10
 
11
- --sa-input-icon-subtle: #505258;
12
- --sa-input-icon-subtlest: #6b6e76;
13
- --sa-input-icon-success: #208958;
14
- --sa-input-icon-disable: rgba(24, 26, 25, 0.56);
11
+ --sa-input-icon-subtle: var(--sa-icon-subtle, #505258);
12
+ --sa-input-icon-subtlest: var(--sa-icon-subtlest, #6b6e76);
13
+ --sa-input-icon-success: var(--sa-icon-success, #208958);
14
+ --sa-input-icon-disable: var(--sa-icon-disable, #181a198f);
15
15
 
16
- --sa-input-border-subtle: rgba(11, 18, 14, 0.14);
17
- --sa-input-border-brand: #1976d2;
18
- --sa-input-border-brand-subtle: #90caf9;
19
- --sa-input-border-danger: #c9184a;
20
- --sa-input-border-danger-subtle: #ffb3c1;
21
- --sa-input-border-success: #28ac6e;
22
- --sa-input-border-disabled: rgba(24, 26, 25, 0.56);
16
+ --sa-input-border-subtle: var(--sa-border-subtle, #0b120e24);
17
+ --sa-input-border-brand: var(--sa-border-focused, #1a4fa0);
18
+ --sa-input-border-brand-subtle: var(--sa-color-brand-200, #99b3db);
19
+ --sa-input-border-danger: var(--sa-border-danger, #c9184a);
20
+ --sa-input-border-danger-subtle: var(--sa-color-error-200, #ffb3c1);
21
+ --sa-input-border-success: var(--sa-background-success, #28ac6e);
22
+ --sa-input-border-disabled: var(--sa-border-disabled, #181a198f);
23
23
 
24
- --sa-input-bg-neutral: #f0f1f2;
25
- --sa-input-bg-error-subtlest: #fff0f3;
26
- --sa-input-bg-success-subtlest: #ecfff6;
27
- --sa-input-accent-subtle: #f0f1f2;
24
+ --sa-input-bg-neutral: var(--sa-background-neutral, #f0f1f2);
25
+ --sa-input-bg-error-subtlest: var(--sa-background-error-subtlest, #fff0f3);
26
+ --sa-input-bg-success-subtlest: var(--sa-background-success-subtlest, #ecfff6);
27
+ --sa-input-accent-subtle: var(--sa-background-neutral, #f0f1f2);
28
28
 
29
- --sa-input-text-placeholder: rgb(201, 206, 204);
29
+ --sa-input-text-placeholder: var(--sa-text-subtle, #8c8f97);
30
30
 
31
- --sa-input-radius: 6px;
32
- --sa-input-padding-x: 12px;
33
- --sa-input-padding-y: 8px;
34
- --sa-input-gap: 8px;
31
+ --sa-input-radius: var(--sa-radii-sm, 6px);
32
+ --sa-input-padding-x: var(--sa-spacing-md, 12px);
33
+ --sa-input-padding-y: var(--sa-spacing-sm, 8px);
34
+ --sa-input-gap: var(--sa-spacing-sm, 8px);
35
35
  }
36
36
 
37
37
  /* ROOT */
@@ -564,4 +564,4 @@
564
564
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
565
565
  min-height: 80px;
566
566
  }
567
- `,y=t=>t==="lg"||t==="xl"?18:16,j={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"rgba(24, 26, 25, 0.56)"},J=(t,a)=>a?j.disable:j[t]??j.default;function bn(t){return Number(t.replace(/\./g,""))}function O(t){let a=t.replace(/[^\d]/g,"");return a=a.replace(/^0+(?=\d)/,""),a.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function hn(t,a){if(a<=0)return 0;let r=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(r+=1,r===a))return l+1;return t.length}const gn=o.forwardRef(({options:t,value:a,setValue:r,isComponentVisible:l,onOptionChange:d},f)=>{const[v,V]=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(),z=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,z>=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(()=>{V((t==null?void 0:t.filter(g=>g.toLowerCase().startsWith(a.toLowerCase())))||[])},[a,t]),n.jsx("div",{ref:c,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px rgba(0, 0, 0, 0.08)",borderRadius:"8px",background:"white",overflow:"auto",zIndex:5e4},children:v==null?void 0:v.map(g=>xn(g,a,r,d))})}),xn=(t,a,r,l)=>{const d=t.toLowerCase().indexOf(a.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{r(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+a.length)}),t.slice(d+a.length)]})};function vn(t){const[a,r]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&r(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:a,setIsComponentVisible:r}}const Q="starasia-input-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(Q)){const a=document.createElement("style");a.id=Q,a.textContent=t,document.head.appendChild(a)}})(pn);const mn=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"})]}),wn=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"})]}),Z=o.forwardRef((t,a)=>{const{size:r="md",variant:l="outline",status:d="default",label:f,labelPosition:v="outside-top",required:V,optional:c,description:u,helperText:g,errorText:p,leftIcon:m,rightIcon:z,leftAddons:S,rightAddons:B,onClickLeftIcon:R,onClickRightIcon:nn,fullWidth:zn=!1,highlightPlaceholder:$,currency:L,options:E,onOptionChange:Y,clearable:kn=!0,onClear:M,...s}=t,P=s.value!==void 0,[W,k]=o.useState(()=>{const e=s.value!==void 0?String(s.value??""):String(s.defaultValue??"");return L?O(e):e}),[tn,en]=o.useState(!1),[Cn,sn]=o.useState(""),C=o.useRef(null),N=o.useRef(null);o.useImperativeHandle(a,()=>N.current);const an=o.useRef(s.id??`sa-input-${Math.random().toString(36).slice(2,9)}`),{isComponentVisible:rn,ref:q,setIsComponentVisible:Nn}=vn(!1);o.useLayoutEffect(()=>{if(!P)return;const e=s.value===void 0||s.value===null?"":String(s.value),i=L?O(e):e;k(b=>b===i?b:i)},[s.value,L,P]),o.useLayoutEffect(()=>{if(C.current===null)return;const e=N.current,i=C.current;if(C.current=null,!!e)try{e.setSelectionRange(i,i)}catch{}},[W]);const I=W,D=I!==""&&I!==void 0,w=d==="disable"||s.disabled,A=w?"disable":d,H=v==="inside",In=H&&(D||tn),K=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${r}`,`sa-tf-status-${A}`,`sa-tf-label-${v}`,tn?"sa-tf-focused":"",w?"sa-tf-disabled":"",In?"sa-tf-floating":"",f?"":"sa-tf-no-label",zn?"sa-tf-fullwidth":""].filter(Boolean).join(" "),Sn=()=>{var e;return(e=N.current)==null?void 0:e.focus()},Bn=e=>{var cn,un;if(!L){const T=e.target.selectionStart;T!==null&&(C.current=T),k(e.target.value),(cn=s.onChange)==null||cn.call(s,e);return}const i=e.target.value;let b=i,x=e.target.selectionStart??i.length;if(Cn==="Backspace"){const T=W.replace(/\D/g,""),Tn=i.replace(/\D/g,"");T.length===Tn.length&&x>0&&(b=i.slice(0,x-1)+i.slice(x),x-=1)}const G=O(b),Dn=b.slice(0,x).replace(/\D/g,"").length,Fn=hn(G,Dn);C.current=Fn,k(G),(un=s.onChange)==null||un.call(s,{...e,target:{...e.target,value:String(bn(G)),name:e.target.name}}),sn("")},_=e=>f?n.jsxs("div",{className:e,children:[n.jsx("label",{htmlFor:an.current,style:{cursor:w?"not-allowed":"pointer"},children:f}),c?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,V?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]}),F=(e,i)=>n.jsx("span",{className:`sa-tf-icon${i?" sa-tf-icon-clickable":""}`,onClick:i,children:o.cloneElement(e,{width:y(r),height:y(r),color:J(A,w),style:{color:J(A,w)}})}),on=d==="success"?n.jsx("span",{className:"sa-tf-icon sa-tf-success-mark","aria-hidden":"true",children:n.jsx(mn,{width:y(r),height:y(r)})}):null,Ln=e=>{var b;e.stopPropagation(),P||k("");const i={target:{value:"",name:s.name},currentTarget:{value:"",name:s.name}};(b=s.onChange)==null||b.call(s,i),M==null||M(),C.current=0,requestAnimationFrame(()=>{var x;return(x=N.current)==null?void 0:x.focus()})},ln=kn&&!w?n.jsx("button",{type:"button",className:`sa-tf-icon sa-tf-clear${D?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!D,tabIndex:-1,onClick:Ln,onMouseDown:e=>e.preventDefault(),children:n.jsx(wn,{width:y(r),height:y(r)})}):null,En=!D&&!!s.placeholder&&!!$,dn=n.jsxs("div",{className:"sa-tf-field-wrap",children:[n.jsx("input",{...s,id:an.current,ref:N,className:"sa-tf-input",disabled:w,placeholder:$?"":s.placeholder,value:I,onFocus:e=>{var i;en(!0),Nn(!0),(i=s.onFocus)==null||i.call(s,e)},onBlur:e=>{var i;en(!1),(i=s.onBlur)==null||i.call(s,e)},onKeyDown:e=>{var i;e.key==="Backspace"&&sn(e.key),(i=s.onKeyDown)==null||i.call(s,e)},onChange:Bn}),En?yn(s.placeholder,$):null]}),fn=I&&rn&&(E!=null&&E.length)?n.jsx(gn,{options:E,value:I,setValue:k,ref:q,isComponentVisible:rn,onOptionChange:e=>{Y==null||Y(e),k(e)}}):null,X=H?n.jsxs("div",{className:"sa-tf-box",ref:q,onClick:Sn,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?F(m,R):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[_("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:dn})]}),ln,on,z?F(z,nn):null]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,fn]}):n.jsxs("div",{className:"sa-tf-box",ref:q,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?F(m,R):null,dn,ln,on,z?F(z,nn):null]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,fn]});return v==="outside-left"?n.jsxs("div",{className:K,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[_("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[X,U]})]}):H?n.jsxs("div",{className:K,children:[X,U]}):n.jsxs("div",{className:K,children:[_("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null,X,U]})}),yn=(t,a)=>{if(!t)return null;if(!a)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const r=t.toLowerCase().indexOf(a.toLowerCase());return r===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,r),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(r,r+a.length)}),t.slice(r+a.length)]})};Z.displayName="Input",h.Input=Z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
567
+ `,y=t=>t==="lg"||t==="xl"?18:16,j={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)"},J=(t,a)=>a?j.disable:j[t]??j.default;function bn(t){return Number(t.replace(/\./g,""))}function O(t){let a=t.replace(/[^\d]/g,"");return a=a.replace(/^0+(?=\d)/,""),a.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function hn(t,a){if(a<=0)return 0;let i=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(i+=1,i===a))return l+1;return t.length}const xn=o.forwardRef(({options:t,value:a,setValue:i,isComponentVisible:l,onOptionChange:d},f)=>{const[v,V]=o.useState([]),c=o.useRef(null),u=()=>{if(f!=null&&f.current&&c.current){const x=window.innerHeight,p=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),k=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,k>=x-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(()=>{V((t==null?void 0:t.filter(x=>x.toLowerCase().startsWith(a.toLowerCase())))||[])},[a,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(x=>gn(x,a,i,d))})}),gn=(t,a,i,l)=>{const d=t.toLowerCase().indexOf(a.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+a.length)}),t.slice(d+a.length)]})};function vn(t){const[a,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:a,setIsComponentVisible:i}}const Q="starasia-input-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(Q)){const a=document.createElement("style");a.id=Q,a.textContent=t,document.head.appendChild(a)}})(pn);const mn=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"})]}),wn=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"})]}),Z=o.forwardRef((t,a)=>{const{size:i="md",variant:l="outline",status:d="default",label:f,labelPosition:v="outside-top",required:V,optional:c,description:u,helperText:x,errorText:p,leftIcon:m,rightIcon:k,leftAddons:S,rightAddons:L,onClickLeftIcon:R,onClickRightIcon:nn,fullWidth:kn=!1,highlightPlaceholder:$,currency:B,options:E,onOptionChange:Y,clearable:zn=!0,onClear:M,...s}=t,P=s.value!==void 0,[W,z]=o.useState(()=>{const e=s.value!==void 0?String(s.value??""):String(s.defaultValue??"");return B?O(e):e}),[tn,en]=o.useState(!1),[Cn,sn]=o.useState(""),C=o.useRef(null),N=o.useRef(null);o.useImperativeHandle(a,()=>N.current);const an=o.useRef(s.id??`sa-input-${Math.random().toString(36).slice(2,9)}`),{isComponentVisible:rn,ref:q,setIsComponentVisible:Nn}=vn(!1);o.useLayoutEffect(()=>{if(!P)return;const e=s.value===void 0||s.value===null?"":String(s.value),r=B?O(e):e;z(b=>b===r?b:r)},[s.value,B,P]),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{}},[W]);const I=W,D=I!==""&&I!==void 0,w=d==="disable"||s.disabled,A=w?"disable":d,H=v==="inside",In=H&&(D||tn),K=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${i}`,`sa-tf-status-${A}`,`sa-tf-label-${v}`,tn?"sa-tf-focused":"",w?"sa-tf-disabled":"",In?"sa-tf-floating":"",f?"":"sa-tf-no-label",kn?"sa-tf-fullwidth":""].filter(Boolean).join(" "),Sn=()=>{var e;return(e=N.current)==null?void 0:e.focus()},Ln=e=>{var cn,un;if(!B){const F=e.target.selectionStart;F!==null&&(C.current=F),z(e.target.value),(cn=s.onChange)==null||cn.call(s,e);return}const r=e.target.value;let b=r,g=e.target.selectionStart??r.length;if(Cn==="Backspace"){const F=W.replace(/\D/g,""),Fn=r.replace(/\D/g,"");F.length===Fn.length&&g>0&&(b=r.slice(0,g-1)+r.slice(g),g-=1)}const G=O(b),Dn=b.slice(0,g).replace(/\D/g,"").length,Tn=hn(G,Dn);C.current=Tn,z(G),(un=s.onChange)==null||un.call(s,{...e,target:{...e.target,value:String(bn(G)),name:e.target.name}}),sn("")},_=e=>f?n.jsxs("div",{className:e,children:[n.jsx("label",{htmlFor:an.current,style:{cursor:w?"not-allowed":"pointer"},children:f}),c?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,V?n.jsx("span",{className:"sa-tf-required","aria-hidden":"true",children:"*"}):null]}):null,U=n.jsxs(n.Fragment,{children:[x?n.jsx("p",{className:"sa-tf-helper",children:x}):null,p&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:p}):null]}),T=(e,r)=>n.jsx("span",{className:`sa-tf-icon${r?" sa-tf-icon-clickable":""}`,onClick:r,children:o.cloneElement(e,{width:y(i),height:y(i),color:J(A,w),style:{color:J(A,w)}})}),on=d==="success"?n.jsx("span",{className:"sa-tf-icon sa-tf-success-mark","aria-hidden":"true",children:n.jsx(mn,{width:y(i),height:y(i)})}):null,Bn=e=>{var b;e.stopPropagation(),P||z("");const r={target:{value:"",name:s.name},currentTarget:{value:"",name:s.name}};(b=s.onChange)==null||b.call(s,r),M==null||M(),C.current=0,requestAnimationFrame(()=>{var g;return(g=N.current)==null?void 0:g.focus()})},ln=zn&&!w?n.jsx("button",{type:"button",className:`sa-tf-icon sa-tf-clear${D?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!D,tabIndex:-1,onClick:Bn,onMouseDown:e=>e.preventDefault(),children:n.jsx(wn,{width:y(i),height:y(i)})}):null,En=!D&&!!s.placeholder&&!!$,dn=n.jsxs("div",{className:"sa-tf-field-wrap",children:[n.jsx("input",{...s,id:an.current,ref:N,className:"sa-tf-input",disabled:w,placeholder:$?"":s.placeholder,value:I,onFocus:e=>{var r;en(!0),Nn(!0),(r=s.onFocus)==null||r.call(s,e)},onBlur:e=>{var r;en(!1),(r=s.onBlur)==null||r.call(s,e)},onKeyDown:e=>{var r;e.key==="Backspace"&&sn(e.key),(r=s.onKeyDown)==null||r.call(s,e)},onChange:Ln}),En?yn(s.placeholder,$):null]}),fn=I&&rn&&(E!=null&&E.length)?n.jsx(xn,{options:E,value:I,setValue:z,ref:q,isComponentVisible:rn,onOptionChange:e=>{Y==null||Y(e),z(e)}}):null,X=H?n.jsxs("div",{className:"sa-tf-box",ref:q,onClick:Sn,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?T(m,R):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[_("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:dn})]}),ln,on,k?T(k,nn):null]}),L?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:L}):null,fn]}):n.jsxs("div",{className:"sa-tf-box",ref:q,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?T(m,R):null,dn,ln,on,k?T(k,nn):null]}),L?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:L}):null,fn]});return v==="outside-left"?n.jsxs("div",{className:K,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[_("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[X,U]})]}):H?n.jsxs("div",{className:K,children:[X,U]}):n.jsxs("div",{className:K,children:[_("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null,X,U]})}),yn=(t,a)=>{if(!t)return null;if(!a)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const i=t.toLowerCase().indexOf(a.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+a.length)}),t.slice(i+a.length)]})};Z.displayName="Input",h.Input=Z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/input",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "input component for starasia UI",
5
5
  "author": "Rizki Izzul Haq",
6
6
  "main": "dist/input.umd.js",
@@ -12,10 +12,6 @@
12
12
  "dist/*.map",
13
13
  "dist/*.css"
14
14
  ],
15
- "scripts": {
16
- "dev": "vite --config vite.config.ts --port 3000",
17
- "build": "vite build --config vite.config.ts"
18
- },
19
15
  "keywords": [],
20
16
  "license": "ISC",
21
17
  "type": "module",
@@ -37,5 +33,9 @@
37
33
  "react-dom": "^18.2.0",
38
34
  "@types/react": "^18.2.55",
39
35
  "@types/react-dom": "^18.2.19"
36
+ },
37
+ "scripts": {
38
+ "dev": "vite --config vite.config.ts --port 3000",
39
+ "build": "vite build --config vite.config.ts"
40
40
  }
41
- }
41
+ }