import * as React from 'react' ; import PropTypes from 'prop-types' ; import { useInput , FieldTitle , InputProps } from 'ra-core' ; import { TextFieldProps } from '@material-ui/core/TextField' ; import ResettableTextField from './ResettableTextField' ; import InputHelperText from './InputHelperText' ; import sanitizeInputRestProps from './sanitizeInputRestProps' ; export type TextInputProps = InputProps < TextFieldProps > & Omit < TextFieldProps , 'label' | 'helperText' > ; example example const TextInput = ( props ) => { const { label , format , helperText , onBlur , onFocus , onChange , options , parse , resource , source , validate , ... rest } = props ; const { id , input , isRequired , meta : { error , submitError , touched } , } = useInput ( { format , onBlur , onChange , onFocus , parse , resource , source , type : 'text' , validate , ... rest , } ) ; return ( < ResettableTextField id = { id } { ... input } label = { label !== '' && label !== false && ( < FieldTitle label = { label } source = { source } resource = { resource } isRequired = { isRequired } / > ) } error = { ! ! ( touched && ( error || submitError ) ) } helperText = { < InputHelperText touched = { touched } error = { error || submitError } helperText = { helperText } / > } { ... options } { ... sanitizeInputRestProps ( rest ) } />); } ; TextInput . propTypes = { className : PropTypes . string , label : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . bool ] ) , options : PropTypes . object , resource : PropTypes . string , source : PropTypes . string , } ; TextInput . defaultProps = { options : { } , } ; export default TextInput ;