umami/components/common/Modal.js

27 lines
724 B
JavaScript
Raw Normal View History

2020-08-07 11:27:12 +02:00
import React from 'react';
2021-02-16 13:28:32 +01:00
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
2020-08-07 11:27:12 +02:00
import { useSpring, animated } from 'react-spring';
import styles from './Modal.module.css';
2021-02-16 13:28:32 +01:00
function Modal({ title, children }) {
2020-08-07 11:27:12 +02:00
const props = useSpring({ opacity: 1, from: { opacity: 0 } });
return ReactDOM.createPortal(
2020-08-07 11:27:12 +02:00
<animated.div className={styles.modal} style={props}>
<div className={styles.content}>
{title && <div className={styles.header}>{title}</div>}
<div className={styles.body}>{children}</div>
</div>
</animated.div>,
document.getElementById('__modals'),
2020-08-07 11:27:12 +02:00
);
}
2021-02-16 13:28:32 +01:00
Modal.propTypes = {
title: PropTypes.node,
children: PropTypes.node,
};
export default Modal;