From 7cdc7a4ed3bae47c2959d0e1cbbe19368c0ce7fb Mon Sep 17 00:00:00 2001 From: djhi Date: Tue, 13 Aug 2019 20:54:00 +0200 Subject: [PATCH 1/3] [RFR] Migrate NumberInput to TypeScript --- .../{NumberInput.spec.js => NumberInput.spec.tsx} | 8 +++++--- .../src/input/{NumberInput.js => NumberInput.tsx} | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) rename packages/ra-ui-materialui/src/input/{NumberInput.spec.js => NumberInput.spec.tsx} (98%) rename packages/ra-ui-materialui/src/input/{NumberInput.js => NumberInput.tsx} (86%) diff --git a/packages/ra-ui-materialui/src/input/NumberInput.spec.js b/packages/ra-ui-materialui/src/input/NumberInput.spec.tsx similarity index 98% rename from packages/ra-ui-materialui/src/input/NumberInput.spec.js rename to packages/ra-ui-materialui/src/input/NumberInput.spec.tsx index af8ef048abe..c5166a8ec72 100644 --- a/packages/ra-ui-materialui/src/input/NumberInput.spec.js +++ b/packages/ra-ui-materialui/src/input/NumberInput.spec.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { render, cleanup, fireEvent } from '@testing-library/react'; - -import NumberInput from './NumberInput'; import { Form } from 'react-final-form'; import { required } from 'ra-core/lib'; +import NumberInput from './NumberInput'; + describe('', () => { afterEach(cleanup); @@ -21,7 +21,9 @@ describe('', () => { render={() => } /> ); - const input = getByLabelText('resources.posts.fields.views'); + const input = getByLabelText( + 'resources.posts.fields.views' + ) as HTMLInputElement; expect(input.value).toEqual('12'); expect(input.getAttribute('type')).toEqual('number'); }); diff --git a/packages/ra-ui-materialui/src/input/NumberInput.js b/packages/ra-ui-materialui/src/input/NumberInput.tsx similarity index 86% rename from packages/ra-ui-materialui/src/input/NumberInput.js rename to packages/ra-ui-materialui/src/input/NumberInput.tsx index 82a95731c53..6a515a75f6e 100644 --- a/packages/ra-ui-materialui/src/input/NumberInput.js +++ b/packages/ra-ui-materialui/src/input/NumberInput.tsx @@ -1,7 +1,7 @@ -import React from 'react'; +import React, { FunctionComponent } from 'react'; import PropTypes from 'prop-types'; -import TextField from '@material-ui/core/TextField'; -import { useInput, FieldTitle } from 'ra-core'; +import TextField, { TextFieldProps } from '@material-ui/core/TextField'; +import { useInput, FieldTitle, InputProps } from 'ra-core'; import InputHelperText from './InputHelperText'; import sanitizeRestProps from './sanitizeRestProps'; @@ -24,7 +24,9 @@ const parse = value => { * * The object passed as `options` props is passed to the material-ui component */ -const NumberInput = ({ +const NumberInput: FunctionComponent< + InputProps & Omit +> = ({ helperText, label, options, From f38c7a20b823d7d268aaeee35ef3b1169ff78cb7 Mon Sep 17 00:00:00 2001 From: djhi Date: Tue, 13 Aug 2019 20:56:56 +0200 Subject: [PATCH 2/3] Fix propTypes --- packages/ra-ui-materialui/src/input/NumberInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ra-ui-materialui/src/input/NumberInput.tsx b/packages/ra-ui-materialui/src/input/NumberInput.tsx index 6a515a75f6e..4faf0421c81 100644 --- a/packages/ra-ui-materialui/src/input/NumberInput.tsx +++ b/packages/ra-ui-materialui/src/input/NumberInput.tsx @@ -89,7 +89,7 @@ NumberInput.propTypes = { options: PropTypes.object, resource: PropTypes.string, source: PropTypes.string, - step: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + step: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), }; NumberInput.defaultProps = { From 88087c3b4c405dc48e8cdf9731b1b55b0dcd07f9 Mon Sep 17 00:00:00 2001 From: djhi Date: Fri, 16 Aug 2019 18:40:38 +0200 Subject: [PATCH 3/3] Review --- packages/ra-ui-materialui/src/input/NumberInput.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/ra-ui-materialui/src/input/NumberInput.tsx b/packages/ra-ui-materialui/src/input/NumberInput.tsx index 4faf0421c81..cd9542f2940 100644 --- a/packages/ra-ui-materialui/src/input/NumberInput.tsx +++ b/packages/ra-ui-materialui/src/input/NumberInput.tsx @@ -12,6 +12,10 @@ const parse = value => { return isNaN(float) ? null : float; }; +interface Props { + step: string | number; +} + /** * An Input component for a number * @@ -25,7 +29,9 @@ const parse = value => { * The object passed as `options` props is passed to the material-ui component */ const NumberInput: FunctionComponent< - InputProps & Omit + Props & + InputProps & + Omit > = ({ helperText, label,