Skip to content

Commit 6bb1f5b

Browse files
author
asvarcas
committed
Remove FC usage from Input components
1 parent ef0f0bf commit 6bb1f5b

13 files changed

+93
-99
lines changed

packages/ra-ui-materialui/src/input/AutocompleteSuggestionItem.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { FunctionComponent, isValidElement, cloneElement } from 'react';
2+
import { isValidElement, cloneElement } from 'react';
33
import parse from 'autosuggest-highlight/parse';
44
import match from 'autosuggest-highlight/match';
55
import { MenuItem } from '@material-ui/core';
@@ -37,9 +37,10 @@ export interface AutocompleteSuggestionItemProps {
3737
getSuggestionText: (suggestion: any) => string;
3838
}
3939

40-
const AutocompleteSuggestionItem: FunctionComponent<
41-
AutocompleteSuggestionItemProps & MenuItemProps<'li', { button?: true }>
42-
> = props => {
40+
const AutocompleteSuggestionItem = (
41+
props: AutocompleteSuggestionItemProps &
42+
MenuItemProps<'li', { button?: true }>
43+
) => {
4344
const {
4445
createValue,
4546
suggestion,

packages/ra-ui-materialui/src/input/AutocompleteSuggestionList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { ReactNode, FunctionComponent } from 'react';
2+
import { ReactNode } from 'react';
33
import classnames from 'classnames';
44
import { Paper, Popper } from '@material-ui/core';
55
import { makeStyles } from '@material-ui/core/styles';
@@ -27,7 +27,7 @@ interface Props {
2727
suggestionsContainerProps?: any;
2828
}
2929

30-
const AutocompleteSuggestionList: FunctionComponent<Props> = props => {
30+
const AutocompleteSuggestionList = (props: Props) => {
3131
const {
3232
children,
3333
className,

packages/ra-ui-materialui/src/input/BooleanInput.tsx

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { FunctionComponent, useCallback } from 'react';
2+
import { useCallback } from 'react';
33
import PropTypes from 'prop-types';
44
import FormControlLabel from '@material-ui/core/FormControlLabel';
55
import FormHelperText from '@material-ui/core/FormHelperText';
@@ -11,22 +11,23 @@ import sanitizeInputRestProps from './sanitizeInputRestProps';
1111
import InputHelperText from './InputHelperText';
1212
import InputPropTypes from './InputPropTypes';
1313

14-
const BooleanInput: FunctionComponent<BooleanInputProps> = ({
15-
format,
16-
label,
17-
fullWidth,
18-
helperText,
19-
onBlur,
20-
onChange,
21-
onFocus,
22-
options,
23-
disabled,
24-
parse,
25-
resource,
26-
source,
27-
validate,
28-
...rest
29-
}) => {
14+
const BooleanInput = (props: BooleanInputProps) => {
15+
const {
16+
format,
17+
label,
18+
fullWidth,
19+
helperText,
20+
onBlur,
21+
onChange,
22+
onFocus,
23+
options,
24+
disabled,
25+
parse,
26+
resource,
27+
source,
28+
validate,
29+
...rest
30+
} = props;
3031
const {
3132
id,
3233
input: { onChange: finalFormOnChange, type, value, ...inputProps },

packages/ra-ui-materialui/src/input/FileInputPreview.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { useEffect, ReactNode, FunctionComponent } from 'react';
2+
import { useEffect, ReactNode } from 'react';
33
import PropTypes from 'prop-types';
44
import { makeStyles } from '@material-ui/core/styles';
55
import RemoveCircle from '@material-ui/icons/RemoveCircle';
@@ -24,7 +24,7 @@ interface Props {
2424
file: any;
2525
}
2626

27-
const FileInputPreview: FunctionComponent<Props> = props => {
27+
const FileInputPreview = (props: Props) => {
2828
const {
2929
children,
3030
classes: classesOverride,

packages/ra-ui-materialui/src/input/InputHelperText.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { FunctionComponent } from 'react';
32
import { useTranslate, ValidationError, ValidationErrorMessage } from 'ra-core';
43

54
export interface InputHelperTextProps {
@@ -8,11 +7,8 @@ export interface InputHelperTextProps {
87
touched: boolean;
98
}
109

11-
const InputHelperText: FunctionComponent<InputHelperTextProps> = ({
12-
helperText,
13-
touched,
14-
error,
15-
}) => {
10+
const InputHelperText = (props: InputHelperTextProps) => {
11+
const { helperText, touched, error } = props;
1612
const translate = useTranslate();
1713

1814
return touched && error ? (

packages/ra-ui-materialui/src/input/Labeled.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { FunctionComponent, ReactElement } from 'react';
2+
import { ReactElement } from 'react';
33
import PropTypes from 'prop-types';
44
import InputLabel from '@material-ui/core/InputLabel';
55
import FormControl from '@material-ui/core/FormControl';
@@ -56,7 +56,7 @@ export interface LabeledProps {
5656
* <FooComponent source="title" />
5757
* </Labeled>
5858
*/
59-
const Labeled: FunctionComponent<LabeledProps> = props => {
59+
const Labeled = (props: LabeledProps) => {
6060
const {
6161
children,
6262
className,

packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { FunctionComponent } from 'react';
32
import PropTypes from 'prop-types';
43
import TextField, { TextFieldProps } from '@material-ui/core/TextField';
54
import MenuItem from '@material-ui/core/MenuItem';
@@ -36,7 +35,7 @@ export type NullableBooleanInputProps = InputProps<TextFieldProps> &
3635
trueLabel?: string;
3736
};
3837

39-
const NullableBooleanInput: FunctionComponent<NullableBooleanInputProps> = props => {
38+
const NullableBooleanInput = (props: NullableBooleanInputProps) => {
4039
const {
4140
className,
4241
classes: classesOverride,

packages/ra-ui-materialui/src/input/PasswordInput.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { FC, useState } from 'react';
2+
import { useState } from 'react';
33
import { useTranslate } from 'ra-core';
44
import { InputAdornment, IconButton } from '@material-ui/core';
55
import Visibility from '@material-ui/icons/Visibility';
@@ -11,10 +11,8 @@ export interface PasswordInputProps extends TextInputProps {
1111
initiallyVisible?: boolean;
1212
}
1313

14-
const PasswordInput: FC<PasswordInputProps> = ({
15-
initiallyVisible = false,
16-
...props
17-
}) => {
14+
const PasswordInput = (props: PasswordInputProps) => {
15+
const { initiallyVisible = false, ...rest } = props;
1816
const [visible, setVisible] = useState(initiallyVisible);
1917
const translate = useTranslate();
2018

@@ -24,7 +22,7 @@ const PasswordInput: FC<PasswordInputProps> = ({
2422

2523
return (
2624
<TextInput
27-
{...props}
25+
{...rest}
2826
type={visible ? 'text' : 'password'}
2927
InputProps={{
3028
endAdornment: (

packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { FunctionComponent } from 'react';
32
import PropTypes from 'prop-types';
43
import {
54
FormControl,
@@ -88,7 +87,7 @@ const useStyles = makeStyles(
8887
*
8988
* The object passed as `options` props is passed to the material-ui <RadioButtonGroup> component
9089
*/
91-
const RadioButtonGroupInput: FunctionComponent<RadioButtonGroupInputProps> = props => {
90+
const RadioButtonGroupInput = (props: RadioButtonGroupInputProps) => {
9291
const {
9392
choices = [],
9493
classes: classesOverride,

packages/ra-ui-materialui/src/input/ReferenceInput.tsx

+38-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {
22
Children,
33
cloneElement,
4-
FunctionComponent,
54
ReactElement,
65
} from 'react';
76
import PropTypes from 'prop-types';
@@ -98,29 +97,30 @@ import ReferenceError from './ReferenceError';
9897
* <AutocompleteInput optionText="title" />
9998
* </ReferenceInput>
10099
*/
101-
const ReferenceInput: FunctionComponent<ReferenceInputProps> = ({
102-
format,
103-
onBlur,
104-
onChange,
105-
onFocus,
106-
parse,
107-
validate,
108-
...props
109-
}) => {
100+
const ReferenceInput = (props: ReferenceInputProps) => {
101+
const {
102+
format,
103+
onBlur,
104+
onChange,
105+
onFocus,
106+
parse,
107+
validate,
108+
...rest
109+
} = props;
110110
const inputProps = useInput({
111111
format,
112112
onBlur,
113113
onChange,
114114
onFocus,
115115
parse,
116116
validate,
117-
...props,
117+
...rest,
118118
});
119119
return (
120120
<ReferenceInputView
121121
{...inputProps}
122-
{...props}
123-
{...useReferenceInputController({ ...props, ...inputProps })}
122+
{...rest}
123+
{...useReferenceInputController({ ...rest, ...inputProps })}
124124
/>
125125
);
126126
};
@@ -188,30 +188,31 @@ export interface ReferenceInputViewProps
188188
ReferenceInputProps,
189189
Omit<UseInputValue, 'id'> {}
190190

191-
export const ReferenceInputView: FunctionComponent<ReferenceInputViewProps> = ({
192-
allowEmpty,
193-
basePath,
194-
children,
195-
choices,
196-
classes,
197-
className,
198-
error,
199-
helperText,
200-
id,
201-
input,
202-
isRequired,
203-
label,
204-
meta,
205-
possibleValues,
206-
resource,
207-
reference,
208-
setFilter,
209-
setPagination,
210-
setSort,
211-
source,
212-
warning,
213-
...rest
214-
}) => {
191+
export const ReferenceInputView = (props: ReferenceInputViewProps) => {
192+
const {
193+
allowEmpty,
194+
basePath,
195+
children,
196+
choices,
197+
classes,
198+
className,
199+
error,
200+
helperText,
201+
id,
202+
input,
203+
isRequired,
204+
label,
205+
meta,
206+
possibleValues,
207+
resource,
208+
reference,
209+
setFilter,
210+
setPagination,
211+
setSort,
212+
source,
213+
warning,
214+
...rest
215+
} = props;
215216
if (Children.count(children) !== 1) {
216217
throw new Error('<ReferenceInput> only accepts a single child');
217218
}

packages/ra-ui-materialui/src/input/ResettableTextField.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Styles } from '@material-ui/styles';
1818
/**
1919
* An override of the default Material-UI TextField which is resettable
2020
*/
21-
function ResettableTextField(props: ResettableTextFieldProps) {
21+
const ResettableTextField = (props: ResettableTextFieldProps) => {
2222
const {
2323
classes: classesOverride,
2424
clearAlwaysVisible,
@@ -170,7 +170,7 @@ function ResettableTextField(props: ResettableTextFieldProps) {
170170
onBlur={handleBlur}
171171
/>
172172
);
173-
}
173+
};
174174

175175
export const resettableStyles: Styles<Theme, ResettableTextFieldProps> = {
176176
clearIcon: {

packages/ra-ui-materialui/src/input/SearchInput.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { FunctionComponent } from 'react';
32
import PropTypes from 'prop-types';
43
import SearchIcon from '@material-ui/icons/Search';
54
import { InputAdornment } from '@material-ui/core';
@@ -18,7 +17,7 @@ const useStyles = makeStyles(
1817
{ name: 'RaSearchInput' }
1918
);
2019

21-
const SearchInput: FunctionComponent<SearchInputProps> = props => {
20+
const SearchInput = (props: SearchInputProps) => {
2221
const { classes: classesOverride, ...rest } = props;
2322
const translate = useTranslate();
2423
const classes = useStyles(props);

packages/ra-ui-materialui/src/input/TextInput.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { FunctionComponent } from 'react';
32
import PropTypes from 'prop-types';
43
import { useInput, FieldTitle, InputProps } from 'ra-core';
54
import { TextFieldProps } from '@material-ui/core/TextField';
@@ -25,20 +24,21 @@ export type TextInputProps = InputProps<TextFieldProps> &
2524
*
2625
* The object passed as `options` props is passed to the <ResettableTextField> component
2726
*/
28-
const TextInput: FunctionComponent<TextInputProps> = ({
29-
label,
30-
format,
31-
helperText,
32-
onBlur,
33-
onFocus,
34-
onChange,
35-
options,
36-
parse,
37-
resource,
38-
source,
39-
validate,
40-
...rest
41-
}) => {
27+
const TextInput = (props: TextInputProps) => {
28+
const {
29+
label,
30+
format,
31+
helperText,
32+
onBlur,
33+
onFocus,
34+
onChange,
35+
options,
36+
parse,
37+
resource,
38+
source,
39+
validate,
40+
...rest
41+
} = props;
4242
const {
4343
id,
4444
input,

0 commit comments

Comments
 (0)