From 2cff61e9ce02ea7074dda9a75b14232cf6f0b430 Mon Sep 17 00:00:00 2001 From: djhi Date: Tue, 13 Aug 2019 19:03:02 +0200 Subject: [PATCH] [RFR] Migrate NullableBooleanInput to TypeScript --- ...put.spec.js => NullableBooleanInput.spec.tsx} | 0 ...eBooleanInput.js => NullableBooleanInput.tsx} | 16 +++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) rename packages/ra-ui-materialui/src/input/{NullableBooleanInput.spec.js => NullableBooleanInput.spec.tsx} (100%) rename packages/ra-ui-materialui/src/input/{NullableBooleanInput.js => NullableBooleanInput.tsx} (82%) diff --git a/packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.js b/packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.tsx similarity index 100% rename from packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.js rename to packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.tsx diff --git a/packages/ra-ui-materialui/src/input/NullableBooleanInput.js b/packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx similarity index 82% rename from packages/ra-ui-materialui/src/input/NullableBooleanInput.js rename to packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx index 7266e11738f..5b1580431af 100644 --- a/packages/ra-ui-materialui/src/input/NullableBooleanInput.js +++ b/packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx @@ -1,10 +1,10 @@ -import React from 'react'; +import React, { FunctionComponent } from 'react'; import PropTypes from 'prop-types'; -import TextField from '@material-ui/core/TextField'; +import TextField, { TextFieldProps } from '@material-ui/core/TextField'; import MenuItem from '@material-ui/core/MenuItem'; import { makeStyles } from '@material-ui/core/styles'; import classnames from 'classnames'; -import { useInput, useTranslate, FieldTitle } from 'ra-core'; +import { useInput, useTranslate, FieldTitle, InputProps } from 'ra-core'; import sanitizeRestProps from './sanitizeRestProps'; import InputHelperText from './InputHelperText'; @@ -13,19 +13,21 @@ const useStyles = makeStyles(theme => ({ input: { width: theme.spacing(16) }, })); -const getBooleanFromString = value => { +const getBooleanFromString = (value: string): boolean | null => { if (value === 'true') return true; if (value === 'false') return false; return null; }; -const getStringFromBoolean = value => { +const getStringFromBoolean = (value?: boolean | null): string => { if (value === true) return 'true'; if (value === false) return 'false'; return ''; }; -const NullableBooleanInput = ({ +const NullableBooleanInput: FunctionComponent< + InputProps & Omit +> = ({ className, helperText, label, @@ -38,7 +40,7 @@ const NullableBooleanInput = ({ validate, ...rest }) => { - const classes = useStyles(); + const classes = useStyles({}); const translate = useTranslate(); const {