@orbe-agro/client-core 5.5.75 → 5.5.76
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/@types/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericNumberFormSectionPrice.d.ts.map +1 -1
- package/dist/@types/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericStringFormSection.d.ts.map +1 -1
- package/dist/@types/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.d.ts +14 -0
- package/dist/@types/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.d.ts.map +1 -0
- package/dist/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericNumberFormSectionPrice.js.map +1 -1
- package/dist/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericStringFormSection.js.map +1 -1
- package/dist/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.js +98 -0
- package/dist/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.js.map +1 -0
- package/lib/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.tsx +117 -0
- package/package.json +1 -1
- /package/dist/@types/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericNumberFormSectionPrice.d.ts +0 -0
- /package/dist/@types/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericStringFormSection.d.ts +0 -0
- /package/dist/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericNumberFormSectionPrice.js +0 -0
- /package/dist/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericStringFormSection.js +0 -0
- /package/lib/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericNumberFormSectionPrice.tsx +0 -0
- /package/lib/base/components/forms/{GenericFomrsSetValue → GenericFormsSetValue}/GenericStringFormSection.tsx +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericNumberFormSectionPrice.d.ts","sourceRoot":"","sources":["../../../../../../lib/base/components/forms/
|
|
1
|
+
{"version":3,"file":"GenericNumberFormSectionPrice.d.ts","sourceRoot":"","sources":["../../../../../../lib/base/components/forms/GenericFormsSetValue/GenericNumberFormSectionPrice.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAc,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE/D,KAAK,uBAAuB,CAAC,CAAC,SAAS,WAAW,IAC9C,qBAAqB,CAAC,CAAC,CAAC,GAAG;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAEL,iBAAS,6BAA6B,CAAC,CAAC,SAAS,WAAW,EAAE,EAC1D,OAAO,EACP,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,KAAK,EACL,YAAgB,GACnB,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAqC5B;AAED,eAAe,6BAA6B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericStringFormSection.d.ts","sourceRoot":"","sources":["../../../../../../lib/base/components/forms/
|
|
1
|
+
{"version":3,"file":"GenericStringFormSection.d.ts","sourceRoot":"","sources":["../../../../../../lib/base/components/forms/GenericFormsSetValue/GenericStringFormSection.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAc,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE/D,KAAK,uBAAuB,CAAC,CAAC,SAAS,WAAW,IAC9C,qBAAqB,CAAC,CAAC,CAAC,GAAG;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;CACtB,CAAA;AAEL,iBAAS,wBAAwB,CAAC,CAAC,SAAS,WAAW,EAAE,EACrD,OAAO,EACP,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,KAAK,EACR,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAuB5B;AAED,eAAe,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IFormSectionBaseProps } from '@base/@types/forms';
|
|
2
|
+
import { FieldValues, Path } from 'react-hook-form';
|
|
3
|
+
type GeneralFormSectionProps<T extends FieldValues> = IFormSectionBaseProps<T> & {
|
|
4
|
+
name: Path<T>;
|
|
5
|
+
label: string;
|
|
6
|
+
placeholder: string;
|
|
7
|
+
decimalScale?: number;
|
|
8
|
+
prefix?: string;
|
|
9
|
+
thousandSeparator?: string;
|
|
10
|
+
decimalSeparator?: string;
|
|
11
|
+
};
|
|
12
|
+
declare function GenericNumberFormSectionDecimalFirst<T extends FieldValues>({ control, errors, isView, name, label, placeholder, decimalScale, prefix, }: GeneralFormSectionProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export default GenericNumberFormSectionDecimalFirst;
|
|
14
|
+
//# sourceMappingURL=GenericNumberFormSectionDecimalFirst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericNumberFormSectionDecimalFirst.d.ts","sourceRoot":"","sources":["../../../../../../lib/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,OAAO,EAAc,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAG/D,KAAK,uBAAuB,CAAC,CAAC,SAAS,WAAW,IAC9C,qBAAqB,CAAC,CAAC,CAAC,GAAG;IACvB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAEL,iBAAS,oCAAoC,CAAC,CAAC,SAAS,WAAW,EAAE,EACjE,OAAO,EACP,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,YAAgB,EAChB,MAAW,GACd,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAwF5B;AAED,eAAe,oCAAoC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericNumberFormSectionPrice.js","sources":["../../../../../lib/base/components/forms/
|
|
1
|
+
{"version":3,"file":"GenericNumberFormSectionPrice.js","sources":["../../../../../lib/base/components/forms/GenericFormsSetValue/GenericNumberFormSectionPrice.tsx"],"sourcesContent":["import { NumericInput } from '@/components/shared'\nimport { FormItem } from '@/components/ui'\nimport { IFormSectionBaseProps } from '@base/@types/forms'\nimport { Controller, FieldValues, Path } from 'react-hook-form'\n\ntype GeneralFormSectionProps<T extends FieldValues> =\n IFormSectionBaseProps<T> & {\n value: number\n name: Path<T>\n label: string\n placeholder: string\n decimalScale?: number\n }\n\nfunction GenericNumberFormSectionPrice<T extends FieldValues>({\n control,\n errors,\n isView,\n name,\n label,\n placeholder,\n value,\n decimalScale = 2,\n}: GeneralFormSectionProps<T>) {\n return (\n <>\n <FormItem\n label={label}\n invalid={Boolean(errors?.[name])}\n errorMessage={errors?.[name]?.message as string}\n >\n <Controller\n name={name}\n control={control}\n render={({ field }) => (\n <NumericInput\n thousandSeparator=\".\"\n decimalSeparator=\",\"\n prefix=\"R$ \"\n type=\"text\"\n autoComplete=\"off\"\n placeholder=\"R$ 0,00\"\n displayType=\"input\"\n disabled={isView}\n decimalScale={decimalScale}\n fixedDecimalScale\n // importante: não espalhar {...field}, porque ele injeta onChange errado\n value={field.value ?? 0}\n onValueChange={(values) => {\n field.onChange(values.floatValue ?? 0) // só o float vai para o form\n }}\n // se precisar de blur/focus, pega manualmente\n onBlur={field.onBlur}\n name={field.name}\n />\n )}\n />\n </FormItem>\n </>\n )\n}\n\nexport default GenericNumberFormSectionPrice\n"],"names":[],"mappings":";;;;;;AAcA,SAAS,8BAAqD;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AACnB,GAA+B;AAC3B,SACI,oBAAA,UAAA,EACI,UAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG;AAAA,MACA,SAAS,QAAQ,SAAS,IAAI,CAAC;AAAA,MAC/B,cAAc,SAAS,IAAI,GAAG;AAAA,MAE9B,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACG;AAAA,UACA;AAAA,UACA,QAAQ,CAAC,EAAE,MAAA,MACP;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,mBAAkB;AAAA,cAClB,kBAAiB;AAAA,cACjB,QAAO;AAAA,cACP,MAAK;AAAA,cACL,cAAa;AAAA,cACb,aAAY;AAAA,cACZ,aAAY;AAAA,cACZ,UAAU;AAAA,cACV;AAAA,cACA,mBAAiB;AAAA,cAEjB,OAAO,MAAM,SAAS;AAAA,cACtB,eAAe,CAAC,WAAW;AACvB,sBAAM,SAAS,OAAO,cAAc,CAAC;AAAA,cACzC;AAAA,cAEA,QAAQ,MAAM;AAAA,cACd,MAAM,MAAM;AAAA,YAAA;AAAA,UAAA;AAAA,QAChB;AAAA,MAAA;AAAA,IAER;AAAA,EAAA,GAER;AAER;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericStringFormSection.js","sources":["../../../../../lib/base/components/forms/
|
|
1
|
+
{"version":3,"file":"GenericStringFormSection.js","sources":["../../../../../lib/base/components/forms/GenericFormsSetValue/GenericStringFormSection.tsx"],"sourcesContent":["import { FormItem, Input } from '@/components/ui'\nimport { IFormSectionBaseProps } from '@base/@types/forms'\nimport { Controller, FieldValues, Path } from 'react-hook-form'\n\ntype GeneralFormSectionProps<T extends FieldValues> =\n IFormSectionBaseProps<T> & {\n value: string\n name: Path<T>\n label: string\n placeholder: string\n }\n\nfunction GenericStringFormSection<T extends FieldValues>({\n control,\n errors,\n isView,\n name,\n label,\n placeholder,\n value\n}: GeneralFormSectionProps<T>) {\n return (\n <FormItem\n label={label}\n invalid={Boolean(errors?.[name])}\n errorMessage={errors?.[name]?.message as string}\n >\n <Controller\n name={name}\n control={control}\n render={({ field }) => (\n <Input\n required\n disabled={isView}\n type=\"text\"\n placeholder={placeholder}\n {...field}\n value={value}\n />\n )}\n />\n </FormItem>\n )\n}\n\nexport default GenericStringFormSection"],"names":[],"mappings":";;;;;AAYA,SAAS,yBAAgD;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GAA+B;AAC3B,SACI;AAAA,IAAC;AAAA,IAAA;AAAA,MACG;AAAA,MACA,SAAS,QAAQ,SAAS,IAAI,CAAC;AAAA,MAC/B,cAAc,SAAS,IAAI,GAAG;AAAA,MAE9B,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACG;AAAA,UACA;AAAA,UACA,QAAQ,CAAC,EAAE,MAAA,MACP;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,UAAQ;AAAA,cACR,UAAU;AAAA,cACV,MAAK;AAAA,cACL;AAAA,cACC,GAAG;AAAA,cACJ;AAAA,YAAA;AAAA,UAAA;AAAA,QACJ;AAAA,MAAA;AAAA,IAER;AAAA,EAAA;AAGZ;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "../../../../@ecme/components/ui/index.js";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
import { useState, useCallback, useEffect } from "react";
|
|
5
|
+
import FormItem from "../../../../@ecme/components/ui/Form/FormItem.js";
|
|
6
|
+
import Input from "../../../../@ecme/components/ui/Input/Input.js";
|
|
7
|
+
function GenericNumberFormSectionDecimalFirst({
|
|
8
|
+
control,
|
|
9
|
+
errors,
|
|
10
|
+
isView,
|
|
11
|
+
name,
|
|
12
|
+
label,
|
|
13
|
+
placeholder,
|
|
14
|
+
decimalScale = 2,
|
|
15
|
+
prefix = ""
|
|
16
|
+
}) {
|
|
17
|
+
const [displayValue, setDisplayValue] = useState("");
|
|
18
|
+
const formatValue = useCallback((input, decimals) => {
|
|
19
|
+
const numbersOnly = input.replace(/\D/g, "");
|
|
20
|
+
if (numbersOnly === "") {
|
|
21
|
+
return { display: "", value: 0 };
|
|
22
|
+
}
|
|
23
|
+
const numericValue = parseInt(numbersOnly, 10) / Math.pow(10, decimals);
|
|
24
|
+
const formatted = new Intl.NumberFormat("pt-BR", {
|
|
25
|
+
minimumFractionDigits: decimals,
|
|
26
|
+
maximumFractionDigits: decimals
|
|
27
|
+
}).format(numericValue);
|
|
28
|
+
return {
|
|
29
|
+
display: `${prefix}${formatted}`,
|
|
30
|
+
value: numericValue
|
|
31
|
+
};
|
|
32
|
+
}, [prefix]);
|
|
33
|
+
const handleInputChange = useCallback((inputValue, onChange, decimals) => {
|
|
34
|
+
const { display, value } = formatValue(inputValue, decimals);
|
|
35
|
+
setDisplayValue(display);
|
|
36
|
+
onChange(value);
|
|
37
|
+
}, [formatValue]);
|
|
38
|
+
const handleKeyDown = useCallback((e) => {
|
|
39
|
+
const allowedKeys = [
|
|
40
|
+
"Backspace",
|
|
41
|
+
"Delete",
|
|
42
|
+
"Tab",
|
|
43
|
+
"Escape",
|
|
44
|
+
"Enter",
|
|
45
|
+
"ArrowLeft",
|
|
46
|
+
"ArrowRight",
|
|
47
|
+
"ArrowUp",
|
|
48
|
+
"ArrowDown"
|
|
49
|
+
];
|
|
50
|
+
if (allowedKeys.includes(e.key) || e.key >= "0" && e.key <= "9") {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
}, []);
|
|
55
|
+
return /* @__PURE__ */ jsx(
|
|
56
|
+
FormItem,
|
|
57
|
+
{
|
|
58
|
+
label,
|
|
59
|
+
invalid: Boolean(errors?.[name]),
|
|
60
|
+
errorMessage: errors?.[name]?.message,
|
|
61
|
+
children: /* @__PURE__ */ jsx(
|
|
62
|
+
Controller,
|
|
63
|
+
{
|
|
64
|
+
name,
|
|
65
|
+
control,
|
|
66
|
+
render: ({ field }) => {
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (field.value !== void 0 && field.value !== null && displayValue === "") {
|
|
69
|
+
const valueAsIntString = Math.round(field.value * Math.pow(10, decimalScale)).toString();
|
|
70
|
+
const { display } = formatValue(valueAsIntString, decimalScale);
|
|
71
|
+
setDisplayValue(display);
|
|
72
|
+
}
|
|
73
|
+
}, [field.value, decimalScale, formatValue]);
|
|
74
|
+
return /* @__PURE__ */ jsx(
|
|
75
|
+
Input,
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
autoComplete: "off",
|
|
79
|
+
placeholder,
|
|
80
|
+
value: displayValue,
|
|
81
|
+
disabled: isView,
|
|
82
|
+
onChange: (e) => {
|
|
83
|
+
handleInputChange(e.target.value, field.onChange, decimalScale);
|
|
84
|
+
},
|
|
85
|
+
onKeyDown: handleKeyDown,
|
|
86
|
+
onBlur: field.onBlur
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
GenericNumberFormSectionDecimalFirst as default
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=GenericNumberFormSectionDecimalFirst.js.map
|
package/dist/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericNumberFormSectionDecimalFirst.js","sources":["../../../../../lib/base/components/forms/NumberFormVariant/GenericNumberFormSectionDecimalFirst.tsx"],"sourcesContent":["import { FormItem } from '@/components/ui'\nimport { IFormSectionBaseProps } from '@base/@types/forms'\nimport { Input } from '@/components/ui'\nimport { Controller, FieldValues, Path } from 'react-hook-form'\nimport { useState, useCallback, useEffect } from 'react'\n\ntype GeneralFormSectionProps<T extends FieldValues> =\n IFormSectionBaseProps<T> & {\n name: Path<T>\n label: string\n placeholder: string\n decimalScale?: number\n prefix?: string\n thousandSeparator?: string\n decimalSeparator?: string\n }\n\nfunction GenericNumberFormSectionDecimalFirst<T extends FieldValues>({\n control,\n errors,\n isView,\n name,\n label,\n placeholder,\n decimalScale = 2,\n prefix = '',\n}: GeneralFormSectionProps<T>) {\n const [displayValue, setDisplayValue] = useState('')\n\n // Função core de formatação\n const formatValue = useCallback((input: string, decimals: number): { display: string; value: number } => {\n // Remove tudo que não é dígito\n const numbersOnly = input.replace(/\\D/g, '')\n \n if (numbersOnly === '') {\n return { display: '', value: 0 }\n }\n\n // Converte para número real (ex: \"50002\" com 5 decimais vira 0.50002)\n const numericValue = parseInt(numbersOnly, 10) / Math.pow(10, decimals)\n \n // Formata usando o padrão brasileiro\n const formatted = new Intl.NumberFormat('pt-BR', {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n }).format(numericValue)\n\n return { \n display: `${prefix}${formatted}`, \n value: numericValue \n }\n }, [prefix])\n\n const handleInputChange = useCallback((\n inputValue: string,\n onChange: (value: number) => void,\n decimals: number\n ) => {\n const { display, value } = formatValue(inputValue, decimals)\n setDisplayValue(display)\n onChange(value)\n }, [formatValue])\n\n const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {\n const allowedKeys = [\n 'Backspace', 'Delete', 'Tab', 'Escape', 'Enter',\n 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'\n ]\n \n if (allowedKeys.includes(e.key) || (e.key >= '0' && e.key <= '9')) {\n return\n }\n \n e.preventDefault()\n }, [])\n\n return (\n <FormItem\n label={label}\n invalid={Boolean(errors?.[name])}\n errorMessage={errors?.[name]?.message as string}\n >\n <Controller\n name={name}\n control={control}\n render={({ field }) => {\n // Sincronização inicial: converte o valor numérico do banco para a máscara\n useEffect(() => {\n if (field.value !== undefined && field.value !== null && displayValue === '') {\n // Transforma o número em string de dígitos puros respeitando a escala\n const valueAsIntString = Math.round(field.value * Math.pow(10, decimalScale)).toString()\n const { display } = formatValue(valueAsIntString, decimalScale)\n setDisplayValue(display)\n }\n }, [field.value, decimalScale, formatValue])\n\n return (\n <Input\n type=\"text\"\n autoComplete=\"off\"\n placeholder={placeholder}\n value={displayValue}\n disabled={isView}\n onChange={(e) => {\n handleInputChange(e.target.value, field.onChange, decimalScale)\n }}\n onKeyDown={handleKeyDown}\n onBlur={field.onBlur}\n />\n )\n }}\n />\n </FormItem>\n )\n}\n\nexport default GenericNumberFormSectionDecimalFirst"],"names":[],"mappings":";;;;;;AAiBA,SAAS,qCAA4D;AAAA,EACjE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,SAAS;AACb,GAA+B;AAC3B,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,EAAE;AAGnD,QAAM,cAAc,YAAY,CAAC,OAAe,aAAyD;AAErG,UAAM,cAAc,MAAM,QAAQ,OAAO,EAAE;AAE3C,QAAI,gBAAgB,IAAI;AACpB,aAAO,EAAE,SAAS,IAAI,OAAO,EAAA;AAAA,IACjC;AAGA,UAAM,eAAe,SAAS,aAAa,EAAE,IAAI,KAAK,IAAI,IAAI,QAAQ;AAGtE,UAAM,YAAY,IAAI,KAAK,aAAa,SAAS;AAAA,MAC7C,uBAAuB;AAAA,MACvB,uBAAuB;AAAA,IAAA,CAC1B,EAAE,OAAO,YAAY;AAEtB,WAAO;AAAA,MACH,SAAS,GAAG,MAAM,GAAG,SAAS;AAAA,MAC9B,OAAO;AAAA,IAAA;AAAA,EAEf,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,oBAAoB,YAAY,CAClC,YACA,UACA,aACC;AACD,UAAM,EAAE,SAAS,MAAA,IAAU,YAAY,YAAY,QAAQ;AAC3D,oBAAgB,OAAO;AACvB,aAAS,KAAK;AAAA,EAClB,GAAG,CAAC,WAAW,CAAC;AAEhB,QAAM,gBAAgB,YAAY,CAAC,MAA6C;AAC5E,UAAM,cAAc;AAAA,MAChB;AAAA,MAAa;AAAA,MAAU;AAAA,MAAO;AAAA,MAAU;AAAA,MACxC;AAAA,MAAa;AAAA,MAAc;AAAA,MAAW;AAAA,IAAA;AAG1C,QAAI,YAAY,SAAS,EAAE,GAAG,KAAM,EAAE,OAAO,OAAO,EAAE,OAAO,KAAM;AAC/D;AAAA,IACJ;AAEA,MAAE,eAAA;AAAA,EACN,GAAG,CAAA,CAAE;AAEL,SACI;AAAA,IAAC;AAAA,IAAA;AAAA,MACG;AAAA,MACA,SAAS,QAAQ,SAAS,IAAI,CAAC;AAAA,MAC/B,cAAc,SAAS,IAAI,GAAG;AAAA,MAE9B,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACG;AAAA,UACA;AAAA,UACA,QAAQ,CAAC,EAAE,YAAY;AAEnB,sBAAU,MAAM;AACZ,kBAAI,MAAM,UAAU,UAAa,MAAM,UAAU,QAAQ,iBAAiB,IAAI;AAE1E,sBAAM,mBAAmB,KAAK,MAAM,MAAM,QAAQ,KAAK,IAAI,IAAI,YAAY,CAAC,EAAE,SAAA;AAC9E,sBAAM,EAAE,QAAA,IAAY,YAAY,kBAAkB,YAAY;AAC9D,gCAAgB,OAAO;AAAA,cAC3B;AAAA,YACJ,GAAG,CAAC,MAAM,OAAO,cAAc,WAAW,CAAC;AAE3C,mBACI;AAAA,cAAC;AAAA,cAAA;AAAA,gBACG,MAAK;AAAA,gBACL,cAAa;AAAA,gBACb;AAAA,gBACA,OAAO;AAAA,gBACP,UAAU;AAAA,gBACV,UAAU,CAAC,MAAM;AACb,oCAAkB,EAAE,OAAO,OAAO,MAAM,UAAU,YAAY;AAAA,gBAClE;AAAA,gBACA,WAAW;AAAA,gBACX,QAAQ,MAAM;AAAA,cAAA;AAAA,YAAA;AAAA,UAG1B;AAAA,QAAA;AAAA,MAAA;AAAA,IACJ;AAAA,EAAA;AAGZ;"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { FormItem } from '@/components/ui'
|
|
2
|
+
import { IFormSectionBaseProps } from '@base/@types/forms'
|
|
3
|
+
import { Input } from '@/components/ui'
|
|
4
|
+
import { Controller, FieldValues, Path } from 'react-hook-form'
|
|
5
|
+
import { useState, useCallback, useEffect } from 'react'
|
|
6
|
+
|
|
7
|
+
type GeneralFormSectionProps<T extends FieldValues> =
|
|
8
|
+
IFormSectionBaseProps<T> & {
|
|
9
|
+
name: Path<T>
|
|
10
|
+
label: string
|
|
11
|
+
placeholder: string
|
|
12
|
+
decimalScale?: number
|
|
13
|
+
prefix?: string
|
|
14
|
+
thousandSeparator?: string
|
|
15
|
+
decimalSeparator?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function GenericNumberFormSectionDecimalFirst<T extends FieldValues>({
|
|
19
|
+
control,
|
|
20
|
+
errors,
|
|
21
|
+
isView,
|
|
22
|
+
name,
|
|
23
|
+
label,
|
|
24
|
+
placeholder,
|
|
25
|
+
decimalScale = 2,
|
|
26
|
+
prefix = '',
|
|
27
|
+
}: GeneralFormSectionProps<T>) {
|
|
28
|
+
const [displayValue, setDisplayValue] = useState('')
|
|
29
|
+
|
|
30
|
+
// Função core de formatação
|
|
31
|
+
const formatValue = useCallback((input: string, decimals: number): { display: string; value: number } => {
|
|
32
|
+
// Remove tudo que não é dígito
|
|
33
|
+
const numbersOnly = input.replace(/\D/g, '')
|
|
34
|
+
|
|
35
|
+
if (numbersOnly === '') {
|
|
36
|
+
return { display: '', value: 0 }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Converte para número real (ex: "50002" com 5 decimais vira 0.50002)
|
|
40
|
+
const numericValue = parseInt(numbersOnly, 10) / Math.pow(10, decimals)
|
|
41
|
+
|
|
42
|
+
// Formata usando o padrão brasileiro
|
|
43
|
+
const formatted = new Intl.NumberFormat('pt-BR', {
|
|
44
|
+
minimumFractionDigits: decimals,
|
|
45
|
+
maximumFractionDigits: decimals,
|
|
46
|
+
}).format(numericValue)
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
display: `${prefix}${formatted}`,
|
|
50
|
+
value: numericValue
|
|
51
|
+
}
|
|
52
|
+
}, [prefix])
|
|
53
|
+
|
|
54
|
+
const handleInputChange = useCallback((
|
|
55
|
+
inputValue: string,
|
|
56
|
+
onChange: (value: number) => void,
|
|
57
|
+
decimals: number
|
|
58
|
+
) => {
|
|
59
|
+
const { display, value } = formatValue(inputValue, decimals)
|
|
60
|
+
setDisplayValue(display)
|
|
61
|
+
onChange(value)
|
|
62
|
+
}, [formatValue])
|
|
63
|
+
|
|
64
|
+
const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
65
|
+
const allowedKeys = [
|
|
66
|
+
'Backspace', 'Delete', 'Tab', 'Escape', 'Enter',
|
|
67
|
+
'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
if (allowedKeys.includes(e.key) || (e.key >= '0' && e.key <= '9')) {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
e.preventDefault()
|
|
75
|
+
}, [])
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<FormItem
|
|
79
|
+
label={label}
|
|
80
|
+
invalid={Boolean(errors?.[name])}
|
|
81
|
+
errorMessage={errors?.[name]?.message as string}
|
|
82
|
+
>
|
|
83
|
+
<Controller
|
|
84
|
+
name={name}
|
|
85
|
+
control={control}
|
|
86
|
+
render={({ field }) => {
|
|
87
|
+
// Sincronização inicial: converte o valor numérico do banco para a máscara
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (field.value !== undefined && field.value !== null && displayValue === '') {
|
|
90
|
+
// Transforma o número em string de dígitos puros respeitando a escala
|
|
91
|
+
const valueAsIntString = Math.round(field.value * Math.pow(10, decimalScale)).toString()
|
|
92
|
+
const { display } = formatValue(valueAsIntString, decimalScale)
|
|
93
|
+
setDisplayValue(display)
|
|
94
|
+
}
|
|
95
|
+
}, [field.value, decimalScale, formatValue])
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Input
|
|
99
|
+
type="text"
|
|
100
|
+
autoComplete="off"
|
|
101
|
+
placeholder={placeholder}
|
|
102
|
+
value={displayValue}
|
|
103
|
+
disabled={isView}
|
|
104
|
+
onChange={(e) => {
|
|
105
|
+
handleInputChange(e.target.value, field.onChange, decimalScale)
|
|
106
|
+
}}
|
|
107
|
+
onKeyDown={handleKeyDown}
|
|
108
|
+
onBlur={field.onBlur}
|
|
109
|
+
/>
|
|
110
|
+
)
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
</FormItem>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default GenericNumberFormSectionDecimalFirst
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|