@seedgrid/fe-components 0.2.4 → 0.2.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/package.json +3 -2
- package/dist/buttons/SgSpeedDial.d.ts +0 -40
- package/dist/buttons/SgSpeedDial.d.ts.map +0 -1
- package/dist/buttons/SgSpeedDial.js +0 -149
- package/dist/clock/SgClock.d.ts +0 -28
- package/dist/clock/SgClock.d.ts.map +0 -1
- package/dist/clock/SgClock.js +0 -280
- package/dist/clock/SgTimeProvider.d.ts +0 -13
- package/dist/clock/SgTimeProvider.d.ts.map +0 -1
- package/dist/clock/SgTimeProvider.js +0 -44
- package/dist/clock/themes/SgClockThemePicker.d.ts +0 -14
- package/dist/clock/themes/SgClockThemePicker.d.ts.map +0 -1
- package/dist/clock/themes/SgClockThemePicker.js +0 -71
- package/dist/clock/themes/SgClockThemePreview.d.ts +0 -7
- package/dist/clock/themes/SgClockThemePreview.d.ts.map +0 -1
- package/dist/clock/themes/SgClockThemePreview.js +0 -11
- package/dist/clock/themes/builtins.d.ts +0 -3
- package/dist/clock/themes/builtins.d.ts.map +0 -1
- package/dist/clock/themes/builtins.js +0 -241
- package/dist/clock/themes/index.d.ts +0 -9
- package/dist/clock/themes/index.d.ts.map +0 -1
- package/dist/clock/themes/index.js +0 -7
- package/dist/clock/themes/provider.d.ts +0 -19
- package/dist/clock/themes/provider.d.ts.map +0 -1
- package/dist/clock/themes/provider.js +0 -54
- package/dist/clock/themes/registry.d.ts +0 -9
- package/dist/clock/themes/registry.d.ts.map +0 -1
- package/dist/clock/themes/registry.js +0 -25
- package/dist/clock/themes/renderTheme.d.ts +0 -7
- package/dist/clock/themes/renderTheme.d.ts.map +0 -1
- package/dist/clock/themes/renderTheme.js +0 -41
- package/dist/clock/themes/types.d.ts +0 -21
- package/dist/clock/themes/types.d.ts.map +0 -1
- package/dist/clock/themes/types.js +0 -1
- package/dist/clock/themes/urlThemeCache.d.ts +0 -2
- package/dist/clock/themes/urlThemeCache.d.ts.map +0 -1
- package/dist/clock/themes/urlThemeCache.js +0 -11
- package/dist/clock/themes/useDarkFlag.d.ts +0 -2
- package/dist/clock/themes/useDarkFlag.d.ts.map +0 -1
- package/dist/clock/themes/useDarkFlag.js +0 -14
- package/dist/commons/SgButton.d.ts +0 -39
- package/dist/commons/SgButton.d.ts.map +0 -1
- package/dist/commons/SgButton.js +0 -116
- package/dist/commons/SgPopup.d.ts +0 -42
- package/dist/commons/SgPopup.d.ts.map +0 -1
- package/dist/commons/SgPopup.js +0 -218
- package/dist/inputs/FloatingInput.d.ts +0 -13
- package/dist/inputs/FloatingInput.d.ts.map +0 -1
- package/dist/inputs/FloatingInput.js +0 -53
- package/dist/inputs/FloatingSelect.d.ts +0 -15
- package/dist/inputs/FloatingSelect.d.ts.map +0 -1
- package/dist/inputs/FloatingSelect.js +0 -52
- package/dist/inputs/FloatingTextArea.d.ts +0 -11
- package/dist/inputs/FloatingTextArea.d.ts.map +0 -1
- package/dist/inputs/FloatingTextArea.js +0 -34
- package/dist/inputs/InputBirthDate.d.ts +0 -13
- package/dist/inputs/InputBirthDate.d.ts.map +0 -1
- package/dist/inputs/InputBirthDate.js +0 -46
- package/dist/inputs/InputDate.d.ts +0 -8
- package/dist/inputs/InputDate.d.ts.map +0 -1
- package/dist/inputs/InputDate.js +0 -23
- package/dist/inputs/InputEmail.d.ts +0 -14
- package/dist/inputs/InputEmail.d.ts.map +0 -1
- package/dist/inputs/InputEmail.js +0 -43
- package/dist/inputs/InputPassword.d.ts +0 -12
- package/dist/inputs/InputPassword.d.ts.map +0 -1
- package/dist/inputs/InputPassword.js +0 -42
- package/dist/inputs/MaskedInputs.d.ts +0 -27
- package/dist/inputs/MaskedInputs.d.ts.map +0 -1
- package/dist/inputs/MaskedInputs.js +0 -161
- package/dist/inputs/SgInputCEP.d.ts +0 -33
- package/dist/inputs/SgInputCEP.d.ts.map +0 -1
- package/dist/inputs/SgInputCEP.js +0 -117
- package/dist/inputs/SgInputFone.d.ts +0 -15
- package/dist/inputs/SgInputFone.d.ts.map +0 -1
- package/dist/inputs/SgInputFone.js +0 -60
- package/dist/inputs/SgInputMasked.d.ts +0 -27
- package/dist/inputs/SgInputMasked.d.ts.map +0 -1
- package/dist/inputs/SgInputMasked.js +0 -161
- package/dist/layout/GroupBox.d.ts +0 -10
- package/dist/layout/GroupBox.d.ts.map +0 -1
- package/dist/layout/GroupBox.js +0 -14
- /package/dist/wizard/{SGWizard.d.ts → SgWizard.d.ts} +0 -0
- /package/dist/wizard/{SGWizard.d.ts.map → SgWizard.d.ts.map} +0 -0
- /package/dist/wizard/{SGWizard.js → SgWizard.js} +0 -0
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { SgInputDate } from "./InputDate";
|
|
5
|
-
import { validateBirthDate } from "../validators";
|
|
6
|
-
export function SgInputBirthDate(props) {
|
|
7
|
-
const today = new Date();
|
|
8
|
-
const todayStr = today.toISOString().slice(0, 10);
|
|
9
|
-
const { minAge, maxAge, onValidation, inputProps, minDate, maxDate, alwaysFloat, required, requiredMessage, validateOnBlur, error, ...rest } = props;
|
|
10
|
-
const derivedMaxDate = maxAge !== undefined && maxAge >= 0
|
|
11
|
-
? new Date(today.getFullYear() - maxAge, today.getMonth(), today.getDate()).toISOString().slice(0, 10)
|
|
12
|
-
: undefined;
|
|
13
|
-
const derivedMinDate = minAge !== undefined && minAge >= 0
|
|
14
|
-
? new Date(today.getFullYear() - minAge, today.getMonth(), today.getDate()).toISOString().slice(0, 10)
|
|
15
|
-
: undefined;
|
|
16
|
-
const [internalError, setInternalError] = React.useState(null);
|
|
17
|
-
const runValidation = React.useCallback((value) => {
|
|
18
|
-
if (!value && !required) {
|
|
19
|
-
setInternalError(null);
|
|
20
|
-
onValidation?.(null);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (!value && required) {
|
|
24
|
-
const message = requiredMessage ?? "Informe a data de nascimento.";
|
|
25
|
-
setInternalError(message);
|
|
26
|
-
onValidation?.(message);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const message = validateBirthDate(value, { minAge, maxAge });
|
|
30
|
-
setInternalError(message);
|
|
31
|
-
onValidation?.(message);
|
|
32
|
-
}, [maxAge, minAge, onValidation, required, requiredMessage]);
|
|
33
|
-
const handleBlur = (event) => {
|
|
34
|
-
runValidation(event.currentTarget.value);
|
|
35
|
-
inputProps?.onBlur?.(event);
|
|
36
|
-
};
|
|
37
|
-
return (_jsx(SgInputDate, { ...rest, error: error ?? internalError ?? undefined, inputProps: {
|
|
38
|
-
...inputProps,
|
|
39
|
-
onBlur: (event) => {
|
|
40
|
-
if (validateOnBlur ?? true)
|
|
41
|
-
handleBlur(event);
|
|
42
|
-
else
|
|
43
|
-
inputProps?.onBlur?.(event);
|
|
44
|
-
}
|
|
45
|
-
}, alwaysFloat: alwaysFloat ?? true, maxDate: maxDate ?? derivedMinDate ?? todayStr, minDate: minDate ?? derivedMaxDate }));
|
|
46
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type SgInputTextProps } from "./SgInputText";
|
|
2
|
-
export type SgInputDateProps = Omit<SgInputTextProps, "type"> & {
|
|
3
|
-
minDate?: string | Date;
|
|
4
|
-
maxDate?: string | Date;
|
|
5
|
-
alwaysFloat?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare function SgInputDate(props: SgInputDateProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
-
//# sourceMappingURL=InputDate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InputDate.d.ts","sourceRoot":"","sources":["../../src/inputs/InputDate.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG;IAC9D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAQF,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CAiClD"}
|
package/dist/inputs/InputDate.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { SgInputText } from "./SgInputText";
|
|
4
|
-
function toDateValue(value) {
|
|
5
|
-
if (!value)
|
|
6
|
-
return undefined;
|
|
7
|
-
if (typeof value === "string")
|
|
8
|
-
return value;
|
|
9
|
-
return value.toISOString().slice(0, 10);
|
|
10
|
-
}
|
|
11
|
-
export function SgInputDate(props) {
|
|
12
|
-
const { minDate, maxDate, inputProps, alwaysFloat, ...rest } = props;
|
|
13
|
-
const showStaticLabel = Boolean(alwaysFloat);
|
|
14
|
-
const mergedInputProps = {
|
|
15
|
-
...inputProps,
|
|
16
|
-
placeholder: showStaticLabel ? " " : (inputProps?.placeholder ?? rest.label),
|
|
17
|
-
min: toDateValue(minDate),
|
|
18
|
-
max: toDateValue(maxDate)
|
|
19
|
-
};
|
|
20
|
-
const inputClassName = mergedInputProps.className ??
|
|
21
|
-
"peer h-11 w-full rounded-md border border-border bg-white px-3 py-2.5 text-sm shadow-sm placeholder-transparent focus:border-[hsl(var(--primary))] focus:outline-none focus:ring-2 focus:ring-[hsl(var(--primary)/0.25)]";
|
|
22
|
-
return (_jsxs("div", { className: showStaticLabel ? "relative" : undefined, children: [showStaticLabel && rest.label ? (_jsx("label", { htmlFor: rest.id, className: "pointer-events-none absolute left-3 top-0 z-10 -translate-y-1/2 bg-white px-1 text-[11px] font-medium leading-none text-foreground/70", children: rest.label })) : null, _jsx(SgInputText, { ...rest, type: "date", inputProps: mergedInputProps, className: inputClassName, labelClassName: showStaticLabel ? "sr-only" : undefined })] }));
|
|
23
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { type SgInputTextProps } from "./SgInputText";
|
|
3
|
-
export type SgInputEmailProps = Omit<SgInputTextProps, "type" | "error"> & {
|
|
4
|
-
error?: string;
|
|
5
|
-
required?: boolean;
|
|
6
|
-
requiredMessage?: string;
|
|
7
|
-
invalidMessage?: string;
|
|
8
|
-
validation?: (value: string) => string | null;
|
|
9
|
-
validateOnBlur?: boolean;
|
|
10
|
-
onValidation?: (message: string | null) => void;
|
|
11
|
-
iconButtons?: React.ReactNode[];
|
|
12
|
-
};
|
|
13
|
-
export declare function SgInputEmail(props: SgInputEmailProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
-
//# sourceMappingURL=InputEmail.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InputEmail.d.ts","sourceRoot":"","sources":["../../src/inputs/InputEmail.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGnE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC9C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;CACjC,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,2CAkDpD"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { SgInputText } from "./SgInputText";
|
|
5
|
-
import { isValidEmail } from "../validators";
|
|
6
|
-
export function SgInputEmail(props) {
|
|
7
|
-
const { required, requiredMessage, invalidMessage, validateOnBlur, onValidation, error, inputProps, iconButtons, validation, ...rest } = props;
|
|
8
|
-
const [internalError, setInternalError] = React.useState(null);
|
|
9
|
-
const runValidation = React.useCallback((value) => {
|
|
10
|
-
if (!value && !required) {
|
|
11
|
-
setInternalError(null);
|
|
12
|
-
onValidation?.(null);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (!value && required) {
|
|
16
|
-
const message = requiredMessage ?? "Campo obrigatório ";
|
|
17
|
-
setInternalError(message);
|
|
18
|
-
onValidation?.(message);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (validation) {
|
|
22
|
-
const custom = validation(value);
|
|
23
|
-
if (custom) {
|
|
24
|
-
setInternalError(custom);
|
|
25
|
-
onValidation?.(custom);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const valid = isValidEmail(value);
|
|
30
|
-
const message = valid ? null : (invalidMessage ?? "Email inválido.");
|
|
31
|
-
setInternalError(message);
|
|
32
|
-
onValidation?.(message);
|
|
33
|
-
}, [invalidMessage, onValidation, required, requiredMessage, validation]);
|
|
34
|
-
const mergedInputProps = {
|
|
35
|
-
...inputProps,
|
|
36
|
-
onBlur: (event) => {
|
|
37
|
-
if (validateOnBlur ?? true)
|
|
38
|
-
runValidation(event.currentTarget.value);
|
|
39
|
-
inputProps?.onBlur?.(event);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return (_jsx(SgInputText, { ...rest, type: "email", error: error ?? internalError ?? undefined, inputProps: mergedInputProps, iconButtons: iconButtons }));
|
|
43
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type SgInputTextProps } from "./SgInputText";
|
|
2
|
-
import { type PasswordPolicy } from "../validators";
|
|
3
|
-
export type SgInputPasswordProps = Omit<SgInputTextProps, "type" | "error"> & {
|
|
4
|
-
error?: string;
|
|
5
|
-
policy?: PasswordPolicy;
|
|
6
|
-
onValidation?: (message: string | null) => void;
|
|
7
|
-
required?: boolean;
|
|
8
|
-
requiredMessage?: string;
|
|
9
|
-
validateOnBlur?: boolean;
|
|
10
|
-
};
|
|
11
|
-
export declare function SgInputPassword(props: SgInputPasswordProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
-
//# sourceMappingURL=InputPassword.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InputPassword.d.ts","sourceRoot":"","sources":["../../src/inputs/InputPassword.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEtE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,2CA+C1D"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { SgInputText } from "./SgInputText";
|
|
5
|
-
import { validatePassword } from "../validators";
|
|
6
|
-
export function SgInputPassword(props) {
|
|
7
|
-
const { inputProps, policy, onValidation, required, requiredMessage, validateOnBlur, error, ...rest } = props;
|
|
8
|
-
const onBlur = inputProps.onBlur;
|
|
9
|
-
const [internalError, setInternalError] = React.useState(null);
|
|
10
|
-
const runValidation = React.useCallback((value) => {
|
|
11
|
-
if (!value && !required) {
|
|
12
|
-
setInternalError(null);
|
|
13
|
-
onValidation?.(null);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (!value && required) {
|
|
17
|
-
const message = requiredMessage ?? "Informe a senha.";
|
|
18
|
-
setInternalError(message);
|
|
19
|
-
onValidation?.(message);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const message = validatePassword(value, policy);
|
|
23
|
-
setInternalError(message);
|
|
24
|
-
onValidation?.(message);
|
|
25
|
-
}, [onValidation, policy, required, requiredMessage]);
|
|
26
|
-
const mergedInputProps = {
|
|
27
|
-
...inputProps,
|
|
28
|
-
onBlur: (event) => {
|
|
29
|
-
runValidation(event.currentTarget.value);
|
|
30
|
-
onBlur?.(event);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
return (_jsx(SgInputText, { ...rest, type: "password", error: error ?? internalError ?? undefined, inputProps: {
|
|
34
|
-
...mergedInputProps,
|
|
35
|
-
onBlur: (event) => {
|
|
36
|
-
if (validateOnBlur ?? true)
|
|
37
|
-
mergedInputProps.onBlur?.(event);
|
|
38
|
-
else
|
|
39
|
-
onBlur?.(event);
|
|
40
|
-
}
|
|
41
|
-
} }));
|
|
42
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { type SgInputTextProps } from "./SgInputText";
|
|
3
|
-
type MaskedInputProps = Omit<SgInputTextProps, "inputProps" | "error"> & {
|
|
4
|
-
inputProps: React.InputHTMLAttributes<HTMLInputElement>;
|
|
5
|
-
mask: (value: string) => string;
|
|
6
|
-
};
|
|
7
|
-
type ValidationProps = {
|
|
8
|
-
error?: string;
|
|
9
|
-
required?: boolean;
|
|
10
|
-
requiredMessage?: string;
|
|
11
|
-
lengthMessage?: string;
|
|
12
|
-
invalidMessage?: string;
|
|
13
|
-
onValidation?: (message: string | null) => void;
|
|
14
|
-
validateOnBlur?: boolean;
|
|
15
|
-
};
|
|
16
|
-
export type SgInputCPFProps = Omit<MaskedInputProps, "mask"> & ValidationProps;
|
|
17
|
-
export declare function SgInputCPF(props: SgInputCPFProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
-
export type SgInputCNPJProps = Omit<MaskedInputProps, "mask"> & ValidationProps;
|
|
19
|
-
export declare function SgInputCNPJ(props: SgInputCNPJProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
-
export type SgInputCPFCNPJProps = Omit<MaskedInputProps, "mask"> & ValidationProps;
|
|
21
|
-
export declare function SgInputCPFCNPJ(props: SgInputCPFCNPJProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export type SgInputCEPProps = Omit<MaskedInputProps, "mask"> & ValidationProps;
|
|
23
|
-
export declare function SgInputCEP(props: SgInputCEPProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
-
export type SgInputFoneProps = Omit<MaskedInputProps, "mask"> & ValidationProps;
|
|
25
|
-
export declare function SgInputFone(props: SgInputFoneProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=MaskedInputs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MaskedInputs.d.ts","sourceRoot":"","sources":["../../src/inputs/MaskedInputs.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAInE,KAAK,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG;IACvE,UAAU,EAAE,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACxD,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACjC,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAqCF,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC;AAE/E,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,2CA4BhD;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC;AAEhF,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CA4BlD;AAED,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC;AAEnF,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CA+BxD;AAED,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC;AAE/E,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,2CA2BhD;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC;AAEhF,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CA6BlD"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { SgInputText } from "./SgInputText";
|
|
5
|
-
import { maskCep, maskCnpj, maskCpf, maskCpfCnpj, maskPhone } from "../masks";
|
|
6
|
-
import { isValidCnpj, isValidCpf } from "../validators";
|
|
7
|
-
function onlyDigits(value) {
|
|
8
|
-
return value.replace(/\D/g, "");
|
|
9
|
-
}
|
|
10
|
-
function useValidationState(props, validateFn) {
|
|
11
|
-
const [internalError, setInternalError] = React.useState(null);
|
|
12
|
-
const runValidation = React.useCallback((value) => {
|
|
13
|
-
const message = validateFn(value);
|
|
14
|
-
setInternalError(message);
|
|
15
|
-
props.onValidation?.(message);
|
|
16
|
-
return message;
|
|
17
|
-
}, [props, validateFn]);
|
|
18
|
-
return { internalError, runValidation };
|
|
19
|
-
}
|
|
20
|
-
function applyMaskProps(props, inputMode) {
|
|
21
|
-
const { inputProps, mask } = props;
|
|
22
|
-
const onChange = inputProps.onChange;
|
|
23
|
-
return {
|
|
24
|
-
...inputProps,
|
|
25
|
-
inputMode: inputProps.inputMode ?? inputMode,
|
|
26
|
-
onChange: (event) => {
|
|
27
|
-
event.target.value = mask(event.target.value);
|
|
28
|
-
onChange?.(event);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export function SgInputCPF(props) {
|
|
33
|
-
const { required, requiredMessage, lengthMessage, invalidMessage, validateOnBlur, error, ...rest } = props;
|
|
34
|
-
const { internalError, runValidation } = useValidationState(props, (value) => {
|
|
35
|
-
const digits = onlyDigits(value);
|
|
36
|
-
if (!digits && !required)
|
|
37
|
-
return null;
|
|
38
|
-
if (!digits && required)
|
|
39
|
-
return requiredMessage ?? "Informe o CPF.";
|
|
40
|
-
if (digits.length !== 11)
|
|
41
|
-
return lengthMessage ?? "CPF deve ter 11 dígitos.";
|
|
42
|
-
if (!isValidCpf(value))
|
|
43
|
-
return invalidMessage ?? "CPF inválido.";
|
|
44
|
-
return null;
|
|
45
|
-
});
|
|
46
|
-
const inputProps = applyMaskProps({ ...rest, mask: maskCpf }, "numeric");
|
|
47
|
-
const onBlur = inputProps.onBlur;
|
|
48
|
-
const shouldValidateOnBlur = validateOnBlur ?? true;
|
|
49
|
-
return (_jsx(SgInputText, { ...rest, error: error ?? internalError ?? undefined, inputProps: {
|
|
50
|
-
...inputProps,
|
|
51
|
-
onBlur: (event) => {
|
|
52
|
-
if (shouldValidateOnBlur)
|
|
53
|
-
runValidation(event.currentTarget.value);
|
|
54
|
-
onBlur?.(event);
|
|
55
|
-
}
|
|
56
|
-
} }));
|
|
57
|
-
}
|
|
58
|
-
export function SgInputCNPJ(props) {
|
|
59
|
-
const { required, requiredMessage, lengthMessage, invalidMessage, validateOnBlur, error, ...rest } = props;
|
|
60
|
-
const { internalError, runValidation } = useValidationState(props, (value) => {
|
|
61
|
-
const digits = onlyDigits(value);
|
|
62
|
-
if (!digits && !required)
|
|
63
|
-
return null;
|
|
64
|
-
if (!digits && required)
|
|
65
|
-
return requiredMessage ?? "Informe o CNPJ.";
|
|
66
|
-
if (digits.length !== 14)
|
|
67
|
-
return lengthMessage ?? "CNPJ deve ter 14 dígitos.";
|
|
68
|
-
if (!isValidCnpj(value))
|
|
69
|
-
return invalidMessage ?? "CNPJ inválido.";
|
|
70
|
-
return null;
|
|
71
|
-
});
|
|
72
|
-
const inputProps = applyMaskProps({ ...rest, mask: maskCnpj }, "numeric");
|
|
73
|
-
const onBlur = inputProps.onBlur;
|
|
74
|
-
const shouldValidateOnBlur = validateOnBlur ?? true;
|
|
75
|
-
return (_jsx(SgInputText, { ...rest, error: error ?? internalError ?? undefined, inputProps: {
|
|
76
|
-
...inputProps,
|
|
77
|
-
onBlur: (event) => {
|
|
78
|
-
if (shouldValidateOnBlur)
|
|
79
|
-
runValidation(event.currentTarget.value);
|
|
80
|
-
onBlur?.(event);
|
|
81
|
-
}
|
|
82
|
-
} }));
|
|
83
|
-
}
|
|
84
|
-
export function SgInputCPFCNPJ(props) {
|
|
85
|
-
const { required, requiredMessage, lengthMessage, invalidMessage, validateOnBlur, error, ...rest } = props;
|
|
86
|
-
const { internalError, runValidation } = useValidationState(props, (value) => {
|
|
87
|
-
const digits = onlyDigits(value);
|
|
88
|
-
if (!digits && !required)
|
|
89
|
-
return null;
|
|
90
|
-
if (!digits && required)
|
|
91
|
-
return requiredMessage ?? "Informe o documento.";
|
|
92
|
-
if (digits.length <= 11) {
|
|
93
|
-
if (digits.length !== 11)
|
|
94
|
-
return lengthMessage ?? "CPF deve ter 11 dígitos.";
|
|
95
|
-
return isValidCpf(value) ? null : (invalidMessage ?? "CPF inválido.");
|
|
96
|
-
}
|
|
97
|
-
if (digits.length !== 14)
|
|
98
|
-
return lengthMessage ?? "CNPJ deve ter 14 dígitos.";
|
|
99
|
-
return isValidCnpj(value) ? null : (invalidMessage ?? "CNPJ inválido.");
|
|
100
|
-
});
|
|
101
|
-
const inputProps = applyMaskProps({ ...rest, mask: maskCpfCnpj }, "numeric");
|
|
102
|
-
const onBlur = inputProps.onBlur;
|
|
103
|
-
const shouldValidateOnBlur = validateOnBlur ?? true;
|
|
104
|
-
return (_jsx(SgInputText, { ...rest, error: error ?? internalError ?? undefined, inputProps: {
|
|
105
|
-
...inputProps,
|
|
106
|
-
onBlur: (event) => {
|
|
107
|
-
if (shouldValidateOnBlur)
|
|
108
|
-
runValidation(event.currentTarget.value);
|
|
109
|
-
onBlur?.(event);
|
|
110
|
-
}
|
|
111
|
-
} }));
|
|
112
|
-
}
|
|
113
|
-
export function SgInputCEP(props) {
|
|
114
|
-
const { required, requiredMessage, lengthMessage, validateOnBlur, error, ...rest } = props;
|
|
115
|
-
const { internalError, runValidation } = useValidationState(props, (value) => {
|
|
116
|
-
const digits = onlyDigits(value);
|
|
117
|
-
if (!digits && !required)
|
|
118
|
-
return null;
|
|
119
|
-
if (!digits && required)
|
|
120
|
-
return requiredMessage ?? "Informe o CEP.";
|
|
121
|
-
if (digits.length !== 8)
|
|
122
|
-
return lengthMessage ?? "CEP deve ter 8 dígitos.";
|
|
123
|
-
return null;
|
|
124
|
-
});
|
|
125
|
-
const inputProps = applyMaskProps({ ...rest, mask: maskCep }, "numeric");
|
|
126
|
-
const onBlur = inputProps.onBlur;
|
|
127
|
-
const shouldValidateOnBlur = validateOnBlur ?? true;
|
|
128
|
-
return (_jsx(SgInputText, { ...rest, error: error ?? internalError ?? undefined, inputProps: {
|
|
129
|
-
...inputProps,
|
|
130
|
-
onBlur: (event) => {
|
|
131
|
-
if (shouldValidateOnBlur)
|
|
132
|
-
runValidation(event.currentTarget.value);
|
|
133
|
-
onBlur?.(event);
|
|
134
|
-
}
|
|
135
|
-
} }));
|
|
136
|
-
}
|
|
137
|
-
export function SgInputFone(props) {
|
|
138
|
-
const { required, requiredMessage, lengthMessage, invalidMessage, validateOnBlur, error, ...rest } = props;
|
|
139
|
-
const { internalError, runValidation } = useValidationState(props, (value) => {
|
|
140
|
-
const digits = onlyDigits(value);
|
|
141
|
-
if (!digits && !required)
|
|
142
|
-
return null;
|
|
143
|
-
if (!digits && required)
|
|
144
|
-
return requiredMessage ?? "Informe o telefone.";
|
|
145
|
-
if (digits.length !== 10 && digits.length !== 11) {
|
|
146
|
-
return lengthMessage ?? invalidMessage ?? "Telefone inválido.";
|
|
147
|
-
}
|
|
148
|
-
return null;
|
|
149
|
-
});
|
|
150
|
-
const inputProps = applyMaskProps({ ...rest, mask: maskPhone }, "numeric");
|
|
151
|
-
const onBlur = inputProps.onBlur;
|
|
152
|
-
const shouldValidateOnBlur = validateOnBlur ?? true;
|
|
153
|
-
return (_jsx(SgInputText, { ...rest, error: error ?? internalError ?? undefined, inputProps: {
|
|
154
|
-
...inputProps,
|
|
155
|
-
onBlur: (event) => {
|
|
156
|
-
if (shouldValidateOnBlur)
|
|
157
|
-
runValidation(event.currentTarget.value);
|
|
158
|
-
onBlur?.(event);
|
|
159
|
-
}
|
|
160
|
-
} }));
|
|
161
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { type SgInputTextProps } from "./SgInputText";
|
|
3
|
-
export type ViaCepResponse = {
|
|
4
|
-
cep?: string;
|
|
5
|
-
logradouro?: string;
|
|
6
|
-
complemento?: string;
|
|
7
|
-
bairro?: string;
|
|
8
|
-
localidade?: string;
|
|
9
|
-
uf?: string;
|
|
10
|
-
ibge?: string;
|
|
11
|
-
gia?: string;
|
|
12
|
-
ddd?: string;
|
|
13
|
-
siafi?: string;
|
|
14
|
-
erro?: boolean;
|
|
15
|
-
};
|
|
16
|
-
export type SgInputCEPProps = Omit<SgInputTextProps, "inputProps" | "error"> & {
|
|
17
|
-
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
|
|
18
|
-
error?: string;
|
|
19
|
-
required?: boolean;
|
|
20
|
-
requiredMessage?: string;
|
|
21
|
-
lengthMessage?: string;
|
|
22
|
-
invalidMessage?: string;
|
|
23
|
-
validation?: (value: string) => string | null;
|
|
24
|
-
onValidation?: (message: string | null) => void;
|
|
25
|
-
validateOnBlur?: boolean;
|
|
26
|
-
validateWithViaCep?: boolean;
|
|
27
|
-
viaCepErrorMessage?: string;
|
|
28
|
-
viaCepFetch?: (cep: string) => Promise<ViaCepResponse>;
|
|
29
|
-
onViaCepResult?: (data: ViaCepResponse) => void;
|
|
30
|
-
onViaCepError?: (error: unknown) => void;
|
|
31
|
-
};
|
|
32
|
-
export declare function SgInputCEP(props: Readonly<SgInputCEPProps>): import("react/jsx-runtime").JSX.Element;
|
|
33
|
-
//# sourceMappingURL=SgInputCEP.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SgInputCEP.d.ts","sourceRoot":"","sources":["../../src/inputs/SgInputCEP.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAInE,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG;IAC7E,UAAU,CAAC,EAAE,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC9C,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IACvD,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C,CAAC;AAWF,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,2CAoI1D"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { SgInputText } from "./SgInputText";
|
|
5
|
-
import { maskCep } from "../masks";
|
|
6
|
-
import { t, useComponentsI18n } from "../i18n";
|
|
7
|
-
function onlyDigits(value) {
|
|
8
|
-
return value.replace(/\D/g, "");
|
|
9
|
-
}
|
|
10
|
-
const defaultViaCepFetch = async (cep) => {
|
|
11
|
-
const response = await fetch(`https://viacep.com.br/ws/${cep}/json/`);
|
|
12
|
-
return (await response.json());
|
|
13
|
-
};
|
|
14
|
-
export function SgInputCEP(props) {
|
|
15
|
-
const i18n = useComponentsI18n();
|
|
16
|
-
const { required, requiredMessage, lengthMessage, invalidMessage, validateOnBlur, error, validation, onClear, inputProps, validateWithViaCep, viaCepErrorMessage, viaCepFetch, onViaCepResult, onViaCepError, ...rest } = props;
|
|
17
|
-
const [internalError, setInternalError] = React.useState(null);
|
|
18
|
-
const [hasInteracted, setHasInteracted] = React.useState(false);
|
|
19
|
-
const lastValidatedCepRef = React.useRef(null);
|
|
20
|
-
const lastViaCepErroRef = React.useRef(null);
|
|
21
|
-
const runValidation = React.useCallback(async (value) => {
|
|
22
|
-
const digits = onlyDigits(value);
|
|
23
|
-
if (!digits && !required) {
|
|
24
|
-
setInternalError(null);
|
|
25
|
-
props.onValidation?.(null);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (!digits && required) {
|
|
29
|
-
const message = requiredMessage ?? t(i18n, "components.inputs.required");
|
|
30
|
-
setInternalError(message);
|
|
31
|
-
props.onValidation?.(message);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (validation) {
|
|
35
|
-
const message = validation(value);
|
|
36
|
-
if (message) {
|
|
37
|
-
setInternalError(message);
|
|
38
|
-
props.onValidation?.(message);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (digits.length !== 8) {
|
|
43
|
-
const message = lengthMessage ?? t(i18n, "components.inputs.cep.length");
|
|
44
|
-
setInternalError(message);
|
|
45
|
-
props.onValidation?.(message);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (validateWithViaCep) {
|
|
49
|
-
if (lastValidatedCepRef.current === digits) {
|
|
50
|
-
const message = viaCepErrorMessage ?? invalidMessage ?? t(i18n, "components.inputs.cep.invalid");
|
|
51
|
-
if (lastViaCepErroRef.current) {
|
|
52
|
-
setInternalError(message);
|
|
53
|
-
props.onValidation?.(message);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
setInternalError(null);
|
|
57
|
-
props.onValidation?.(null);
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
const checker = viaCepFetch ?? defaultViaCepFetch;
|
|
63
|
-
const data = await checker(digits);
|
|
64
|
-
lastValidatedCepRef.current = digits;
|
|
65
|
-
lastViaCepErroRef.current = Boolean(data?.erro);
|
|
66
|
-
onViaCepResult?.(data);
|
|
67
|
-
if (data?.erro) {
|
|
68
|
-
const message = viaCepErrorMessage ?? invalidMessage ?? t(i18n, "components.inputs.cep.invalid");
|
|
69
|
-
setInternalError(message);
|
|
70
|
-
props.onValidation?.(message);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
onViaCepError?.(err);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
setInternalError(null);
|
|
79
|
-
props.onValidation?.(null);
|
|
80
|
-
}, [
|
|
81
|
-
i18n,
|
|
82
|
-
invalidMessage,
|
|
83
|
-
lengthMessage,
|
|
84
|
-
onViaCepError,
|
|
85
|
-
onViaCepResult,
|
|
86
|
-
props,
|
|
87
|
-
required,
|
|
88
|
-
requiredMessage,
|
|
89
|
-
validateWithViaCep,
|
|
90
|
-
validation,
|
|
91
|
-
viaCepErrorMessage,
|
|
92
|
-
viaCepFetch
|
|
93
|
-
]);
|
|
94
|
-
const mergedInputProps = {
|
|
95
|
-
...inputProps,
|
|
96
|
-
inputMode: inputProps?.inputMode ?? "numeric",
|
|
97
|
-
onChange: (event) => {
|
|
98
|
-
setHasInteracted(true);
|
|
99
|
-
event.target.value = maskCep(event.target.value);
|
|
100
|
-
runValidation(event.currentTarget.value);
|
|
101
|
-
inputProps?.onChange?.(event);
|
|
102
|
-
},
|
|
103
|
-
onBlur: (event) => {
|
|
104
|
-
if ((validateOnBlur ?? true) || hasInteracted) {
|
|
105
|
-
runValidation(event.currentTarget.value);
|
|
106
|
-
}
|
|
107
|
-
inputProps?.onBlur?.(event);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
return (_jsx(SgInputText, { ...rest, maxLength: rest.maxLength ?? 10, error: error ?? internalError ?? undefined, textInputType: props.textInputType ?? "numeric", onClear: () => {
|
|
111
|
-
setInternalError(null);
|
|
112
|
-
props.onValidation?.(null);
|
|
113
|
-
onClear?.();
|
|
114
|
-
lastValidatedCepRef.current = null;
|
|
115
|
-
lastViaCepErroRef.current = null;
|
|
116
|
-
}, inputProps: mergedInputProps }));
|
|
117
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { type SgInputTextProps } from "./SgInputText";
|
|
3
|
-
export type SgInputFoneProps = Omit<SgInputTextProps, "inputProps" | "error"> & {
|
|
4
|
-
inputProps: React.InputHTMLAttributes<HTMLInputElement>;
|
|
5
|
-
error?: string;
|
|
6
|
-
required?: boolean;
|
|
7
|
-
requiredMessage?: string;
|
|
8
|
-
lengthMessage?: string;
|
|
9
|
-
invalidMessage?: string;
|
|
10
|
-
validation?: (value: string) => string | null;
|
|
11
|
-
onValidation?: (message: string | null) => void;
|
|
12
|
-
validateOnBlur?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export declare function SgInputFone(props: SgInputFoneProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
//# sourceMappingURL=SgInputFone.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SgInputFone.d.ts","sourceRoot":"","sources":["../../src/inputs/SgInputFone.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGnE,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG;IAC9E,UAAU,EAAE,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC9C,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAMF,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CA+DlD"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { SgInputText } from "./SgInputText";
|
|
5
|
-
import { maskPhone } from "../masks";
|
|
6
|
-
function onlyDigits(value) {
|
|
7
|
-
return value.replace(/\D/g, "");
|
|
8
|
-
}
|
|
9
|
-
export function SgInputFone(props) {
|
|
10
|
-
const { required, requiredMessage, lengthMessage, invalidMessage, validateOnBlur, error, validation, ...rest } = props;
|
|
11
|
-
const [internalError, setInternalError] = React.useState(null);
|
|
12
|
-
const runValidation = React.useCallback((value) => {
|
|
13
|
-
const digits = onlyDigits(value);
|
|
14
|
-
if (!digits && !required) {
|
|
15
|
-
setInternalError(null);
|
|
16
|
-
props.onValidation?.(null);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (!digits && required) {
|
|
20
|
-
const message = requiredMessage ?? "Campo obrigatório ";
|
|
21
|
-
setInternalError(message);
|
|
22
|
-
props.onValidation?.(message);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (validation) {
|
|
26
|
-
const message = validation(value);
|
|
27
|
-
if (message) {
|
|
28
|
-
setInternalError(message);
|
|
29
|
-
props.onValidation?.(message);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (digits.length !== 10 && digits.length !== 11) {
|
|
34
|
-
const message = lengthMessage ?? invalidMessage ?? "Telefone inválido.";
|
|
35
|
-
setInternalError(message);
|
|
36
|
-
props.onValidation?.(message);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
setInternalError(null);
|
|
40
|
-
props.onValidation?.(null);
|
|
41
|
-
}, [required, requiredMessage, lengthMessage, invalidMessage, validation, props]);
|
|
42
|
-
const inputProps = {
|
|
43
|
-
...rest.inputProps,
|
|
44
|
-
inputMode: rest.inputProps.inputMode ?? "numeric",
|
|
45
|
-
onChange: (event) => {
|
|
46
|
-
event.target.value = maskPhone(event.target.value);
|
|
47
|
-
rest.inputProps.onChange?.(event);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const onBlur = inputProps.onBlur;
|
|
51
|
-
const shouldValidateOnBlur = validateOnBlur ?? true;
|
|
52
|
-
return (_jsx(SgInputText, { ...rest, error: error ?? internalError ?? undefined, inputProps: {
|
|
53
|
-
...inputProps,
|
|
54
|
-
onBlur: (event) => {
|
|
55
|
-
if (shouldValidateOnBlur)
|
|
56
|
-
runValidation(event.currentTarget.value);
|
|
57
|
-
onBlur?.(event);
|
|
58
|
-
}
|
|
59
|
-
} }));
|
|
60
|
-
}
|