@starasia/input 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/input.es.js +105 -86
- package/dist/input.umd.js +20 -1
- package/package.json +1 -1
package/dist/input.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import Bn, { forwardRef as hn, useState as I, useRef as L, useEffect as
|
|
1
|
+
import { jsx as s, jsxs as o, Fragment as Ln } from "react/jsx-runtime";
|
|
2
|
+
import Bn, { forwardRef as hn, useState as I, useRef as L, useEffect as O, useImperativeHandle as Rn, useLayoutEffect as un } from "react";
|
|
3
3
|
const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
4
4
|
|
|
5
5
|
:root {
|
|
@@ -394,6 +394,25 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
394
394
|
-webkit-text-fill-color: var(--sa-input-text-disable);
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
+
/* Autofill — neutralize the browser's yellow background on Chrome/Safari/Edge,
|
|
398
|
+
* Firefox modern, and the spec-track :autofill selector. The trick is that
|
|
399
|
+
* browsers ignore \`background-color\`, so we paint a giant inset box-shadow
|
|
400
|
+
* instead and freeze the autofill background-color transition. */
|
|
401
|
+
.sa-tf-input:-webkit-autofill,
|
|
402
|
+
.sa-tf-input:-webkit-autofill:hover,
|
|
403
|
+
.sa-tf-input:-webkit-autofill:focus,
|
|
404
|
+
.sa-tf-input:-webkit-autofill:active {
|
|
405
|
+
-webkit-box-shadow: 0 0 0 1000px transparent inset !important;
|
|
406
|
+
-webkit-text-fill-color: var(--sa-input-text-primary) !important;
|
|
407
|
+
caret-color: var(--sa-input-text-primary);
|
|
408
|
+
transition: background-color 9999s ease-in-out 0s,
|
|
409
|
+
color 9999s ease-in-out 0s;
|
|
410
|
+
}
|
|
411
|
+
.sa-tf-input:autofill {
|
|
412
|
+
background-color: transparent !important;
|
|
413
|
+
color: var(--sa-input-text-primary);
|
|
414
|
+
}
|
|
415
|
+
|
|
397
416
|
.sa-tf-placeholder {
|
|
398
417
|
position: absolute;
|
|
399
418
|
inset: 0;
|
|
@@ -571,42 +590,42 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
571
590
|
error: "var(--sa-text-error, #a4133c)",
|
|
572
591
|
success: "var(--sa-text-success, #208958)",
|
|
573
592
|
disable: "var(--sa-icon-disable, #181a198f)"
|
|
574
|
-
},
|
|
593
|
+
}, pn = (n, a) => a ? G.disable : G[n] ?? G.default;
|
|
575
594
|
function En(n) {
|
|
576
595
|
return Number(n.replace(/\./g, ""));
|
|
577
596
|
}
|
|
578
597
|
function J(n) {
|
|
579
|
-
let
|
|
580
|
-
return
|
|
598
|
+
let a = n.replace(/[^\d]/g, "");
|
|
599
|
+
return a = a.replace(/^0+(?=\d)/, ""), a.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
581
600
|
}
|
|
582
|
-
function Dn(n,
|
|
583
|
-
if (
|
|
601
|
+
function Dn(n, a) {
|
|
602
|
+
if (a <= 0)
|
|
584
603
|
return 0;
|
|
585
604
|
let r = 0;
|
|
586
605
|
for (let l = 0; l < n.length; l++)
|
|
587
|
-
if (/\d/.test(n[l]) && (r += 1, r ===
|
|
606
|
+
if (/\d/.test(n[l]) && (r += 1, r === a))
|
|
588
607
|
return l + 1;
|
|
589
608
|
return n.length;
|
|
590
609
|
}
|
|
591
610
|
const Fn = hn(
|
|
592
|
-
({ options: n, value:
|
|
611
|
+
({ options: n, value: a, setValue: r, isComponentVisible: l, onOptionChange: d }, f) => {
|
|
593
612
|
const [g, V] = I([]), c = L(null), u = () => {
|
|
594
613
|
if (f != null && f.current && c.current) {
|
|
595
|
-
const h = window.innerHeight,
|
|
596
|
-
c.current.style.left = `${
|
|
614
|
+
const h = window.innerHeight, p = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(), w = p.bottom + m.height;
|
|
615
|
+
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`;
|
|
597
616
|
}
|
|
598
617
|
};
|
|
599
|
-
return
|
|
618
|
+
return O(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
|
|
600
619
|
window.removeEventListener("scroll", u), window.removeEventListener("resize", u);
|
|
601
|
-
}), [f, c]),
|
|
620
|
+
}), [f, c]), O(() => {
|
|
602
621
|
u();
|
|
603
|
-
}, [l]),
|
|
622
|
+
}, [l]), O(() => {
|
|
604
623
|
V(
|
|
605
624
|
(n == null ? void 0 : n.filter(
|
|
606
|
-
(h) => h.toLowerCase().startsWith(
|
|
625
|
+
(h) => h.toLowerCase().startsWith(a.toLowerCase())
|
|
607
626
|
)) || []
|
|
608
627
|
);
|
|
609
|
-
}, [
|
|
628
|
+
}, [a, n]), /* @__PURE__ */ s(
|
|
610
629
|
"div",
|
|
611
630
|
{
|
|
612
631
|
ref: c,
|
|
@@ -621,13 +640,13 @@ const Fn = hn(
|
|
|
621
640
|
zIndex: 5e4
|
|
622
641
|
},
|
|
623
642
|
children: g == null ? void 0 : g.map(
|
|
624
|
-
(h) =>
|
|
643
|
+
(h) => Tn(h, a, r, d)
|
|
625
644
|
)
|
|
626
645
|
}
|
|
627
646
|
);
|
|
628
647
|
}
|
|
629
|
-
),
|
|
630
|
-
const d = n.toLowerCase().indexOf(
|
|
648
|
+
), Tn = (n, a, r, l) => {
|
|
649
|
+
const d = n.toLowerCase().indexOf(a.toLowerCase());
|
|
631
650
|
return /* @__PURE__ */ o(
|
|
632
651
|
"p",
|
|
633
652
|
{
|
|
@@ -643,24 +662,24 @@ const Fn = hn(
|
|
|
643
662
|
},
|
|
644
663
|
children: [
|
|
645
664
|
n.slice(0, d),
|
|
646
|
-
/* @__PURE__ */
|
|
647
|
-
n.slice(d +
|
|
665
|
+
/* @__PURE__ */ s("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + a.length) }),
|
|
666
|
+
n.slice(d + a.length)
|
|
648
667
|
]
|
|
649
668
|
}
|
|
650
669
|
);
|
|
651
670
|
};
|
|
652
|
-
function
|
|
653
|
-
const [
|
|
671
|
+
function On(n) {
|
|
672
|
+
const [a, r] = I(n), l = L(null), d = (f) => {
|
|
654
673
|
l.current && !l.current.contains(f.target) && r(!1);
|
|
655
674
|
};
|
|
656
|
-
return
|
|
675
|
+
return O(() => (document.addEventListener("click", d, !0), () => {
|
|
657
676
|
document.removeEventListener("click", d, !0);
|
|
658
|
-
}), []), { ref: l, isComponentVisible:
|
|
677
|
+
}), []), { ref: l, isComponentVisible: a, setIsComponentVisible: r };
|
|
659
678
|
}
|
|
660
|
-
const
|
|
661
|
-
if (!(typeof document > "u") && !document.getElementById(
|
|
662
|
-
const
|
|
663
|
-
|
|
679
|
+
const bn = "sa-input-styles", Vn = (n) => {
|
|
680
|
+
if (!(typeof document > "u") && !document.getElementById(bn)) {
|
|
681
|
+
const a = document.createElement("style");
|
|
682
|
+
a.id = bn, a.textContent = n, document.head.appendChild(a);
|
|
664
683
|
}
|
|
665
684
|
};
|
|
666
685
|
Vn(Sn);
|
|
@@ -672,8 +691,8 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
672
691
|
xmlns: "http://www.w3.org/2000/svg",
|
|
673
692
|
...n,
|
|
674
693
|
children: [
|
|
675
|
-
/* @__PURE__ */
|
|
676
|
-
/* @__PURE__ */
|
|
694
|
+
/* @__PURE__ */ s("circle", { cx: "8", cy: "8", r: "6.5", stroke: "currentColor", strokeWidth: "1.2" }),
|
|
695
|
+
/* @__PURE__ */ s(
|
|
677
696
|
"path",
|
|
678
697
|
{
|
|
679
698
|
d: "M5.2 8.2l1.8 1.8 3.8-4.2",
|
|
@@ -693,8 +712,8 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
693
712
|
xmlns: "http://www.w3.org/2000/svg",
|
|
694
713
|
...n,
|
|
695
714
|
children: [
|
|
696
|
-
/* @__PURE__ */
|
|
697
|
-
/* @__PURE__ */
|
|
715
|
+
/* @__PURE__ */ s("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
716
|
+
/* @__PURE__ */ s(
|
|
698
717
|
"path",
|
|
699
718
|
{
|
|
700
719
|
d: "M5.5 5.5l5 5M10.5 5.5l-5 5",
|
|
@@ -706,9 +725,9 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
706
725
|
]
|
|
707
726
|
}
|
|
708
727
|
), Yn = hn(
|
|
709
|
-
(n,
|
|
728
|
+
(n, a) => {
|
|
710
729
|
const {
|
|
711
|
-
size: r = "
|
|
730
|
+
size: r = "md",
|
|
712
731
|
variant: l = "outline",
|
|
713
732
|
status: d = "default",
|
|
714
733
|
label: f,
|
|
@@ -717,7 +736,7 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
717
736
|
optional: c,
|
|
718
737
|
description: u,
|
|
719
738
|
helperText: h,
|
|
720
|
-
errorText:
|
|
739
|
+
errorText: p,
|
|
721
740
|
leftIcon: m,
|
|
722
741
|
rightIcon: w,
|
|
723
742
|
leftAddons: B,
|
|
@@ -732,24 +751,24 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
732
751
|
clearable: gn = !0,
|
|
733
752
|
onClear: Y,
|
|
734
753
|
...e
|
|
735
|
-
} = n,
|
|
754
|
+
} = n, A = e.value !== void 0, [W, y] = I(() => {
|
|
736
755
|
const t = e.value !== void 0 ? String(e.value ?? "") : String(e.defaultValue ?? "");
|
|
737
756
|
return S ? J(t) : t;
|
|
738
757
|
}), [nn, tn] = I(!1), [mn, en] = I(""), k = L(null), C = L(null);
|
|
739
|
-
Rn(
|
|
740
|
-
const
|
|
758
|
+
Rn(a, () => C.current);
|
|
759
|
+
const an = L(
|
|
741
760
|
e.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
|
|
742
761
|
), {
|
|
743
|
-
isComponentVisible:
|
|
762
|
+
isComponentVisible: sn,
|
|
744
763
|
ref: M,
|
|
745
764
|
setIsComponentVisible: vn
|
|
746
|
-
} =
|
|
765
|
+
} = On(!1);
|
|
747
766
|
un(() => {
|
|
748
|
-
if (!
|
|
767
|
+
if (!A)
|
|
749
768
|
return;
|
|
750
769
|
const t = e.value === void 0 || e.value === null ? "" : String(e.value), i = S ? J(t) : t;
|
|
751
|
-
y((
|
|
752
|
-
}, [e.value, S,
|
|
770
|
+
y((b) => b === i ? b : i);
|
|
771
|
+
}, [e.value, S, A]), un(() => {
|
|
753
772
|
if (k.current === null)
|
|
754
773
|
return;
|
|
755
774
|
const t = C.current, i = k.current;
|
|
@@ -758,8 +777,8 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
758
777
|
t.setSelectionRange(i, i);
|
|
759
778
|
} catch {
|
|
760
779
|
}
|
|
761
|
-
}, [
|
|
762
|
-
const N =
|
|
780
|
+
}, [W]);
|
|
781
|
+
const N = W, D = N !== "" && N !== void 0, v = d === "disable" || e.disabled, P = v ? "disable" : d, H = g === "inside", wn = H && (D || nn), q = [
|
|
763
782
|
"sa-tf",
|
|
764
783
|
`sa-tf-variant-${l}`,
|
|
765
784
|
`sa-tf-size-${r}`,
|
|
@@ -776,17 +795,17 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
776
795
|
}, kn = (t) => {
|
|
777
796
|
var fn, cn;
|
|
778
797
|
if (!S) {
|
|
779
|
-
const
|
|
780
|
-
|
|
798
|
+
const T = t.target.selectionStart;
|
|
799
|
+
T !== null && (k.current = T), y(t.target.value), (fn = e.onChange) == null || fn.call(e, t);
|
|
781
800
|
return;
|
|
782
801
|
}
|
|
783
802
|
const i = t.target.value;
|
|
784
|
-
let
|
|
803
|
+
let b = i, x = t.target.selectionStart ?? i.length;
|
|
785
804
|
if (mn === "Backspace") {
|
|
786
|
-
const
|
|
787
|
-
|
|
805
|
+
const T = W.replace(/\D/g, ""), In = i.replace(/\D/g, "");
|
|
806
|
+
T.length === In.length && x > 0 && (b = i.slice(0, x - 1) + i.slice(x), x -= 1);
|
|
788
807
|
}
|
|
789
|
-
const X = J(
|
|
808
|
+
const X = J(b), Cn = b.slice(0, x).replace(/\D/g, "").length, Nn = Dn(X, Cn);
|
|
790
809
|
k.current = Nn, y(X), (cn = e.onChange) == null || cn.call(e, {
|
|
791
810
|
...t,
|
|
792
811
|
target: {
|
|
@@ -796,20 +815,20 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
796
815
|
}
|
|
797
816
|
}), en("");
|
|
798
817
|
}, K = (t) => f ? /* @__PURE__ */ o("div", { className: t, children: [
|
|
799
|
-
/* @__PURE__ */
|
|
818
|
+
/* @__PURE__ */ s(
|
|
800
819
|
"label",
|
|
801
820
|
{
|
|
802
|
-
htmlFor:
|
|
821
|
+
htmlFor: an.current,
|
|
803
822
|
style: { cursor: v ? "not-allowed" : "pointer" },
|
|
804
823
|
children: f
|
|
805
824
|
}
|
|
806
825
|
),
|
|
807
|
-
c ? /* @__PURE__ */
|
|
808
|
-
V ? /* @__PURE__ */
|
|
826
|
+
c ? /* @__PURE__ */ s("span", { className: "sa-tf-optional", children: "Optional" }) : null,
|
|
827
|
+
V ? /* @__PURE__ */ s("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
|
|
809
828
|
] }) : null, _ = /* @__PURE__ */ o(Ln, { children: [
|
|
810
|
-
h ? /* @__PURE__ */
|
|
811
|
-
|
|
812
|
-
] }), F = (t, i) => /* @__PURE__ */
|
|
829
|
+
h ? /* @__PURE__ */ s("p", { className: "sa-tf-helper", children: h }) : null,
|
|
830
|
+
p && d === "error" ? /* @__PURE__ */ s("p", { className: "sa-tf-error", children: p }) : null
|
|
831
|
+
] }), F = (t, i) => /* @__PURE__ */ s(
|
|
813
832
|
"span",
|
|
814
833
|
{
|
|
815
834
|
className: `sa-tf-icon${i ? " sa-tf-icon-clickable" : ""}`,
|
|
@@ -817,17 +836,17 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
817
836
|
children: Bn.cloneElement(t, {
|
|
818
837
|
width: z(r),
|
|
819
838
|
height: z(r),
|
|
820
|
-
color:
|
|
821
|
-
style: { color:
|
|
839
|
+
color: pn(P, v),
|
|
840
|
+
style: { color: pn(P, v) }
|
|
822
841
|
})
|
|
823
842
|
}
|
|
824
|
-
), rn = d === "success" ? /* @__PURE__ */
|
|
843
|
+
), rn = d === "success" ? /* @__PURE__ */ s("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ s(
|
|
825
844
|
$n,
|
|
826
845
|
{
|
|
827
846
|
width: z(r),
|
|
828
847
|
height: z(r)
|
|
829
848
|
}
|
|
830
|
-
) }) : null, on = gn && !v ? /* @__PURE__ */
|
|
849
|
+
) }) : null, on = gn && !v ? /* @__PURE__ */ s(
|
|
831
850
|
"button",
|
|
832
851
|
{
|
|
833
852
|
type: "button",
|
|
@@ -836,19 +855,19 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
836
855
|
"aria-hidden": !D,
|
|
837
856
|
tabIndex: -1,
|
|
838
857
|
onClick: (t) => {
|
|
839
|
-
var
|
|
840
|
-
t.stopPropagation(),
|
|
858
|
+
var b;
|
|
859
|
+
t.stopPropagation(), A || y("");
|
|
841
860
|
const i = {
|
|
842
861
|
target: { value: "", name: e.name },
|
|
843
862
|
currentTarget: { value: "", name: e.name }
|
|
844
863
|
};
|
|
845
|
-
(
|
|
864
|
+
(b = e.onChange) == null || b.call(e, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
|
|
846
865
|
var x;
|
|
847
866
|
return (x = C.current) == null ? void 0 : x.focus();
|
|
848
867
|
});
|
|
849
868
|
},
|
|
850
869
|
onMouseDown: (t) => t.preventDefault(),
|
|
851
|
-
children: /* @__PURE__ */
|
|
870
|
+
children: /* @__PURE__ */ s(
|
|
852
871
|
jn,
|
|
853
872
|
{
|
|
854
873
|
width: z(r),
|
|
@@ -857,11 +876,11 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
857
876
|
)
|
|
858
877
|
}
|
|
859
878
|
) : null, zn = !D && !!e.placeholder && !!$, ln = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
|
|
860
|
-
/* @__PURE__ */
|
|
879
|
+
/* @__PURE__ */ s(
|
|
861
880
|
"input",
|
|
862
881
|
{
|
|
863
882
|
...e,
|
|
864
|
-
id:
|
|
883
|
+
id: an.current,
|
|
865
884
|
ref: C,
|
|
866
885
|
className: "sa-tf-input",
|
|
867
886
|
disabled: v,
|
|
@@ -882,15 +901,15 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
882
901
|
onChange: kn
|
|
883
902
|
}
|
|
884
903
|
),
|
|
885
|
-
zn ?
|
|
886
|
-
] }), dn = N &&
|
|
904
|
+
zn ? An(e.placeholder, $) : null
|
|
905
|
+
] }), dn = N && sn && (E != null && E.length) ? /* @__PURE__ */ s(
|
|
887
906
|
Fn,
|
|
888
907
|
{
|
|
889
908
|
options: E,
|
|
890
909
|
value: N,
|
|
891
910
|
setValue: y,
|
|
892
911
|
ref: M,
|
|
893
|
-
isComponentVisible:
|
|
912
|
+
isComponentVisible: sn,
|
|
894
913
|
onOptionChange: (t) => {
|
|
895
914
|
j == null || j(t), y(t);
|
|
896
915
|
}
|
|
@@ -902,23 +921,23 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
902
921
|
ref: M,
|
|
903
922
|
onClick: yn,
|
|
904
923
|
children: [
|
|
905
|
-
B ? /* @__PURE__ */
|
|
924
|
+
B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
|
|
906
925
|
/* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
|
|
907
926
|
m ? F(m, Q) : null,
|
|
908
927
|
/* @__PURE__ */ o("div", { className: "sa-tf-inside-stack", children: [
|
|
909
928
|
K("sa-tf-inside-label-row"),
|
|
910
|
-
/* @__PURE__ */
|
|
929
|
+
/* @__PURE__ */ s("div", { className: "sa-tf-inside-row", children: ln })
|
|
911
930
|
] }),
|
|
912
931
|
on,
|
|
913
932
|
rn,
|
|
914
933
|
w ? F(w, Z) : null
|
|
915
934
|
] }),
|
|
916
|
-
R ? /* @__PURE__ */
|
|
935
|
+
R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: R }) : null,
|
|
917
936
|
dn
|
|
918
937
|
]
|
|
919
938
|
}
|
|
920
939
|
) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: M, children: [
|
|
921
|
-
B ? /* @__PURE__ */
|
|
940
|
+
B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
|
|
922
941
|
/* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
|
|
923
942
|
m ? F(m, Q) : null,
|
|
924
943
|
ln,
|
|
@@ -926,13 +945,13 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
926
945
|
rn,
|
|
927
946
|
w ? F(w, Z) : null
|
|
928
947
|
] }),
|
|
929
|
-
R ? /* @__PURE__ */
|
|
948
|
+
R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: R }) : null,
|
|
930
949
|
dn
|
|
931
950
|
] });
|
|
932
951
|
return g === "outside-left" ? /* @__PURE__ */ o("div", { className: q, children: [
|
|
933
952
|
/* @__PURE__ */ o("div", { className: "sa-tf-label-col", children: [
|
|
934
953
|
K("sa-tf-label"),
|
|
935
|
-
u ? /* @__PURE__ */
|
|
954
|
+
u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null
|
|
936
955
|
] }),
|
|
937
956
|
/* @__PURE__ */ o("div", { className: "sa-tf-input-col", children: [
|
|
938
957
|
U,
|
|
@@ -943,21 +962,21 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
943
962
|
_
|
|
944
963
|
] }) : /* @__PURE__ */ o("div", { className: q, children: [
|
|
945
964
|
K("sa-tf-label"),
|
|
946
|
-
u ? /* @__PURE__ */
|
|
965
|
+
u ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: u }) : null,
|
|
947
966
|
U,
|
|
948
967
|
_
|
|
949
968
|
] });
|
|
950
969
|
}
|
|
951
|
-
),
|
|
970
|
+
), An = (n, a) => {
|
|
952
971
|
if (!n)
|
|
953
972
|
return null;
|
|
954
|
-
if (!
|
|
955
|
-
return /* @__PURE__ */
|
|
956
|
-
const r = n.toLowerCase().indexOf(
|
|
957
|
-
return r === -1 ? /* @__PURE__ */
|
|
973
|
+
if (!a)
|
|
974
|
+
return /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n });
|
|
975
|
+
const r = n.toLowerCase().indexOf(a.toLowerCase());
|
|
976
|
+
return r === -1 ? /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ o("p", { className: "sa-tf-placeholder", children: [
|
|
958
977
|
n.slice(0, r),
|
|
959
|
-
/* @__PURE__ */
|
|
960
|
-
n.slice(r +
|
|
978
|
+
/* @__PURE__ */ s("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + a.length) }),
|
|
979
|
+
n.slice(r + a.length)
|
|
961
980
|
] });
|
|
962
981
|
};
|
|
963
982
|
Yn.displayName = "Input";
|
package/dist/input.umd.js
CHANGED
|
@@ -392,6 +392,25 @@
|
|
|
392
392
|
-webkit-text-fill-color: var(--sa-input-text-disable);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
/* Autofill — neutralize the browser's yellow background on Chrome/Safari/Edge,
|
|
396
|
+
* Firefox modern, and the spec-track :autofill selector. The trick is that
|
|
397
|
+
* browsers ignore \`background-color\`, so we paint a giant inset box-shadow
|
|
398
|
+
* instead and freeze the autofill background-color transition. */
|
|
399
|
+
.sa-tf-input:-webkit-autofill,
|
|
400
|
+
.sa-tf-input:-webkit-autofill:hover,
|
|
401
|
+
.sa-tf-input:-webkit-autofill:focus,
|
|
402
|
+
.sa-tf-input:-webkit-autofill:active {
|
|
403
|
+
-webkit-box-shadow: 0 0 0 1000px transparent inset !important;
|
|
404
|
+
-webkit-text-fill-color: var(--sa-input-text-primary) !important;
|
|
405
|
+
caret-color: var(--sa-input-text-primary);
|
|
406
|
+
transition: background-color 9999s ease-in-out 0s,
|
|
407
|
+
color 9999s ease-in-out 0s;
|
|
408
|
+
}
|
|
409
|
+
.sa-tf-input:autofill {
|
|
410
|
+
background-color: transparent !important;
|
|
411
|
+
color: var(--sa-input-text-primary);
|
|
412
|
+
}
|
|
413
|
+
|
|
395
414
|
.sa-tf-placeholder {
|
|
396
415
|
position: absolute;
|
|
397
416
|
inset: 0;
|
|
@@ -564,4 +583,4 @@
|
|
|
564
583
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
565
584
|
min-height: 80px;
|
|
566
585
|
}
|
|
567
|
-
`,y=t=>t==="lg"||t==="xl"?18:16,j={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"var(--sa-icon-disable, #181a198f)"},J=(t,a)=>a?j.disable:j[t]??j.default;function bn(t){return Number(t.replace(/\./g,""))}function O(t){let a=t.replace(/[^\d]/g,"");return a=a.replace(/^0+(?=\d)/,""),a.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function hn(t,a){if(a<=0)return 0;let i=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(i+=1,i===a))return l+1;return t.length}const xn=o.forwardRef(({options:t,value:a,setValue:i,isComponentVisible:l,onOptionChange:d},f)=>{const[v,V]=o.useState([]),c=o.useRef(null),u=()=>{if(f!=null&&f.current&&c.current){const x=window.innerHeight,p=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),k=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,k>=x-10?c.current.style.top=`${p.top-m.height-5}px`:c.current.style.top=`${p.top+p.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",u),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u),window.removeEventListener("resize",u)}),[f,c]),o.useEffect(()=>{u()},[l]),o.useEffect(()=>{V((t==null?void 0:t.filter(x=>x.toLowerCase().startsWith(a.toLowerCase())))||[])},[a,t]),n.jsx("div",{ref:c,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",borderRadius:"8px",background:"white",overflow:"auto",zIndex:5e4},children:v==null?void 0:v.map(x=>gn(x,a,i,d))})}),gn=(t,a,i,l)=>{const d=t.toLowerCase().indexOf(a.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{i(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+a.length)}),t.slice(d+a.length)]})};function vn(t){const[a,i]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&i(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:a,setIsComponentVisible:i}}const Q="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)}})(pn);const mn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.5",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.2 8.2l1.8 1.8 3.8-4.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),wn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),Z=o.forwardRef((t,a)=>{const{size:i="
|
|
586
|
+
`,y=t=>t==="lg"||t==="xl"?18:16,j={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"var(--sa-icon-disable, #181a198f)"},J=(t,a)=>a?j.disable:j[t]??j.default;function bn(t){return Number(t.replace(/\./g,""))}function O(t){let a=t.replace(/[^\d]/g,"");return a=a.replace(/^0+(?=\d)/,""),a.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function hn(t,a){if(a<=0)return 0;let i=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(i+=1,i===a))return l+1;return t.length}const xn=o.forwardRef(({options:t,value:a,setValue:i,isComponentVisible:l,onOptionChange:d},f)=>{const[v,V]=o.useState([]),c=o.useRef(null),u=()=>{if(f!=null&&f.current&&c.current){const x=window.innerHeight,p=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),k=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,k>=x-10?c.current.style.top=`${p.top-m.height-5}px`:c.current.style.top=`${p.top+p.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",u),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u),window.removeEventListener("resize",u)}),[f,c]),o.useEffect(()=>{u()},[l]),o.useEffect(()=>{V((t==null?void 0:t.filter(x=>x.toLowerCase().startsWith(a.toLowerCase())))||[])},[a,t]),n.jsx("div",{ref:c,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",borderRadius:"8px",background:"white",overflow:"auto",zIndex:5e4},children:v==null?void 0:v.map(x=>gn(x,a,i,d))})}),gn=(t,a,i,l)=>{const d=t.toLowerCase().indexOf(a.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{i(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+a.length)}),t.slice(d+a.length)]})};function vn(t){const[a,i]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&i(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:a,setIsComponentVisible:i}}const Q="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)}})(pn);const mn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.5",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.2 8.2l1.8 1.8 3.8-4.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),wn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),Z=o.forwardRef((t,a)=>{const{size:i="md",variant:l="outline",status:d="default",label:f,labelPosition:v="outside-top",required:V,optional:c,description:u,helperText:x,errorText:p,leftIcon:m,rightIcon:k,leftAddons:S,rightAddons:L,onClickLeftIcon:R,onClickRightIcon:nn,fullWidth:kn=!1,highlightPlaceholder:$,currency:B,options:E,onOptionChange:Y,clearable:zn=!0,onClear: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(b=>b===r?b: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 b=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&&(b=r.slice(0,g-1)+r.slice(g),g-=1)}const G=O(b),Tn=b.slice(0,g).replace(/\D/g,"").length,Dn=hn(G,Tn);C.current=Dn,z(G),(un=s.onChange)==null||un.call(s,{...e,target:{...e.target,value:String(bn(G)),name:e.target.name}}),sn("")},_=e=>f?n.jsxs("div",{className:e,children:[n.jsx("label",{htmlFor:an.current,style:{cursor:w?"not-allowed":"pointer"},children:f}),c?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,V?n.jsx("span",{className:"sa-tf-required","aria-hidden":"true",children:"*"}):null]}):null,U=n.jsxs(n.Fragment,{children:[x?n.jsx("p",{className:"sa-tf-helper",children:x}):null,p&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:p}):null]}),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 b;e.stopPropagation(),M||z("");const r={target:{value:"",name:s.name},currentTarget:{value:"",name:s.name}};(b=s.onChange)==null||b.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(xn,{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",h.Input=Z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|