Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import * as React from 'react';
|
|
import Button from '@mui/material/Button';
|
|
import Snackbar from '@mui/material/Snackbar';
|
|
import Fade from '@mui/material/Fade';
|
|
import Slide, { SlideProps } from '@mui/material/Slide';
|
|
import Grow, { GrowProps } from '@mui/material/Grow';
|
|
import { TransitionProps } from '@mui/material/transitions';
|
|
|
|
function SlideTransition(props: SlideProps) {
|
|
return <Slide {...props} direction="up" />;
|
|
}
|
|
|
|
function GrowTransition(props: GrowProps) {
|
|
return <Grow {...props} />;
|
|
}
|
|
|
|
export default function TransitionsSnackbar() {
|
|
const [state, setState] = React.useState<{
|
|
open: boolean;
|
|
Transition: React.ComponentType<
|
|
TransitionProps & {
|
|
children: React.ReactElement<any, any>;
|
|
}
|
|
>;
|
|
}>({
|
|
open: false,
|
|
Transition: Fade,
|
|
});
|
|
|
|
const handleClick =
|
|
(
|
|
Transition: React.ComponentType<
|
|
TransitionProps & {
|
|
children: React.ReactElement<any, any>;
|
|
}
|
|
>,
|
|
) =>
|
|
() => {
|
|
setState({
|
|
open: true,
|
|
Transition,
|
|
});
|
|
};
|
|
|
|
const handleClose = () => {
|
|
setState({
|
|
...state,
|
|
open: false,
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<Button onClick={handleClick(GrowTransition)}>Grow Transition</Button>
|
|
<Button onClick={handleClick(Fade)}>Fade Transition</Button>
|
|
<Button onClick={handleClick(SlideTransition)}>Slide Transition</Button>
|
|
<Snackbar
|
|
open={state.open}
|
|
onClose={handleClose}
|
|
slots={{ transition: state.Transition }}
|
|
message="I love snacks"
|
|
key={state.Transition.name}
|
|
autoHideDuration={1200}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|