@starasia/input 4.0.1 → 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.
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;
@@ -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/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 a, 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 */
@@ -90,6 +90,8 @@ const Sn = `@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 Sn = `@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 Sn = `@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 Sn = `@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 Sn = `@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 Sn = `@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 Sn = `@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 Sn = `@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,47 +609,47 @@ const Sn = `@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, G = {
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
- }, bn = (n, a) => a ? G.disable : G[n] ?? G.default;
602
- function En(n) {
617
+ }, xn = (n, e) => e ? J.disable : J[n] ?? J.default;
618
+ function Fn(n) {
603
619
  return Number(n.replace(/\./g, ""));
604
620
  }
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, ".");
621
+ function Q(n) {
622
+ let e = n.replace(/[^\d]/g, "");
623
+ return e = e.replace(/^0+(?=\d)/, ""), e.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
608
624
  }
609
- function Dn(n, a) {
610
- if (a <= 0)
625
+ function Dn(n, e) {
626
+ if (e <= 0)
611
627
  return 0;
612
628
  let r = 0;
613
629
  for (let l = 0; l < n.length; l++)
614
- if (/\d/.test(n[l]) && (r += 1, r === a))
630
+ if (/\d/.test(n[l]) && (r += 1, r === e))
615
631
  return l + 1;
616
632
  return n.length;
617
633
  }
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 = () => {
634
+ const Tn = mn(
635
+ ({ options: n, value: e, setValue: r, isComponentVisible: l, onOptionChange: d }, f) => {
636
+ const [h, T] = I([]), c = R(null), u = () => {
621
637
  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`;
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
- return O(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
642
+ return D(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
627
643
  window.removeEventListener("scroll", u), window.removeEventListener("resize", u);
628
- }), [f, c]), O(() => {
644
+ }), [f, c]), D(() => {
629
645
  u();
630
- }, [l]), O(() => {
631
- V(
646
+ }, [l]), D(() => {
647
+ T(
632
648
  (n == null ? void 0 : n.filter(
633
- (x) => x.toLowerCase().startsWith(a.toLowerCase())
649
+ (x) => x.toLowerCase().startsWith(e.toLowerCase())
634
650
  )) || []
635
651
  );
636
- }, [a, n]), /* @__PURE__ */ s(
652
+ }, [e, n]), /* @__PURE__ */ a(
637
653
  "div",
638
654
  {
639
655
  ref: c,
@@ -648,13 +664,13 @@ const Fn = xn(
648
664
  zIndex: 5e4
649
665
  },
650
666
  children: h == null ? void 0 : h.map(
651
- (x) => Tn(x, a, r, d)
667
+ (x) => Vn(x, e, r, d)
652
668
  )
653
669
  }
654
670
  );
655
671
  }
656
- ), Tn = (n, a, r, l) => {
657
- const d = n.toLowerCase().indexOf(a.toLowerCase());
672
+ ), Vn = (n, e, r, l) => {
673
+ const d = n.toLowerCase().indexOf(e.toLowerCase());
658
674
  return /* @__PURE__ */ o(
659
675
  "p",
660
676
  {
@@ -670,28 +686,28 @@ const Fn = xn(
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 + a.length) }),
674
- n.slice(d + a.length)
689
+ /* @__PURE__ */ a("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + e.length) }),
690
+ n.slice(d + e.length)
675
691
  ]
676
692
  }
677
693
  );
678
694
  };
679
695
  function On(n) {
680
- const [a, r] = I(n), l = L(null), d = (f) => {
696
+ const [e, r] = I(n), l = R(null), d = (f) => {
681
697
  l.current && !l.current.contains(f.target) && r(!1);
682
698
  };
683
- return O(() => (document.addEventListener("click", d, !0), () => {
699
+ return D(() => (document.addEventListener("click", d, !0), () => {
684
700
  document.removeEventListener("click", d, !0);
685
- }), []), { ref: l, isComponentVisible: a, setIsComponentVisible: r };
701
+ }), []), { ref: l, isComponentVisible: e, setIsComponentVisible: r };
686
702
  }
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);
703
+ const gn = "sa-input-styles", jn = (n) => {
704
+ if (!(typeof document > "u") && !document.getElementById(gn)) {
705
+ const e = document.createElement("style");
706
+ e.id = gn, e.textContent = n, document.head.appendChild(e);
691
707
  }
692
708
  };
