@starasia/input 4.0.1 → 4.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.
package/dist/Kbd.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ export interface KbdProps extends React.HTMLAttributes<HTMLSpanElement> {
3
+ /** Keys to render, one cap each. e.g. ['⌘', 'K'] */
4
+ keys: React.ReactNode[];
5
+ /** Optional separator rendered between caps. Default: none (gap only). */
6
+ separator?: React.ReactNode;
7
+ }
8
+ export declare function Kbd({ keys, separator, className, ...rest }: KbdProps): React.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { Input } from "./Input";
2
+ export { Kbd } from "./Kbd";
3
+ export type { KbdProps } from "./Kbd";
2
4
  export * from "./types";
package/dist/input.es.js CHANGED
@@ -1,6 +1,6 @@
1
- import { jsx as s, jsxs as o, Fragment as Ln } from "react/jsx-runtime";
2
- import Bn, { forwardRef as xn, useState as I, useRef as L, useEffect as O, useImperativeHandle as Rn, useLayoutEffect as un } from "react";
3
- const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ import { jsx as s, jsxs as o, Fragment as Sn } from "react/jsx-runtime";
2
+ import Z, { forwardRef as mn, useState as I, useRef as R, useEffect as D, useImperativeHandle as En, useLayoutEffect as pn } from "react";
3
+ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
4
 
5
5
  :root {
6
6
  /* Layer 3 — references Layer 2 semantic tokens */
@@ -593,50 +593,50 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
593
593
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
594
594
  min-height: 80px;
595
595
  }
596
- `, z = (n) => n === "lg" || n === "xl" ? 18 : 16, G = {
596
+ `, z = (n) => n === "lg" || n === "xl" ? 18 : 16, J = {
597
597
  default: "var(--sa-color-gray-800, #505258)",
598
598
  error: "var(--sa-text-error, #a4133c)",
599
599
  success: "var(--sa-text-success, #208958)",
600
600
  disable: "var(--sa-icon-disable, #181a198f)"
601
- }, bn = (n, a) => a ? G.disable : G[n] ?? G.default;
602
- function En(n) {
601
+ }, gn = (n, e) => e ? J.disable : J[n] ?? J.default;
602
+ function Fn(n) {
603
603
  return Number(n.replace(/\./g, ""));
604
604
  }
