Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eeb1b93

Browse files
committed
emotion: EnterpriseSnackbar
1 parent 8d7e9a8 commit eeb1b93

File tree

1 file changed

+34
-49
lines changed

1 file changed

+34
-49
lines changed

site/src/components/GlobalSnackbar/EnterpriseSnackbar.tsx

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import IconButton from "@mui/material/IconButton";
22
import Snackbar, {
33
SnackbarProps as MuiSnackbarProps,
44
} from "@mui/material/Snackbar";
5-
import { makeStyles } from "@mui/styles";
65
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";
99

1010
type EnterpriseSnackbarVariant = "error" | "info" | "success";
1111

@@ -30,7 +30,18 @@ export interface EnterpriseSnackbarProps extends MuiSnackbarProps {
3030
export const EnterpriseSnackbar: FC<
3131
React.PropsWithChildren<EnterpriseSnackbarProps>
3232
> = ({ 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+
`;
3445

3546
return (
3647
<Snackbar
@@ -40,67 +51,41 @@ export const EnterpriseSnackbar: FC<
4051
}}
4152
{...rest}
4253
action={
43-
<div className={styles.actionWrapper}>
54+
<div css={styles.actionWrapper}>
4455
{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" />
5158
</IconButton>
5259
</div>
5360
}
5461
ContentProps={{
5562
...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,
6264
}}
6365
onClose={onClose}
6466
/>
6567
);
6668
};
6769

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 = {
6982
actionWrapper: {
7083
display: "flex",
7184
alignItems: "center",
7285
},
73-
iconButton: {
74-
padding: 0,
75-
},
76-
closeIcon: {
86+
closeIcon: (theme) => ({
7787
width: 25,
7888
height: 25,
7989
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

Comments
 (0)