@@ -2,10 +2,10 @@ import IconButton from "@mui/material/IconButton";
2
2
import Snackbar , {
3
3
SnackbarProps as MuiSnackbarProps ,
4
4
} from "@mui/material/Snackbar" ;
5
- import { makeStyles } from "@mui/styles" ;
6
5
import CloseIcon from "@mui/icons-material/Close" ;
7
- import { FC } from "react" ;
8
- import { combineClasses } from "utils/combineClasses" ;
6
+ import { type FC } from "react" ;
7
+ import { css } from "@emotion/css" ;
8
+ import { type Interpolation , type Theme , useTheme } from "@emotion/react" ;
9
9
10
10
type EnterpriseSnackbarVariant = "error" | "info" | "success" ;
11
11
@@ -30,7 +30,18 @@ export interface EnterpriseSnackbarProps extends MuiSnackbarProps {
30
30
export const EnterpriseSnackbar : FC <
31
31
React . PropsWithChildren < EnterpriseSnackbarProps >
32
32
> = ( { onClose, variant = "info" , ContentProps = { } , action, ...rest } ) => {
33
- const styles = useStyles ( ) ;
33
+ const theme = useTheme ( ) ;
34
+
35
+ const snackbarContentStyles = css `
36
+ border : 1px solid ${ theme . palette . divider } ;
37
+ border-left : 4px solid ${ variantColor ( variant , theme ) } ;
38
+ border-radius : ${ theme . shape . borderRadius } px;
39
+ padding : ${ theme . spacing ( 1 , 3 , 1 , 2 ) } ;
40
+ box-shadow : ${ theme . shadows [ 6 ] } ;
41
+ align-items : inherit;
42
+ background-color : ${ theme . palette . background . paper } ;
43
+ color : ${ theme . palette . text . secondary } ;
44
+ ` ;
34
45
35
46
return (
36
47
< Snackbar
@@ -40,67 +51,41 @@ export const EnterpriseSnackbar: FC<
40
51
} }
41
52
{ ...rest }
42
53
action = {
43
- < div className = { styles . actionWrapper } >
54
+ < div css = { styles . actionWrapper } >
44
55
{ action }
45
- < IconButton
46
- onClick = { onClose }
47
- className = { styles . iconButton }
48
- size = "large"
49
- >
50
- < CloseIcon className = { styles . closeIcon } aria-label = "close" />
56
+ < IconButton onClick = { onClose } css = { { padding : 0 } } size = "large" >
57
+ < CloseIcon css = { styles . closeIcon } aria-label = "close" />
51
58
</ IconButton >
52
59
</ div >
53
60
}
54
61
ContentProps = { {
55
62
...ContentProps ,
56
- className : combineClasses ( {
57
- [ styles . snackbarContent ] : true ,
58
- [ styles . snackbarContentInfo ] : variant === "info" ,
59
- [ styles . snackbarContentError ] : variant === "error" ,
60
- [ styles . snackbarContentSuccess ] : variant === "success" ,
61
- } ) ,
63
+ className : snackbarContentStyles ,
62
64
} }
63
65
onClose = { onClose }
64
66
/>
65
67
) ;
66
68
} ;
67
69
68
- const useStyles = makeStyles ( ( theme ) => ( {
70
+ const variantColor = ( variant : EnterpriseSnackbarVariant , theme : Theme ) => {
71
+ switch ( variant ) {
72
+ case "error" :
73
+ return theme . palette . error . main ;
74
+ case "info" :
75
+ return theme . palette . info . main ;
76
+ case "success" :
77
+ return theme . palette . success . main ;
78
+ }
79
+ } ;
80
+
81
+ const styles = {
69
82
actionWrapper : {
70
83
display : "flex" ,
71
84
alignItems : "center" ,
72
85
} ,
73
- iconButton : {
74
- padding : 0 ,
75
- } ,
76
- closeIcon : {
86
+ closeIcon : ( theme ) => ( {
77
87
width : 25 ,
78
88
height : 25 ,
79
89
color : theme . palette . primary . contrastText ,
80
- } ,
81
- snackbarContent : {
82
- border : `1px solid ${ theme . palette . divider } ` ,
83
- borderLeft : `4px solid ${ theme . palette . primary . main } ` ,
84
- borderRadius : theme . shape . borderRadius ,
85
- padding : `
86
- ${ theme . spacing ( 1 ) } px
87
- ${ theme . spacing ( 3 ) } px
88
- ${ theme . spacing ( 1 ) } px
89
- ${ theme . spacing ( 2 ) } px
90
- ` ,
91
- boxShadow : theme . shadows [ 6 ] ,
92
- alignItems : "inherit" ,
93
- backgroundColor : theme . palette . background . paper ,
94
- color : theme . palette . text . secondary ,
95
- } ,
96
- snackbarContentInfo : {
97
- // Use success color as a highlight
98
- borderLeftColor : theme . palette . primary . main ,
99
- } ,
100
- snackbarContentError : {
101
- borderLeftColor : theme . palette . error . main ,
102
- } ,
103
- snackbarContentSuccess : {
104
- borderLeftColor : theme . palette . success . main ,
105
- } ,
106
- } ) ) ;
90
+ } ) ,
91
+ } satisfies Record < string , Interpolation < Theme > > ;
0 commit comments