605
- function J(n) {
606
- let a = n.replace(/[^\d]/g, "");
607
- return a = a.replace(/^0+(?=\d)/, ""), a.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
605
+ function Q(n) {
606
+ let e = n.replace(/[^\d]/g, "");
607
+ return e = e.replace(/^0+(?=\d)/, ""), e.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
608
608
  }
609
- function Dn(n, a) {
610
- if (a <= 0)
609
+ function Dn(n, e) {
610
+ if (e <= 0)
611
611
  return 0;
612
612
  let r = 0;
613
613
  for (let l = 0; l < n.length; l++)
614
- if (/\d/.test(n[l]) && (r += 1, r === a))
614
+ if (/\d/.test(n[l]) && (r += 1, r === e))
615
615
  return l + 1;
616
616
  return n.length;
617
617
  }
618
- const Fn = xn(
619
- ({ options: n, value: a, setValue: r, isComponentVisible: l, onOptionChange: d }, f) => {
620
- const [h, V] = I([]), c = L(null), u = () => {
621
- if (f != null && f.current && c.current) {
622
- const x = window.innerHeight, b = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(), w = b.bottom + m.height;
623
- c.current.style.left = `${b.left}px`, c.current.style.width = `${b.width}px`, w >= x - 10 ? c.current.style.top = `${b.top - m.height - 5}px` : c.current.style.top = `${b.top + b.height}px`;
618
+ 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`;
624
624
  }
625
625
  };
626
- return O(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
626
+ return D(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
627
627
  window.removeEventListener("scroll", u), window.removeEventListener("resize", u);
628
- }), [f, c]), O(() => {
628
+ }), [c, f]), D(() => {
629
629
  u();
630
- }, [l]), O(() => {
631
- V(
630
+ }, [l]), D(() => {
631
+ T(
632
632
  (n == null ? void 0 : n.filter(
633
- (x) => x.toLowerCase().startsWith(a.toLowerCase())
633
+ (g) => g.toLowerCase().startsWith(e.toLowerCase())
634
634
  )) || []
635
635
  );
636
- }, [a, n]), /* @__PURE__ */ s(
636
+ }, [e, n]), /* @__PURE__ */ s(
637
637
  "div",
638
638
  {
639
- ref: c,
639
+ ref: f,
640
640
  style: {
641
641
  position: "fixed",
642
642
  padding: "8px",
@@ -647,14 +647,14 @@ const Fn = xn(
647
647
  overflow: "auto",
648
648
  zIndex: 5e4
649
649
  },
650
- children: h == null ? void 0 : h.map(
651
- (x) => Tn(x, a, r, d)
650
+ children: x == null ? void 0 : x.map(
651
+ (g) => Vn(g, e, r, d)
652
652
  )
653
653
  }
654
654
  );
655
655
  }
656
- ), Tn = (n, a, r, l) => {
657
- const d = n.toLowerCase().indexOf(a.toLowerCase());
656
+ ), Vn = (n, e, r, l) => {
657
+ const d = n.toLowerCase().indexOf(e.toLowerCase());
658
658
  return /* @__PURE__ */ o(
659
659
  "p",
660
660
  {
@@ -670,28 +670,28 @@ const Fn = xn(
670
670
  },
671
671
  children: [
672
672
  n.slice(0, d),
673
- /* @__PURE__ */ s("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + a.length) }),
674
- n.slice(d + a.length)
673
+ /* @__PURE__ */ s("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + e.length) }),
674
+ n.slice(d + e.length)
675
675
  ]
676
676
  }
677
677
  );
678
678
  };
679
679
  function On(n) {
680
- const [a, r] = I(n), l = L(null), d = (f) => {
681
- l.current && !l.current.contains(f.target) && r(!1);
680
+ const [e, r] = I(n), l = R(null), d = (c) => {
681
+ l.current && !l.current.contains(c.target) && r(!1);
682
682
  };
683
- return O(() => (document.addEventListener("click", d, !0), () => {
683
+ return D(() => (document.addEventListener("click", d, !0), () => {
684
684
  document.removeEventListener("click", d, !0);
685
- }), []), { ref: l, isComponentVisible: a, setIsComponentVisible: r };
685
+ }), []), { ref: l, isComponentVisible: e, setIsComponentVisible: r };
686
686
  }
687
- const pn = "sa-input-styles", Vn = (n) => {
688
- if (!(typeof document > "u") && !document.getElementById(pn)) {
689
- const a = document.createElement("style");
690
- a.id = pn, a.textContent = n, document.head.appendChild(a);
687
+ const hn = "sa-input-styles", jn = (n) => {
688
+ if (!(typeof document > "u") && !document.getElementById(hn)) {
689
+ const e = document.createElement("style");
690
+ e.id = hn, e.textContent = n, document.head.appendChild(e);
691
691
  }
692
692
  };
693
- Vn(Sn);
694
- const $n = (n) => /* @__PURE__ */ o(
693
+ jn($n);
694
+ const Yn = (n) => /* @__PURE__ */ o(
695
695
  "svg",
696
696
  {
697
697
  viewBox: "0 0 16 16",
@@ -712,7 +712,7 @@ const $n = (n) => /* @__PURE__ */ o(
712
712
  )
713
713
  ]
714
714
  }
715
- ), jn = (n) => /* @__PURE__ */ o(
715
+ ), An = (n) => /* @__PURE__ */ o(
716
716
  "svg",
717
717
  {
718
718
  viewBox: "0 0 16 16",
@@ -732,51 +732,51 @@ const $n = (n) => /* @__PURE__ */ o(
732
732
  )
733
733
  ]
734
734
  }
735
- ), Yn = xn(
736
- (n, a) => {
735
+ ), Wn = mn(
736
+ (n, e) => {
737
737
  const {
738
738
  size: r = "md",
739
739
  variant: l = "outline",
740
740
  status: d = "default",
741
- label: f,
742
- labelPosition: h = "outside-top",
743
- required: V,
744
- optional: c,
741
+ label: c,
742
+ labelPosition: x = "outside-top",
743
+ required: T,
744
+ optional: f,
745
745
  description: u,
746
- helperText: x,
746
+ helperText: g,
747
747
  errorText: b,
748
748
  leftIcon: m,
749
- rightIcon: w,
749
+ rightIcon: v,
750
750
  leftAddons: B,
751
- rightAddons: R,
752
- onClickLeftIcon: Q,
753
- onClickRightIcon: Z,
754
- fullWidth: gn = !0,
755
- highlightPlaceholder: $,
751
+ rightAddons: L,
752
+ onClickLeftIcon: nn,
753
+ onClickRightIcon: V,
754
+ fullWidth: vn = !0,
755
+ highlightPlaceholder: O,
756
756
  currency: S,
757
757
  options: E,
758
758
  onOptionChange: j,
759
- clearable: hn = !0,
759
+ clearable: wn = !0,
760
760
  onClear: Y,
761
- ...e
762
- } = n, A = e.value !== void 0, [W, y] = I(() => {
763
- const t = e.value !== void 0 ? String(e.value ?? "") : String(e.defaultValue ?? "");
764
- return S ? J(t) : t;
765
- }), [nn, tn] = I(!1), [mn, en] = I(""), k = L(null), C = L(null);
766
- Rn(a, () => C.current);
767
- const an = L(
768
- e.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
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 ?? "");
764
+ return S ? Q(t) : t;
765
+ }), [tn, en] = I(!1), [yn, an] = I(""), k = R(null), C = R(null);
766
+ En(e, () => C.current);
767
+ const sn = R(
768
+ a.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
769
769
  ), {
770
- isComponentVisible: sn,
771
- ref: M,
772
- setIsComponentVisible: vn
770
+ isComponentVisible: rn,
771
+ ref: _,
772
+ setIsComponentVisible: kn
773
773
  } = On(!1);
774
- un(() => {
774
+ pn(() => {
775
775
  if (!A)
776
776
  return;
777
- const t = e.value === void 0 || e.value === null ? "" : String(e.value), i = S ? J(t) : t;
777
+ const t = a.value === void 0 || a.value === null ? "" : String(a.value), i = S ? Q(t) : t;
778
778
  y((p) => p === i ? p : i);
779
- }, [e.value, S, A]), un(() => {
779
+ }, [a.value, S, A]), pn(() => {
780
780
  if (k.current === null)
781
781
  return;
782
782
  const t = C.current, i = k.current;
@@ -786,208 +786,264 @@ const $n = (n) => /* @__PURE__ */ o(
786
786
  } catch {
787
787
  }
788
788
  }, [W]);
789
- const N = W, D = N !== "" && N !== void 0, v = d === "disable" || e.disabled, P = v ? "disable" : d, H = h === "inside", wn = H && (D || nn), q = [
789
+ const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || a.disabled, M = w ? "disable" : d, P = x === "inside", zn = P && ($ || tn), H = [
790
790
  "sa-tf",
791
791
  `sa-tf-variant-${l}`,
792
792
  `sa-tf-size-${r}`,
793
- `sa-tf-status-${P}`,
794
- `sa-tf-label-${h}`,
795
- nn ? "sa-tf-focused" : "",
796
- v ? "sa-tf-disabled" : "",
797
- wn ? "sa-tf-floating" : "",
798
- f ? "" : "sa-tf-no-label",
799
- gn ? "sa-tf-fullwidth" : ""
800
- ].filter(Boolean).join(" "), yn = () => {
793
+ `sa-tf-status-${M}`,
794
+ `sa-tf-label-${x}`,
795
+ tn ? "sa-tf-focused" : "",
796
+ w ? "sa-tf-disabled" : "",
797
+ zn ? "sa-tf-floating" : "",
798
+ c ? "" : "sa-tf-no-label",
799
+ vn ? "sa-tf-fullwidth" : ""
800
+ ].filter(Boolean).join(" "), Cn = () => {
801
801
  var t;
802
802
  return (t = C.current) == null ? void 0 : t.focus();
803
- }, kn = (t) => {
804
- var fn, cn;
803
+ }, Nn = (t) => {
804
+ var un, bn;
805
805
  if (!S) {
806
- const T = t.target.selectionStart;
807
- T !== null && (k.current = T), y(t.target.value), (fn = e.onChange) == null || fn.call(e, t);
806
+ const F = t.target.selectionStart;
807
+ F !== null && (k.current = F), y(t.target.value), (un = a.onChange) == null || un.call(a, t);
808
808
  return;
809
809
  }
810
810
  const i = t.target.value;
811
- let p = i, g = t.target.selectionStart ?? i.length;
812
- if (mn === "Backspace") {
813
- const T = W.replace(/\D/g, ""), In = i.replace(/\D/g, "");
814
- T.length === In.length && g > 0 && (p = i.slice(0, g - 1) + i.slice(g), g -= 1);
811
+ let p = i, h = t.target.selectionStart ?? i.length;
812
+ if (yn === "Backspace") {
813
+ 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);
815
815
  }
816
- const X = J(p), Cn = p.slice(0, g).replace(/\D/g, "").length, Nn = Dn(X, Cn);
817
- k.current = Nn, y(X), (cn = e.onChange) == null || cn.call(e, {
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, {
818
818
  ...t,
819
819
  target: {
820
820
  ...t.target,
821
- value: String(En(X)),
821
+ value: String(Fn(G)),
822
822
  name: t.target.name
823
823
  }
824
- }), en("");
825
- }, K = (t) => f ? /* @__PURE__ */ o("div", { className: t, children: [
824
+ }), an("");
825
+ }, q = (t) => c ? /* @__PURE__ */ o("div", { className: t, children: [
826
826
  /* @__PURE__ */ s(
827
827
  "label",
828
828
  {
829
- htmlFor: an.current,
830
- style: { cursor: v ? "not-allowed" : "pointer" },
831
- children: f
829
+ htmlFor: sn.current,
830
+ style: { cursor: w ? "not-allowed" : "pointer" },
831
+ children: c
832
832
  }
833
833
  ),
834
- c ? /* @__PURE__ */ s("span", { className: "sa-tf-optional", children: "Optional" }) : null,
835
- V ? /* @__PURE__ */ s("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
836
- ] }) : null, _ = /* @__PURE__ */ o(Ln, { children: [
837
- x ? /* @__PURE__ */ s("p", { className: "sa-tf-helper", children: x }) : null,
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
836
+ ] }) : null, K = /* @__PURE__ */ o(Sn, { children: [
837
+ g ? /* @__PURE__ */ s("p", { className: "sa-tf-helper", children: g }) : null,
838
838
  b && d === "error" ? /* @__PURE__ */ s("p", { className: "sa-tf-error", children: b }) : null
839
- ] }), F = (t, i) => /* @__PURE__ */ s(
839
+ ] }), U = (t, i) => /* @__PURE__ */ s(
840
840
  "span",
841
841
  {
842
842
  className: `sa-tf-icon${i ? " sa-tf-icon-clickable" : ""}`,
843
843
  onClick: i,
844
- children: Bn.cloneElement(t, {
844
+ children: Z.cloneElement(t, {
845
845
  width: z(r),
846
846
  height: z(r),
847
- color: bn(P, v),
848
- style: { color: bn(P, v) }
847
+ color: gn(M, w),
848
+ style: { color: gn(M, w) }
849
849
  })
850
850
  }
851
- ), rn = d === "success" ? /* @__PURE__ */ s("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ s(
852
- $n,
851
+ ), on = () => {
852
+ var i;
853
+ return v == null ? null : !Z.isValidElement(v) || ((i = v.type) == null ? void 0 : i.__saRaw) === !0 ? /* @__PURE__ */ s(
854
+ "span",
855
+ {
856
+ className: `sa-tf-icon${V ? " sa-tf-icon-clickable" : ""}`,
857
+ onClick: V,
858
+ children: v
859
+ }
860
+ ) : U(v, V);
861
+ }, ln = d === "success" ? /* @__PURE__ */ s("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ s(
862
+ Yn,
853
863
  {
854
864
  width: z(r),
855
865
  height: z(r)
856
866
  }
857
- ) }) : null, on = hn && !v ? /* @__PURE__ */ s(
867
+ ) }) : null, dn = wn && !w ? /* @__PURE__ */ s(
858
868
  "button",
859
869
  {
860
870
  type: "button",
861
- className: `sa-tf-icon sa-tf-clear${D ? "" : " sa-tf-clear-hidden"}`,
871
+ className: `sa-tf-icon sa-tf-clear${$ ? "" : " sa-tf-clear-hidden"}`,
862
872
  "aria-label": "Clear input",
863
- "aria-hidden": !D,
873
+ "aria-hidden": !$,
864
874
  tabIndex: -1,
865
875
  onClick: (t) => {
866
876
  var p;
867
877
  t.stopPropagation(), A || y("");
868
878
  const i = {
869
- target: { value: "", name: e.name },
870
- currentTarget: { value: "", name: e.name }
879
+ target: { value: "", name: a.name },
880
+ currentTarget: { value: "", name: a.name }
871
881
  };
872
- (p = e.onChange) == null || p.call(e, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
873
- var g;
874
- return (g = C.current) == null ? void 0 : g.focus();
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();
875
885
  });
876
886
  },
877
887
  onMouseDown: (t) => t.preventDefault(),
878
888
  children: /* @__PURE__ */ s(
879
- jn,
889
+ An,
880
890
  {
881
891
  width: z(r),
882
892
  height: z(r)
883
893
  }
884
894
  )
885
895
  }
886
- ) : null, zn = !D && !!e.placeholder && !!$, ln = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
896
+ ) : null, In = !$ && !!a.placeholder && !!O, cn = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
887
897
  /* @__PURE__ */ s(
888
898
  "input",
889
899
  {
890
- ...e,
891
- id: an.current,
900
+ ...a,
901
+ id: sn.current,
892
902
  ref: C,
893
903
  className: "sa-tf-input",
894
- disabled: v,
895
- placeholder: $ ? "" : e.placeholder,
904
+ disabled: w,
905
+ placeholder: O ? "" : a.placeholder,
896
906
  value: N,
897
907
  onFocus: (t) => {
898
908
  var i;
899
- tn(!0), vn(!0), (i = e.onFocus) == null || i.call(e, t);
909
+ en(!0), kn(!0), (i = a.onFocus) == null || i.call(a, t);
900
910
  },
901
911
  onBlur: (t) => {
902
912
  var i;
903
- tn(!1), (i = e.onBlur) == null || i.call(e, t);
913
+ en(!1), (i = a.onBlur) == null || i.call(a, t);
904
914
  },
905
915
  onKeyDown: (t) => {
906
916
  var i;
907
- t.key === "Backspace" && en(t.key), (i = e.onKeyDown) == null || i.call(e, t);
917
+ t.key === "Backspace" && an(t.key), (i = a.onKeyDown) == null || i.call(a, t);
908
918
  },
909
- onChange: kn
919
+ onChange: Nn
910
920
  }
911
921
  ),
912
- zn ? An(e.placeholder, $) : null
913
- ] }), dn = N && sn && (E != null && E.length) ? /* @__PURE__ */ s(
914
- Fn,
922
+ In ? _n(a.placeholder, O) : null
923
+ ] }), fn = N && rn && (E != null && E.length) ? /* @__PURE__ */ s(
924
+ Tn,
915
925
  {
916
926
  options: E,
917
927
  value: N,
918
928
  setValue: y,
919
- ref: M,
920
- isComponentVisible: sn,
929
+ ref: _,
930
+ isComponentVisible: rn,
921
931
  onOptionChange: (t) => {
922
932
  j == null || j(t), y(t);
923
933
  }
924
934
  }
925
- ) : null, U = H ? /* @__PURE__ */ o(
935
+ ) : null, X = P ? /* @__PURE__ */ o(
926
936
  "div",
927
937
  {
928
938
  className: "sa-tf-box",
929
- ref: M,
930
- onClick: yn,
939
+ ref: _,
940
+ onClick: Cn,
931
941
  children: [
932
942
  B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
933
943
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
934
- m ? F(m, Q) : null,
944
+ m ? U(m, nn) : null,
935
945
  /* @__PURE__ */ o("div", { className: "sa-tf-inside-stack", children: [
936
- K("sa-tf-inside-label-row"),
937
- /* @__PURE__ */ s("div", { className: "sa-tf-inside-row", children: ln })
946
+ q("sa-tf-inside-label-row"),
947
+ /* @__PURE__ */ s("div", { className: "sa-tf-inside-row", children: cn })
938
948
  ] }),
939
- on,
940
- rn,
941
- w ? F(w, Z) : null
949
+ dn,
950
+ ln,
951
+ on()
942
952
  ] }),
943
- R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: R }) : null,
944
- dn
953
+ L ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
954
+ fn
945
955
  ]
946
956
  }
947
- ) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: M, children: [
957
+ ) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: _, children: [
948
958
  B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
949
959
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
950
- m ? F(m, Q) : null,
960
+ m ? U(m, nn) : null,
961
+ cn,
962
+ dn,
951
963
  ln,
952
- on,
953
- rn,
954
- w ? F(w, Z) : null
964
+ on()
955
965
  ] }),
956
- R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: R }) : null,
957
- dn
966
+ L ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
967
+ fn
958
968
  ] });
959
- return h === "outside-left" ? /* @__PURE__ */ o("div", { className: q, children: [
969
+ return x === "outside-left" ? /* @__PURE__ */ o("div", { className: H, children: [
960
970
  /* @__PURE__ */ o("div", { className: "sa-tf-label-col", children: [
961
- K("sa-tf-label"),
971
+ q("sa-tf-label"),
962
972
  u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null
963
973
  ] }),
964
974
  /* @__PURE__ */ o("div", { className: "sa-tf-input-col", children: [
965
- U,
966
- _
975
+ X,
976
+ K
967
977
  ] })
968
- ] }) : H ? /* @__PURE__ */ o("div", { className: q, children: [
969
- U,
970
- _
971
- ] }) : /* @__PURE__ */ o("div", { className: q, children: [
972
- K("sa-tf-label"),
978
+ ] }) : P ? /* @__PURE__ */ o("div", { className: H, children: [
979
+ X,
980
+ K
981
+ ] }) : /* @__PURE__ */ o("div", { className: H, children: [
982
+ q("sa-tf-label"),
973
983
  u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null,
974
- U,
975
- _
984
+ X,
985
+ K
976
986
  ] });
977
987
  }
978
- ), An = (n, a) => {
988
+ ), _n = (n, e) => {
979
989
  if (!n)
980
990
  return null;
981
- if (!a)
991
+ if (!e)
982
992
  return /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n });
983
- const r = n.toLowerCase().indexOf(a.toLowerCase());
993
+ const r = n.toLowerCase().indexOf(e.toLowerCase());
984
994
  return r === -1 ? /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ o("p", { className: "sa-tf-placeholder", children: [
985
995
  n.slice(0, r),
986
- /* @__PURE__ */ s("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + a.length) }),
987
- n.slice(r + a.length)
996
+ /* @__PURE__ */ s("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + e.length) }),
997
+ n.slice(r + e.length)
988
998
  ] });
989
999
  };
990
- Yn.displayName = "Input";
1000
+ Wn.displayName = "Input";
1001
+ const Mn = `.sa-kbd {
1002
+ display: inline-flex;
1003
+ align-items: center;
1004
+ gap: var(--sa-spacing-4, 4px);
1005
+ vertical-align: middle;
1006
+ }
1007
+
1008
+ .sa-kbd-key {
1009
+ display: inline-flex;
1010
+ align-items: center;
1011
+ justify-content: center;
1012
+ min-width: 1.5em;
1013
+ padding: 0 var(--sa-spacing-6, 6px);
1014
+ background-color: var(--sa-background-neutral, #f0f1f2);
1015
+ border: 1px solid var(--sa-border-subtle, #0b120e24);
1016
+ border-radius: var(--sa-radii-xs, 4px);
1017
+ color: var(--sa-text-subtle, #505258);
1018
+ font-family: inherit;
1019
+ font-size: var(--sa-font-size-sm, 12px);
1020
+ font-weight: var(--sa-font-weight-medium, 400);
1021
+ line-height: 1.6;
1022
+ white-space: nowrap;
1023
+ }
1024
+
1025
+ .sa-kbd-sep {
1026
+ display: inline-flex;
1027
+ align-items: center;
1028
+ color: var(--sa-text-subtlest, #6b6e76);
1029
+ font-size: var(--sa-font-size-sm, 12px);
1030
+ user-select: none;
1031
+ }
1032
+ `, xn = "sa-kbd-styles", Pn = (n) => {
1033
+ if (!(typeof document > "u") && !document.getElementById(xn)) {
1034
+ const e = document.createElement("style");
1035
+ e.id = xn, e.textContent = n, document.head.appendChild(e);
1036
+ }
1037
+ };
1038
+ Pn(Mn);
1039
+ 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)) });
1044
+ }
1045
+ Hn.__saRaw = !0;
991
1046
  export {
992
- Yn as Input
1047
+ Wn as Input,
1048
+ Hn as Kbd
993
1049
  };
package/dist/input.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(x,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):(x=typeof globalThis<"u"?globalThis:x||self,n(x.Input={},x.jsxRuntime,x.React))})(this,function(x,n,o){"use strict";const bn=`@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 gn=`@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 */
@@ -591,4 +591,35 @@
591
591
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
592
592
  min-height: 80px;
593
593
  }
594
- `,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 pn(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 xn(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 hn=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 h=window.innerHeight,b=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),k=b.bottom+m.height;c.current.style.left=`${b.left}px`,c.current.style.width=`${b.width}px`,k>=h-10?c.current.style.top=`${b.top-m.height-5}px`:c.current.style.top=`${b.top+b.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(h=>h.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(h=>gn(h,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="sa-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)}})(bn);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:h,errorText:b,leftIcon:m,rightIcon:k,leftAddons:S,rightAddons:L,onClickLeftIcon:R,onClickRightIcon:nn,fullWidth:kn=!0,highlightPlaceholder:$,currency:B,options:E,onOptionChange:Y,clearable:zn=!0,onClear:A,...s}=t,M=s.value!==void 0,[P,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:W,setIsComponentVisible:Nn}=vn(!1);o.useLayoutEffect(()=>{if(!M)return;const e=s.value===void 0||s.value===null?"":String(s.value),r=B?O(e):e;z(p=>p===r?p:r)},[s.value,B,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,T=I!==""&&I!==void 0,w=d==="disable"||s.disabled,q=w?"disable":d,H=v==="inside",In=H&&(T||tn),K=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${i}`,`sa-tf-status-${q}`,`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 p=r,g=e.target.selectionStart??r.length;if(Cn==="Backspace"){const F=P.replace(/\D/g,""),Fn=r.replace(/\D/g,"");F.length===Fn.length&&g>0&&(p=r.slice(0,g-1)+r.slice(g),g-=1)}const G=O(p),Tn=p.slice(0,g).replace(/\D/g,"").length,Dn=xn(G,Tn);C.current=Dn,z(G),(un=s.onChange)==null||un.call(s,{...e,target:{...e.target,value:String(pn(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:[h?n.jsx("p",{className:"sa-tf-helper",children:h}):null,b&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:b}):null]}),D=(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(q,w),style:{color:J(q,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 p;e.stopPropagation(),M||z("");const r={target:{value:"",name:s.name},currentTarget:{value:"",name:s.name}};(p=s.onChange)==null||p.call(s,r),A==null||A(),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${T?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!T,tabIndex:-1,onClick:Bn,onMouseDown:e=>e.preventDefault(),children:n.jsx(wn,{width:y(i),height:y(i)})}):null,En=!T&&!!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(hn,{options:E,value:I,setValue:z,ref:W,isComponentVisible:rn,onOptionChange:e=>{Y==null||Y(e),z(e)}}):null,X=H?n.jsxs("div",{className:"sa-tf-box",ref:W,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?D(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?D(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: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?D(m,R):null,dn,ln,on,k?D(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",x.Input=Z,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
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 {
595
+ display: inline-flex;
596
+ align-items: center;
597
+ gap: var(--sa-spacing-4, 4px);
598
+ vertical-align: middle;
599
+ }
600
+
601
+ .sa-kbd-key {
602
+ display: inline-flex;
603
+ align-items: center;
604
+ justify-content: center;
605
+ min-width: 1.5em;
606
+ padding: 0 var(--sa-spacing-6, 6px);
607
+ background-color: var(--sa-background-neutral, #f0f1f2);
608
+ border: 1px solid var(--sa-border-subtle, #0b120e24);
609
+ border-radius: var(--sa-radii-xs, 4px);
610
+ color: var(--sa-text-subtle, #505258);
611
+ font-family: inherit;
612
+ font-size: var(--sa-font-size-sm, 12px);
613
+ font-weight: var(--sa-font-weight-medium, 400);
614
+ line-height: 1.6;
615
+ white-space: nowrap;
616
+ }
617
+
618
+ .sa-kbd-sep {
619
+ display: inline-flex;
620
+ align-items: center;
621
+ color: var(--sa-text-subtlest, #6b6e76);
622
+ font-size: var(--sa-font-size-sm, 12px);
623
+ user-select: none;
624
+ }
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"})});
package/dist/types.d.ts CHANGED
@@ -17,7 +17,11 @@ export interface IInputProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
17
17
  helperText?: string;
18
18
  errorText?: string;
19
19
  leftIcon?: ReactElement<IconInputProps>;
20
- rightIcon?: ReactElement<IconInputProps>;
20
+ /**
21
+ * Right-side slot. Accepts an SVG icon (sized/colored automatically) or any
22
+ * ReactNode such as a <Kbd /> keycap (rendered as-is).
23
+ */
24
+ rightIcon?: ReactNode;
21
25
  leftAddons?: ReactNode;
22
26
  rightAddons?: ReactNode;
23
27
  onClickLeftIcon?: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/input",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "input component for starasia UI",
5
5
  "author": "Rizki Izzul Haq",
6
6
  "main": "dist/input.umd.js",