693
- Vn(Sn);
694
- const $n = (n) => /* @__PURE__ */ o(
709
+ jn($n);
710
+ const Yn = (n) => /* @__PURE__ */ o(
695
711
  "svg",
696
712
  {
697
713
  viewBox: "0 0 16 16",
@@ -699,8 +715,8 @@ const $n = (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",
@@ -712,7 +728,7 @@ const $n = (n) => /* @__PURE__ */ o(
712
728
  )
713
729
  ]
714
730
  }
715
- ), jn = (n) => /* @__PURE__ */ o(
731
+ ), An = (n) => /* @__PURE__ */ o(
716
732
  "svg",
717
733
  {
718
734
  viewBox: "0 0 16 16",
@@ -720,8 +736,8 @@ const $n = (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",
@@ -732,51 +748,51 @@ const $n = (n) => /* @__PURE__ */ o(
732
748
  )
733
749
  ]
734
750
  }
735
- ), Yn = xn(
736
- (n, a) => {
751
+ ), Wn = mn(
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
757
  label: f,
742
758
  labelPosition: h = "outside-top",
743
- required: V,
759
+ required: T,
744
760
  optional: c,
745
761
  description: u,
746
762
  helperText: x,
747
763
  errorText: b,
748
764
  leftIcon: m,
749
- rightIcon: w,
765
+ rightIcon: v,
750
766
  leftAddons: B,
751
- rightAddons: R,
752
- onClickLeftIcon: Q,
753
- onClickRightIcon: Z,
754
- fullWidth: gn = !0,
755
- highlightPlaceholder: $,
767
+ rightAddons: L,
768
+ onClickLeftIcon: nn,
769
+ onClickRightIcon: V,
770
+ fullWidth: vn = !0,
771
+ highlightPlaceholder: O,
756
772
  currency: S,
757
773
  options: E,
758
774
  onOptionChange: j,
759
- clearable: hn = !0,
775
+ clearable: wn = !0,
760
776
  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)}`
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 ?? "");
780
+ return S ? Q(t) : t;
781
+ }), [tn, en] = I(!1), [yn, sn] = I(""), k = R(null), C = R(null);
782
+ En(e, () => C.current);
783
+ const an = R(
784
+ s.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
769
785
  ), {
770
- isComponentVisible: sn,
771
- ref: M,
772
- setIsComponentVisible: vn
786
+ isComponentVisible: rn,
787
+ ref: _,
788
+ setIsComponentVisible: kn
773
789
  } = On(!1);
774
- un(() => {
790
+ pn(() => {
775
791
  if (!A)
776
792
  return;
777
- const t = e.value === void 0 || e.value === null ? "" : String(e.value), i = S ? J(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
- }, [e.value, S, A]), un(() => {
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,208 +802,264 @@ const $n = (n) => /* @__PURE__ */ o(
786
802
  } catch {
787
803
  }
788
804
  }, [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 = [
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
- `sa-tf-status-${P}`,
809
+ `sa-tf-status-${M}`,
794
810
  `sa-tf-label-${h}`,
795
- nn ? "sa-tf-focused" : "",
796
- v ? "sa-tf-disabled" : "",
797
- wn ? "sa-tf-floating" : "",
811
+ tn ? "sa-tf-focused" : "",
812
+ w ? "sa-tf-disabled" : "",
813
+ zn ? "sa-tf-floating" : "",
798
814
  f ? "" : "sa-tf-no-label",
799
- gn ? "sa-tf-fullwidth" : ""
800
- ].filter(Boolean).join(" "), yn = () => {
815
+ vn ? "sa-tf-fullwidth" : ""
816
+ ].filter(Boolean).join(" "), Cn = () => {
801
817
  var t;
802
818
  return (t = C.current) == null ? void 0 : t.focus();
803
- }, kn = (t) => {
804
- var fn, cn;
819
+ }, Nn = (t) => {
820
+ var un, bn;
805
821
  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);
822
+ const F = t.target.selectionStart;
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
827
  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);
828
+ if (yn === "Backspace") {
829
+ const F = W.replace(/\D/g, ""), Ln = i.replace(/\D/g, "");
830
+ F.length === Ln.length && g > 0 && (p = i.slice(0, g - 1) + i.slice(g), g -= 1);
815
831
  }
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, {
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
- value: String(En(X)),
837
+ value: String(Fn(G)),
822
838
  name: t.target.name
823
839
  }
824
- }), en("");
825
- }, K = (t) => f ? /* @__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
845
  htmlFor: an.current,
830
- style: { cursor: v ? "not-allowed" : "pointer" },
846
+ style: { cursor: w ? "not-allowed" : "pointer" },
831
847
  children: f
832
848
  }
833
849
  ),
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,
838
- b && d === "error" ? /* @__PURE__ */ s("p", { className: "sa-tf-error", children: b }) : null
839
- ] }), F = (t, i) => /* @__PURE__ */ s(
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
852
+ ] }) : null, K = /* @__PURE__ */ o(Sn, { children: [
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" : ""}`,
843
859
  onClick: i,
844
- children: Bn.cloneElement(t, {
860
+ children: Z.cloneElement(t, {
845
861
  width: z(r),
846
862
  height: z(r),
847
- color: bn(P, v),
848
- style: { color: bn(P, v) }
863
+ color: xn(M, w),
864
+ style: { color: xn(M, w) }
849
865
  })
850
866
  }
851
- ), rn = d === "success" ? /* @__PURE__ */ s("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ s(
852
- $n,
867
+ ), on = () => {
868
+ var i;
869
+ return v == null ? null : !Z.isValidElement(v) || ((i = v.type) == null ? void 0 : i.__saRaw) === !0 ? /* @__PURE__ */ a(
870
+ "span",
871
+ {
872
+ className: `sa-tf-icon${V ? " sa-tf-icon-clickable" : ""}`,
873
+ onClick: V,
874
+ children: v
875
+ }
876
+ ) : U(v, V);
877
+ }, ln = d === "success" ? /* @__PURE__ */ a("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ a(
878
+ Yn,
853
879
  {
854
880
  width: z(r),
855
881
  height: z(r)
856
882
  }
857
- ) }) : null, on = hn && !v ? /* @__PURE__ */ s(
883
+ ) }) : null, dn = wn && !w ? /* @__PURE__ */ a(
858
884
  "button",
859
885
  {
860
886
  type: "button",
861
- className: `sa-tf-icon sa-tf-clear${D ? "" : " sa-tf-clear-hidden"}`,
887
+ className: `sa-tf-icon sa-tf-clear${$ ? "" : " sa-tf-clear-hidden"}`,
862
888
  "aria-label": "Clear input",
863
- "aria-hidden": !D,
889
+ "aria-hidden": !$,
864
890
  tabIndex: -1,
865
891
  onClick: (t) => {
866
892
  var p;
867
893
  t.stopPropagation(), A || y("");
868
894
  const i = {
869
- target: { value: "", name: e.name },
870
- currentTarget: { value: "", name: e.name }
895
+ target: { value: "", name: s.name },
896
+ currentTarget: { value: "", name: s.name }
871
897
  };
872
- (p = e.onChange) == null || p.call(e, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
898
+ (p = s.onChange) == null || p.call(s, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
873
899
  var g;
874
900
  return (g = C.current) == null ? void 0 : g.focus();
875
901
  });
876
902
  },
877
903
  onMouseDown: (t) => t.preventDefault(),
878
- children: /* @__PURE__ */ s(
879
- jn,
904
+ children: /* @__PURE__ */ a(
905
+ An,
880
906
  {
881
907
  width: z(r),
882
908
  height: z(r)
883
909
  }
884
910
  )
885
911
  }
886
- ) : null, zn = !D && !!e.placeholder && !!$, ln = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
887
- /* @__PURE__ */ s(
912
+ ) : null, In = !$ && !!s.placeholder && !!O, fn = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
913
+ /* @__PURE__ */ a(
888
914
  "input",
889
915
  {
890
- ...e,
916
+ ...s,
891
917
  id: an.current,
892
918
  ref: C,
893
919
  className: "sa-tf-input",
894
- disabled: v,
895
- placeholder: $ ? "" : e.placeholder,
920
+ disabled: w,
921
+ placeholder: O ? "" : s.placeholder,
896
922
  value: N,
897
923
  onFocus: (t) => {
898
924
  var i;
899
- tn(!0), vn(!0), (i = e.onFocus) == null || i.call(e, t);
925
+ en(!0), kn(!0), (i = s.onFocus) == null || i.call(s, t);
900
926
  },
901
927
  onBlur: (t) => {
902
928
  var i;
903
- tn(!1), (i = e.onBlur) == null || i.call(e, t);
929
+ en(!1), (i = s.onBlur) == null || i.call(s, t);
904
930
  },
905
931
  onKeyDown: (t) => {
906
932
  var i;
907
- t.key === "Backspace" && en(t.key), (i = e.onKeyDown) == null || i.call(e, t);
933
+ t.key === "Backspace" && sn(t.key), (i = s.onKeyDown) == null || i.call(s, t);
908
934
  },
909
- onChange: kn
935
+ onChange: Nn
910
936
  }
911
937
  ),
912
- zn ? An(e.placeholder, $) : null
913
- ] }), dn = N && sn && (E != null && E.length) ? /* @__PURE__ */ s(
914
- Fn,
938
+ In ? _n(s.placeholder, O) : null
939
+ ] }), cn = N && rn && (E != null && E.length) ? /* @__PURE__ */ a(
940
+ Tn,
915
941
  {
916
942
  options: E,
917
943
  value: N,
918
944
  setValue: y,
919
- ref: M,
920
- isComponentVisible: sn,
945
+ ref: _,
946
+ isComponentVisible: rn,
921
947
  onOptionChange: (t) => {
922
948
  j == null || j(t), y(t);
923
949
  }
924
950
  }
925
- ) : null, U = H ? /* @__PURE__ */ o(
951
+ ) : null, X = P ? /* @__PURE__ */ o(
926
952
  "div",
927
953
  {
928
954
  className: "sa-tf-box",
929
- ref: M,
930
- onClick: yn,
955
+ ref: _,
956
+ onClick: Cn,
931
957
  children: [
932
- 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,
933
959
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
934
- m ? F(m, Q) : null,
960
+ m ? U(m, nn) : null,
935
961
  /* @__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 })
962
+ q("sa-tf-inside-label-row"),
963
+ /* @__PURE__ */ a("div", { className: "sa-tf-inside-row", children: fn })
938
964
  ] }),
