-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathSearchInput.tsx
57 lines (50 loc) · 1.57 KB
/
SearchInput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as React from 'react';
import { FunctionComponent } from 'react';
import PropTypes from 'prop-types';
import SearchIcon from '@material-ui/icons/Search';
import { InputAdornment } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import { TextFieldProps } from '@material-ui/core/TextField';
import { useTranslate, InputProps } from 'ra-core';
import TextInput from './TextInput';
const useStyles = makeStyles(
{
input: {
marginTop: 32,
},
},
{ name: 'RaSearchInput' }
);
const SearchInput: FunctionComponent<SearchInputProps> = props => {
const { classes: classesOverride, ...rest } = props;
const translate = useTranslate();
const classes = useStyles(props);
if (props.label) {
throw new Error(
"<SearchInput> isn't designed to be used with a label prop. Use <TextInput> if you need a label."
);
}
return (
<TextInput
hiddenLabel
label=""
resettable
placeholder={translate('ra.action.search')}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<SearchIcon color="disabled" />
</InputAdornment>
),
}}
className={classes.input}
{...rest}
/>
);
};
SearchInput.propTypes = {
classes: PropTypes.object,
};
export type SearchInputProps = InputProps<TextFieldProps> &
Omit<TextFieldProps, 'label' | 'helperText'>;
export default SearchInput;