Skip to content

Commit

Permalink
[RFR] Migrate NullableBooleanInput to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Aug 14, 2019
1 parent 25f72cd commit 2cff61e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<TextFieldProps> & Omit<TextFieldProps, 'label' | 'helperText'>
> = ({
className,
helperText,
label,
Expand All @@ -38,7 +40,7 @@ const NullableBooleanInput = ({
validate,
...rest
}) => {
const classes = useStyles();
const classes = useStyles({});
const translate = useTranslate();

const {
Expand Down

0 comments on commit 2cff61e

Please sign in to comment.