939
- on,
940
- rn,
941
- w ? F(w, Z) : null
965
+ dn,
966
+ ln,
967
+ on()
942
968
  ] }),
943
- R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: R }) : null,
944
- dn
969
+ L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
970
+ cn
945
971
  ]
946
972
  }
947
- ) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: M, children: [
948
- B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
973
+ ) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: _, children: [
974
+ B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
949
975
  /* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
950
- m ? F(m, Q) : null,
976
+ m ? U(m, nn) : null,
977
+ fn,
978
+ dn,
951
979
  ln,
952
- on,
953
- rn,
954
- w ? F(w, Z) : null
980
+ on()
955
981
  ] }),
956
- R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: R }) : null,
957
- dn
982
+ L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
983
+ cn
958
984
  ] });
959
- return h === "outside-left" ? /* @__PURE__ */ o("div", { className: q, children: [
985
+ return h === "outside-left" ? /* @__PURE__ */ o("div", { className: H, children: [
960
986
  /* @__PURE__ */ o("div", { className: "sa-tf-label-col", children: [
961
- K("sa-tf-label"),
962
- u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null
987
+ q("sa-tf-label"),
988
+ u ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: u }) : null
963
989
  ] }),
964
990
  /* @__PURE__ */ o("div", { className: "sa-tf-input-col", children: [
965
- U,
966
- _
991
+ X,
992
+ K
967
993
  ] })
968
- ] }) : H ? /* @__PURE__ */ o("div", { className: q, children: [
969
- U,
970
- _
971
- ] }) : /* @__PURE__ */ o("div", { className: q, children: [
972
- K("sa-tf-label"),
973
- u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null,
974
- U,
975
- _
994
+ ] }) : P ? /* @__PURE__ */ o("div", { className: H, children: [
995
+ X,
996
+ K
997
+ ] }) : /* @__PURE__ */ o("div", { className: H, children: [
998
+ q("sa-tf-label"),
999
+ u ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: u }) : null,
1000
+ X,
1001
+ K
976
1002
  ] });
