@lets-events/react 11.7.5 → 11.7.7
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +90 -48
- package/dist/index.mjs +90 -48
- package/package.json +1 -1
- package/src/components/FormFields/BirthDateFormField.tsx +11 -12
- package/src/components/TextField.tsx +86 -37
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @lets-events/react@11.7.
|
|
3
|
+
> @lets-events/react@11.7.7 build
|
|
4
4
|
> tsup src/index.tsx --format esm,cjs --dts --external react
|
|
5
5
|
|
|
6
6
|
[1G[0K[34mCLI[39m Building entry: src/index.tsx
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
[34mCLI[39m Target: es6
|
|
10
10
|
[34mESM[39m Build start
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
13
|
-
[32mESM[39m ⚡️ Build success in
|
|
14
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
15
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m321.38 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 276ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m333.60 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 277ms
|
|
16
16
|
DTS Build start
|
|
17
|
-
DTS ⚡️ Build success in
|
|
18
|
-
DTS dist/index.d.mts 374.
|
|
19
|
-
DTS dist/index.d.ts 374.
|
|
17
|
+
DTS ⚡️ Build success in 4801ms
|
|
18
|
+
DTS dist/index.d.mts 374.51 KB
|
|
19
|
+
DTS dist/index.d.ts 374.51 KB
|
|
20
20
|
[1G[0K⠙[1G[0K
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -2685,6 +2685,7 @@ type TextFieldProps = ComponentProps<typeof TextFieldStyled> & {
|
|
|
2685
2685
|
children?: React__default.ReactNode;
|
|
2686
2686
|
isValid?: boolean;
|
|
2687
2687
|
name?: string;
|
|
2688
|
+
maxLength?: number;
|
|
2688
2689
|
typography?: string;
|
|
2689
2690
|
fontWeight?: "regular" | "medium" | "semibold" | "bold";
|
|
2690
2691
|
textAlign?: "left" | "right" | "center";
|
package/dist/index.d.ts
CHANGED
|
@@ -2685,6 +2685,7 @@ type TextFieldProps = ComponentProps<typeof TextFieldStyled> & {
|
|
|
2685
2685
|
children?: React__default.ReactNode;
|
|
2686
2686
|
isValid?: boolean;
|
|
2687
2687
|
name?: string;
|
|
2688
|
+
maxLength?: number;
|
|
2688
2689
|
typography?: string;
|
|
2689
2690
|
fontWeight?: "regular" | "medium" | "semibold" | "bold";
|
|
2690
2691
|
textAlign?: "left" | "right" | "center";
|
package/dist/index.js
CHANGED
|
@@ -2812,6 +2812,22 @@ var InputAddon = styled(TextStyle, {
|
|
|
2812
2812
|
}
|
|
2813
2813
|
}
|
|
2814
2814
|
});
|
|
2815
|
+
var TextFieldLimitIndicator = styled("div", {
|
|
2816
|
+
width: "fit-content",
|
|
2817
|
+
display: "flex",
|
|
2818
|
+
justifyContent: "flex-end",
|
|
2819
|
+
position: "absolute",
|
|
2820
|
+
top: "0.5rem",
|
|
2821
|
+
right: "1rem",
|
|
2822
|
+
span: {
|
|
2823
|
+
color: "$neutral700",
|
|
2824
|
+
borderRadius: "$2xs",
|
|
2825
|
+
padding: "$4",
|
|
2826
|
+
fontSize: "$labelSmall",
|
|
2827
|
+
backgroundColor: "$neutral200",
|
|
2828
|
+
fontFamily: "$default"
|
|
2829
|
+
}
|
|
2830
|
+
});
|
|
2815
2831
|
var maskFormat = import_mask.format;
|
|
2816
2832
|
var maskUnformat = import_mask.unformat;
|
|
2817
2833
|
var TextField = import_react2.default.forwardRef(
|
|
@@ -2825,7 +2841,8 @@ var TextField = import_react2.default.forwardRef(
|
|
|
2825
2841
|
fontWeight,
|
|
2826
2842
|
addon,
|
|
2827
2843
|
textAlign = "left",
|
|
2828
|
-
mask
|
|
2844
|
+
mask,
|
|
2845
|
+
maxLength
|
|
2829
2846
|
} = _b, props = __objRest(_b, [
|
|
2830
2847
|
"children",
|
|
2831
2848
|
"isValid",
|
|
@@ -2835,47 +2852,70 @@ var TextField = import_react2.default.forwardRef(
|
|
|
2835
2852
|
"fontWeight",
|
|
2836
2853
|
"addon",
|
|
2837
2854
|
"textAlign",
|
|
2838
|
-
"mask"
|
|
2855
|
+
"mask",
|
|
2856
|
+
"maxLength"
|
|
2839
2857
|
]);
|
|
2840
2858
|
const maskRef = mask ? (0, import_mask.useMask)(mask) : void 0;
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2859
|
+
const inputRef = import_react2.default.useRef(null);
|
|
2860
|
+
const badgeRef = import_react2.default.useRef(null);
|
|
2861
|
+
const updateCharCountBadge = () => {
|
|
2862
|
+
var _a2, _b2;
|
|
2863
|
+
if (!maxLength || !badgeRef.current) return;
|
|
2864
|
+
const currentLength = (_b2 = (_a2 = inputRef.current) == null ? void 0 : _a2.value.length) != null ? _b2 : 0;
|
|
2865
|
+
badgeRef.current.textContent = String(maxLength - currentLength);
|
|
2866
|
+
};
|
|
2867
|
+
const handleInput = (e) => {
|
|
2868
|
+
var _a2;
|
|
2869
|
+
updateCharCountBadge();
|
|
2870
|
+
(_a2 = props.onInput) == null ? void 0 : _a2.call(props, e);
|
|
2871
|
+
};
|
|
2872
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Flex2, { direction: "column", css: { width: "100%" }, children: [
|
|
2873
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Flex2, { gap: "0", css: { width: "100%", position: "relative" }, children: [
|
|
2874
|
+
!!addon && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InputAddon, { color, typography: "labelSmall", children: addon }),
|
|
2875
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
2876
|
+
TextFieldStyled,
|
|
2877
|
+
__spreadProps(__spreadValues({
|
|
2878
|
+
color,
|
|
2879
|
+
isValid: isValid2,
|
|
2880
|
+
name,
|
|
2881
|
+
typography,
|
|
2882
|
+
fontWeight,
|
|
2883
|
+
textAlign,
|
|
2884
|
+
maxLength,
|
|
2885
|
+
ref: (r) => {
|
|
2886
|
+
if (!r) return;
|
|
2887
|
+
inputRef.current = r;
|
|
2888
|
+
if (maskRef) maskRef.current = r;
|
|
2889
|
+
if (fowardedRef) {
|
|
2890
|
+
if (typeof fowardedRef === "function") fowardedRef(r);
|
|
2891
|
+
else fowardedRef.current = r;
|
|
2874
2892
|
}
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2893
|
+
},
|
|
2894
|
+
onInput: handleInput
|
|
2895
|
+
}, props), {
|
|
2896
|
+
style: addon ? {
|
|
2897
|
+
borderTopLeftRadius: "0px",
|
|
2898
|
+
borderBottomLeftRadius: "0px"
|
|
2899
|
+
} : void 0,
|
|
2900
|
+
children: [
|
|
2901
|
+
children,
|
|
2902
|
+
isValid2 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2903
|
+
TextFieldSlot,
|
|
2904
|
+
{
|
|
2905
|
+
position: "flex-end",
|
|
2906
|
+
name,
|
|
2907
|
+
color,
|
|
2908
|
+
typography,
|
|
2909
|
+
fontWeight,
|
|
2910
|
+
textAlign,
|
|
2911
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon_default, { name: "check" })
|
|
2912
|
+
}
|
|
2913
|
+
)
|
|
2914
|
+
]
|
|
2915
|
+
})
|
|
2916
|
+
)
|
|
2917
|
+
] }),
|
|
2918
|
+
maxLength && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextFieldLimitIndicator, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { ref: badgeRef, children: maxLength }) })
|
|
2879
2919
|
] });
|
|
2880
2920
|
}
|
|
2881
2921
|
);
|
|
@@ -10160,16 +10200,18 @@ var isValidDate = (day, month, year) => {
|
|
|
10160
10200
|
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
|
10161
10201
|
};
|
|
10162
10202
|
var isValidBirthDate = (value, language) => {
|
|
10163
|
-
|
|
10164
|
-
let day = 0
|
|
10203
|
+
if (!/^\d{8}$/.test(value)) return false;
|
|
10204
|
+
let day = 0;
|
|
10205
|
+
let month = 0;
|
|
10206
|
+
let year = 0;
|
|
10165
10207
|
if (language === "en") {
|
|
10166
|
-
month =
|
|
10167
|
-
day =
|
|
10168
|
-
year =
|
|
10208
|
+
month = Number(value.slice(0, 2));
|
|
10209
|
+
day = Number(value.slice(2, 4));
|
|
10210
|
+
year = Number(value.slice(4));
|
|
10169
10211
|
} else {
|
|
10170
|
-
day =
|
|
10171
|
-
month =
|
|
10172
|
-
year =
|
|
10212
|
+
day = Number(value.slice(0, 2));
|
|
10213
|
+
month = Number(value.slice(2, 4));
|
|
10214
|
+
year = Number(value.slice(4));
|
|
10173
10215
|
}
|
|
10174
10216
|
if (!isValidDate(day, month, year)) return false;
|
|
10175
10217
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -10188,7 +10230,7 @@ var BirthDateFormField = ({
|
|
|
10188
10230
|
validationErrorMessage,
|
|
10189
10231
|
language
|
|
10190
10232
|
}) => {
|
|
10191
|
-
const inputPlaceholder = placeholder || (language === "
|
|
10233
|
+
const inputPlaceholder = placeholder || (language === "pt-BR" ? "DD/MM/AAAA" : "MM/DD/YYYY");
|
|
10192
10234
|
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
10193
10235
|
TextFormField,
|
|
10194
10236
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -2705,6 +2705,22 @@ var InputAddon = styled(TextStyle, {
|
|
|
2705
2705
|
}
|
|
2706
2706
|
}
|
|
2707
2707
|
});
|
|
2708
|
+
var TextFieldLimitIndicator = styled("div", {
|
|
2709
|
+
width: "fit-content",
|
|
2710
|
+
display: "flex",
|
|
2711
|
+
justifyContent: "flex-end",
|
|
2712
|
+
position: "absolute",
|
|
2713
|
+
top: "0.5rem",
|
|
2714
|
+
right: "1rem",
|
|
2715
|
+
span: {
|
|
2716
|
+
color: "$neutral700",
|
|
2717
|
+
borderRadius: "$2xs",
|
|
2718
|
+
padding: "$4",
|
|
2719
|
+
fontSize: "$labelSmall",
|
|
2720
|
+
backgroundColor: "$neutral200",
|
|
2721
|
+
fontFamily: "$default"
|
|
2722
|
+
}
|
|
2723
|
+
});
|
|
2708
2724
|
var maskFormat = format;
|
|
2709
2725
|
var maskUnformat = unformat;
|
|
2710
2726
|
var TextField = React.forwardRef(
|
|
@@ -2718,7 +2734,8 @@ var TextField = React.forwardRef(
|
|
|
2718
2734
|
fontWeight,
|
|
2719
2735
|
addon,
|
|
2720
2736
|
textAlign = "left",
|
|
2721
|
-
mask
|
|
2737
|
+
mask,
|
|
2738
|
+
maxLength
|
|
2722
2739
|
} = _b, props = __objRest(_b, [
|
|
2723
2740
|
"children",
|
|
2724
2741
|
"isValid",
|
|
@@ -2728,47 +2745,70 @@ var TextField = React.forwardRef(
|
|
|
2728
2745
|
"fontWeight",
|
|
2729
2746
|
"addon",
|
|
2730
2747
|
"textAlign",
|
|
2731
|
-
"mask"
|
|
2748
|
+
"mask",
|
|
2749
|
+
"maxLength"
|
|
2732
2750
|
]);
|
|
2733
2751
|
const maskRef = mask ? useMask(mask) : void 0;
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2752
|
+
const inputRef = React.useRef(null);
|
|
2753
|
+
const badgeRef = React.useRef(null);
|
|
2754
|
+
const updateCharCountBadge = () => {
|
|
2755
|
+
var _a2, _b2;
|
|
2756
|
+
if (!maxLength || !badgeRef.current) return;
|
|
2757
|
+
const currentLength = (_b2 = (_a2 = inputRef.current) == null ? void 0 : _a2.value.length) != null ? _b2 : 0;
|
|
2758
|
+
badgeRef.current.textContent = String(maxLength - currentLength);
|
|
2759
|
+
};
|
|
2760
|
+
const handleInput = (e) => {
|
|
2761
|
+
var _a2;
|
|
2762
|
+
updateCharCountBadge();
|
|
2763
|
+
(_a2 = props.onInput) == null ? void 0 : _a2.call(props, e);
|
|
2764
|
+
};
|
|
2765
|
+
return /* @__PURE__ */ jsxs(Flex2, { direction: "column", css: { width: "100%" }, children: [
|
|
2766
|
+
/* @__PURE__ */ jsxs(Flex2, { gap: "0", css: { width: "100%", position: "relative" }, children: [
|
|
2767
|
+
!!addon && /* @__PURE__ */ jsx7(InputAddon, { color, typography: "labelSmall", children: addon }),
|
|
2768
|
+
/* @__PURE__ */ jsxs(
|
|
2769
|
+
TextFieldStyled,
|
|
2770
|
+
__spreadProps(__spreadValues({
|
|
2771
|
+
color,
|
|
2772
|
+
isValid: isValid2,
|
|
2773
|
+
name,
|
|
2774
|
+
typography,
|
|
2775
|
+
fontWeight,
|
|
2776
|
+
textAlign,
|
|
2777
|
+
maxLength,
|
|
2778
|
+
ref: (r) => {
|
|
2779
|
+
if (!r) return;
|
|
2780
|
+
inputRef.current = r;
|
|
2781
|
+
if (maskRef) maskRef.current = r;
|
|
2782
|
+
if (fowardedRef) {
|
|
2783
|
+
if (typeof fowardedRef === "function") fowardedRef(r);
|
|
2784
|
+
else fowardedRef.current = r;
|
|
2767
2785
|
}
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2786
|
+
},
|
|
2787
|
+
onInput: handleInput
|
|
2788
|
+
}, props), {
|
|
2789
|
+
style: addon ? {
|
|
2790
|
+
borderTopLeftRadius: "0px",
|
|
2791
|
+
borderBottomLeftRadius: "0px"
|
|
2792
|
+
} : void 0,
|
|
2793
|
+
children: [
|
|
2794
|
+
children,
|
|
2795
|
+
isValid2 && /* @__PURE__ */ jsx7(
|
|
2796
|
+
TextFieldSlot,
|
|
2797
|
+
{
|
|
2798
|
+
position: "flex-end",
|
|
2799
|
+
name,
|
|
2800
|
+
color,
|
|
2801
|
+
typography,
|
|
2802
|
+
fontWeight,
|
|
2803
|
+
textAlign,
|
|
2804
|
+
children: /* @__PURE__ */ jsx7(Icon_default, { name: "check" })
|
|
2805
|
+
}
|
|
2806
|
+
)
|
|
2807
|
+
]
|
|
2808
|
+
})
|
|
2809
|
+
)
|
|
2810
|
+
] }),
|
|
2811
|
+
maxLength && /* @__PURE__ */ jsx7(TextFieldLimitIndicator, { children: /* @__PURE__ */ jsx7("span", { ref: badgeRef, children: maxLength }) })
|
|
2772
2812
|
] });
|
|
2773
2813
|
}
|
|
2774
2814
|
);
|
|
@@ -10066,16 +10106,18 @@ var isValidDate = (day, month, year) => {
|
|
|
10066
10106
|
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
|
10067
10107
|
};
|
|
10068
10108
|
var isValidBirthDate = (value, language) => {
|
|
10069
|
-
|
|
10070
|
-
let day = 0
|
|
10109
|
+
if (!/^\d{8}$/.test(value)) return false;
|
|
10110
|
+
let day = 0;
|
|
10111
|
+
let month = 0;
|
|
10112
|
+
let year = 0;
|
|
10071
10113
|
if (language === "en") {
|
|
10072
|
-
month =
|
|
10073
|
-
day =
|
|
10074
|
-
year =
|
|
10114
|
+
month = Number(value.slice(0, 2));
|
|
10115
|
+
day = Number(value.slice(2, 4));
|
|
10116
|
+
year = Number(value.slice(4));
|
|
10075
10117
|
} else {
|
|
10076
|
-
day =
|
|
10077
|
-
month =
|
|
10078
|
-
year =
|
|
10118
|
+
day = Number(value.slice(0, 2));
|
|
10119
|
+
month = Number(value.slice(2, 4));
|
|
10120
|
+
year = Number(value.slice(4));
|
|
10079
10121
|
}
|
|
10080
10122
|
if (!isValidDate(day, month, year)) return false;
|
|
10081
10123
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -10094,7 +10136,7 @@ var BirthDateFormField = ({
|
|
|
10094
10136
|
validationErrorMessage,
|
|
10095
10137
|
language
|
|
10096
10138
|
}) => {
|
|
10097
|
-
const inputPlaceholder = placeholder || (language === "
|
|
10139
|
+
const inputPlaceholder = placeholder || (language === "pt-BR" ? "DD/MM/AAAA" : "MM/DD/YYYY");
|
|
10098
10140
|
return /* @__PURE__ */ jsx39(
|
|
10099
10141
|
TextFormField,
|
|
10100
10142
|
{
|
package/package.json
CHANGED
|
@@ -19,21 +19,20 @@ const isValidDate = (day: number, month: number, year: number): boolean => {
|
|
|
19
19
|
date.getDate() === day
|
|
20
20
|
);
|
|
21
21
|
};
|
|
22
|
-
|
|
23
22
|
const isValidBirthDate = (value: string, language: Language): boolean => {
|
|
24
|
-
|
|
25
|
-
let day = 0,
|
|
26
|
-
month = 0,
|
|
27
|
-
year = 0;
|
|
23
|
+
if (!/^\d{8}$/.test(value)) return false;
|
|
28
24
|
|
|
25
|
+
let day = 0;
|
|
26
|
+
let month = 0;
|
|
27
|
+
let year = 0;
|
|
29
28
|
if (language === "en") {
|
|
30
|
-
month =
|
|
31
|
-
day =
|
|
32
|
-
year =
|
|
29
|
+
month = Number(value.slice(0, 2));
|
|
30
|
+
day = Number(value.slice(2, 4));
|
|
31
|
+
year = Number(value.slice(4));
|
|
33
32
|
} else {
|
|
34
|
-
day =
|
|
35
|
-
month =
|
|
36
|
-
year =
|
|
33
|
+
day = Number(value.slice(0, 2));
|
|
34
|
+
month = Number(value.slice(2, 4));
|
|
35
|
+
year = Number(value.slice(4));
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
if (!isValidDate(day, month, year)) return false;
|
|
@@ -63,7 +62,7 @@ export const BirthDateFormField = ({
|
|
|
63
62
|
language,
|
|
64
63
|
}: BirthDateFormFieldProps) => {
|
|
65
64
|
const inputPlaceholder =
|
|
66
|
-
placeholder || (language === "
|
|
65
|
+
placeholder || (language === "pt-BR" ? "DD/MM/AAAA" : "MM/DD/YYYY");
|
|
67
66
|
|
|
68
67
|
return (
|
|
69
68
|
<TextFormField
|
|
@@ -168,6 +168,7 @@ export type TextFieldProps = ComponentProps<typeof TextFieldStyled> & {
|
|
|
168
168
|
children?: React.ReactNode;
|
|
169
169
|
isValid?: boolean;
|
|
170
170
|
name?: string;
|
|
171
|
+
maxLength?: number;
|
|
171
172
|
typography?: string;
|
|
172
173
|
fontWeight?: "regular" | "medium" | "semibold" | "bold";
|
|
173
174
|
textAlign?: "left" | "right" | "center";
|
|
@@ -215,6 +216,22 @@ const InputAddon = styled(TextStyle, {
|
|
|
215
216
|
},
|
|
216
217
|
},
|
|
217
218
|
});
|
|
219
|
+
const TextFieldLimitIndicator = styled("div", {
|
|
220
|
+
width: "fit-content",
|
|
221
|
+
display: "flex",
|
|
222
|
+
justifyContent: "flex-end",
|
|
223
|
+
position: "absolute",
|
|
224
|
+
top: "0.5rem",
|
|
225
|
+
right: "1rem",
|
|
226
|
+
span: {
|
|
227
|
+
color: "$neutral700",
|
|
228
|
+
borderRadius: "$2xs",
|
|
229
|
+
padding: "$4",
|
|
230
|
+
fontSize: "$labelSmall",
|
|
231
|
+
backgroundColor: "$neutral200",
|
|
232
|
+
fontFamily: "$default",
|
|
233
|
+
},
|
|
234
|
+
});
|
|
218
235
|
export const maskFormat = format;
|
|
219
236
|
export const maskUnformat = unformat;
|
|
220
237
|
|
|
@@ -230,52 +247,84 @@ export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
|
|
|
230
247
|
addon,
|
|
231
248
|
textAlign = "left",
|
|
232
249
|
mask,
|
|
250
|
+
maxLength,
|
|
233
251
|
...props
|
|
234
252
|
},
|
|
235
253
|
fowardedRef
|
|
236
254
|
) => {
|
|
237
255
|
const maskRef = mask ? useMask(mask) : undefined;
|
|
256
|
+
const inputRef = React.useRef<HTMLInputElement>(null);
|
|
257
|
+
const badgeRef = React.useRef<HTMLSpanElement>(null);
|
|
258
|
+
|
|
259
|
+
const updateCharCountBadge = () => {
|
|
260
|
+
if (!maxLength || !badgeRef.current) return;
|
|
261
|
+
const currentLength = inputRef.current?.value.length ?? 0;
|
|
262
|
+
badgeRef.current.textContent = String(maxLength - currentLength);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const handleInput = (e: React.FormEvent<HTMLInputElement>) => {
|
|
266
|
+
updateCharCountBadge();
|
|
267
|
+
props.onInput?.(e);
|
|
268
|
+
};
|
|
269
|
+
|
|
238
270
|
return (
|
|
239
|
-
<Flex
|
|
240
|
-
|
|
271
|
+
<Flex direction="column" css={{ width: "100%" }}>
|
|
272
|
+
<Flex gap={"0"} css={{ width: "100%", position: "relative" }}>
|
|
273
|
+
{!!addon && (
|
|
274
|
+
<InputAddon color={color} typography="labelSmall">
|
|
275
|
+
{addon}
|
|
276
|
+
</InputAddon>
|
|
277
|
+
)}
|
|
241
278
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
279
|
+
<TextFieldStyled
|
|
280
|
+
color={color}
|
|
281
|
+
isValid={isValid}
|
|
282
|
+
name={name}
|
|
283
|
+
typography={typography}
|
|
284
|
+
fontWeight={fontWeight}
|
|
285
|
+
textAlign={textAlign}
|
|
286
|
+
maxLength={maxLength}
|
|
287
|
+
ref={(r) => {
|
|
288
|
+
if (!r) return;
|
|
289
|
+
inputRef.current = r;
|
|
290
|
+
if (maskRef) maskRef.current = r;
|
|
252
291
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
292
|
+
if (fowardedRef) {
|
|
293
|
+
if (typeof fowardedRef === "function") fowardedRef(r);
|
|
294
|
+
else fowardedRef.current = r;
|
|
295
|
+
}
|
|
296
|
+
}}
|
|
297
|
+
onInput={handleInput}
|
|
298
|
+
{...props}
|
|
299
|
+
style={
|
|
300
|
+
addon
|
|
301
|
+
? {
|
|
302
|
+
borderTopLeftRadius: "0px",
|
|
303
|
+
borderBottomLeftRadius: "0px",
|
|
304
|
+
}
|
|
305
|
+
: undefined
|
|
256
306
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
</TextFieldStyled>
|
|
307
|
+
>
|
|
308
|
+
{children}
|
|
309
|
+
{isValid && (
|
|
310
|
+
<TextFieldSlot
|
|
311
|
+
position="flex-end"
|
|
312
|
+
name={name}
|
|
313
|
+
color={color as TextFieldSlotProps["color"]}
|
|
314
|
+
typography={typography}
|
|
315
|
+
fontWeight={fontWeight}
|
|
316
|
+
textAlign={textAlign}
|
|
317
|
+
>
|
|
318
|
+
<Icon name="check" />
|
|
319
|
+
</TextFieldSlot>
|
|
320
|
+
)}
|
|
321
|
+
</TextFieldStyled>
|
|
322
|
+
</Flex>
|
|
323
|
+
{maxLength && (
|
|
324
|
+
<TextFieldLimitIndicator>
|
|
325
|
+
<span ref={badgeRef}>{maxLength}</span>
|
|
326
|
+
</TextFieldLimitIndicator>
|
|
327
|
+
)}
|
|
279
328
|
</Flex>
|
|
280
329
|
);
|
|
281
330
|
}
|