@starasia/input 6.0.3 → 6.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/input.es.js +115 -101
- package/dist/input.umd.js +16 -2
- package/package.json +1 -1
package/dist/input.es.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import Z, { forwardRef as mn, useState as I, useRef as
|
|
3
|
-
const $n =
|
|
1
|
+
import { jsx as s, jsxs as l, Fragment as Ln } from "react/jsx-runtime";
|
|
2
|
+
import Z, { forwardRef as mn, useState as I, useRef as S, useEffect as F, useImperativeHandle as En, useLayoutEffect as bn } from "react";
|
|
3
|
+
const $n = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
|
|
4
|
+
starasia, components, utilities). CSS app/Tailwind utility selalu bisa
|
|
5
|
+
menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
|
|
6
|
+
@layer starasia.components {
|
|
7
|
+
|
|
8
|
+
|
|
4
9
|
:root {
|
|
5
10
|
/* Layer 3 — references Layer 2 semantic tokens */
|
|
6
11
|
--sa-input-text-primary: var(--sa-text-primary, #292a2e);
|
|
@@ -613,31 +618,33 @@ const $n = `
|
|
|
613
618
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
614
619
|
min-height: 80px;
|
|
615
620
|
}
|
|
621
|
+
|
|
622
|
+
} /* @layer starasia.components */
|
|
616
623
|
`, z = (n) => n === "lg" || n === "xl" ? 18 : n === "xs" ? 14 : 16, J = {
|
|
617
624
|
default: "var(--sa-color-gray-800, #505258)",
|
|
618
625
|
error: "var(--sa-text-error, #a4133c)",
|
|
619
626
|
success: "var(--sa-text-success, #186742)",
|
|
620
627
|
disable: "var(--sa-icon-disable, #181a198f)"
|
|
621
|
-
}, xn = (n,
|
|
628
|
+
}, xn = (n, a) => a ? J.disable : J[n] ?? J.default;
|
|
622
629
|
function Dn(n) {
|
|
623
630
|
return Number(n.replace(/\./g, ""));
|
|
624
631
|
}
|
|
625
632
|
function Q(n) {
|
|
626
|
-
let
|
|
627
|
-
return
|
|
633
|
+
let a = n.replace(/[^\d]/g, "");
|
|
634
|
+
return a = a.replace(/^0+(?=\d)/, ""), a.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
628
635
|
}
|
|
629
|
-
function Fn(n,
|
|
630
|
-
if (
|
|
636
|
+
function Fn(n, a) {
|
|
637
|
+
if (a <= 0)
|
|
631
638
|
return 0;
|
|
632
639
|
let r = 0;
|
|
633
640
|
for (let o = 0; o < n.length; o++)
|
|
634
|
-
if (/\d/.test(n[o]) && (r += 1, r ===
|
|
641
|
+
if (/\d/.test(n[o]) && (r += 1, r === a))
|
|
635
642
|
return o + 1;
|
|
636
643
|
return n.length;
|
|
637
644
|
}
|
|
638
645
|
const Tn = mn(
|
|
639
|
-
({ options: n, value:
|
|
640
|
-
const [c, T] = I([]), u =
|
|
646
|
+
({ options: n, value: a, setValue: r, isComponentVisible: o, onOptionChange: d }, f) => {
|
|
647
|
+
const [c, T] = I([]), u = S(null), p = () => {
|
|
641
648
|
if (f != null && f.current && u.current) {
|
|
642
649
|
const g = window.innerHeight, b = f == null ? void 0 : f.current.getBoundingClientRect(), m = u.current.getBoundingClientRect(), v = b.bottom + m.height;
|
|
643
650
|
u.current.style.left = `${b.left}px`, u.current.style.width = `${b.width}px`, v >= g - 10 ? u.current.style.top = `${b.top - m.height - 5}px` : u.current.style.top = `${b.top + b.height}px`;
|
|
@@ -650,10 +657,10 @@ const Tn = mn(
|
|
|
650
657
|
}, [o]), F(() => {
|
|
651
658
|
T(
|
|
652
659
|
(n == null ? void 0 : n.filter(
|
|
653
|
-
(g) => g.toLowerCase().startsWith(
|
|
660
|
+
(g) => g.toLowerCase().startsWith(a.toLowerCase())
|
|
654
661
|
)) || []
|
|
655
662
|
);
|
|
656
|
-
}, [
|
|
663
|
+
}, [a, n]), /* @__PURE__ */ s(
|
|
657
664
|
"div",
|
|
658
665
|
{
|
|
659
666
|
ref: u,
|
|
@@ -668,13 +675,13 @@ const Tn = mn(
|
|
|
668
675
|
zIndex: 5e4
|
|
669
676
|
},
|
|
670
677
|
children: c == null ? void 0 : c.map(
|
|
671
|
-
(g) =>
|
|
678
|
+
(g) => jn(g, a, r, d)
|
|
672
679
|
)
|
|
673
680
|
}
|
|
674
681
|
);
|
|
675
682
|
}
|
|
676
|
-
),
|
|
677
|
-
const d = n.toLowerCase().indexOf(
|
|
683
|
+
), jn = (n, a, r, o) => {
|
|
684
|
+
const d = n.toLowerCase().indexOf(a.toLowerCase());
|
|
678
685
|
return /* @__PURE__ */ l(
|
|
679
686
|
"p",
|
|
680
687
|
{
|
|
@@ -690,27 +697,27 @@ const Tn = mn(
|
|
|
690
697
|
},
|
|
691
698
|
children: [
|
|
692
699
|
n.slice(0, d),
|
|
693
|
-
/* @__PURE__ */
|
|
694
|
-
n.slice(d +
|
|
700
|
+
/* @__PURE__ */ s("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + a.length) }),
|
|
701
|
+
n.slice(d + a.length)
|
|
695
702
|
]
|
|
696
703
|
}
|
|
697
704
|
);
|
|
698
705
|
};
|
|
699
|
-
function
|
|
700
|
-
const [
|
|
706
|
+
function Vn(n) {
|
|
707
|
+
const [a, r] = I(n), o = S(null), d = (f) => {
|
|
701
708
|
o.current && !o.current.contains(f.target) && r(!1);
|
|
702
709
|
};
|
|
703
710
|
return F(() => (document.addEventListener("click", d, !0), () => {
|
|
704
711
|
document.removeEventListener("click", d, !0);
|
|
705
|
-
}), []), { ref: o, isComponentVisible:
|
|
712
|
+
}), []), { ref: o, isComponentVisible: a, setIsComponentVisible: r };
|
|
706
713
|
}
|
|
707
|
-
const gn = "sa-input-styles",
|
|
714
|
+
const gn = "sa-input-styles", On = (n) => {
|
|
708
715
|
if (!(typeof document > "u") && !document.getElementById(gn)) {
|
|
709
|
-
const
|
|
710
|
-
|
|
716
|
+
const a = document.createElement("style");
|
|
717
|
+
a.id = gn, a.textContent = n, document.head.appendChild(a);
|
|
711
718
|
}
|
|
712
719
|
};
|
|
713
|
-
|
|
720
|
+
On($n);
|
|
714
721
|
const Yn = (n) => /* @__PURE__ */ l(
|
|
715
722
|
"svg",
|
|
716
723
|
{
|
|
@@ -719,8 +726,8 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
719
726
|
xmlns: "http://www.w3.org/2000/svg",
|
|
720
727
|
...n,
|
|
721
728
|
children: [
|
|
722
|
-
/* @__PURE__ */
|
|
723
|
-
/* @__PURE__ */
|
|
729
|
+
/* @__PURE__ */ s("circle", { cx: "8", cy: "8", r: "6.5", stroke: "currentColor", strokeWidth: "1.2" }),
|
|
730
|
+
/* @__PURE__ */ s(
|
|
724
731
|
"path",
|
|
725
732
|
{
|
|
726
733
|
d: "M5.2 8.2l1.8 1.8 3.8-4.2",
|
|
@@ -740,8 +747,8 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
740
747
|
xmlns: "http://www.w3.org/2000/svg",
|
|
741
748
|
...n,
|
|
742
749
|
children: [
|
|
743
|
-
/* @__PURE__ */
|
|
744
|
-
/* @__PURE__ */
|
|
750
|
+
/* @__PURE__ */ s("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
751
|
+
/* @__PURE__ */ s(
|
|
745
752
|
"path",
|
|
746
753
|
{
|
|
747
754
|
d: "M5.5 5.5l5 5M10.5 5.5l-5 5",
|
|
@@ -753,7 +760,7 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
753
760
|
]
|
|
754
761
|
}
|
|
755
762
|
), Wn = mn(
|
|
756
|
-
(n,
|
|
763
|
+
(n, a) => {
|
|
757
764
|
const {
|
|
758
765
|
size: r = "sm",
|
|
759
766
|
variant: o = "outline",
|
|
@@ -767,36 +774,36 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
767
774
|
errorText: b,
|
|
768
775
|
leftIcon: m,
|
|
769
776
|
rightIcon: v,
|
|
770
|
-
leftAddons:
|
|
771
|
-
rightAddons:
|
|
777
|
+
leftAddons: R,
|
|
778
|
+
rightAddons: B,
|
|
772
779
|
onClickLeftIcon: nn,
|
|
773
|
-
onClickRightIcon:
|
|
780
|
+
onClickRightIcon: j,
|
|
774
781
|
fullWidth: vn = !0,
|
|
775
|
-
highlightPlaceholder:
|
|
782
|
+
highlightPlaceholder: V,
|
|
776
783
|
currency: L,
|
|
777
784
|
options: E,
|
|
778
|
-
onOptionChange:
|
|
785
|
+
onOptionChange: O,
|
|
779
786
|
clearable: wn = !0,
|
|
780
787
|
onClear: Y,
|
|
781
|
-
...
|
|
782
|
-
} = n, A =
|
|
783
|
-
const t =
|
|
788
|
+
...e
|
|
789
|
+
} = n, A = e.value !== void 0, [W, k] = I(() => {
|
|
790
|
+
const t = e.value !== void 0 ? String(e.value ?? "") : String(e.defaultValue ?? "");
|
|
784
791
|
return L ? Q(t) : t;
|
|
785
|
-
}), [tn,
|
|
786
|
-
En(
|
|
787
|
-
const
|
|
788
|
-
|
|
792
|
+
}), [tn, an] = I(!1), [kn, en] = I(""), y = S(null), C = S(null);
|
|
793
|
+
En(a, () => C.current);
|
|
794
|
+
const sn = S(
|
|
795
|
+
e.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
|
|
789
796
|
), {
|
|
790
797
|
isComponentVisible: rn,
|
|
791
798
|
ref: _,
|
|
792
799
|
setIsComponentVisible: yn
|
|
793
|
-
} =
|
|
800
|
+
} = Vn(!1);
|
|
794
801
|
bn(() => {
|
|
795
802
|
if (!A)
|
|
796
803
|
return;
|
|
797
|
-
const t =
|
|
804
|
+
const t = e.value === void 0 || e.value === null ? "" : String(e.value), i = L ? Q(t) : t;
|
|
798
805
|
k((x) => x === i ? x : i);
|
|
799
|
-
}, [
|
|
806
|
+
}, [e.value, L, A]), bn(() => {
|
|
800
807
|
if (y.current === null)
|
|
801
808
|
return;
|
|
802
809
|
const t = C.current, i = y.current;
|
|
@@ -806,7 +813,7 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
806
813
|
} catch {
|
|
807
814
|
}
|
|
808
815
|
}, [W]);
|
|
809
|
-
const N = W, $ = N !== "" && N !== void 0, w = d === "disable" ||
|
|
816
|
+
const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || e.disabled, M = w ? "disable" : d, H = c === "inside", zn = H && ($ || tn), q = [
|
|
810
817
|
"sa-tf",
|
|
811
818
|
`sa-tf-variant-${o}`,
|
|
812
819
|
`sa-tf-size-${r}`,
|
|
@@ -824,39 +831,39 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
824
831
|
var un, pn;
|
|
825
832
|
if (!L) {
|
|
826
833
|
const D = t.target.selectionStart;
|
|
827
|
-
D !== null && (y.current = D), k(t.target.value), (un =
|
|
834
|
+
D !== null && (y.current = D), k(t.target.value), (un = e.onChange) == null || un.call(e, t);
|
|
828
835
|
return;
|
|
829
836
|
}
|
|
830
837
|
const i = t.target.value;
|
|
831
838
|
let x = i, h = t.target.selectionStart ?? i.length;
|
|
832
839
|
if (kn === "Backspace") {
|
|
833
|
-
const D = W.replace(/\D/g, ""),
|
|
834
|
-
D.length ===
|
|
840
|
+
const D = W.replace(/\D/g, ""), Bn = i.replace(/\D/g, "");
|
|
841
|
+
D.length === Bn.length && h > 0 && (x = i.slice(0, h - 1) + i.slice(h), h -= 1);
|
|
835
842
|
}
|
|
836
|
-
const G = Q(x),
|
|
837
|
-
y.current =
|
|
843
|
+
const G = Q(x), Sn = x.slice(0, h).replace(/\D/g, "").length, Rn = Fn(G, Sn);
|
|
844
|
+
y.current = Rn, k(G), (pn = e.onChange) == null || pn.call(e, {
|
|
838
845
|
...t,
|
|
839
846
|
target: {
|
|
840
847
|
...t.target,
|
|
841
848
|
value: String(Dn(G)),
|
|
842
849
|
name: t.target.name
|
|
843
850
|
}
|
|
844
|
-
}),
|
|
851
|
+
}), en("");
|
|
845
852
|
}, K = (t) => f ? /* @__PURE__ */ l("div", { className: t, children: [
|
|
846
|
-
/* @__PURE__ */
|
|
853
|
+
/* @__PURE__ */ s(
|
|
847
854
|
"label",
|
|
848
855
|
{
|
|
849
|
-
htmlFor:
|
|
856
|
+
htmlFor: sn.current,
|
|
850
857
|
style: { cursor: w ? "not-allowed" : "pointer" },
|
|
851
858
|
children: f
|
|
852
859
|
}
|
|
853
860
|
),
|
|
854
|
-
u ? /* @__PURE__ */
|
|
855
|
-
T ? /* @__PURE__ */
|
|
861
|
+
u ? /* @__PURE__ */ s("span", { className: "sa-tf-optional", children: "Optional" }) : null,
|
|
862
|
+
T ? /* @__PURE__ */ s("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
|
|
856
863
|
] }) : null, P = /* @__PURE__ */ l(Ln, { children: [
|
|
857
|
-
g ? /* @__PURE__ */
|
|
858
|
-
b && d === "error" ? /* @__PURE__ */
|
|
859
|
-
] }), U = (t, i) => /* @__PURE__ */
|
|
864
|
+
g ? /* @__PURE__ */ s("p", { className: "sa-tf-helper", children: g }) : null,
|
|
865
|
+
b && d === "error" ? /* @__PURE__ */ s("p", { className: "sa-tf-error", children: b }) : null
|
|
866
|
+
] }), U = (t, i) => /* @__PURE__ */ s(
|
|
860
867
|
"span",
|
|
861
868
|
{
|
|
862
869
|
className: `sa-tf-icon${i ? " sa-tf-icon-clickable" : ""}`,
|
|
@@ -870,21 +877,21 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
870
877
|
}
|
|
871
878
|
), on = () => {
|
|
872
879
|
var i;
|
|
873
|
-
return v == null ? null : !Z.isValidElement(v) || ((i = v.type) == null ? void 0 : i.__saRaw) === !0 ? /* @__PURE__ */
|
|
880
|
+
return v == null ? null : !Z.isValidElement(v) || ((i = v.type) == null ? void 0 : i.__saRaw) === !0 ? /* @__PURE__ */ s(
|
|
874
881
|
"span",
|
|
875
882
|
{
|
|
876
|
-
className: `sa-tf-icon${
|
|
877
|
-
onClick:
|
|
883
|
+
className: `sa-tf-icon${j ? " sa-tf-icon-clickable" : ""}`,
|
|
884
|
+
onClick: j,
|
|
878
885
|
children: v
|
|
879
886
|
}
|
|
880
|
-
) : U(v,
|
|
881
|
-
}, ln = d === "success" ? /* @__PURE__ */
|
|
887
|
+
) : U(v, j);
|
|
888
|
+
}, ln = d === "success" ? /* @__PURE__ */ s("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ s(
|
|
882
889
|
Yn,
|
|
883
890
|
{
|
|
884
891
|
width: z(r),
|
|
885
892
|
height: z(r)
|
|
886
893
|
}
|
|
887
|
-
) }) : null, dn = wn && !w ? /* @__PURE__ */
|
|
894
|
+
) }) : null, dn = wn && !w ? /* @__PURE__ */ s(
|
|
888
895
|
"button",
|
|
889
896
|
{
|
|
890
897
|
type: "button",
|
|
@@ -896,16 +903,16 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
896
903
|
var x;
|
|
897
904
|
t.stopPropagation(), A || k("");
|
|
898
905
|
const i = {
|
|
899
|
-
target: { value: "", name:
|
|
900
|
-
currentTarget: { value: "", name:
|
|
906
|
+
target: { value: "", name: e.name },
|
|
907
|
+
currentTarget: { value: "", name: e.name }
|
|
901
908
|
};
|
|
902
|
-
(x =
|
|
909
|
+
(x = e.onChange) == null || x.call(e, i), Y == null || Y(), y.current = 0, requestAnimationFrame(() => {
|
|
903
910
|
var h;
|
|
904
911
|
return (h = C.current) == null ? void 0 : h.focus();
|
|
905
912
|
});
|
|
906
913
|
},
|
|
907
914
|
onMouseDown: (t) => t.preventDefault(),
|
|
908
|
-
children: /* @__PURE__ */
|
|
915
|
+
children: /* @__PURE__ */ s(
|
|
909
916
|
An,
|
|
910
917
|
{
|
|
911
918
|
width: z(r),
|
|
@@ -913,34 +920,34 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
913
920
|
}
|
|
914
921
|
)
|
|
915
922
|
}
|
|
916
|
-
) : null, In = !$ && !!
|
|
917
|
-
/* @__PURE__ */
|
|
923
|
+
) : null, In = !$ && !!e.placeholder && !!V, fn = /* @__PURE__ */ l("div", { className: "sa-tf-field-wrap", children: [
|
|
924
|
+
/* @__PURE__ */ s(
|
|
918
925
|
"input",
|
|
919
926
|
{
|
|
920
|
-
...
|
|
921
|
-
id:
|
|
927
|
+
...e,
|
|
928
|
+
id: sn.current,
|
|
922
929
|
ref: C,
|
|
923
930
|
className: "sa-tf-input",
|
|
924
931
|
disabled: w,
|
|
925
|
-
placeholder:
|
|
932
|
+
placeholder: V ? "" : e.placeholder,
|
|
926
933
|
value: N,
|
|
927
934
|
onFocus: (t) => {
|
|
928
935
|
var i;
|
|
929
|
-
|
|
936
|
+
an(!0), yn(!0), (i = e.onFocus) == null || i.call(e, t);
|
|
930
937
|
},
|
|
931
938
|
onBlur: (t) => {
|
|
932
939
|
var i;
|
|
933
|
-
|
|
940
|
+
an(!1), (i = e.onBlur) == null || i.call(e, t);
|
|
934
941
|
},
|
|
935
942
|
onKeyDown: (t) => {
|
|
936
943
|
var i;
|
|
937
|
-
t.key === "Backspace" &&
|
|
944
|
+
t.key === "Backspace" && en(t.key), (i = e.onKeyDown) == null || i.call(e, t);
|
|
938
945
|
},
|
|
939
946
|
onChange: Nn
|
|
940
947
|
}
|
|
941
948
|
),
|
|
942
|
-
In ? _n(
|
|
943
|
-
] }), cn = N && rn && (E != null && E.length) ? /* @__PURE__ */
|
|
949
|
+
In ? _n(e.placeholder, V) : null
|
|
950
|
+
] }), cn = N && rn && (E != null && E.length) ? /* @__PURE__ */ s(
|
|
944
951
|
Tn,
|
|
945
952
|
{
|
|
946
953
|
options: E,
|
|
@@ -949,7 +956,7 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
949
956
|
ref: _,
|
|
950
957
|
isComponentVisible: rn,
|
|
951
958
|
onOptionChange: (t) => {
|
|
952
|
-
|
|
959
|
+
O == null || O(t), k(t);
|
|
953
960
|
}
|
|
954
961
|
}
|
|
955
962
|
) : null, X = H ? /* @__PURE__ */ l(
|
|
@@ -959,23 +966,23 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
959
966
|
ref: _,
|
|
960
967
|
onClick: Cn,
|
|
961
968
|
children: [
|
|
962
|
-
|
|
969
|
+
R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: R }) : null,
|
|
963
970
|
/* @__PURE__ */ l("div", { className: "sa-tf-box-content", children: [
|
|
964
971
|
m ? U(m, nn) : null,
|
|
965
972
|
/* @__PURE__ */ l("div", { className: "sa-tf-inside-stack", children: [
|
|
966
973
|
K("sa-tf-inside-label-row"),
|
|
967
|
-
/* @__PURE__ */
|
|
974
|
+
/* @__PURE__ */ s("div", { className: "sa-tf-inside-row", children: fn })
|
|
968
975
|
] }),
|
|
969
976
|
dn,
|
|
970
977
|
ln,
|
|
971
978
|
on()
|
|
972
979
|
] }),
|
|
973
|
-
|
|
980
|
+
B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: B }) : null,
|
|
974
981
|
cn
|
|
975
982
|
]
|
|
976
983
|
}
|
|
977
984
|
) : /* @__PURE__ */ l("div", { className: "sa-tf-box", ref: _, children: [
|
|
978
|
-
|
|
985
|
+
R ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-left", children: R }) : null,
|
|
979
986
|
/* @__PURE__ */ l("div", { className: "sa-tf-box-content", children: [
|
|
980
987
|
m ? U(m, nn) : null,
|
|
981
988
|
fn,
|
|
@@ -983,13 +990,13 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
983
990
|
ln,
|
|
984
991
|
on()
|
|
985
992
|
] }),
|
|
986
|
-
|
|
993
|
+
B ? /* @__PURE__ */ s("div", { className: "sa-tf-addon sa-tf-addon-right", children: B }) : null,
|
|
987
994
|
cn
|
|
988
995
|
] });
|
|
989
996
|
return c === "outside-left" ? /* @__PURE__ */ l("div", { className: q, children: [
|
|
990
997
|
/* @__PURE__ */ l("div", { className: "sa-tf-label-col", children: [
|
|
991
998
|
K("sa-tf-label"),
|
|
992
|
-
p ? /* @__PURE__ */
|
|
999
|
+
p ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: p }) : null
|
|
993
1000
|
] }),
|
|
994
1001
|
/* @__PURE__ */ l("div", { className: "sa-tf-input-col", children: [
|
|
995
1002
|
X,
|
|
@@ -1000,25 +1007,30 @@ const Yn = (n) => /* @__PURE__ */ l(
|
|
|
1000
1007
|
P
|
|
1001
1008
|
] }) : /* @__PURE__ */ l("div", { className: q, children: [
|
|
1002
1009
|
K("sa-tf-label"),
|
|
1003
|
-
p ? /* @__PURE__ */
|
|
1010
|
+
p ? /* @__PURE__ */ s("p", { className: "sa-tf-desc-top", children: p }) : null,
|
|
1004
1011
|
X,
|
|
1005
1012
|
P
|
|
1006
1013
|
] });
|
|
1007
1014
|
}
|
|
1008
|
-
), _n = (n,
|
|
1015
|
+
), _n = (n, a) => {
|
|
1009
1016
|
if (!n)
|
|
1010
1017
|
return null;
|
|
1011
|
-
if (!
|
|
1012
|
-
return /* @__PURE__ */
|
|
1013
|
-
const r = n.toLowerCase().indexOf(
|
|
1014
|
-
return r === -1 ? /* @__PURE__ */
|
|
1018
|
+
if (!a)
|
|
1019
|
+
return /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n });
|
|
1020
|
+
const r = n.toLowerCase().indexOf(a.toLowerCase());
|
|
1021
|
+
return r === -1 ? /* @__PURE__ */ s("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ l("p", { className: "sa-tf-placeholder", children: [
|
|
1015
1022
|
n.slice(0, r),
|
|
1016
|
-
/* @__PURE__ */
|
|
1017
|
-
n.slice(r +
|
|
1023
|
+
/* @__PURE__ */ s("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + a.length) }),
|
|
1024
|
+
n.slice(r + a.length)
|
|
1018
1025
|
] });
|
|
1019
1026
|
};
|
|
1020
1027
|
Wn.displayName = "Input";
|
|
1021
|
-
const Mn =
|
|
1028
|
+
const Mn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
|
|
1029
|
+
starasia, components, utilities). CSS app/Tailwind utility selalu bisa
|
|
1030
|
+
menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
|
|
1031
|
+
@layer starasia.components {
|
|
1032
|
+
|
|
1033
|
+
.sa-kbd {
|
|
1022
1034
|
display: inline-flex;
|
|
1023
1035
|
align-items: center;
|
|
1024
1036
|
gap: var(--sa-spacing-4, 4px);
|
|
@@ -1096,22 +1108,24 @@ const Mn = `.sa-kbd {
|
|
|
1096
1108
|
.sa-kbd-size-lg .sa-kbd-sep {
|
|
1097
1109
|
font-size: 16px;
|
|
1098
1110
|
}
|
|
1111
|
+
|
|
1112
|
+
} /* @layer starasia.components */
|
|
1099
1113
|
`, hn = "sa-kbd-styles", Hn = (n) => {
|
|
1100
1114
|
if (!(typeof document > "u") && !document.getElementById(hn)) {
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1115
|
+
const a = document.createElement("style");
|
|
1116
|
+
a.id = hn, a.textContent = n, document.head.appendChild(a);
|
|
1103
1117
|
}
|
|
1104
1118
|
};
|
|
1105
1119
|
Hn(Mn);
|
|
1106
|
-
function qn({ keys: n, separator:
|
|
1107
|
-
return /* @__PURE__ */
|
|
1120
|
+
function qn({ keys: n, separator: a, size: r = "sm", className: o, ...d }) {
|
|
1121
|
+
return /* @__PURE__ */ s(
|
|
1108
1122
|
"span",
|
|
1109
1123
|
{
|
|
1110
1124
|
className: `sa-kbd sa-kbd-size-${r}${o ? ` ${o}` : ""}`,
|
|
1111
1125
|
...d,
|
|
1112
1126
|
children: n.map((f, c) => /* @__PURE__ */ l(Z.Fragment, { children: [
|
|
1113
|
-
c > 0 &&
|
|
1114
|
-
/* @__PURE__ */
|
|
1127
|
+
c > 0 && a != null ? /* @__PURE__ */ s("span", { className: "sa-kbd-sep", "aria-hidden": "true", children: a }) : null,
|
|
1128
|
+
/* @__PURE__ */ s("kbd", { className: "sa-kbd-key", children: f })
|
|
1115
1129
|
] }, c))
|
|
1116
1130
|
}
|
|
1117
1131
|
);
|
package/dist/input.umd.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
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
|
|
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=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
|
|
2
|
+
starasia, components, utilities). CSS app/Tailwind utility selalu bisa
|
|
3
|
+
menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
|
|
4
|
+
@layer starasia.components {
|
|
5
|
+
|
|
6
|
+
|
|
2
7
|
:root {
|
|
3
8
|
/* Layer 3 — references Layer 2 semantic tokens */
|
|
4
9
|
--sa-input-text-primary: var(--sa-text-primary, #292a2e);
|
|
@@ -611,7 +616,14 @@
|
|
|
611
616
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
612
617
|
min-height: 80px;
|
|
613
618
|
}
|
|
614
|
-
|
|
619
|
+
|
|
620
|
+
} /* @layer starasia.components */
|
|
621
|
+
`,k=s=>s==="lg"||s==="xl"?18:s==="xs"?14:16,T={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #186742)",disable:"var(--sa-icon-disable, #181a198f)"},Q=(s,e)=>e?T.disable:T[s]??T.default;function hn(s){return Number(s.replace(/\./g,""))}function D(s){let e=s.replace(/[^\d]/g,"");return e=e.replace(/^0+(?=\d)/,""),e.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function mn(s,e){if(e<=0)return 0;let r=0;for(let l=0;l<s.length;l++)if(/\d/.test(s[l])&&(r+=1,r===e))return l+1;return s.length}const vn=o.forwardRef(({options:s,value:e,setValue:r,isComponentVisible:l,onOptionChange:d},f)=>{const[c,F]=o.useState([]),u=o.useRef(null),p=()=>{if(f!=null&&f.current&&u.current){const h=window.innerHeight,x=f==null?void 0:f.current.getBoundingClientRect(),v=u.current.getBoundingClientRect(),w=x.bottom+v.height;u.current.style.left=`${x.left}px`,u.current.style.width=`${x.width}px`,w>=h-10?u.current.style.top=`${x.top-v.height-5}px`:u.current.style.top=`${x.top+x.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",p),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p),window.removeEventListener("resize",p)}),[f,u]),o.useEffect(()=>{p()},[l]),o.useEffect(()=>{F((s==null?void 0:s.filter(h=>h.toLowerCase().startsWith(e.toLowerCase())))||[])},[e,s]),n.jsx("div",{ref:u,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",borderRadius:"var(--sa-radii-md, 8px)",background:"var(--sa-background-primary, #ffffff)",overflow:"auto",zIndex:5e4},children:c==null?void 0:c.map(h=>wn(h,e,r,d))})}),wn=(s,e,r,l)=>{const d=s.toLowerCase().indexOf(e.toLowerCase());return n.jsxs("p",{style:{fontFamily:'var(--sa-font-family, "Inter", sans-serif)',color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{r(s),l&&l(s)},children:[s.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:s.slice(d,d+e.length)}),s.slice(d+e.length)]})};function yn(s){const[e,r]=o.useState(s),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&r(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:r}}const Z="sa-input-styles";(s=>{if(!(typeof document>"u")&&!document.getElementById(Z)){const e=document.createElement("style");e.id=Z,e.textContent=s,document.head.appendChild(e)}})(gn);const kn=s=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...s,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=s=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...s,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((s,e)=>{const{size:r="sm",variant:l="outline",status:d="default",label:f,labelPosition:c="outside-top",required:F,optional:u,description:p,helperText:h,errorText:x,leftIcon:v,rightIcon:w,leftAddons:S,rightAddons:B,onClickLeftIcon:tn,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:E,options:L,onOptionChange:Y,clearable:Sn=!0,onClear:A,...a}=s,M=a.value!==void 0,[W,z]=o.useState(()=>{const t=a.value!==void 0?String(a.value??""):String(a.defaultValue??"");return E?D(t):t}),[en,an]=o.useState(!1),[Bn,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:_,setIsComponentVisible:En}=yn(!1);o.useLayoutEffect(()=>{if(!M)return;const t=a.value===void 0||a.value===null?"":String(a.value),i=E?D(t):t;z(g=>g===i?g:i)},[a.value,E,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const t=N.current,i=C.current;if(C.current=null,!!t)try{t.setSelectionRange(i,i)}catch{}},[W]);const I=W,$=I!==""&&I!==void 0,y=d==="disable"||a.disabled,q=y?"disable":d,H=c==="inside",Ln=H&&($||en),K=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${r}`,`sa-tf-status-${q}`,`sa-tf-label-${c}`,en?"sa-tf-focused":"",y?"sa-tf-disabled":"",Ln?"sa-tf-floating":"",f?"":"sa-tf-no-label",In?"sa-tf-fullwidth":""].filter(Boolean).join(" "),$n=()=>{var t;return(t=N.current)==null?void 0:t.focus()},jn=t=>{var bn,xn;if(!E){const j=t.target.selectionStart;j!==null&&(C.current=j),z(t.target.value),(bn=a.onChange)==null||bn.call(a,t);return}const i=t.target.value;let g=i,m=t.target.selectionStart??i.length;if(Bn==="Backspace"){const j=W.replace(/\D/g,""),Vn=i.replace(/\D/g,"");j.length===Vn.length&&m>0&&(g=i.slice(0,m-1)+i.slice(m),m-=1)}const J=D(g),Fn=g.slice(0,m).replace(/\D/g,"").length,On=mn(J,Fn);C.current=On,z(J),(xn=a.onChange)==null||xn.call(a,{...t,target:{...t.target,value:String(hn(J)),name:t.target.name}}),rn("")},P=t=>f?n.jsxs("div",{className:t,children:[n.jsx("label",{htmlFor:on.current,style:{cursor:y?"not-allowed":"pointer"},children:f}),u?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,F?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,x&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:x}):null]}),X=(t,i)=>n.jsx("span",{className:`sa-tf-icon${i?" sa-tf-icon-clickable":""}`,onClick:i,children:o.cloneElement(t,{width:k(r),height:k(r),color:Q(q,y),style:{color:Q(q,y)}})}),dn=()=>{var i;return w==null?null:!o.isValidElement(w)||((i=w.type)==null?void 0:i.__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(r),height:k(r)})}):null,Tn=t=>{var g;t.stopPropagation(),M||z("");const i={target:{value:"",name:a.name},currentTarget:{value:"",name:a.name}};(g=a.onChange)==null||g.call(a,i),A==null||A(),C.current=0,requestAnimationFrame(()=>{var m;return(m=N.current)==null?void 0:m.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:Tn,onMouseDown:t=>t.preventDefault(),children:n.jsx(zn,{width:k(r),height:k(r)})}):null,Dn=!$&&!!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:t=>{var i;an(!0),En(!0),(i=a.onFocus)==null||i.call(a,t)},onBlur:t=>{var i;an(!1),(i=a.onBlur)==null||i.call(a,t)},onKeyDown:t=>{var i;t.key==="Backspace"&&rn(t.key),(i=a.onKeyDown)==null||i.call(a,t)},onChange:jn}),Dn?Cn(a.placeholder,V):null]}),pn=I&&ln&&(L!=null&&L.length)?n.jsx(vn,{options:L,value:I,setValue:z,ref:_,isComponentVisible:ln,onOptionChange:t=>{Y==null||Y(t),z(t)}}):null,G=H?n.jsxs("div",{className:"sa-tf-box",ref:_,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:[v?X(v,tn):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[P("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:un})]}),cn,fn,dn()]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,pn]}):n.jsxs("div",{className:"sa-tf-box",ref:_,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:[v?X(v,tn):null,un,cn,fn,dn()]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,pn]});return c==="outside-left"?n.jsxs("div",{className:K,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[P("sa-tf-label"),p?n.jsx("p",{className:"sa-tf-desc-top",children:p}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[G,U]})]}):H?n.jsxs("div",{className:K,children:[G,U]}):n.jsxs("div",{className:K,children:[P("sa-tf-label"),p?n.jsx("p",{className:"sa-tf-desc-top",children:p}):null,G,U]})}),Cn=(s,e)=>{if(!s)return null;if(!e)return n.jsx("p",{className:"sa-tf-placeholder",children:s});const r=s.toLowerCase().indexOf(e.toLowerCase());return r===-1?n.jsx("p",{className:"sa-tf-placeholder",children:s}):n.jsxs("p",{className:"sa-tf-placeholder",children:[s.slice(0,r),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:s.slice(r,r+e.length)}),s.slice(r+e.length)]})};R.displayName="Input";const Nn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
|
|
622
|
+
starasia, components, utilities). CSS app/Tailwind utility selalu bisa
|
|
623
|
+
menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
|
|
624
|
+
@layer starasia.components {
|
|
625
|
+
|
|
626
|
+
.sa-kbd {
|
|
615
627
|
display: inline-flex;
|
|
616
628
|
align-items: center;
|
|
617
629
|
gap: var(--sa-spacing-4, 4px);
|
|
@@ -689,4 +701,6 @@
|
|
|
689
701
|
.sa-kbd-size-lg .sa-kbd-sep {
|
|
690
702
|
font-size: 16px;
|
|
691
703
|
}
|
|
704
|
+
|
|
705
|
+
} /* @layer starasia.components */
|
|
692
706
|
`,nn="sa-kbd-styles";(s=>{if(!(typeof document>"u")&&!document.getElementById(nn)){const e=document.createElement("style");e.id=nn,e.textContent=s,document.head.appendChild(e)}})(Nn);function sn({keys:s,separator:e,size:r="sm",className:l,...d}){return n.jsx("span",{className:`sa-kbd sa-kbd-size-${r}${l?` ${l}`:""}`,...d,children:s.map((f,c)=>n.jsxs(o.Fragment,{children:[c>0&&e!=null?n.jsx("span",{className:"sa-kbd-sep","aria-hidden":"true",children:e}):null,n.jsx("kbd",{className:"sa-kbd-key",children:f})]},c))})}sn.__saRaw=!0,b.Input=R,b.Kbd=sn,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|