-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathSearchInput.tsx
49 lines (41 loc) · 1.32 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
import * as React from 'react';
import { styled } from '@mui/material/styles';
import SearchIcon from '@mui/icons-material/Search';
import { InputAdornment } from '@mui/material';
import { useTranslate } from 'ra-core';
import { CommonInputProps } from './CommonInputProps';
import { TextInput, TextInputProps } from './TextInput';
export const SearchInput = (props: SearchInputProps) => {
const { label, ...rest } = props;
const translate = useTranslate();
if (label) {
throw new Error(
"<SearchInput> isn't designed to be used with a label prop. Use <TextInput> if you need a label."
);
}
return (
<StyledTextInput
hiddenLabel
label=""
resettable
placeholder={translate('ra.action.search')}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<SearchIcon color="disabled" />
</InputAdornment>
),
}}
size="small"
{...rest}
/>
);
};
export type SearchInputProps = CommonInputProps & TextInputProps;
const PREFIX = 'RaSearchInput';
const StyledTextInput = styled(TextInput, {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
})({
marginTop: 0,
});