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
98 lines
2.3 KiB
JavaScript
98 lines
2.3 KiB
JavaScript
import * as React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import Backdrop from '@mui/material/Backdrop';
|
|
import Box from '@mui/material/Box';
|
|
import Modal from '@mui/material/Modal';
|
|
import Button from '@mui/material/Button';
|
|
import Typography from '@mui/material/Typography';
|
|
import { useSpring, animated } from '@react-spring/web';
|
|
|
|
const Fade = React.forwardRef(function Fade(props, ref) {
|
|
const {
|
|
children,
|
|
in: open,
|
|
onClick,
|
|
onEnter,
|
|
onExited,
|
|
ownerState,
|
|
...other
|
|
} = props;
|
|
const style = useSpring({
|
|
from: { opacity: 0 },
|
|
to: { opacity: open ? 1 : 0 },
|
|
onStart: () => {
|
|
if (open && onEnter) {
|
|
onEnter(null, true);
|
|
}
|
|
},
|
|
onRest: () => {
|
|
if (!open && onExited) {
|
|
onExited(null, true);
|
|
}
|
|
},
|
|
});
|
|
|
|
return (
|
|
<animated.div ref={ref} style={style} {...other}>
|
|
{React.cloneElement(children, { onClick })}
|
|
</animated.div>
|
|
);
|
|
});
|
|
|
|
Fade.propTypes = {
|
|
children: PropTypes.element.isRequired,
|
|
in: PropTypes.bool,
|
|
onClick: PropTypes.any,
|
|
onEnter: PropTypes.func,
|
|
onExited: PropTypes.func,
|
|
ownerState: PropTypes.any,
|
|
};
|
|
|
|
const style = {
|
|
position: 'absolute',
|
|
top: '50%',
|
|
left: '50%',
|
|
transform: 'translate(-50%, -50%)',
|
|
width: 400,
|
|
bgcolor: 'background.paper',
|
|
border: '2px solid #000',
|
|
boxShadow: 24,
|
|
p: 4,
|
|
};
|
|
|
|
export default function SpringModal() {
|
|
const [open, setOpen] = React.useState(false);
|
|
const handleOpen = () => setOpen(true);
|
|
const handleClose = () => setOpen(false);
|
|
|
|
return (
|
|
<div>
|
|
<Button onClick={handleOpen}>Open modal</Button>
|
|
<Modal
|
|
aria-labelledby="spring-modal-title"
|
|
aria-describedby="spring-modal-description"
|
|
open={open}
|
|
onClose={handleClose}
|
|
closeAfterTransition
|
|
slots={{ backdrop: Backdrop }}
|
|
slotProps={{
|
|
backdrop: {
|
|
TransitionComponent: Fade,
|
|
},
|
|
}}
|
|
>
|
|
<Fade in={open}>
|
|
<Box sx={style}>
|
|
<Typography id="spring-modal-title" variant="h6" component="h2">
|
|
Text in a modal
|
|
</Typography>
|
|
<Typography id="spring-modal-description" sx={{ mt: 2 }}>
|
|
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
|
|
</Typography>
|
|
</Box>
|
|
</Fade>
|
|
</Modal>
|
|
</div>
|
|
);
|
|
}
|