977
1003
  }
978
- ), An = (n, a) => {
1004
+ ), _n = (n, e) => {
979
1005
  if (!n)
980
1006
  return null;
981
- if (!a)
982
- return /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n });
983
- const r = n.toLowerCase().indexOf(a.toLowerCase());
984
- return r === -1 ? /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ o("p", { className: "sa-tf-placeholder", children: [
1007
+ if (!e)
1008
+ return /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n });
1009
+ const r = n.toLowerCase().indexOf(e.toLowerCase());
1010
+ return r === -1 ? /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ o("p", { className: "sa-tf-placeholder", children: [
985
1011
  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)
1012
+ /* @__PURE__ */ a("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + e.length) }),
1013
+ n.slice(r + e.length)
988
1014
  ] });
989
1015
  };
990
- Yn.displayName = "Input";
1016
+ Wn.displayName = "Input";
1017
+ const Mn = `.sa-kbd {
1018
+ display: inline-flex;
1019
+ align-items: center;
1020
+ gap: var(--sa-spacing-4, 4px);
1021
+ vertical-align: middle;
1022
+ }
1023
+
1024
+ .sa-kbd-key {
1025
+ display: inline-flex;
1026
+ align-items: center;
1027
+ justify-content: center;
1028
+ min-width: 1.5em;
1029
+ padding: 0 var(--sa-spacing-6, 6px);
1030
+ background-color: var(--sa-background-neutral, #f0f1f2);
1031
+ border: 1px solid var(--sa-border-subtle, #0b120e24);
1032
+ border-radius: var(--sa-radii-xs, 4px);
1033
+ color: var(--sa-text-subtle, #505258);
1034
+ font-family: inherit;
1035
+ font-size: var(--sa-font-size-sm, 12px);
1036
+ font-weight: var(--sa-font-weight-medium, 400);
1037
+ line-height: 1.6;
1038
+ white-space: nowrap;
1039
+ }
1040
+
1041
+ .sa-kbd-sep {
1042
+ display: inline-flex;
1043
+ align-items: center;
1044
+ color: var(--sa-text-subtlest, #6b6e76);
1045
+ font-size: var(--sa-font-size-sm, 12px);
1046
+ user-select: none;
1047
+ }
1048
+ `, hn = "sa-kbd-styles", Pn = (n) => {
1049
+ if (!(typeof document > "u") && !document.getElementById(hn)) {
1050
+ const e = document.createElement("style");
1051
+ e.id = hn, e.textContent = n, document.head.appendChild(e);
1052
+ }
1053
+ };
1054
+ Pn(Mn);
1055
+ function Hn({ keys: n, separator: e, className: r, ...l }) {
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)) });
1060
+ }
1061
+ Hn.__saRaw = !0;
991
1062
  export {
992
- Yn as Input
1063
+ Wn as Input,
1064
+ Hn as Kbd
993
1065
  };
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 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,4 +607,35 @@
591
607
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
592
608
  min-height: 80px;
