|
23 | 23 | THE SOFTWARE. |
24 | 24 | */ |
25 | 25 | import React from 'react'; |
26 | | -import { |
27 | | - CellProps, |
28 | | - Formatted, |
29 | | - WithClassname, |
30 | | -} from '@jsonforms/core'; |
| 26 | +import { CellProps, Formatted, WithClassname } from '@jsonforms/core'; |
31 | 27 | import Input from '@material-ui/core/Input'; |
| 28 | +import { areEqual } from '@jsonforms/react'; |
32 | 29 |
|
33 | | -export const MuiInputNumberFormat = (props: CellProps & WithClassname & Formatted<number>) => { |
34 | | - const { |
35 | | - className, |
36 | | - id, |
37 | | - enabled, |
38 | | - uischema, |
39 | | - isValid, |
40 | | - path, |
41 | | - handleChange, |
42 | | - schema |
43 | | - } = props; |
44 | | - const maxLength = schema.maxLength; |
45 | | - let config; |
46 | | - if (uischema.options && uischema.options.restrict) { |
47 | | - config = {'maxLength': maxLength}; |
48 | | - } else { |
49 | | - config = {}; |
50 | | - } |
51 | | - const trim = uischema.options && uischema.options.trim; |
52 | | - const formattedNumber = props.toFormatted(props.data); |
| 30 | +export const MuiInputNumberFormat = React.memo( |
| 31 | + (props: CellProps & WithClassname & Formatted<number>) => { |
| 32 | + const { |
| 33 | + className, |
| 34 | + id, |
| 35 | + enabled, |
| 36 | + uischema, |
| 37 | + isValid, |
| 38 | + path, |
| 39 | + handleChange, |
| 40 | + schema |
| 41 | + } = props; |
| 42 | + const maxLength = schema.maxLength; |
| 43 | + let config; |
| 44 | + if (uischema.options && uischema.options.restrict) { |
| 45 | + config = { maxLength: maxLength }; |
| 46 | + } else { |
| 47 | + config = {}; |
| 48 | + } |
| 49 | + const trim = uischema.options && uischema.options.trim; |
| 50 | + const formattedNumber = props.toFormatted(props.data); |
53 | 51 |
|
54 | | - const onChange = (ev: any) => { |
55 | | - const validStringNumber = props.fromFormatted(ev.currentTarget.value); |
56 | | - handleChange(path, validStringNumber); |
57 | | - }; |
| 52 | + const onChange = (ev: any) => { |
| 53 | + const validStringNumber = props.fromFormatted(ev.currentTarget.value); |
| 54 | + handleChange(path, validStringNumber); |
| 55 | + }; |
58 | 56 |
|
59 | | - return ( |
60 | | - <Input |
61 | | - type='text' |
62 | | - value={formattedNumber} |
63 | | - onChange={onChange} |
64 | | - className={className} |
65 | | - id={id} |
66 | | - disabled={!enabled} |
67 | | - autoFocus={uischema.options && uischema.options.focus} |
68 | | - multiline={uischema.options && uischema.options.multi} |
69 | | - fullWidth={!trim || maxLength === undefined} |
70 | | - inputProps={config} |
71 | | - error={!isValid} |
72 | | - /> |
73 | | - ); |
74 | | -}; |
| 57 | + return ( |
| 58 | + <Input |
| 59 | + type='text' |
| 60 | + value={formattedNumber} |
| 61 | + onChange={onChange} |
| 62 | + className={className} |
| 63 | + id={id} |
| 64 | + disabled={!enabled} |
| 65 | + autoFocus={uischema.options && uischema.options.focus} |
| 66 | + multiline={uischema.options && uischema.options.multi} |
| 67 | + fullWidth={!trim || maxLength === undefined} |
| 68 | + inputProps={config} |
| 69 | + error={!isValid} |
| 70 | + /> |
| 71 | + ); |
| 72 | + }, |
| 73 | + areEqual |
| 74 | +); |
0 commit comments