import * as React from 'react'; import Button from '@mui/joy/Button'; import List from '@mui/joy/List'; import ListItem from '@mui/joy/ListItem'; import Typography from '@mui/joy/Typography'; import Stack from '@mui/joy/Stack'; import Snackbar, { SnackbarCloseReason as SnackbarCloseReasonType, } from '@mui/joy/Snackbar'; import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank'; import CheckBoxIcon from '@mui/icons-material/CheckBox'; export default function SnackbarCloseReason() { const [open, setOpen] = React.useState(false); const [reasons, setReasons] = React.useState([]); React.useEffect(() => { if ( (['timeout', 'clickaway', 'escapeKeyDown'] as const).every((item) => reasons.includes(item), ) ) { setOpen(false); } }, [reasons]); return (
{ // @ts-ignore setReasons((prev) => [...new Set([...prev, reason])]); }} onUnmount={() => { setReasons([]); }} sx={{ minWidth: 360 }} > To close this snackbar, you have to: {reasons.includes('timeout') ? ( ) : ( )}{' '} Wait for 3 seconds. {reasons.includes('clickaway') ? ( ) : ( )}{' '} Click outside of the snackbar. {reasons.includes('escapeKeyDown') ? ( ) : ( )}{' '} Press ESC key.
); }