This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/components/Modal/Modal.js

94 lines
1.7 KiB
JavaScript
Raw Normal View History

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';
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
// 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)`
animation: ${fadeAndScaleIn} 250ms ease;
2017-07-10 03:02:10 +00:00
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
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);