Skip to content

Commit

Permalink
Merge pull request #332 from nginformatica/fix/rollback-number-formar…
Browse files Browse the repository at this point in the history
…t-version

fix: rollback number format version
  • Loading branch information
renanponick authored Dec 1, 2023
2 parents 1bec8cb + c343f61 commit af2e941
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 91 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flipper-ui",
"version": "0.30.4",
"version": "0.30.5",
"description": "",
"main": "dist/index.js",
"homepage": "https://flipper-ui.ngi.com.br/",
Expand Down Expand Up @@ -42,7 +42,7 @@
"nginformatica-styleguide": "1.0.2",
"ramda": "0.25.0",
"react-loading-skeleton": "3.3.1",
"react-number-format": "5.3.1",
"react-number-format": "4.4.1",
"sprintf-js": "1.1.3",
"styled-component": "2.8.0",
"uuid": "9.0.1"
Expand Down
9 changes: 2 additions & 7 deletions src/core/data-display/data-table/rows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,8 @@ const renderEditMode = <D extends Data>(
<MaskField
fixedDecimalScale
type='text'
onError={
hasError
? () => {
hasError
}
: undefined
}
fullWidth
error={hasError}
thousandSeparator='.'
decimalSeparator=','
decimalScale={decimalScale}
Expand Down
79 changes: 19 additions & 60 deletions src/core/inputs/mask-field/index.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,29 @@
import React, { ChangeEvent } from 'react'
import TextField, { IOption, TextFieldProps } from '@/core/inputs/text-field'
import { NumericFormat } from 'react-number-format'
import { FormatInputValueFunction } from 'react-number-format/types/types'
import React from 'react'
import TextField, { TextFieldProps } from '@/core/inputs/text-field'
import NumberFormat, { NumberFormatProps } from 'react-number-format'

export interface MaskFieldProps
extends Omit<TextFieldProps, 'format' | 'size'> {
error?: boolean
showEdit?: boolean
hasClear?: boolean
autoFocus?: boolean
multiline?: boolean
select?: boolean
fullWidth?: boolean
required?: boolean
disabled?: boolean
fixedDecimalScale?: boolean
thousandSeparator?: boolean | string
margin?: string
id?: string
name?: string
export interface MaskFieldProps extends NumberFormatProps {
mask?: string
placeholder?: string
label?: string
autoComplete?: string
type?: 'text' | 'tel' | 'password'
decimalSeparator?: string
format?: string | FormatInputValueFunction
defaultValue?: string | number
value?: string | number
rows?: string | number
rowsMax?: string | number
format?: string
decimalScale?: number
SelectProps?: object
InputProps?: object
inputProps?: object
InputLabelProps?: object
options?: IOption[] | string
children?: React.ReactNode
helperText?: React.ReactNode
helperIcon?: React.ReactNode
style?: React.CSSProperties
inputRef?: React.Ref<HTMLInputElement>
type?: 'text' | 'tel' | 'password'
variant?: 'standard' | 'outlined' | 'filled'
color?: 'primary' | 'secondary' | undefined
customInput?: React.ComponentType
onClear?: () => void
onBlur?: () => void
onHelperClick?: () => void
onChange?: (event: ChangeEvent<HTMLInputElement>) => void
onKeyUp?: (event: React.KeyboardEvent<HTMLInputElement>) => void
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void
onPaste?: (event: React.ClipboardEvent<HTMLInputElement>) => void
thousandSeparator?: boolean | string
fixedDecimalScale?: boolean
customInput?: React.ComponentType<TextFieldProps>
}

const MaskField: React.FC<MaskFieldProps> = ({
customInput = TextField,
format,
...otherProps
}) => {
const formattedProps = {
...otherProps,
customInput,
format: format !== undefined ? format : undefined
}
export const MaskField = (props: MaskFieldProps) => {
const { customInput, ...otherProps } = props

return <NumericFormat {...formattedProps} />
return (
// Although react-number-format allow use of additional props,
// shows problem with some props like have been do this
// actually on flipper-ui. (e.g. errors treatment)
<NumberFormat
{...otherProps}
customInput={customInput || TextField}></NumberFormat>
)
}

export default MaskField
36 changes: 18 additions & 18 deletions src/core/inputs/mask-field/mask-field.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ describe('MaskField', () => {
expect(input.value).toBe('123')
})

it('should render with format as string', async () => {
render(<MaskField placeholder='Description' format='####' />)
// it('should render with format as string', async () => {
// render(<MaskField placeholder='Description' format='####' />)

const input = screen.getByPlaceholderText(
'Description'
) as HTMLInputElement
// const input = screen.getByPlaceholderText(
// 'Description'
// ) as HTMLInputElement

await act(async () => await userEvent.type(input, '789'))
// await act(async () => await userEvent.type(input, '789'))

expect(input.value).toBe('789')
})
// expect(input.value).toBe('789')
// })

it('should render with format as a function', async () => {
const formatFunction = jest.fn(value => value)
render(<MaskField placeholder='Description' format={formatFunction} />)
// it('should render with format as a function', async () => {
// const formatFunction = 'jest.fn(value => value)'
// render(<MaskField placeholder='Description' format={formatFunction} />)

const input = screen.getByPlaceholderText(
'Description'
) as HTMLInputElement
// const input = screen.getByPlaceholderText(
// 'Description'
// ) as HTMLInputElement

await act(async () => await userEvent.type(input, '1'))
// await act(async () => await userEvent.type(input, '1'))

expect(input.value).toBe('1')
expect(formatFunction)
})
// expect(input.value).toBe('1')
// expect(formatFunction)
// })
})
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13321,10 +13321,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/react-loading-skeleton/-/react-loading-skeleton-3.3.1.tgz#cd6e3a626ee86c76a46c14e2379243f2f8834e1b"
integrity sha512-NilqqwMh2v9omN7LteiDloEVpFyMIa0VGqF+ukqp0ncVlYu1sKYbYGX9JEl+GtOT9TKsh04zCHAbavnQ2USldA==

react-number-format@5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/react-number-format/-/react-number-format-5.3.1.tgz#840c257da9cb4b248990d8db46e4d23e8bac67ff"
integrity sha512-qpYcQLauIeEhCZUZY9jXZnnroOtdy3jYaS1zQ3M1Sr6r/KMOBEIGNIb7eKT19g2N1wbYgFgvDzs19hw5TrB8XQ==
react-number-format@4.4.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/react-number-format/-/react-number-format-4.4.1.tgz#d5614dd25edfc21ed48b97356213440081437a94"
integrity sha512-ZGFMXZ0U7DcmQ3bSZY3FULOA1mfqreT9NIMYZNoa/ouiSgiTQiYA95Uj2KN8ge6BRr+ghA5vraozqWqsHZQw3Q==
dependencies:
prop-types "^15.7.2"

Expand Down

0 comments on commit af2e941

Please sign in to comment.