@starasia/input 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Kbd.d.ts +8 -0
- package/dist/functions.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/input.es.js +235 -163
- package/dist/input.umd.js +49 -2
- package/dist/types.d.ts +6 -2
- package/package.json +1 -1
package/dist/Kbd.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface KbdProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
/** Keys to render, one cap each. e.g. ['⌘', 'K'] */
|
|
4
|
+
keys: React.ReactNode[];
|
|
5
|
+
/** Optional separator rendered between caps. Default: none (gap only). */
|
|
6
|
+
separator?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare function Kbd({ keys, separator, className, ...rest }: KbdProps): React.JSX.Element;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InputSize, InputStatus } from "./types";
|
|
2
|
-
export declare const renderIconSize: (size: InputSize | undefined) => 18 | 16;
|
|
2
|
+
export declare const renderIconSize: (size: InputSize | undefined) => 18 | 14 | 16;
|
|
3
3
|
export declare const renderIconColor: (status: InputStatus, disabled?: boolean) => string;
|
|
4
4
|
export declare const renderColorLeftIcon: (status: InputStatus, disabled?: boolean) => string;
|
|
5
5
|
export declare const renderColorRightIcon: (status: InputStatus, disabled?: boolean) => string;
|
package/dist/index.d.ts
CHANGED
package/dist/input.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsx as a, jsxs as o, Fragment as Sn } from "react/jsx-runtime";
|
|
2
|
+
import Z, { forwardRef as mn, useState as I, useRef as R, useEffect as D, useImperativeHandle as En, useLayoutEffect as pn } from "react";
|
|
3
|
+
const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
4
4
|
|
|
5
5
|
:root {
|
|
6
6
|
/* Layer 3 — references Layer 2 semantic tokens */
|
|
@@ -90,6 +90,8 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
90
90
|
line-height: normal;
|
|
91
91
|
margin: 0;
|
|
92
92
|
}
|
|
93
|
+
.sa-tf-size-xs .sa-tf-label,
|
|
94
|
+
.sa-tf-size-xs .sa-tf-label-inside-text,
|
|
93
95
|
.sa-tf-size-sm .sa-tf-label,
|
|
94
96
|
.sa-tf-size-sm .sa-tf-label-inside-text {
|
|
95
97
|
font-size: 12px;
|
|
@@ -127,6 +129,9 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
127
129
|
.sa-tf-error {
|
|
128
130
|
color: var(--sa-input-text-error);
|
|
129
131
|
}
|
|
132
|
+
.sa-tf-size-xs .sa-tf-desc-top,
|
|
133
|
+
.sa-tf-size-xs .sa-tf-helper,
|
|
134
|
+
.sa-tf-size-xs .sa-tf-error,
|
|
130
135
|
.sa-tf-size-sm .sa-tf-desc-top,
|
|
131
136
|
.sa-tf-size-sm .sa-tf-helper,
|
|
132
137
|
.sa-tf-size-sm .sa-tf-error {
|
|
@@ -157,6 +162,12 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
/* sizes */
|
|
165
|
+
.sa-tf-size-xs .sa-tf-box {
|
|
166
|
+
min-height: 28px;
|
|
167
|
+
}
|
|
168
|
+
.sa-tf-size-xs .sa-tf-box-content {
|
|
169
|
+
padding-block: 4px;
|
|
170
|
+
}
|
|
160
171
|
.sa-tf-size-sm .sa-tf-box {
|
|
161
172
|
min-height: 32px;
|
|
162
173
|
}
|
|
@@ -357,6 +368,7 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
357
368
|
.sa-tf-addon-right {
|
|
358
369
|
border-left: 1px solid var(--sa-input-border-subtle);
|
|
359
370
|
}
|
|
371
|
+
.sa-tf-size-xs .sa-tf-addon,
|
|
360
372
|
.sa-tf-size-sm .sa-tf-addon {
|
|
361
373
|
font-size: 12px;
|
|
362
374
|
line-height: 18px;
|
|
@@ -383,6 +395,7 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
383
395
|
line-height: 21px;
|
|
384
396
|
color: var(--sa-input-text-primary);
|
|
385
397
|
}
|
|
398
|
+
.sa-tf-size-xs .sa-tf-input,
|
|
386
399
|
.sa-tf-size-sm .sa-tf-input {
|
|
387
400
|
font-size: 12px;
|
|
388
401
|
line-height: 18px;
|
|
@@ -436,6 +449,7 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
436
449
|
overflow: hidden;
|
|
437
450
|
text-overflow: ellipsis;
|
|
438
451
|
}
|
|
452
|
+
.sa-tf-size-xs .sa-tf-placeholder,
|
|
439
453
|
.sa-tf-size-sm .sa-tf-placeholder {
|
|
440
454
|
font-size: 12px;
|
|
441
455
|
line-height: 18px;
|
|
@@ -493,6 +507,7 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
493
507
|
.sa-tf-label-inside.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
|
|
494
508
|
transform: translateY(11px);
|
|
495
509
|
}
|
|
510
|
+
.sa-tf-label-inside.sa-tf-size-xs.sa-tf-floating .sa-tf-box-content > .sa-tf-icon,
|
|
496
511
|
.sa-tf-label-inside.sa-tf-size-sm.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
|
|
497
512
|
transform: translateY(9px);
|
|
498
513
|
}
|
|
@@ -521,6 +536,7 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
521
536
|
.sa-tf-label-inside .sa-tf-inside-label-row label {
|
|
522
537
|
pointer-events: auto;
|
|
523
538
|
}
|
|
539
|
+
.sa-tf-label-inside.sa-tf-size-xs .sa-tf-inside-label-row,
|
|
524
540
|
.sa-tf-label-inside.sa-tf-size-sm .sa-tf-inside-label-row {
|
|
525
541
|
font-size: 12px;
|
|
526
542
|
line-height: 18px;
|
|
@@ -593,47 +609,47 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
593
609
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
594
610
|
min-height: 80px;
|
|
595
611
|
}
|
|
596
|
-
`, z = (n) => n === "lg" || n === "xl" ? 18 : 16,
|
|
612
|
+
`, z = (n) => n === "lg" || n === "xl" ? 18 : n === "xs" ? 14 : 16, J = {
|
|
597
613
|
default: "var(--sa-color-gray-800, #505258)",
|
|
598
614
|
error: "var(--sa-text-error, #a4133c)",
|
|
599
615
|
success: "var(--sa-text-success, #208958)",
|
|
600
616
|
disable: "var(--sa-icon-disable, #181a198f)"
|
|
601
|
-
},
|
|
602
|
-
function
|
|
617
|
+
}, xn = (n, e) => e ? J.disable : J[n] ?? J.default;
|
|
618
|
+
function Fn(n) {
|
|
603
619
|
return Number(n.replace(/\./g, ""));
|
|
604
620
|
}
|
|
605
|
-
function
|
|
606
|
-
let
|
|
607
|
-
return
|
|
621
|
+
function Q(n) {
|
|
622
|
+
let e = n.replace(/[^\d]/g, "");
|
|
623
|
+
return e = e.replace(/^0+(?=\d)/, ""), e.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
608
624
|
}
|
|
609
|
-
function Dn(n,
|
|
610
|
-
if (
|
|
625
|
+
function Dn(n, e) {
|
|
626
|
+
if (e <= 0)
|
|
611
627
|
return 0;
|
|
612
628
|
let r = 0;
|
|
613
629
|
for (let l = 0; l < n.length; l++)
|
|
614
|
-
if (/\d/.test(n[l]) && (r += 1, r ===
|
|
630
|
+
if (/\d/.test(n[l]) && (r += 1, r === e))
|
|
615
631
|
return l + 1;
|
|
616
632
|
return n.length;
|
|
617
633
|
}
|
|
618
|
-
const
|
|
619
|
-
({ options: n, value:
|
|
620
|
-
const [h,
|
|
634
|
+
const Tn = mn(
|
|
635
|
+
({ options: n, value: e, setValue: r, isComponentVisible: l, onOptionChange: d }, f) => {
|
|
636
|
+
const [h, T] = I([]), c = R(null), u = () => {
|
|
621
637
|
if (f != null && f.current && c.current) {
|
|
622
|
-
const x = window.innerHeight, b = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(),
|
|
623
|
-
c.current.style.left = `${b.left}px`, c.current.style.width = `${b.width}px`,
|
|
638
|
+
const x = window.innerHeight, b = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(), v = b.bottom + m.height;
|
|
639
|
+
c.current.style.left = `${b.left}px`, c.current.style.width = `${b.width}px`, v >= x - 10 ? c.current.style.top = `${b.top - m.height - 5}px` : c.current.style.top = `${b.top + b.height}px`;
|
|
624
640
|
}
|
|
625
641
|
};
|
|
626
|
-
return
|
|
642
|
+
return D(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
|
|
627
643
|
window.removeEventListener("scroll", u), window.removeEventListener("resize", u);
|
|
628
|
-
}), [f, c]),
|
|
644
|
+
}), [f, c]), D(() => {
|
|
629
645
|
u();
|
|
630
|
-
}, [l]),
|
|
631
|
-
|
|
646
|
+
}, [l]), D(() => {
|
|
647
|
+
T(
|
|
632
648
|
(n == null ? void 0 : n.filter(
|
|
633
|
-
(x) => x.toLowerCase().startsWith(
|
|
649
|
+
(x) => x.toLowerCase().startsWith(e.toLowerCase())
|
|
634
650
|
)) || []
|
|
635
651
|
);
|
|
636
|
-
}, [
|
|
652
|
+
}, [e, n]), /* @__PURE__ */ a(
|
|
637
653
|
"div",
|
|
638
654
|
{
|
|
639
655
|
ref: c,
|
|
@@ -648,13 +664,13 @@ const Fn = xn(
|
|
|
648
664
|
zIndex: 5e4
|
|
649
665
|
},
|
|
650
666
|
children: h == null ? void 0 : h.map(
|
|
651
|
-
(x) =>
|
|
667
|
+
(x) => Vn(x, e, r, d)
|
|
652
668
|
)
|
|
653
669
|
}
|
|
654
670
|
);
|
|
655
671
|
}
|
|
656
|
-
),
|
|
657
|
-
const d = n.toLowerCase().indexOf(
|
|
672
|
+
), Vn = (n, e, r, l) => {
|
|
673
|
+
const d = n.toLowerCase().indexOf(e.toLowerCase());
|
|
658
674
|
return /* @__PURE__ */ o(
|
|
659
675
|
"p",
|
|
660
676
|
{
|
|
@@ -670,28 +686,28 @@ const Fn = xn(
|
|
|
670
686
|
},
|
|
671
687
|
children: [
|
|
672
688
|
n.slice(0, d),
|
|
673
|
-
/* @__PURE__ */
|
|
674
|
-
n.slice(d +
|
|
689
|
+
/* @__PURE__ */ a("span", { style: { color: "var(--sa-text-primary, #292a2e)" }, children: n.slice(d, d + e.length) }),
|
|
690
|
+
n.slice(d + e.length)
|
|
675
691
|
]
|
|
676
692
|
}
|
|
677
693
|
);
|
|
678
694
|
};
|
|
679
695
|
function On(n) {
|
|
680
|
-
const [
|
|
696
|
+
const [e, r] = I(n), l = R(null), d = (f) => {
|
|
681
697
|
l.current && !l.current.contains(f.target) && r(!1);
|
|
682
698
|
};
|
|
683
|
-
return
|
|
699
|
+
return D(() => (document.addEventListener("click", d, !0), () => {
|
|
684
700
|
document.removeEventListener("click", d, !0);
|
|
685
|
-
}), []), { ref: l, isComponentVisible:
|
|
701
|
+
}), []), { ref: l, isComponentVisible: e, setIsComponentVisible: r };
|
|
686
702
|
}
|
|
687
|
-
const
|
|
688
|
-
if (!(typeof document > "u") && !document.getElementById(
|
|
689
|
-
const
|
|
690
|
-
|
|
703
|
+
const gn = "sa-input-styles", jn = (n) => {
|
|
704
|
+
if (!(typeof document > "u") && !document.getElementById(gn)) {
|
|
705
|
+
const e = document.createElement("style");
|
|
706
|
+
e.id = gn, e.textContent = n, document.head.appendChild(e);
|
|
691
707
|
}
|
|
692
708
|
};
|
|
693
|
-
|
|
694
|
-
const
|
|
709
|
+
jn($n);
|
|
710
|
+
const Yn = (n) => /* @__PURE__ */ o(
|
|
695
711
|
"svg",
|
|
696
712
|
{
|
|
697
713
|
viewBox: "0 0 16 16",
|
|
@@ -699,8 +715,8 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
699
715
|
xmlns: "http://www.w3.org/2000/svg",
|
|
700
716
|
...n,
|
|
701
717
|
children: [
|
|
702
|
-
/* @__PURE__ */
|
|
703
|
-
/* @__PURE__ */
|
|
718
|
+
/* @__PURE__ */ a("circle", { cx: "8", cy: "8", r: "6.5", stroke: "currentColor", strokeWidth: "1.2" }),
|
|
719
|
+
/* @__PURE__ */ a(
|
|
704
720
|
"path",
|
|
705
721
|
{
|
|
706
722
|
d: "M5.2 8.2l1.8 1.8 3.8-4.2",
|
|
@@ -712,7 +728,7 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
712
728
|
)
|
|
713
729
|
]
|
|
714
730
|
}
|
|
715
|
-
),
|
|
731
|
+
), An = (n) => /* @__PURE__ */ o(
|
|
716
732
|
"svg",
|
|
717
733
|
{
|
|
718
734
|
viewBox: "0 0 16 16",
|
|
@@ -720,8 +736,8 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
720
736
|
xmlns: "http://www.w3.org/2000/svg",
|
|
721
737
|
...n,
|
|
722
738
|
children: [
|
|
723
|
-
/* @__PURE__ */
|
|
724
|
-
/* @__PURE__ */
|
|
739
|
+
/* @__PURE__ */ a("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
740
|
+
/* @__PURE__ */ a(
|
|
725
741
|
"path",
|
|
726
742
|
{
|
|
727
743
|
d: "M5.5 5.5l5 5M10.5 5.5l-5 5",
|
|
@@ -732,51 +748,51 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
732
748
|
)
|
|
733
749
|
]
|
|
734
750
|
}
|
|
735
|
-
),
|
|
736
|
-
(n,
|
|
751
|
+
), Wn = mn(
|
|
752
|
+
(n, e) => {
|
|
737
753
|
const {
|
|
738
|
-
size: r = "
|
|
754
|
+
size: r = "sm",
|
|
739
755
|
variant: l = "outline",
|
|
740
756
|
status: d = "default",
|
|
741
757
|
label: f,
|
|
742
758
|
labelPosition: h = "outside-top",
|
|
743
|
-
required:
|
|
759
|
+
required: T,
|
|
744
760
|
optional: c,
|
|
745
761
|
description: u,
|
|
746
762
|
helperText: x,
|
|
747
763
|
errorText: b,
|
|
748
764
|
leftIcon: m,
|
|
749
|
-
rightIcon:
|
|
765
|
+
rightIcon: v,
|
|
750
766
|
leftAddons: B,
|
|
751
|
-
rightAddons:
|
|
752
|
-
onClickLeftIcon:
|
|
753
|
-
onClickRightIcon:
|
|
754
|
-
fullWidth:
|
|
755
|
-
highlightPlaceholder:
|
|
767
|
+
rightAddons: L,
|
|
768
|
+
onClickLeftIcon: nn,
|
|
769
|
+
onClickRightIcon: V,
|
|
770
|
+
fullWidth: vn = !0,
|
|
771
|
+
highlightPlaceholder: O,
|
|
756
772
|
currency: S,
|
|
757
773
|
options: E,
|
|
758
774
|
onOptionChange: j,
|
|
759
|
-
clearable:
|
|
775
|
+
clearable: wn = !0,
|
|
760
776
|
onClear: Y,
|
|
761
|
-
...
|
|
762
|
-
} = n, A =
|
|
763
|
-
const t =
|
|
764
|
-
return S ?
|
|
765
|
-
}), [
|
|
766
|
-
|
|
767
|
-
const an =
|
|
768
|
-
|
|
777
|
+
...s
|
|
778
|
+
} = n, A = s.value !== void 0, [W, y] = I(() => {
|
|
779
|
+
const t = s.value !== void 0 ? String(s.value ?? "") : String(s.defaultValue ?? "");
|
|
780
|
+
return S ? Q(t) : t;
|
|
781
|
+
}), [tn, en] = I(!1), [yn, sn] = I(""), k = R(null), C = R(null);
|
|
782
|
+
En(e, () => C.current);
|
|
783
|
+
const an = R(
|
|
784
|
+
s.id ?? `sa-input-${Math.random().toString(36).slice(2, 9)}`
|
|
769
785
|
), {
|
|
770
|
-
isComponentVisible:
|
|
771
|
-
ref:
|
|
772
|
-
setIsComponentVisible:
|
|
786
|
+
isComponentVisible: rn,
|
|
787
|
+
ref: _,
|
|
788
|
+
setIsComponentVisible: kn
|
|
773
789
|
} = On(!1);
|
|
774
|
-
|
|
790
|
+
pn(() => {
|
|
775
791
|
if (!A)
|
|
776
792
|
return;
|
|
777
|
-
const t =
|
|
793
|
+
const t = s.value === void 0 || s.value === null ? "" : String(s.value), i = S ? Q(t) : t;
|
|
778
794
|
y((p) => p === i ? p : i);
|
|
779
|
-
}, [
|
|
795
|
+
}, [s.value, S, A]), pn(() => {
|
|
780
796
|
if (k.current === null)
|
|
781
797
|
return;
|
|
782
798
|
const t = C.current, i = k.current;
|
|
@@ -786,208 +802,264 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
786
802
|
} catch {
|
|
787
803
|
}
|
|
788
804
|
}, [W]);
|
|
789
|
-
const N = W,
|
|
805
|
+
const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || s.disabled, M = w ? "disable" : d, P = h === "inside", zn = P && ($ || tn), H = [
|
|
790
806
|
"sa-tf",
|
|
791
807
|
`sa-tf-variant-${l}`,
|
|
792
808
|
`sa-tf-size-${r}`,
|
|
793
|
-
`sa-tf-status-${
|
|
809
|
+
`sa-tf-status-${M}`,
|
|
794
810
|
`sa-tf-label-${h}`,
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
811
|
+
tn ? "sa-tf-focused" : "",
|
|
812
|
+
w ? "sa-tf-disabled" : "",
|
|
813
|
+
zn ? "sa-tf-floating" : "",
|
|
798
814
|
f ? "" : "sa-tf-no-label",
|
|
799
|
-
|
|
800
|
-
].filter(Boolean).join(" "),
|
|
815
|
+
vn ? "sa-tf-fullwidth" : ""
|
|
816
|
+
].filter(Boolean).join(" "), Cn = () => {
|
|
801
817
|
var t;
|
|
802
818
|
return (t = C.current) == null ? void 0 : t.focus();
|
|
803
|
-
},
|
|
804
|
-
var
|
|
819
|
+
}, Nn = (t) => {
|
|
820
|
+
var un, bn;
|
|
805
821
|
if (!S) {
|
|
806
|
-
const
|
|
807
|
-
|
|
822
|
+
const F = t.target.selectionStart;
|
|
823
|
+
F !== null && (k.current = F), y(t.target.value), (un = s.onChange) == null || un.call(s, t);
|
|
808
824
|
return;
|
|
809
825
|
}
|
|
810
826
|
const i = t.target.value;
|
|
811
827
|
let p = i, g = t.target.selectionStart ?? i.length;
|
|
812
|
-
if (
|
|
813
|
-
const
|
|
814
|
-
|
|
828
|
+
if (yn === "Backspace") {
|
|
829
|
+
const F = W.replace(/\D/g, ""), Ln = i.replace(/\D/g, "");
|
|
830
|
+
F.length === Ln.length && g > 0 && (p = i.slice(0, g - 1) + i.slice(g), g -= 1);
|
|
815
831
|
}
|
|
816
|
-
const
|
|
817
|
-
k.current =
|
|
832
|
+
const G = Q(p), Rn = p.slice(0, g).replace(/\D/g, "").length, Bn = Dn(G, Rn);
|
|
833
|
+
k.current = Bn, y(G), (bn = s.onChange) == null || bn.call(s, {
|
|
818
834
|
...t,
|
|
819
835
|
target: {
|
|
820
836
|
...t.target,
|
|
821
|
-
value: String(
|
|
837
|
+
value: String(Fn(G)),
|
|
822
838
|
name: t.target.name
|
|
823
839
|
}
|
|
824
|
-
}),
|
|
825
|
-
},
|
|
826
|
-
/* @__PURE__ */
|
|
840
|
+
}), sn("");
|
|
841
|
+
}, q = (t) => f ? /* @__PURE__ */ o("div", { className: t, children: [
|
|
842
|
+
/* @__PURE__ */ a(
|
|
827
843
|
"label",
|
|
828
844
|
{
|
|
829
845
|
htmlFor: an.current,
|
|
830
|
-
style: { cursor:
|
|
846
|
+
style: { cursor: w ? "not-allowed" : "pointer" },
|
|
831
847
|
children: f
|
|
832
848
|
}
|
|
833
849
|
),
|
|
834
|
-
c ? /* @__PURE__ */
|
|
835
|
-
|
|
836
|
-
] }) : null,
|
|
837
|
-
x ? /* @__PURE__ */
|
|
838
|
-
b && d === "error" ? /* @__PURE__ */
|
|
839
|
-
] }),
|
|
850
|
+
c ? /* @__PURE__ */ a("span", { className: "sa-tf-optional", children: "Optional" }) : null,
|
|
851
|
+
T ? /* @__PURE__ */ a("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
|
|
852
|
+
] }) : null, K = /* @__PURE__ */ o(Sn, { children: [
|
|
853
|
+
x ? /* @__PURE__ */ a("p", { className: "sa-tf-helper", children: x }) : null,
|
|
854
|
+
b && d === "error" ? /* @__PURE__ */ a("p", { className: "sa-tf-error", children: b }) : null
|
|
855
|
+
] }), U = (t, i) => /* @__PURE__ */ a(
|
|
840
856
|
"span",
|
|
841
857
|
{
|
|
842
858
|
className: `sa-tf-icon${i ? " sa-tf-icon-clickable" : ""}`,
|
|
843
859
|
onClick: i,
|
|
844
|
-
children:
|
|
860
|
+
children: Z.cloneElement(t, {
|
|
845
861
|
width: z(r),
|
|
846
862
|
height: z(r),
|
|
847
|
-
color:
|
|
848
|
-
style: { color:
|
|
863
|
+
color: xn(M, w),
|
|
864
|
+
style: { color: xn(M, w) }
|
|
849
865
|
})
|
|
850
866
|
}
|
|
851
|
-
),
|
|
852
|
-
|
|
867
|
+
), on = () => {
|
|
868
|
+
var i;
|
|
869
|
+
return v == null ? null : !Z.isValidElement(v) || ((i = v.type) == null ? void 0 : i.__saRaw) === !0 ? /* @__PURE__ */ a(
|
|
870
|
+
"span",
|
|
871
|
+
{
|
|
872
|
+
className: `sa-tf-icon${V ? " sa-tf-icon-clickable" : ""}`,
|
|
873
|
+
onClick: V,
|
|
874
|
+
children: v
|
|
875
|
+
}
|
|
876
|
+
) : U(v, V);
|
|
877
|
+
}, ln = d === "success" ? /* @__PURE__ */ a("span", { className: "sa-tf-icon sa-tf-success-mark", "aria-hidden": "true", children: /* @__PURE__ */ a(
|
|
878
|
+
Yn,
|
|
853
879
|
{
|
|
854
880
|
width: z(r),
|
|
855
881
|
height: z(r)
|
|
856
882
|
}
|
|
857
|
-
) }) : null,
|
|
883
|
+
) }) : null, dn = wn && !w ? /* @__PURE__ */ a(
|
|
858
884
|
"button",
|
|
859
885
|
{
|
|
860
886
|
type: "button",
|
|
861
|
-
className: `sa-tf-icon sa-tf-clear${
|
|
887
|
+
className: `sa-tf-icon sa-tf-clear${$ ? "" : " sa-tf-clear-hidden"}`,
|
|
862
888
|
"aria-label": "Clear input",
|
|
863
|
-
"aria-hidden":
|
|
889
|
+
"aria-hidden": !$,
|
|
864
890
|
tabIndex: -1,
|
|
865
891
|
onClick: (t) => {
|
|
866
892
|
var p;
|
|
867
893
|
t.stopPropagation(), A || y("");
|
|
868
894
|
const i = {
|
|
869
|
-
target: { value: "", name:
|
|
870
|
-
currentTarget: { value: "", name:
|
|
895
|
+
target: { value: "", name: s.name },
|
|
896
|
+
currentTarget: { value: "", name: s.name }
|
|
871
897
|
};
|
|
872
|
-
(p =
|
|
898
|
+
(p = s.onChange) == null || p.call(s, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
|
|
873
899
|
var g;
|
|
874
900
|
return (g = C.current) == null ? void 0 : g.focus();
|
|
875
901
|
});
|
|
876
902
|
},
|
|
877
903
|
onMouseDown: (t) => t.preventDefault(),
|
|
878
|
-
children: /* @__PURE__ */
|
|
879
|
-
|
|
904
|
+
children: /* @__PURE__ */ a(
|
|
905
|
+
An,
|
|
880
906
|
{
|
|
881
907
|
width: z(r),
|
|
882
908
|
height: z(r)
|
|
883
909
|
}
|
|
884
910
|
)
|
|
885
911
|
}
|
|
886
|
-
) : null,
|
|
887
|
-
/* @__PURE__ */
|
|
912
|
+
) : null, In = !$ && !!s.placeholder && !!O, fn = /* @__PURE__ */ o("div", { className: "sa-tf-field-wrap", children: [
|
|
913
|
+
/* @__PURE__ */ a(
|
|
888
914
|
"input",
|
|
889
915
|
{
|
|
890
|
-
...
|
|
916
|
+
...s,
|
|
891
917
|
id: an.current,
|
|
892
918
|
ref: C,
|
|
893
919
|
className: "sa-tf-input",
|
|
894
|
-
disabled:
|
|
895
|
-
placeholder:
|
|
920
|
+
disabled: w,
|
|
921
|
+
placeholder: O ? "" : s.placeholder,
|
|
896
922
|
value: N,
|
|
897
923
|
onFocus: (t) => {
|
|
898
924
|
var i;
|
|
899
|
-
|
|
925
|
+
en(!0), kn(!0), (i = s.onFocus) == null || i.call(s, t);
|
|
900
926
|
},
|
|
901
927
|
onBlur: (t) => {
|
|
902
928
|
var i;
|
|
903
|
-
|
|
929
|
+
en(!1), (i = s.onBlur) == null || i.call(s, t);
|
|
904
930
|
},
|
|
905
931
|
onKeyDown: (t) => {
|
|
906
932
|
var i;
|
|
907
|
-
t.key === "Backspace" &&
|
|
933
|
+
t.key === "Backspace" && sn(t.key), (i = s.onKeyDown) == null || i.call(s, t);
|
|
908
934
|
},
|
|
909
|
-
onChange:
|
|
935
|
+
onChange: Nn
|
|
910
936
|
}
|
|
911
937
|
),
|
|
912
|
-
|
|
913
|
-
] }),
|
|
914
|
-
|
|
938
|
+
In ? _n(s.placeholder, O) : null
|
|
939
|
+
] }), cn = N && rn && (E != null && E.length) ? /* @__PURE__ */ a(
|
|
940
|
+
Tn,
|
|
915
941
|
{
|
|
916
942
|
options: E,
|
|
917
943
|
value: N,
|
|
918
944
|
setValue: y,
|
|
919
|
-
ref:
|
|
920
|
-
isComponentVisible:
|
|
945
|
+
ref: _,
|
|
946
|
+
isComponentVisible: rn,
|
|
921
947
|
onOptionChange: (t) => {
|
|
922
948
|
j == null || j(t), y(t);
|
|
923
949
|
}
|
|
924
950
|
}
|
|
925
|
-
) : null,
|
|
951
|
+
) : null, X = P ? /* @__PURE__ */ o(
|
|
926
952
|
"div",
|
|
927
953
|
{
|
|
928
954
|
className: "sa-tf-box",
|
|
929
|
-
ref:
|
|
930
|
-
onClick:
|
|
955
|
+
ref: _,
|
|
956
|
+
onClick: Cn,
|
|
931
957
|
children: [
|
|
932
|
-
B ? /* @__PURE__ */
|
|
958
|
+
B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
|
|
933
959
|
/* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
|
|
934
|
-
m ?
|
|
960
|
+
m ? U(m, nn) : null,
|
|
935
961
|
/* @__PURE__ */ o("div", { className: "sa-tf-inside-stack", children: [
|
|
936
|
-
|
|
937
|
-
/* @__PURE__ */
|
|
962
|
+
q("sa-tf-inside-label-row"),
|
|
963
|
+
/* @__PURE__ */ a("div", { className: "sa-tf-inside-row", children: fn })
|
|
938
964
|
] }),
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
965
|
+
dn,
|
|
966
|
+
ln,
|
|
967
|
+
on()
|
|
942
968
|
] }),
|
|
943
|
-
|
|
944
|
-
|
|
969
|
+
L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
|
|
970
|
+
cn
|
|
945
971
|
]
|
|
946
972
|
}
|
|
947
|
-
) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref:
|
|
948
|
-
B ? /* @__PURE__ */
|
|
973
|
+
) : /* @__PURE__ */ o("div", { className: "sa-tf-box", ref: _, children: [
|
|
974
|
+
B ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-left", children: B }) : null,
|
|
949
975
|
/* @__PURE__ */ o("div", { className: "sa-tf-box-content", children: [
|
|
950
|
-
m ?
|
|
976
|
+
m ? U(m, nn) : null,
|
|
977
|
+
fn,
|
|
978
|
+
dn,
|
|
951
979
|
ln,
|
|
952
|
-
on
|
|
953
|
-
rn,
|
|
954
|
-
w ? F(w, Z) : null
|
|
980
|
+
on()
|
|
955
981
|
] }),
|
|
956
|
-
|
|
957
|
-
|
|
982
|
+
L ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: L }) : null,
|
|
983
|
+
cn
|
|
958
984
|
] });
|
|
959
|
-
return h === "outside-left" ? /* @__PURE__ */ o("div", { className:
|
|
985
|
+
return h === "outside-left" ? /* @__PURE__ */ o("div", { className: H, children: [
|
|
960
986
|
/* @__PURE__ */ o("div", { className: "sa-tf-label-col", children: [
|
|
961
|
-
|
|
962
|
-
u ? /* @__PURE__ */
|
|
987
|
+
q("sa-tf-label"),
|
|
988
|
+
u ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: u }) : null
|
|
963
989
|
] }),
|
|
964
990
|
/* @__PURE__ */ o("div", { className: "sa-tf-input-col", children: [
|
|
965
|
-
|
|
966
|
-
|
|
991
|
+
X,
|
|
992
|
+
K
|
|
967
993
|
] })
|
|
968
|
-
] }) :
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
] }) : /* @__PURE__ */ o("div", { className:
|
|
972
|
-
|
|
973
|
-
u ? /* @__PURE__ */
|
|
974
|
-
|
|
975
|
-
|
|
994
|
+
] }) : P ? /* @__PURE__ */ o("div", { className: H, children: [
|
|
995
|
+
X,
|
|
996
|
+
K
|
|
997
|
+
] }) : /* @__PURE__ */ o("div", { className: H, children: [
|
|
998
|
+
q("sa-tf-label"),
|
|
999
|
+
u ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: u }) : null,
|
|
1000
|
+
X,
|
|
1001
|
+
K
|
|
976
1002
|
] });
|
|
977
1003
|
}
|
|
978
|
-
),
|
|
1004
|
+
), _n = (n, e) => {
|
|
979
1005
|
if (!n)
|
|
980
1006
|
return null;
|
|
981
|
-
if (!
|
|
982
|
-
return /* @__PURE__ */
|
|
983
|
-
const r = n.toLowerCase().indexOf(
|
|
984
|
-
return r === -1 ? /* @__PURE__ */
|
|
1007
|
+
if (!e)
|
|
1008
|
+
return /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n });
|
|
1009
|
+
const r = n.toLowerCase().indexOf(e.toLowerCase());
|
|
1010
|
+
return r === -1 ? /* @__PURE__ */ a("p", { className: "sa-tf-placeholder", children: n }) : /* @__PURE__ */ o("p", { className: "sa-tf-placeholder", children: [
|
|
985
1011
|
n.slice(0, r),
|
|
986
|
-
/* @__PURE__ */
|
|
987
|
-
n.slice(r +
|
|
1012
|
+
/* @__PURE__ */ a("span", { className: "sa-tf-placeholder-highlight", children: n.slice(r, r + e.length) }),
|
|
1013
|
+
n.slice(r + e.length)
|
|
988
1014
|
] });
|
|
989
1015
|
};
|
|
990
|
-
|
|
1016
|
+
Wn.displayName = "Input";
|
|
1017
|
+
const Mn = `.sa-kbd {
|
|
1018
|
+
display: inline-flex;
|
|
1019
|
+
align-items: center;
|
|
1020
|
+
gap: var(--sa-spacing-4, 4px);
|
|
1021
|
+
vertical-align: middle;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
.sa-kbd-key {
|
|
1025
|
+
display: inline-flex;
|
|
1026
|
+
align-items: center;
|
|
1027
|
+
justify-content: center;
|
|
1028
|
+
min-width: 1.5em;
|
|
1029
|
+
padding: 0 var(--sa-spacing-6, 6px);
|
|
1030
|
+
background-color: var(--sa-background-neutral, #f0f1f2);
|
|
1031
|
+
border: 1px solid var(--sa-border-subtle, #0b120e24);
|
|
1032
|
+
border-radius: var(--sa-radii-xs, 4px);
|
|
1033
|
+
color: var(--sa-text-subtle, #505258);
|
|
1034
|
+
font-family: inherit;
|
|
1035
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
1036
|
+
font-weight: var(--sa-font-weight-medium, 400);
|
|
1037
|
+
line-height: 1.6;
|
|
1038
|
+
white-space: nowrap;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
.sa-kbd-sep {
|
|
1042
|
+
display: inline-flex;
|
|
1043
|
+
align-items: center;
|
|
1044
|
+
color: var(--sa-text-subtlest, #6b6e76);
|
|
1045
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
1046
|
+
user-select: none;
|
|
1047
|
+
}
|
|
1048
|
+
`, hn = "sa-kbd-styles", Pn = (n) => {
|
|
1049
|
+
if (!(typeof document > "u") && !document.getElementById(hn)) {
|
|
1050
|
+
const e = document.createElement("style");
|
|
1051
|
+
e.id = hn, e.textContent = n, document.head.appendChild(e);
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
Pn(Mn);
|
|
1055
|
+
function Hn({ keys: n, separator: e, className: r, ...l }) {
|
|
1056
|
+
return /* @__PURE__ */ a("span", { className: `sa-kbd${r ? ` ${r}` : ""}`, ...l, children: n.map((d, f) => /* @__PURE__ */ o(Z.Fragment, { children: [
|
|
1057
|
+
f > 0 && e != null ? /* @__PURE__ */ a("span", { className: "sa-kbd-sep", "aria-hidden": "true", children: e }) : null,
|
|
1058
|
+
/* @__PURE__ */ a("kbd", { className: "sa-kbd-key", children: d })
|
|
1059
|
+
] }, f)) });
|
|
1060
|
+
}
|
|
1061
|
+
Hn.__saRaw = !0;
|
|
991
1062
|
export {
|
|
992
|
-
|
|
1063
|
+
Wn as Input,
|
|
1064
|
+
Hn as Kbd
|
|
993
1065
|
};
|
package/dist/input.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(b,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(b=typeof globalThis<"u"?globalThis:b||self,n(b.Input={},b.jsxRuntime,b.React))})(this,function(b,n,o){"use strict";const hn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
2
2
|
|
|
3
3
|
:root {
|
|
4
4
|
/* Layer 3 — references Layer 2 semantic tokens */
|
|
@@ -88,6 +88,8 @@
|
|
|
88
88
|
line-height: normal;
|
|
89
89
|
margin: 0;
|
|
90
90
|
}
|
|
91
|
+
.sa-tf-size-xs .sa-tf-label,
|
|
92
|
+
.sa-tf-size-xs .sa-tf-label-inside-text,
|
|
91
93
|
.sa-tf-size-sm .sa-tf-label,
|
|
92
94
|
.sa-tf-size-sm .sa-tf-label-inside-text {
|
|
93
95
|
font-size: 12px;
|
|
@@ -125,6 +127,9 @@
|
|
|
125
127
|
.sa-tf-error {
|
|
126
128
|
color: var(--sa-input-text-error);
|
|
127
129
|
}
|
|
130
|
+
.sa-tf-size-xs .sa-tf-desc-top,
|
|
131
|
+
.sa-tf-size-xs .sa-tf-helper,
|
|
132
|
+
.sa-tf-size-xs .sa-tf-error,
|
|
128
133
|
.sa-tf-size-sm .sa-tf-desc-top,
|
|
129
134
|
.sa-tf-size-sm .sa-tf-helper,
|
|
130
135
|
.sa-tf-size-sm .sa-tf-error {
|
|
@@ -155,6 +160,12 @@
|
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
/* sizes */
|
|
163
|
+
.sa-tf-size-xs .sa-tf-box {
|
|
164
|
+
min-height: 28px;
|
|
165
|
+
}
|
|
166
|
+
.sa-tf-size-xs .sa-tf-box-content {
|
|
167
|
+
padding-block: 4px;
|
|
168
|
+
}
|
|
158
169
|
.sa-tf-size-sm .sa-tf-box {
|
|
159
170
|
min-height: 32px;
|
|
160
171
|
}
|
|
@@ -355,6 +366,7 @@
|
|
|
355
366
|
.sa-tf-addon-right {
|
|
356
367
|
border-left: 1px solid var(--sa-input-border-subtle);
|
|
357
368
|
}
|
|
369
|
+
.sa-tf-size-xs .sa-tf-addon,
|
|
358
370
|
.sa-tf-size-sm .sa-tf-addon {
|
|
359
371
|
font-size: 12px;
|
|
360
372
|
line-height: 18px;
|
|
@@ -381,6 +393,7 @@
|
|
|
381
393
|
line-height: 21px;
|
|
382
394
|
color: var(--sa-input-text-primary);
|
|
383
395
|
}
|
|
396
|
+
.sa-tf-size-xs .sa-tf-input,
|
|
384
397
|
.sa-tf-size-sm .sa-tf-input {
|
|
385
398
|
font-size: 12px;
|
|
386
399
|
line-height: 18px;
|
|
@@ -434,6 +447,7 @@
|
|
|
434
447
|
overflow: hidden;
|
|
435
448
|
text-overflow: ellipsis;
|
|
436
449
|
}
|
|
450
|
+
.sa-tf-size-xs .sa-tf-placeholder,
|
|
437
451
|
.sa-tf-size-sm .sa-tf-placeholder {
|
|
438
452
|
font-size: 12px;
|
|
439
453
|
line-height: 18px;
|
|
@@ -491,6 +505,7 @@
|
|
|
491
505
|
.sa-tf-label-inside.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
|
|
492
506
|
transform: translateY(11px);
|
|
493
507
|
}
|
|
508
|
+
.sa-tf-label-inside.sa-tf-size-xs.sa-tf-floating .sa-tf-box-content > .sa-tf-icon,
|
|
494
509
|
.sa-tf-label-inside.sa-tf-size-sm.sa-tf-floating .sa-tf-box-content > .sa-tf-icon {
|
|
495
510
|
transform: translateY(9px);
|
|
496
511
|
}
|
|
@@ -519,6 +534,7 @@
|
|
|
519
534
|
.sa-tf-label-inside .sa-tf-inside-label-row label {
|
|
520
535
|
pointer-events: auto;
|
|
521
536
|
}
|
|
537
|
+
.sa-tf-label-inside.sa-tf-size-xs .sa-tf-inside-label-row,
|
|
522
538
|
.sa-tf-label-inside.sa-tf-size-sm .sa-tf-inside-label-row {
|
|
523
539
|
font-size: 12px;
|
|
524
540
|
line-height: 18px;
|
|
@@ -591,4 +607,35 @@
|
|
|
591
607
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
592
608
|
min-height: 80px;
|
|
593
609
|
}
|
|
594
|
-
`,
|
|
610
|
+
`,k=t=>t==="lg"||t==="xl"?18:t==="xs"?14:16,F={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"var(--sa-icon-disable, #181a198f)"},Q=(t,e)=>e?F.disable:F[t]??F.default;function gn(t){return Number(t.replace(/\./g,""))}function T(t){let e=t.replace(/[^\d]/g,"");return e=e.replace(/^0+(?=\d)/,""),e.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function vn(t,e){if(e<=0)return 0;let i=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(i+=1,i===e))return l+1;return t.length}const mn=o.forwardRef(({options:t,value:e,setValue:i,isComponentVisible:l,onOptionChange:d},f)=>{const[v,D]=o.useState([]),c=o.useRef(null),u=()=>{if(f!=null&&f.current&&c.current){const h=window.innerHeight,p=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),w=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,w>=h-10?c.current.style.top=`${p.top-m.height-5}px`:c.current.style.top=`${p.top+p.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",u),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u),window.removeEventListener("resize",u)}),[f,c]),o.useEffect(()=>{u()},[l]),o.useEffect(()=>{D((t==null?void 0:t.filter(h=>h.toLowerCase().startsWith(e.toLowerCase())))||[])},[e,t]),n.jsx("div",{ref:c,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",borderRadius:"8px",background:"white",overflow:"auto",zIndex:5e4},children:v==null?void 0:v.map(h=>wn(h,e,i,d))})}),wn=(t,e,i,l)=>{const d=t.toLowerCase().indexOf(e.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{i(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+e.length)}),t.slice(d+e.length)]})};function yn(t){const[e,i]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&i(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:i}}const Z="sa-input-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(Z)){const e=document.createElement("style");e.id=Z,e.textContent=t,document.head.appendChild(e)}})(hn);const kn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.5",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.2 8.2l1.8 1.8 3.8-4.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),zn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),R=o.forwardRef((t,e)=>{const{size:i="sm",variant:l="outline",status:d="default",label:f,labelPosition:v="outside-top",required:D,optional:c,description:u,helperText:h,errorText:p,leftIcon:m,rightIcon:w,leftAddons:S,rightAddons:E,onClickLeftIcon:sn,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:L,options:B,onOptionChange:Y,clearable:Sn=!0,onClear:A,...a}=t,M=a.value!==void 0,[P,z]=o.useState(()=>{const s=a.value!==void 0?String(a.value??""):String(a.defaultValue??"");return L?T(s):s}),[en,an]=o.useState(!1),[En,rn]=o.useState(""),C=o.useRef(null),N=o.useRef(null);o.useImperativeHandle(e,()=>N.current);const on=o.useRef(a.id??`sa-input-${Math.random().toString(36).slice(2,9)}`),{isComponentVisible:ln,ref:W,setIsComponentVisible:Ln}=yn(!1);o.useLayoutEffect(()=>{if(!M)return;const s=a.value===void 0||a.value===null?"":String(a.value),r=L?T(s):s;z(x=>x===r?x:r)},[a.value,L,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const s=N.current,r=C.current;if(C.current=null,!!s)try{s.setSelectionRange(r,r)}catch{}},[P]);const I=P,$=I!==""&&I!==void 0,y=d==="disable"||a.disabled,_=y?"disable":d,q=v==="inside",Bn=q&&($||en),H=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${i}`,`sa-tf-status-${_}`,`sa-tf-label-${v}`,en?"sa-tf-focused":"",y?"sa-tf-disabled":"",Bn?"sa-tf-floating":"",f?"":"sa-tf-no-label",In?"sa-tf-fullwidth":""].filter(Boolean).join(" "),$n=()=>{var s;return(s=N.current)==null?void 0:s.focus()},jn=s=>{var pn,xn;if(!L){const j=s.target.selectionStart;j!==null&&(C.current=j),z(s.target.value),(pn=a.onChange)==null||pn.call(a,s);return}const r=s.target.value;let x=r,g=s.target.selectionStart??r.length;if(En==="Backspace"){const j=P.replace(/\D/g,""),Vn=r.replace(/\D/g,"");j.length===Vn.length&&g>0&&(x=r.slice(0,g-1)+r.slice(g),g-=1)}const J=T(x),Dn=x.slice(0,g).replace(/\D/g,"").length,On=vn(J,Dn);C.current=On,z(J),(xn=a.onChange)==null||xn.call(a,{...s,target:{...s.target,value:String(gn(J)),name:s.target.name}}),rn("")},K=s=>f?n.jsxs("div",{className:s,children:[n.jsx("label",{htmlFor:on.current,style:{cursor:y?"not-allowed":"pointer"},children:f}),c?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,D?n.jsx("span",{className:"sa-tf-required","aria-hidden":"true",children:"*"}):null]}):null,U=n.jsxs(n.Fragment,{children:[h?n.jsx("p",{className:"sa-tf-helper",children:h}):null,p&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:p}):null]}),X=(s,r)=>n.jsx("span",{className:`sa-tf-icon${r?" sa-tf-icon-clickable":""}`,onClick:r,children:o.cloneElement(s,{width:k(i),height:k(i),color:Q(_,y),style:{color:Q(_,y)}})}),dn=()=>{var r;return w==null?null:!o.isValidElement(w)||((r=w.type)==null?void 0:r.__saRaw)===!0?n.jsx("span",{className:`sa-tf-icon${O?" sa-tf-icon-clickable":""}`,onClick:O,children:w}):X(w,O)},fn=d==="success"?n.jsx("span",{className:"sa-tf-icon sa-tf-success-mark","aria-hidden":"true",children:n.jsx(kn,{width:k(i),height:k(i)})}):null,Fn=s=>{var x;s.stopPropagation(),M||z("");const r={target:{value:"",name:a.name},currentTarget:{value:"",name:a.name}};(x=a.onChange)==null||x.call(a,r),A==null||A(),C.current=0,requestAnimationFrame(()=>{var g;return(g=N.current)==null?void 0:g.focus()})},cn=Sn&&!y?n.jsx("button",{type:"button",className:`sa-tf-icon sa-tf-clear${$?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!$,tabIndex:-1,onClick:Fn,onMouseDown:s=>s.preventDefault(),children:n.jsx(zn,{width:k(i),height:k(i)})}):null,Tn=!$&&!!a.placeholder&&!!V,un=n.jsxs("div",{className:"sa-tf-field-wrap",children:[n.jsx("input",{...a,id:on.current,ref:N,className:"sa-tf-input",disabled:y,placeholder:V?"":a.placeholder,value:I,onFocus:s=>{var r;an(!0),Ln(!0),(r=a.onFocus)==null||r.call(a,s)},onBlur:s=>{var r;an(!1),(r=a.onBlur)==null||r.call(a,s)},onKeyDown:s=>{var r;s.key==="Backspace"&&rn(s.key),(r=a.onKeyDown)==null||r.call(a,s)},onChange:jn}),Tn?Cn(a.placeholder,V):null]}),bn=I&&ln&&(B!=null&&B.length)?n.jsx(mn,{options:B,value:I,setValue:z,ref:W,isComponentVisible:ln,onOptionChange:s=>{Y==null||Y(s),z(s)}}):null,G=q?n.jsxs("div",{className:"sa-tf-box",ref:W,onClick:$n,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,sn):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[K("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:un})]}),cn,fn,dn()]}),E?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:E}):null,bn]}):n.jsxs("div",{className:"sa-tf-box",ref:W,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,sn):null,un,cn,fn,dn()]}),E?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:E}):null,bn]});return v==="outside-left"?n.jsxs("div",{className:H,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[K("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[G,U]})]}):q?n.jsxs("div",{className:H,children:[G,U]}):n.jsxs("div",{className:H,children:[K("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null,G,U]})}),Cn=(t,e)=>{if(!t)return null;if(!e)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const i=t.toLowerCase().indexOf(e.toLowerCase());return i===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,i),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(i,i+e.length)}),t.slice(i+e.length)]})};R.displayName="Input";const Nn=`.sa-kbd {
|
|
611
|
+
display: inline-flex;
|
|
612
|
+
align-items: center;
|
|
613
|
+
gap: var(--sa-spacing-4, 4px);
|
|
614
|
+
vertical-align: middle;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
.sa-kbd-key {
|
|
618
|
+
display: inline-flex;
|
|
619
|
+
align-items: center;
|
|
620
|
+
justify-content: center;
|
|
621
|
+
min-width: 1.5em;
|
|
622
|
+
padding: 0 var(--sa-spacing-6, 6px);
|
|
623
|
+
background-color: var(--sa-background-neutral, #f0f1f2);
|
|
624
|
+
border: 1px solid var(--sa-border-subtle, #0b120e24);
|
|
625
|
+
border-radius: var(--sa-radii-xs, 4px);
|
|
626
|
+
color: var(--sa-text-subtle, #505258);
|
|
627
|
+
font-family: inherit;
|
|
628
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
629
|
+
font-weight: var(--sa-font-weight-medium, 400);
|
|
630
|
+
line-height: 1.6;
|
|
631
|
+
white-space: nowrap;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
.sa-kbd-sep {
|
|
635
|
+
display: inline-flex;
|
|
636
|
+
align-items: center;
|
|
637
|
+
color: var(--sa-text-subtlest, #6b6e76);
|
|
638
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
639
|
+
user-select: none;
|
|
640
|
+
}
|
|
641
|
+
`,nn="sa-kbd-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(nn)){const e=document.createElement("style");e.id=nn,e.textContent=t,document.head.appendChild(e)}})(Nn);function tn({keys:t,separator:e,className:i,...l}){return n.jsx("span",{className:`sa-kbd${i?` ${i}`:""}`,...l,children:t.map((d,f)=>n.jsxs(o.Fragment,{children:[f>0&&e!=null?n.jsx("span",{className:"sa-kbd-sep","aria-hidden":"true",children:e}):null,n.jsx("kbd",{className:"sa-kbd-key",children:d})]},f))})}tn.__saRaw=!0,b.Input=R,b.Kbd=tn,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from "react";
|
|
2
2
|
export interface IconInputProps extends React.SVGProps<SVGSVGElement> {
|
|
3
3
|
}
|
|
4
|
-
export type InputSize = "sm" | "md" | "lg" | "xl";
|
|
4
|
+
export type InputSize = "xs" | "sm" | "md" | "lg" | "xl";
|
|
5
5
|
export type InputVariant = "standard" | "outline" | "flushed" | "borderless";
|
|
6
6
|
export type InputStatus = "default" | "error" | "success" | "disable";
|
|
7
7
|
export type InputLabelPosition = "outside-top" | "outside-left" | "inside";
|
|
@@ -17,7 +17,11 @@ export interface IInputProps extends Omit<React.InputHTMLAttributes<HTMLInputEle
|
|
|
17
17
|
helperText?: string;
|
|
18
18
|
errorText?: string;
|
|
19
19
|
leftIcon?: ReactElement<IconInputProps>;
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Right-side slot. Accepts an SVG icon (sized/colored automatically) or any
|
|
22
|
+
* ReactNode such as a <Kbd /> keycap (rendered as-is).
|
|
23
|
+
*/
|
|
24
|
+
rightIcon?: ReactNode;
|
|
21
25
|
leftAddons?: ReactNode;
|
|
22
26
|
rightAddons?: ReactNode;
|
|
23
27
|
onClickLeftIcon?: () => void;
|