2017-07-09 17:27:29 +00:00
|
|
|
// @flow
|
2017-07-10 06:53:35 +00:00
|
|
|
import React from 'react';
|
2017-09-04 21:48:56 +00:00
|
|
|
import { observer } from 'mobx-react';
|
2017-10-29 22:33:00 +00:00
|
|
|
import styled, { injectGlobal } from 'styled-components';
|
2017-07-09 17:27:29 +00:00
|
|
|
import ReactModal from 'react-modal';
|
2017-10-27 05:42:08 +00:00
|
|
|
import { color } from 'shared/styles/constants';
|
|
|
|
import { fadeAndScaleIn } from 'shared/styles/animations';
|
2017-10-21 21:05:20 +00:00
|
|
|
import CloseIcon from 'components/Icon/CloseIcon';
|
2017-10-29 22:02:24 +00:00
|
|
|
import Flex from 'shared/components/Flex';
|
2017-07-09 17:27:29 +00:00
|
|
|
|
2017-07-10 06:53:35 +00:00
|
|
|
type Props = {
|
|
|
|
children?: React$Element<any>,
|
|
|
|
isOpen: boolean,
|
|
|
|
title?: string,
|
|
|
|
onRequestClose: () => void,
|
|
|
|
};
|
2017-07-09 17:27:29 +00:00
|
|
|
|
2017-11-13 01:05:17 +00:00
|
|
|
// eslint-disable-next-line
|
2017-10-29 22:33:00 +00:00
|
|
|
injectGlobal`
|
2017-11-08 06:02:07 +00:00
|
|
|
.ReactModal__Overlay {
|
|
|
|
z-index: 100;
|
|
|
|
}
|
|
|
|
|
2017-10-29 22:33:00 +00:00
|
|
|
.ReactModal__Body--open {
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2017-07-10 06:53:35 +00:00
|
|
|
const Modal = ({
|
|
|
|
children,
|
|
|
|
isOpen,
|
2017-09-29 06:22:09 +00:00
|
|
|
title = 'Untitled',
|
2017-07-10 06:53:35 +00:00
|
|
|
onRequestClose,
|
|
|
|
...rest
|
|
|
|
}: Props) => {
|
|
|
|
if (!isOpen) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledModal
|
|
|
|
contentLabel={title}
|
|
|
|
onRequestClose={onRequestClose}
|
|
|
|
isOpen={isOpen}
|
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
<Content column>
|
|
|
|
{title && <h1>{title}</h1>}
|
2017-11-10 22:14:30 +00:00
|
|
|
<Close onClick={onRequestClose}>
|
|
|
|
<CloseIcon size={32} />
|
|
|
|
</Close>
|
2017-07-10 06:53:35 +00:00
|
|
|
{children}
|
|
|
|
</Content>
|
|
|
|
</StyledModal>
|
|
|
|
);
|
|
|
|
};
|
2017-07-09 17:27:29 +00:00
|
|
|
|
2017-07-10 03:02:10 +00:00
|
|
|
const Content = styled(Flex)`
|
|
|
|
width: 640px;
|
|
|
|
max-width: 100%;
|
|
|
|
position: relative;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledModal = styled(ReactModal)`
|
2017-07-12 06:24:12 +00:00
|
|
|
animation: ${fadeAndScaleIn} 250ms ease;
|
2017-07-10 03:02:10 +00:00
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
bottom: 0;
|
|
|
|
right: 0;
|
2017-07-12 05:42:30 +00:00
|
|
|
z-index: 100;
|
2017-07-10 03:02:10 +00:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: flex-start;
|
|
|
|
overflow-x: hidden;
|
|
|
|
overflow-y: auto;
|
|
|
|
background: white;
|
2017-09-29 06:18:15 +00:00
|
|
|
padding: 13vh 2rem 2rem;
|
|
|
|
outline: none;
|
2017-07-10 03:02:10 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Close = styled.a`
|
|
|
|
position: fixed;
|
|
|
|
top: 3rem;
|
|
|
|
right: 3rem;
|
2017-11-10 22:14:30 +00:00
|
|
|
opacity: 0.5;
|
2017-09-04 20:23:20 +00:00
|
|
|
color: ${color.text};
|
2017-07-10 03:02:10 +00:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
2017-07-09 17:27:29 +00:00
|
|
|
`;
|
|
|
|
|
2017-09-04 21:48:56 +00:00
|
|
|
export default observer(Modal);
|