Skip to content

Commit d41d307

Browse files
committed
Simplify component
1 parent f6df4fa commit d41d307

File tree

1 file changed

+45
-63
lines changed

1 file changed

+45
-63
lines changed
Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { useTheme } from "@emotion/react";
22
import CloseOutlined from "@mui/icons-material/CloseOutlined";
33
import SearchOutlined from "@mui/icons-material/SearchOutlined";
4-
import FormHelperText from "@mui/material/FormHelperText";
54
import IconButton from "@mui/material/IconButton";
6-
import InputBase from "@mui/material/InputBase";
5+
import InputAdornment from "@mui/material/InputAdornment";
6+
import TextField from "@mui/material/TextField";
77
import Tooltip from "@mui/material/Tooltip";
88
import { visuallyHidden } from "@mui/utils";
99
import type { FC } from "react";
1010

11-
const inputHeight = 36;
12-
const inputBorderRadius = 6;
13-
const inputSidePadding = 12;
14-
1511
type NewFilterProps = {
1612
value: string;
1713
error?: string;
@@ -23,64 +19,50 @@ export const NewFilter: FC<NewFilterProps> = (props) => {
2319
const { value, error, onChange } = props;
2420
const isEmpty = value.length === 0;
2521

26-
const outlineCSS = (color: string) => ({
27-
outline: `2px solid ${color}`,
28-
outlineOffset: -1, // Overrides the border
29-
});
30-
3122
return (
32-
<div
33-
css={{
34-
borderRadius: inputBorderRadius,
35-
border: `1px solid ${theme.palette.divider}`,
36-
height: inputHeight,
37-
padding: `0 ${inputSidePadding}px`,
38-
"&:focus-within": error ? "" : outlineCSS(theme.palette.primary.main),
39-
...(error ? outlineCSS(theme.palette.error.main) : {}),
40-
}}
41-
>
42-
<InputBase
43-
startAdornment={
44-
<SearchOutlined
45-
role="presentation"
46-
css={{
47-
width: 14,
48-
height: 14,
49-
color: theme.palette.text.secondary,
50-
marginRight: inputSidePadding / 2,
51-
}}
52-
/>
53-
}
54-
endAdornment={
55-
!isEmpty && (
56-
<Tooltip title="Clear filter">
57-
<IconButton
58-
size="small"
59-
onClick={() => {
60-
onChange("");
23+
<TextField
24+
error={Boolean(error)}
25+
helperText={error}
26+
type="text"
27+
InputProps={{
28+
size: "small",
29+
startAdornment: (
30+
<InputAdornment position="start">
31+
<SearchOutlined
32+
role="presentation"
33+
css={{
34+
fontSize: 14,
35+
color: theme.palette.text.secondary,
36+
}}
37+
/>
38+
</InputAdornment>
39+
),
40+
endAdornment: !isEmpty && (
41+
<Tooltip title="Clear filter">
42+
<IconButton
43+
size="small"
44+
onClick={() => {
45+
onChange("");
46+
}}
47+
>
48+
<CloseOutlined
49+
css={{
50+
fontSize: 14,
51+
color: theme.palette.text.secondary,
6152
}}
62-
>
63-
<CloseOutlined
64-
css={{
65-
width: 14,
66-
height: 14,
67-
color: theme.palette.text.secondary,
68-
}}
69-
/>
70-
<span css={{ ...visuallyHidden }}>Clear filter</span>
71-
</IconButton>
72-
</Tooltip>
73-
)
74-
}
75-
fullWidth
76-
placeholder="Search..."
77-
css={{ fontSize: 14, height: "100%" }}
78-
value={value}
79-
onChange={(e) => {
80-
onChange(e.currentTarget.value);
81-
}}
82-
/>
83-
{error && <FormHelperText error>{error}</FormHelperText>}
84-
</div>
53+
/>
54+
<span css={{ ...visuallyHidden }}>Clear filter</span>
55+
</IconButton>
56+
</Tooltip>
57+
),
58+
}}
59+
fullWidth
60+
placeholder="Search..."
61+
css={{ fontSize: 14, height: "100%" }}
62+
value={value}
63+
onChange={(e) => {
64+
onChange(e.currentTarget.value);
65+
}}
66+
/>
8567
);
8668
};

0 commit comments

Comments
 (0)