Skip to content
Snippets Groups Projects
Commit 83c0bde2 authored by GyDi's avatar GyDi
Browse files

feat: distinguish level notice

parent 97f2bc87
No related branches found
No related tags found
No related merge requests found
import { useMemo, useState } from "react";
import { IconButton, Slide, Snackbar } from "@mui/material";
import { Close } from "@mui/icons-material";
import { Box, IconButton, Slide, Snackbar } from "@mui/material";
import { Close, CheckCircleRounded, ErrorRounded } from "@mui/icons-material";
interface NoticeInstance {
info: (msg: string) => void;
......@@ -16,6 +16,17 @@ const useNotice = () => {
if (reason !== "clickaway") setMessage("");
};
const msgElement =
level === "info" ? (
message
) : (
<Box sx={{ display: "flex", alignItems: "center" }}>
{level === "error" && <ErrorRounded color="error" />}
{level === "success" && <CheckCircleRounded color="success" />}
<span style={{ marginLeft: 4 }}>{message}</span>
</Box>
);
const element = useMemo(
() => (
<Snackbar
......@@ -23,8 +34,10 @@ const useNotice = () => {
anchorOrigin={{ vertical: "top", horizontal: "right" }}
autoHideDuration={3000}
onClose={handleClose}
message={message}
message={msgElement}
sx={{ maxWidth: 360 }}
TransitionComponent={(p) => <Slide {...p} direction="left" />}
transitionDuration={200}
action={
<IconButton
size="small"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment