@starasia/input 4.2.1 → 4.3.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 +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/input.es.js +155 -96
- package/dist/input.umd.js +56 -4
- package/package.json +1 -1
package/dist/Kbd.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
export type KbdSize = "xs" | "sm" | "md" | "lg";
|
|
2
3
|
export interface KbdProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
3
4
|
/** Keys to render, one cap each. e.g. ['⌘', 'K'] */
|
|
4
5
|
keys: React.ReactNode[];
|
|
5
6
|
/** Optional separator rendered between caps. Default: none (gap only). */
|
|
6
7
|
separator?: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Cap size — matches Input's scale so a `<Kbd>` embedded as an Input icon
|
|
10
|
+
* pairs 1:1. Default `"sm"` (12px, unchanged from before this prop existed).
|
|
11
|
+
*/
|
|
12
|
+
size?: KbdSize;
|
|
7
13
|
}
|
|
8
|
-
export declare function Kbd({ keys, separator, className, ...rest }: KbdProps): React.JSX.Element;
|
|
14
|
+
export declare function Kbd({ keys, separator, size, className, ...rest }: KbdProps): React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
package/dist/input.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as a, jsxs as
|
|
2
|
-
import Z, { forwardRef as mn, useState as I, useRef as R, useEffect as
|
|
1
|
+
import { jsx as a, jsxs as l, Fragment as Ln } from "react/jsx-runtime";
|
|
2
|
+
import Z, { forwardRef as mn, useState as I, useRef as R, useEffect as F, useImperativeHandle as En, useLayoutEffect as bn } from "react";
|
|
3
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 {
|
|
@@ -256,6 +256,11 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
256
256
|
border: 0 !important;
|
|
257
257
|
box-shadow: none !important;
|
|
258
258
|
}
|
|
259
|
+
/* Borderless: tanpa padding (flush ke container) — override base + size padding.
|
|
260
|
+
Ditempatkan setelah aturan size agar menang pada specificity yang setara. */
|
|
261
|
+
.sa-tf-variant-borderless .sa-tf-box-content {
|
|
262
|
+
padding: 0;
|
|
263
|
+
}
|
|
259
264
|
.sa-tf-variant-standard.sa-tf-status-error .sa-tf-box {
|
|
260
265
|
background: var(--sa-input-bg-error-subtlest);
|
|
261
266
|
}
|
|
@@ -615,44 +620,44 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
615
620
|
success: "var(--sa-text-success, #208958)",
|
|
616
621
|
disable: "var(--sa-icon-disable, #181a198f)"
|
|
617
622
|
}, xn = (n, e) => e ? J.disable : J[n] ?? J.default;
|
|
618
|
-
function
|
|
623
|
+
function Dn(n) {
|
|
619
624
|
return Number(n.replace(/\./g, ""));
|
|
620
625
|
}
|
|
621
626
|
function Q(n) {
|
|
622
627
|
let e = n.replace(/[^\d]/g, "");
|
|
623
628
|
return e = e.replace(/^0+(?=\d)/, ""), e.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
624
629
|
}
|
|
625
|
-
function
|
|
630
|
+
function Fn(n, e) {
|
|
626
631
|
if (e <= 0)
|
|
627
632
|
return 0;
|
|
628
633
|
let r = 0;
|
|
629
|
-
for (let
|
|
630
|
-
if (/\d/.test(n[
|
|
631
|
-
return
|
|
634
|
+
for (let o = 0; o < n.length; o++)
|
|
635
|
+
if (/\d/.test(n[o]) && (r += 1, r === e))
|
|
636
|
+
return o + 1;
|
|
632
637
|
return n.length;
|
|
633
638
|
}
|
|
634
639
|
const Tn = mn(
|
|
635
|
-
({ options: n, value: e, setValue: r, isComponentVisible:
|
|
636
|
-
const [
|
|
637
|
-
if (f != null && f.current &&
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
+
({ options: n, value: e, setValue: r, isComponentVisible: o, onOptionChange: d }, f) => {
|
|
641
|
+
const [c, T] = I([]), u = R(null), p = () => {
|
|
642
|
+
if (f != null && f.current && u.current) {
|
|
643
|
+
const g = window.innerHeight, b = f == null ? void 0 : f.current.getBoundingClientRect(), m = u.current.getBoundingClientRect(), v = b.bottom + m.height;
|
|
644
|
+
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`;
|
|
640
645
|
}
|
|
641
646
|
};
|
|
642
|
-
return
|
|
643
|
-
window.removeEventListener("scroll",
|
|
644
|
-
}), [f,
|
|
645
|
-
|
|
646
|
-
}, [
|
|
647
|
+
return F(() => (window.addEventListener("scroll", p), window.addEventListener("resize", p), () => {
|
|
648
|
+
window.removeEventListener("scroll", p), window.removeEventListener("resize", p);
|
|
649
|
+
}), [f, u]), F(() => {
|
|
650
|
+
p();
|
|
651
|
+
}, [o]), F(() => {
|
|
647
652
|
T(
|
|
648
653
|
(n == null ? void 0 : n.filter(
|
|
649
|
-
(
|
|
654
|
+
(g) => g.toLowerCase().startsWith(e.toLowerCase())
|
|
650
655
|
)) || []
|
|
651
656
|
);
|
|
652
657
|
}, [e, n]), /* @__PURE__ */ a(
|
|
653
658
|
"div",
|
|
654
659
|
{
|
|
655
|
-
ref:
|
|
660
|
+
ref: u,
|
|
656
661
|
style: {
|
|
657
662
|
position: "fixed",
|
|
658
663
|
padding: "8px",
|
|
@@ -663,15 +668,15 @@ const Tn = mn(
|
|
|
663
668
|
overflow: "auto",
|
|
664
669
|
zIndex: 5e4
|
|
665
670
|
},
|
|
666
|
-
children:
|
|
667
|
-
(
|
|
671
|
+
children: c == null ? void 0 : c.map(
|
|
672
|
+
(g) => Vn(g, e, r, d)
|
|
668
673
|
)
|
|
669
674
|
}
|
|
670
675
|
);
|
|
671
676
|
}
|
|
672
|
-
), Vn = (n, e, r,
|
|
677
|
+
), Vn = (n, e, r, o) => {
|
|
673
678
|
const d = n.toLowerCase().indexOf(e.toLowerCase());
|
|
674
|
-
return /* @__PURE__ */
|
|
679
|
+
return /* @__PURE__ */ l(
|
|
675
680
|
"p",
|
|
676
681
|
{
|
|
677
682
|
style: {
|
|
@@ -682,7 +687,7 @@ const Tn = mn(
|
|
|
682
687
|
cursor: "pointer"
|
|
683
688
|
},
|
|
684
689
|
onClick: () => {
|
|
685
|
-
r(n),
|
|
690
|
+
r(n), o && o(n);
|
|
686
691
|
},
|
|
687
692
|
children: [
|
|
688
693
|
n.slice(0, d),
|
|
@@ -693,12 +698,12 @@ const Tn = mn(
|
|
|
693
698
|
);
|
|
694
699
|
};
|
|
695
700
|
function On(n) {
|
|
696
|
-
const [e, r] = I(n),
|
|
697
|
-
|
|
701
|
+
const [e, r] = I(n), o = R(null), d = (f) => {
|
|
702
|
+
o.current && !o.current.contains(f.target) && r(!1);
|
|
698
703
|
};
|
|
699
|
-
return
|
|
704
|
+
return F(() => (document.addEventListener("click", d, !0), () => {
|
|
700
705
|
document.removeEventListener("click", d, !0);
|
|
701
|
-
}), []), { ref:
|
|
706
|
+
}), []), { ref: o, isComponentVisible: e, setIsComponentVisible: r };
|
|
702
707
|
}
|
|
703
708
|
const gn = "sa-input-styles", jn = (n) => {
|
|
704
709
|
if (!(typeof document > "u") && !document.getElementById(gn)) {
|
|
@@ -707,7 +712,7 @@ const gn = "sa-input-styles", jn = (n) => {
|
|
|
707
712
|
}
|
|
708
713
|
};
|
|
709
714
|
jn($n);
|
|
710
|
-
const Yn = (n) => /* @__PURE__ */
|
|
715
|
+
const Yn = (n) => /* @__PURE__ */ l(
|
|
711
716
|
"svg",
|
|
712
717
|
{
|
|
713
718
|
viewBox: "0 0 16 16",
|
|
@@ -728,7 +733,7 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
728
733
|
)
|
|
729
734
|
]
|
|
730
735
|
}
|
|
731
|
-
), An = (n) => /* @__PURE__ */
|
|
736
|
+
), An = (n) => /* @__PURE__ */ l(
|
|
732
737
|
"svg",
|
|
733
738
|
{
|
|
734
739
|
viewBox: "0 0 16 16",
|
|
@@ -752,62 +757,62 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
752
757
|
(n, e) => {
|
|
753
758
|
const {
|
|
754
759
|
size: r = "sm",
|
|
755
|
-
variant:
|
|
760
|
+
variant: o = "outline",
|
|
756
761
|
status: d = "default",
|
|
757
762
|
label: f,
|
|
758
|
-
labelPosition:
|
|
763
|
+
labelPosition: c = "outside-top",
|
|
759
764
|
required: T,
|
|
760
|
-
optional:
|
|
761
|
-
description:
|
|
762
|
-
helperText:
|
|
765
|
+
optional: u,
|
|
766
|
+
description: p,
|
|
767
|
+
helperText: g,
|
|
763
768
|
errorText: b,
|
|
764
769
|
leftIcon: m,
|
|
765
770
|
rightIcon: v,
|
|
766
771
|
leftAddons: B,
|
|
767
|
-
rightAddons:
|
|
772
|
+
rightAddons: S,
|
|
768
773
|
onClickLeftIcon: nn,
|
|
769
774
|
onClickRightIcon: V,
|
|
770
775
|
fullWidth: vn = !0,
|
|
771
776
|
highlightPlaceholder: O,
|
|
772
|
-
currency:
|
|
777
|
+
currency: L,
|
|
773
778
|
options: E,
|
|
774
779
|
onOptionChange: j,
|
|
775
780
|
clearable: wn = !0,
|
|
776
781
|
onClear: Y,
|
|
777
782
|
...s
|
|
778
|
-
} = n, A = s.value !== void 0, [W,
|
|
783
|
+
} = n, A = s.value !== void 0, [W, k] = I(() => {
|
|
779
784
|
const t = s.value !== void 0 ? String(s.value ?? "") : String(s.defaultValue ?? "");
|
|
780
|
-
return
|
|
781
|
-
}), [tn, en] = I(!1), [
|
|
785
|
+
return L ? Q(t) : t;
|
|
786
|
+
}), [tn, en] = I(!1), [kn, sn] = I(""), y = R(null), C = R(null);
|
|
782
787
|
En(e, () => C.current);
|
|
783
788
|
const an = R(
|
|
784
789
|
s.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
|
|
785
790
|
), {
|
|
786
791
|
isComponentVisible: rn,
|
|
787
792
|
ref: _,
|
|
788
|
-
setIsComponentVisible:
|
|
793
|
+
setIsComponentVisible: yn
|
|
789
794
|
} = On(!1);
|
|
790
|
-
|
|
795
|
+
bn(() => {
|
|
791
796
|
if (!A)
|
|
792
797
|
return;
|
|
793
|
-
const t = s.value === void 0 || s.value === null ? "" : String(s.value), i =
|
|
794
|
-
|
|
795
|
-
}, [s.value,
|
|
796
|
-
if (
|
|
798
|
+
const t = s.value === void 0 || s.value === null ? "" : String(s.value), i = L ? Q(t) : t;
|
|
799
|
+
k((x) => x === i ? x : i);
|
|
800
|
+
}, [s.value, L, A]), bn(() => {
|
|
801
|
+
if (y.current === null)
|
|
797
802
|
return;
|
|
798
|
-
const t = C.current, i =
|
|
799
|
-
if (
|
|
803
|
+
const t = C.current, i = y.current;
|
|
804
|
+
if (y.current = null, !!t)
|
|
800
805
|
try {
|
|
801
806
|
t.setSelectionRange(i, i);
|
|
802
807
|
} catch {
|
|
803
808
|
}
|
|
804
809
|
}, [W]);
|
|
805
|
-
const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || s.disabled, M = w ? "disable" : d, P =
|
|
810
|
+
const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || s.disabled, M = w ? "disable" : d, P = c === "inside", zn = P && ($ || tn), H = [
|
|
806
811
|
"sa-tf",
|
|
807
|
-
`sa-tf-variant-${
|
|
812
|
+
`sa-tf-variant-${o}`,
|
|
808
813
|
`sa-tf-size-${r}`,
|
|
809
814
|
`sa-tf-status-${M}`,
|
|
810
|
-
`sa-tf-label-${
|
|
815
|
+
`sa-tf-label-${c}`,
|
|
811
816
|
tn ? "sa-tf-focused" : "",
|
|
812
817
|
w ? "sa-tf-disabled" : "",
|
|
813
818
|
zn ? "sa-tf-floating" : "",
|
|
@@ -817,28 +822,28 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
817
822
|
var t;
|
|
818
823
|
return (t = C.current) == null ? void 0 : t.focus();
|
|
819
824
|
}, Nn = (t) => {
|
|
820
|
-
var un,
|
|
821
|
-
if (!
|
|
822
|
-
const
|
|
823
|
-
|
|
825
|
+
var un, pn;
|
|
826
|
+
if (!L) {
|
|
827
|
+
const D = t.target.selectionStart;
|
|
828
|
+
D !== null && (y.current = D), k(t.target.value), (un = s.onChange) == null || un.call(s, t);
|
|
824
829
|
return;
|
|
825
830
|
}
|
|
826
831
|
const i = t.target.value;
|
|
827
|
-
let
|
|
828
|
-
if (
|
|
829
|
-
const
|
|
830
|
-
|
|
832
|
+
let x = i, h = t.target.selectionStart ?? i.length;
|
|
833
|
+
if (kn === "Backspace") {
|
|
834
|
+
const D = W.replace(/\D/g, ""), Sn = i.replace(/\D/g, "");
|
|
835
|
+
D.length === Sn.length && h > 0 && (x = i.slice(0, h - 1) + i.slice(h), h -= 1);
|
|
831
836
|
}
|
|
832
|
-
const G = Q(
|
|
833
|
-
|
|
837
|
+
const G = Q(x), Rn = x.slice(0, h).replace(/\D/g, "").length, Bn = Fn(G, Rn);
|
|
838
|
+
y.current = Bn, k(G), (pn = s.onChange) == null || pn.call(s, {
|
|
834
839
|
...t,
|
|
835
840
|
target: {
|
|
836
841
|
...t.target,
|
|
837
|
-
value: String(
|
|
842
|
+
value: String(Dn(G)),
|
|
838
843
|
name: t.target.name
|
|
839
844
|
}
|
|
840
845
|
}), sn("");
|
|
841
|
-
}, q = (t) => f ? /* @__PURE__ */
|
|
846
|
+
}, q = (t) => f ? /* @__PURE__ */ l("div", { className: t, children: [
|
|
842
847
|
/* @__PURE__ */ a(
|
|
843
848
|
"label",
|
|
844
849
|
{
|
|
@@ -847,10 +852,10 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
847
852
|
children: f
|
|
848
853
|
}
|
|
849
854
|
),
|
|
850
|
-
|
|
855
|
+
u ? /* @__PURE__ */ a("span", { className: "sa-tf-optional", children: "Optional" }) : null,
|
|
851
856
|
T ? /* @__PURE__ */ a("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
|
|
852
|
-
] }) : null, K = /* @__PURE__ */
|
|
853
|
-
|
|
857
|
+
] }) : null, K = /* @__PURE__ */ l(Ln, { children: [
|
|
858
|
+
g ? /* @__PURE__ */ a("p", { className: "sa-tf-helper", children: g }) : null,
|
|
854
859
|
b && d === "error" ? /* @__PURE__ */ a("p", { className: "sa-tf-error", children: b }) : null
|
|
855
860
|
] }), U = (t, i) => /* @__PURE__ */ a(
|
|
856
861
|
"span",
|
|
@@ -889,15 +894,15 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
889
894
|
"aria-hidden": !$,
|
|
890
895
|
tabIndex: -1,
|
|
891
896
|
onClick: (t) => {
|
|
892
|
-
var
|
|
893
|
-
t.stopPropagation(), A ||
|
|
897
|
+
var x;
|
|
898
|
+
t.stopPropagation(), A || k("");
|
|
894
899
|
const i = {
|
|
895
900
|
target: { value: "", name: s.name },
|
|
896
901
|
currentTarget: { value: "", name: s.name }
|
|
897
902
|
};
|
|
898
|
-
(
|
|
899
|
-
var
|
|
900
|
-
return (
|
|
903
|
+
(x = s.onChange) == null || x.call(s, i), Y == null || Y(), y.current = 0, requestAnimationFrame(() => {
|
|
904
|
+
var h;
|
|
905
|
+
return (h = C.current) == null ? void 0 : h.focus();
|
|
901
906
|
});
|
|
902
907
|
},
|
|
903
908
|
onMouseDown: (t) => t.preventDefault(),
|
|
@@ -909,7 +914,7 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
909
914
|
}
|
|
910
915
|
)
|
|
911
916
|
}
|
|
912
|
-
) : null, In = !$ && !!s.placeholder && !!O, fn = /* @__PURE__ */
|
|
917
|
+
) : null, In = !$ && !!s.placeholder && !!O, fn = /* @__PURE__ */ l("div", { className: "sa-tf-field-wrap", children: [
|
|
913
918
|
/* @__PURE__ */ a(
|
|
914
919
|
"input",
|
|
915
920
|
{
|
|
@@ -922,7 +927,7 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
922
927
|
value: N,
|
|
923
928
|
onFocus: (t) => {
|
|
924
929
|
var i;
|
|
925
|
-
en(!0),
|
|
930
|
+
en(!0), yn(!0), (i = s.onFocus) == null || i.call(s, t);
|
|
926
931
|
},
|
|
927
932
|
onBlur: (t) => {
|
|
928
933
|
var i;
|
|
@@ -941,14 +946,14 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
941
946
|
{
|
|
942
947
|
options: E,
|
|
943
948
|
value: N,
|
|
944
|
-
setValue:
|
|
949
|
+
setValue: k,
|
|
945
950
|
ref: _,
|
|
946
951
|
isComponentVisible: rn,
|
|
947
952
|
onOptionChange: (t) => {
|
|
948
|
-
j == null || j(t),
|
|
953
|
+
j == null || j(t), k(t);
|
|
949
954
|
}
|
|
950
955
|
}
|
|
951
|
-
) : null, X = P ? /* @__PURE__ */
|
|
956
|
+
) : null, X = P ? /* @__PURE__ */ l(
|
|
952
957
|
"div",
|
|
953
958
|
{
|
|
954
959
|
className: "sa-tf-box",
|
|
@@ -956,9 +961,9 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
956
961
|
onClick: Cn,
|
|
957
962
|
children: [
|
|
958
963
|
B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
|
|
959
|
-
/* @__PURE__ */
|
|
964
|
+
/* @__PURE__ */ l("div", { className: "sa-tf-box-content", children: [
|
|
960
965
|
m ? U(m, nn) : null,
|
|
961
|
-
/* @__PURE__ */
|
|
966
|
+
/* @__PURE__ */ l("div", { className: "sa-tf-inside-stack", children: [
|
|
962
967
|
q("sa-tf-inside-label-row"),
|
|
963
968
|
/* @__PURE__ */ a("div", { className: "sa-tf-inside-row", children: fn })
|
|
964
969
|
] }),
|
|
@@ -966,37 +971,37 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
966
971
|
ln,
|
|
967
972
|
on()
|
|
968
973
|
] }),
|
|
969
|
-
|
|
974
|
+
S ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: S }) : null,
|
|
970
975
|
cn
|
|
971
976
|
]
|
|
972
977
|
}
|
|
973
|
-
) : /* @__PURE__ */
|
|
978
|
+
) : /* @__PURE__ */ l("div", { className: "sa-tf-box", ref: _, children: [
|
|
974
979
|
B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
|
|
975
|
-
/* @__PURE__ */
|
|
980
|
+
/* @__PURE__ */ l("div", { className: "sa-tf-box-content", children: [
|
|
976
981
|
m ? U(m, nn) : null,
|
|
977
982
|
fn,
|
|
978
983
|
dn,
|
|
979
984
|
ln,
|
|
980
985
|
on()
|
|
981
986
|
] }),
|
|
982
|
-
|
|
987
|
+
S ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: S }) : null,
|
|
983
988
|
cn
|
|
984
989
|
] });
|
|
985
|
-
return
|
|
986
|
-
/* @__PURE__ */
|
|
990
|
+
return c === "outside-left" ? /* @__PURE__ */ l("div", { className: H, children: [
|
|
991
|
+
/* @__PURE__ */ l("div", { className: "sa-tf-label-col", children: [
|
|
987
992
|
q("sa-tf-label"),
|
|
988
|
-
|
|
993
|
+
p ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: p }) : null
|
|
989
994
|
] }),
|
|
990
|
-
/* @__PURE__ */
|
|
995
|
+
/* @__PURE__ */ l("div", { className: "sa-tf-input-col", children: [
|
|
991
996
|
X,
|
|
992
997
|
K
|
|
993
998
|
] })
|
|
994
|
-
] }) : P ? /* @__PURE__ */
|
|
999
|
+
] }) : P ? /* @__PURE__ */ l("div", { className: H, children: [
|
|
995
1000
|
X,
|
|
996
1001
|
K
|
|
997
|
-
] }) : /* @__PURE__ */
|
|
1002
|
+
] }) : /* @__PURE__ */ l("div", { className: H, children: [
|
|
998
1003
|
q("sa-tf-label"),
|
|
999
|
-
|
|
1004
|
+
p ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: p }) : null,
|
|
1000
1005
|
X,
|
|
1001
1006
|
K
|
|
1002
1007
|
] });
|
|
@@ -1007,7 +1012,7 @@ const Yn = (n) => /* @__PURE__ */ o(
|
|
|
1007
1012
|
if (!e)
|
|
1008
1013
|
return /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n });
|
|
1009
1014
|
const r = n.toLowerCase().indexOf(e.toLowerCase());
|
|
1010
|
-
return r === -1 ? /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */
|
|
1015
|
+
return r === -1 ? /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ l("p", { className: "sa-tf-placeholder", children: [
|
|
1011
1016
|
n.slice(0, r),
|
|
1012
1017
|
/* @__PURE__ */ a("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + e.length) }),
|
|
1013
1018
|
n.slice(r + e.length)
|
|
@@ -1025,7 +1030,7 @@ const Mn = `.sa-kbd {
|
|
|
1025
1030
|
display: inline-flex;
|
|
1026
1031
|
align-items: center;
|
|
1027
1032
|
justify-content: center;
|
|
1028
|
-
min-width: 1.5em;
|
|
1033
|
+
min-width: 1.5em; /* relative to font-size → scales with \`size\` */
|
|
1029
1034
|
padding: 0 var(--sa-spacing-6, 6px);
|
|
1030
1035
|
background-color: var(--sa-background-neutral, #f0f1f2);
|
|
1031
1036
|
border: 1px solid var(--sa-border-subtle, #0b120e24);
|
|
@@ -1045,6 +1050,53 @@ const Mn = `.sa-kbd {
|
|
|
1045
1050
|
font-size: var(--sa-font-size-sm, 12px);
|
|
1046
1051
|
user-select: none;
|
|
1047
1052
|
}
|
|
1053
|
+
|
|
1054
|
+
/* ── Sizes (matches Input's xs/sm/md/lg). \`min-width: 1.5em\` auto-scales;
|
|
1055
|
+
font-size + horizontal padding + gap driven per size. Default \`sm\` keeps
|
|
1056
|
+
the pre-existing look. ── */
|
|
1057
|
+
.sa-kbd-size-xs {
|
|
1058
|
+
gap: 3px;
|
|
1059
|
+
}
|
|
1060
|
+
.sa-kbd-size-xs .sa-kbd-key {
|
|
1061
|
+
padding: 0 4px;
|
|
1062
|
+
font-size: 10px;
|
|
1063
|
+
}
|
|
1064
|
+
.sa-kbd-size-xs .sa-kbd-sep {
|
|
1065
|
+
font-size: 10px;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
.sa-kbd-size-sm {
|
|
1069
|
+
gap: var(--sa-spacing-4, 4px);
|
|
1070
|
+
}
|
|
1071
|
+
.sa-kbd-size-sm .sa-kbd-key {
|
|
1072
|
+
padding: 0 var(--sa-spacing-6, 6px);
|
|
1073
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
1074
|
+
}
|
|
1075
|
+
.sa-kbd-size-sm .sa-kbd-sep {
|
|
1076
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
.sa-kbd-size-md {
|
|
1080
|
+
gap: 5px;
|
|
1081
|
+
}
|
|
1082
|
+
.sa-kbd-size-md .sa-kbd-key {
|
|
1083
|
+
padding: 0 8px;
|
|
1084
|
+
font-size: 14px;
|
|
1085
|
+
}
|
|
1086
|
+
.sa-kbd-size-md .sa-kbd-sep {
|
|
1087
|
+
font-size: 14px;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
.sa-kbd-size-lg {
|
|
1091
|
+
gap: 6px;
|
|
1092
|
+
}
|
|
1093
|
+
.sa-kbd-size-lg .sa-kbd-key {
|
|
1094
|
+
padding: 0 10px;
|
|
1095
|
+
font-size: 16px;
|
|
1096
|
+
}
|
|
1097
|
+
.sa-kbd-size-lg .sa-kbd-sep {
|
|
1098
|
+
font-size: 16px;
|
|
1099
|
+
}
|
|
1048
1100
|
`, hn = "sa-kbd-styles", Pn = (n) => {
|
|
1049
1101
|
if (!(typeof document > "u") && !document.getElementById(hn)) {
|
|
1050
1102
|
const e = document.createElement("style");
|
|
@@ -1052,11 +1104,18 @@ const Mn = `.sa-kbd {
|
|
|
1052
1104
|
}
|
|
1053
1105
|
};
|
|
1054
1106
|
Pn(Mn);
|
|
1055
|
-
function Hn({ keys: n, separator: e,
|
|
1056
|
-
return /* @__PURE__ */ a(
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1107
|
+
function Hn({ keys: n, separator: e, size: r = "sm", className: o, ...d }) {
|
|
1108
|
+
return /* @__PURE__ */ a(
|
|
1109
|
+
"span",
|
|
1110
|
+
{
|
|
1111
|
+
className: `sa-kbd sa-kbd-size-${r}${o ? ` ${o}` : ""}`,
|
|
1112
|
+
...d,
|
|
1113
|
+
children: n.map((f, c) => /* @__PURE__ */ l(Z.Fragment, { children: [
|
|
1114
|
+
c > 0 && e != null ? /* @__PURE__ */ a("span", { className: "sa-kbd-sep", "aria-hidden": "true", children: e }) : null,
|
|
1115
|
+
/* @__PURE__ */ a("kbd", { className: "sa-kbd-key", children: f })
|
|
1116
|
+
] }, c))
|
|
1117
|
+
}
|
|
1118
|
+
);
|
|
1060
1119
|
}
|
|
1061
1120
|
Hn.__saRaw = !0;
|
|
1062
1121
|
export {
|
package/dist/input.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
1
|
+
(function(b,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(b=typeof globalThis<"u"?globalThis:b||self,n(b.Input={},b.jsxRuntime,b.React))})(this,function(b,n,o){"use strict";const gn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
2
2
|
|
|
3
3
|
:root {
|
|
4
4
|
/* Layer 3 — references Layer 2 semantic tokens */
|
|
@@ -254,6 +254,11 @@
|
|
|
254
254
|
border: 0 !important;
|
|
255
255
|
box-shadow: none !important;
|
|
256
256
|
}
|
|
257
|
+
/* Borderless: tanpa padding (flush ke container) — override base + size padding.
|
|
258
|
+
Ditempatkan setelah aturan size agar menang pada specificity yang setara. */
|
|
259
|
+
.sa-tf-variant-borderless .sa-tf-box-content {
|
|
260
|
+
padding: 0;
|
|
261
|
+
}
|
|
257
262
|
.sa-tf-variant-standard.sa-tf-status-error .sa-tf-box {
|
|
258
263
|
background: var(--sa-input-bg-error-subtlest);
|
|
259
264
|
}
|
|
@@ -607,7 +612,7 @@
|
|
|
607
612
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
608
613
|
min-height: 80px;
|
|
609
614
|
}
|
|
610
|
-
`,
|
|
615
|
+
`,y=t=>t==="lg"||t==="xl"?18:t==="xs"?14: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)"},Q=(t,e)=>e?j.disable:j[t]??j.default;function hn(t){return Number(t.replace(/\./g,""))}function F(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 r=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(r+=1,r===e))return l+1;return t.length}const mn=o.forwardRef(({options:t,value:e,setValue:r,isComponentVisible:l,onOptionChange:d},f)=>{const[c,T]=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(),m=u.current.getBoundingClientRect(),w=x.bottom+m.height;u.current.style.left=`${x.left}px`,u.current.style.width=`${x.width}px`,w>=h-10?u.current.style.top=`${x.top-m.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(()=>{T((t==null?void 0:t.filter(h=>h.toLowerCase().startsWith(e.toLowerCase())))||[])},[e,t]),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:"8px",background:"white",overflow:"auto",zIndex:5e4},children:c==null?void 0:c.map(h=>wn(h,e,r,d))})}),wn=(t,e,r,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:()=>{r(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+e.length)}),t.slice(d+e.length)]})};function kn(t){const[e,r]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&r(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:r}}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)}})(gn);const yn=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:r="sm",variant:l="outline",status:d="default",label:f,labelPosition:c="outside-top",required:T,optional:u,description:p,helperText:h,errorText:x,leftIcon:m,rightIcon:w,leftAddons:S,rightAddons:B,onClickLeftIcon:sn,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:E,options:L,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 E?F(s):s}),[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:W,setIsComponentVisible:En}=kn(!1);o.useLayoutEffect(()=>{if(!M)return;const s=a.value===void 0||a.value===null?"":String(a.value),i=E?F(s):s;z(g=>g===i?g:i)},[a.value,E,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const s=N.current,i=C.current;if(C.current=null,!!s)try{s.setSelectionRange(i,i)}catch{}},[P]);const I=P,$=I!==""&&I!==void 0,k=d==="disable"||a.disabled,_=k?"disable":d,q=c==="inside",Ln=q&&($||en),H=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${r}`,`sa-tf-status-${_}`,`sa-tf-label-${c}`,en?"sa-tf-focused":"",k?"sa-tf-disabled":"",Ln?"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()},Dn=s=>{var bn,xn;if(!E){const D=s.target.selectionStart;D!==null&&(C.current=D),z(s.target.value),(bn=a.onChange)==null||bn.call(a,s);return}const i=s.target.value;let g=i,v=s.target.selectionStart??i.length;if(Bn==="Backspace"){const D=P.replace(/\D/g,""),Vn=i.replace(/\D/g,"");D.length===Vn.length&&v>0&&(g=i.slice(0,v-1)+i.slice(v),v-=1)}const J=F(g),Tn=g.slice(0,v).replace(/\D/g,"").length,On=vn(J,Tn);C.current=On,z(J),(xn=a.onChange)==null||xn.call(a,{...s,target:{...s.target,value:String(hn(J)),name:s.target.name}}),rn("")},K=s=>f?n.jsxs("div",{className:s,children:[n.jsx("label",{htmlFor:on.current,style:{cursor:k?"not-allowed":"pointer"},children:f}),u?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,T?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=(s,i)=>n.jsx("span",{className:`sa-tf-icon${i?" sa-tf-icon-clickable":""}`,onClick:i,children:o.cloneElement(s,{width:y(r),height:y(r),color:Q(_,k),style:{color:Q(_,k)}})}),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(yn,{width:y(r),height:y(r)})}):null,jn=s=>{var g;s.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 v;return(v=N.current)==null?void 0:v.focus()})},cn=Sn&&!k?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:jn,onMouseDown:s=>s.preventDefault(),children:n.jsx(zn,{width:y(r),height:y(r)})}):null,Fn=!$&&!!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:k,placeholder:V?"":a.placeholder,value:I,onFocus:s=>{var i;an(!0),En(!0),(i=a.onFocus)==null||i.call(a,s)},onBlur:s=>{var i;an(!1),(i=a.onBlur)==null||i.call(a,s)},onKeyDown:s=>{var i;s.key==="Backspace"&&rn(s.key),(i=a.onKeyDown)==null||i.call(a,s)},onChange:Dn}),Fn?Cn(a.placeholder,V):null]}),pn=I&&ln&&(L!=null&&L.length)?n.jsx(mn,{options:L,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()]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,pn]}):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()]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,pn]});return c==="outside-left"?n.jsxs("div",{className:H,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[K("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]})]}):q?n.jsxs("div",{className:H,children:[G,U]}):n.jsxs("div",{className:H,children:[K("sa-tf-label"),p?n.jsx("p",{className:"sa-tf-desc-top",children:p}):null,G,U]})}),Cn=(t,e)=>{if(!t)return null;if(!e)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const r=t.toLowerCase().indexOf(e.toLowerCase());return r===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,r),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(r,r+e.length)}),t.slice(r+e.length)]})};R.displayName="Input";const Nn=`.sa-kbd {
|
|
611
616
|
display: inline-flex;
|
|
612
617
|
align-items: center;
|
|
613
618
|
gap: var(--sa-spacing-4, 4px);
|
|
@@ -618,7 +623,7 @@
|
|
|
618
623
|
display: inline-flex;
|
|
619
624
|
align-items: center;
|
|
620
625
|
justify-content: center;
|
|
621
|
-
min-width: 1.5em;
|
|
626
|
+
min-width: 1.5em; /* relative to font-size → scales with \`size\` */
|
|
622
627
|
padding: 0 var(--sa-spacing-6, 6px);
|
|
623
628
|
background-color: var(--sa-background-neutral, #f0f1f2);
|
|
624
629
|
border: 1px solid var(--sa-border-subtle, #0b120e24);
|
|
@@ -638,4 +643,51 @@
|
|
|
638
643
|
font-size: var(--sa-font-size-sm, 12px);
|
|
639
644
|
user-select: none;
|
|
640
645
|
}
|
|
641
|
-
|
|
646
|
+
|
|
647
|
+
/* ── Sizes (matches Input's xs/sm/md/lg). \`min-width: 1.5em\` auto-scales;
|
|
648
|
+
font-size + horizontal padding + gap driven per size. Default \`sm\` keeps
|
|
649
|
+
the pre-existing look. ── */
|
|
650
|
+
.sa-kbd-size-xs {
|
|
651
|
+
gap: 3px;
|
|
652
|
+
}
|
|
653
|
+
.sa-kbd-size-xs .sa-kbd-key {
|
|
654
|
+
padding: 0 4px;
|
|
655
|
+
font-size: 10px;
|
|
656
|
+
}
|
|
657
|
+
.sa-kbd-size-xs .sa-kbd-sep {
|
|
658
|
+
font-size: 10px;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
.sa-kbd-size-sm {
|
|
662
|
+
gap: var(--sa-spacing-4, 4px);
|
|
663
|
+
}
|
|
664
|
+
.sa-kbd-size-sm .sa-kbd-key {
|
|
665
|
+
padding: 0 var(--sa-spacing-6, 6px);
|
|
666
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
667
|
+
}
|
|
668
|
+
.sa-kbd-size-sm .sa-kbd-sep {
|
|
669
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
.sa-kbd-size-md {
|
|
673
|
+
gap: 5px;
|
|
674
|
+
}
|
|
675
|
+
.sa-kbd-size-md .sa-kbd-key {
|
|
676
|
+
padding: 0 8px;
|
|
677
|
+
font-size: 14px;
|
|
678
|
+
}
|
|
679
|
+
.sa-kbd-size-md .sa-kbd-sep {
|
|
680
|
+
font-size: 14px;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
.sa-kbd-size-lg {
|
|
684
|
+
gap: 6px;
|
|
685
|
+
}
|
|
686
|
+
.sa-kbd-size-lg .sa-kbd-key {
|
|
687
|
+
padding: 0 10px;
|
|
688
|
+
font-size: 16px;
|
|
689
|
+
}
|
|
690
|
+
.sa-kbd-size-lg .sa-kbd-sep {
|
|
691
|
+
font-size: 16px;
|
|
692
|
+
}
|
|
693
|
+
`,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,size:r="sm",className:l,...d}){return n.jsx("span",{className:`sa-kbd sa-kbd-size-${r}${l?` ${l}`:""}`,...d,children:t.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))})}tn.__saRaw=!0,b.Input=R,b.Kbd=tn,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|