1
1
import { useTheme } from "@emotion/react" ;
2
2
import CloseOutlined from "@mui/icons-material/CloseOutlined" ;
3
3
import SearchOutlined from "@mui/icons-material/SearchOutlined" ;
4
- import FormHelperText from "@mui/material/FormHelperText" ;
5
4
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" ;
7
7
import Tooltip from "@mui/material/Tooltip" ;
8
8
import { visuallyHidden } from "@mui/utils" ;
9
9
import type { FC } from "react" ;
10
10
11
- const inputHeight = 36 ;
12
- const inputBorderRadius = 6 ;
13
- const inputSidePadding = 12 ;
14
-
15
11
type NewFilterProps = {
16
12
value : string ;
17
13
error ?: string ;
@@ -23,64 +19,50 @@ export const NewFilter: FC<NewFilterProps> = (props) => {
23
19
const { value, error, onChange } = props ;
24
20
const isEmpty = value . length === 0 ;
25
21
26
- const outlineCSS = ( color : string ) => ( {
27
- outline : `2px solid ${ color } ` ,
28
- outlineOffset : - 1 , // Overrides the border
29
- } ) ;
30
-
31
22
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 ,
61
52
} }
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
+ />
85
67
) ;
86
68
} ;
0 commit comments