linear-react-components-ui 2.0.0-beta.6 → 2.0.0-beta.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.
|
@@ -19,8 +19,7 @@ const NumberField = (props) => {
|
|
|
19
19
|
const numberInputRef = useRef(null);
|
|
20
20
|
const {
|
|
21
21
|
value: maskedValue,
|
|
22
|
-
setValue: setMaskedValue
|
|
23
|
-
unmaskedValue
|
|
22
|
+
setValue: setMaskedValue
|
|
24
23
|
} = useIMask({
|
|
25
24
|
mask: Number,
|
|
26
25
|
max,
|
|
@@ -47,7 +46,7 @@ const NumberField = (props) => {
|
|
|
47
46
|
});
|
|
48
47
|
const handleBlur = (event_0) => {
|
|
49
48
|
if (!_.isNil(min)) {
|
|
50
|
-
const currentValue = parseInt(
|
|
49
|
+
const currentValue = parseInt(maskedValue, 10);
|
|
51
50
|
if (_.isNaN(currentValue) || currentValue < min) {
|
|
52
51
|
setMaskedValue(_.toString(min));
|
|
53
52
|
props?.onChange?.({
|
|
@@ -63,8 +62,8 @@ const NumberField = (props) => {
|
|
|
63
62
|
props?.onBlur?.(event_0);
|
|
64
63
|
};
|
|
65
64
|
useEffect(() => {
|
|
66
|
-
const
|
|
67
|
-
if (!_.isNil(props?.value) && (!_.isEqual(props?.value,
|
|
65
|
+
const floatMaskedValue = Number(maskedValue || "0");
|
|
66
|
+
if (!_.isNil(props?.value) && (!_.isEqual(props?.value, floatMaskedValue) || _.isEqual(props?.value, 0))) {
|
|
68
67
|
setMaskedValue(_.toString(props?.value));
|
|
69
68
|
}
|
|
70
69
|
}, [props?.value]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/lib/inputs/number/index.tsx"],"sourcesContent":["import '../../assets/styles/numbers.scss';\n\nimport React, { useEffect, useRef } from 'react';\nimport _ from 'lodash';\nimport { useIMask } from 'react-imask';\nimport DecimalField from './Decimal';\nimport CurrencyField from './Currency';\nimport { INumberFieldProps } from './types';\nimport InputTextBase from '../base/InputTextBase';\nimport { CustomInputEvent } from '../base/types';\nimport { mergeRefs } from '../../form2/helpers';\n\nconst NumberField = (props: INumberFieldProps) => {\n const {\n textAlign = 'left', themePopover = 'light', popoverAlign = 'left', min = undefined, \n max = undefined, inputRef = undefined,\n } = props;\n const numberInputRef = useRef<HTMLInputElement | null>(null);\n\n const { value: maskedValue, setValue: setMaskedValue
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/lib/inputs/number/index.tsx"],"sourcesContent":["import '../../assets/styles/numbers.scss';\n\nimport React, { useEffect, useRef } from 'react';\nimport _ from 'lodash';\nimport { useIMask } from 'react-imask';\nimport DecimalField from './Decimal';\nimport CurrencyField from './Currency';\nimport { INumberFieldProps } from './types';\nimport InputTextBase from '../base/InputTextBase';\nimport { CustomInputEvent } from '../base/types';\nimport { mergeRefs } from '../../form2/helpers';\n\nconst NumberField = (props: INumberFieldProps) => {\n const {\n textAlign = 'left', themePopover = 'light', popoverAlign = 'left', min = undefined, \n max = undefined, inputRef = undefined,\n } = props;\n const numberInputRef = useRef<HTMLInputElement | null>(null);\n\n const { value: maskedValue, setValue: setMaskedValue } = useIMask({\n mask: Number,\n max,\n min,\n scale: 0,\n enum: undefined,\n to: undefined,\n from: undefined,\n normalizeZeros: true,\n padFractionalZeros: false,\n }, {\n ref: numberInputRef,\n onAccept: (value, __, event) => {\n const parsedValue = parseInt(value, 10);\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: parsedValue as any,\n },\n } as CustomInputEvent);\n },\n });\n\n /**\n * Função sobrescrevendo o evento onBlur para tratar o valor mínimo ao sair do campo, \n * garantindo que o valor não seja menor que o mínimo definido.\n */\n const handleBlur = (event: CustomInputEvent) => {\n if (!_.isNil(min)) {\n const currentValue = parseInt(maskedValue, 10) as number;\n if (_.isNaN(currentValue) || currentValue < min) {\n setMaskedValue(_.toString(min));\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: min as any,\n },\n } as CustomInputEvent);\n }\n }\n props?.onBlur?.(event);\n };\n\n useEffect(() => {\n const floatMaskedValue = Number(maskedValue || '0');\n if (!_.isNil(props?.value) && (!_.isEqual(props?.value,\n floatMaskedValue) || _.isEqual(props?.value, 0))) {\n setMaskedValue(_.toString(props?.value));\n }\n }, [props?.value]);\n\n return (\n <InputTextBase\n {...props}\n inputRef={mergeRefs(numberInputRef, inputRef) as any}\n type=\"number\"\n onChange={() => {}}\n onBlur={handleBlur}\n value={maskedValue}\n textAlign={textAlign}\n themePopover={themePopover}\n popoverAlign={popoverAlign} />\n );\n};\n\nexport default NumberField;\nexport {\n CurrencyField,\n DecimalField,\n};\n"],"names":["NumberField","props","textAlign","themePopover","popoverAlign","min","undefined","max","inputRef","numberInputRef","useRef","value","maskedValue","setValue","setMaskedValue","useIMask","mask","Number","scale","enum","to","from","normalizeZeros","padFractionalZeros","ref","onAccept","__","event","parsedValue","parseInt","onChange","target","name","handleBlur","_","isNil","currentValue","isNaN","toString","onBlur","useEffect","floatMaskedValue","isEqual","mergeRefs"],"mappings":";;;;;;;;;AAYA,MAAMA,cAAcA,CAACC,UAA6B;AAChD,QAAM;AAAA,IACJC,YAAY;AAAA,IAAQC,eAAe;AAAA,IAASC,eAAe;AAAA,IAAQC,MAAMC;AAAAA,IACzEC,MAAMD;AAAAA,IAAWE,WAAWF;AAAAA,EAAAA,IAC1BL;AACJ,QAAMQ,iBAAiBC,OAAgC,IAAI;AAE3D,QAAM;AAAA,IAAEC,OAAOC;AAAAA,IAAaC,UAAUC;AAAAA,EAAAA,IAAmBC,SAAS;AAAA,IAChEC,MAAMC;AAAAA,IACNV;AAAAA,IACAF;AAAAA,IACAa,OAAO;AAAA,IACPC,MAAMb;AAAAA,IACNc,IAAId;AAAAA,IACJe,MAAMf;AAAAA,IACNgB,gBAAgB;AAAA,IAChBC,oBAAoB;AAAA,EAAA,GACnB;AAAA,IACDC,KAAKf;AAAAA,IACLgB,UAAUA,CAACd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