593
609
  }
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"})});
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 {
611
+ display: inline-flex;
612
+ align-items: center;
613
+ gap: var(--sa-spacing-4, 4px);
614
+ vertical-align: middle;
615
+ }
616
+
617
+ .sa-kbd-key {
618
+ display: inline-flex;
619
+ align-items: center;
620
+ justify-content: center;
621
+ min-width: 1.5em;
622
+ padding: 0 var(--sa-spacing-6, 6px);
623
+ background-color: var(--sa-background-neutral, #f0f1f2);
624
+ border: 1px solid var(--sa-border-subtle, #0b120e24);
625
+ border-radius: var(--sa-radii-xs, 4px);
626
+ color: var(--sa-text-subtle, #505258);
627
+ font-family: inherit;
628
+ font-size: var(--sa-font-size-sm, 12px);
629
+ font-weight: var(--sa-font-weight-medium, 400);
630
+ line-height: 1.6;
631
+ white-space: nowrap;
632
+ }
633
+
634
+ .sa-kbd-sep {
635
+ display: inline-flex;
636
+ align-items: center;
637
+ color: var(--sa-text-subtlest, #6b6e76);
638
+ font-size: var(--sa-font-size-sm, 12px);
639
+ user-select: none;
640
+ }
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";
@@ -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.2.0",
4
4
  "description": "input component for starasia UI",
5
5
  "author": "Rizki Izzul Haq",
6
6
  "main": "dist/input.umd.js",