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" ;
4
5
import IconButton from "@mui/material/IconButton" ;
5
6
import InputBase from "@mui/material/InputBase" ;
6
7
import Tooltip from "@mui/material/Tooltip" ;
@@ -13,26 +14,29 @@ const inputSidePadding = 12;
13
14
14
15
type NewFilterProps = {
15
16
value : string ;
17
+ error ?: string ;
16
18
onChange : ( value : string ) => void ;
17
19
} ;
18
20
19
21
export const NewFilter : FC < NewFilterProps > = ( props ) => {
20
22
const theme = useTheme ( ) ;
21
- const { value, onChange } = props ;
23
+ const { value, error , onChange } = props ;
22
24
const isEmpty = value . length === 0 ;
23
25
26
+ const outlineCSS = ( color : string ) => ( {
27
+ outline : `2px solid ${ color } ` ,
28
+ outlineOffset : - 1 , // Overrides the border
29
+ } ) ;
30
+
24
31
return (
25
32
< div
26
33
css = { {
27
34
borderRadius : inputBorderRadius ,
28
35
border : `1px solid ${ theme . palette . divider } ` ,
29
36
height : inputHeight ,
30
37
padding : `0 ${ inputSidePadding } px` ,
31
-
32
- "&:focus-within" : {
33
- outline : `2px solid ${ theme . palette . primary . main } ` ,
34
- outlineOffset : - 1 , // Overrides the border
35
- } ,
38
+ "&:focus-within" : error ? "" : outlineCSS ( theme . palette . primary . main ) ,
39
+ ...( error ? outlineCSS ( theme . palette . error . main ) : { } ) ,
36
40
} }
37
41
>
38
42
< InputBase
@@ -76,6 +80,7 @@ export const NewFilter: FC<NewFilterProps> = (props) => {
76
80
onChange ( e . currentTarget . value ) ;
77
81
} }
78
82
/>
83
+ { error && < FormHelperText error > { error } </ FormHelperText > }
79
84
</ div >
80
85
) ;
81
86
} ;
0 commit comments