Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/migrate react-number-format #356

Merged
merged 5 commits into from
Aug 5, 2024
Merged

Conversation

KarineBrandelli
Copy link
Contributor

@KarineBrandelli KarineBrandelli commented Aug 5, 2024

  • migrate react-number-format from v4 to v5;
  • v5 brings to separated components, insted of one general;
  • create and adjust tests for the migrated component;
  • update @typescript-eslint to v8, the @typescript-eslint/ban-types no longer exists;
  • update ramda;
  • update general dps patch versions;

Before:

<NumberFormat {...otherProps} customInput={customInput || TextField} />

After

        <>
            {hasFormat ? (
                <PatternFormat
                    {...otherProps}
                    format={format}
                    style={{ ...style }}
                    customInput={customInput || TextField}
                />
            ) : (
                <NumericFormat
                    {...otherProps}
                    style={{ ...style }}
                    customInput={customInput || TextField}
                />
            )}
        </>

In order not to have to change all the imports path, a prop hasFormat was added to verifiy if the fields needs a format mask (like: '#####-##'), or if the field is a number or money field, witch needs other props.

The NumericFormat component, when thousandSeparator='.' and/or decimalScale={0} has these configs, the onchange funcion does no work propperly. Insted, the onValueChange has to be used. It has two params, the values object, wich returns { formattedValue, value, floatValue } and the sourceInfo param, wich return the synthetic event. In cases you need to avoid the onChange triggers when the component is mounted, just set !sourceInfo.event.

            <NumericFormat
                fixedDecimalScale
                placeholder='Quantidade'
                value={amount}
                disabled={disabled}
                thousandSeparator='.'
                decimalSeparator=','
                decimalScale={0}
                onValueChange={(values: IValues, sourceInfo) => {
                    if (!sourceInfo.event) {
                        return
                    }

                    handleChange({
                        target: {
                            value: values.value
                        }
                    } as ChangeEvent<HTMLInputElement>)
                }}
            />

@KarineBrandelli KarineBrandelli merged commit b6babda into master Aug 5, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants