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.js

101 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-07-09 17:27:29 +00:00
// @flow
2018-05-05 23:16:08 +00:00
import * as React from 'react';
2017-09-04 21:48:56 +00:00
import { observer } from 'mobx-react';
2018-11-07 05:58:32 +00:00
import styled, { createGlobalStyle } from 'styled-components';
import breakpoint from 'styled-components-breakpoint';
2017-07-09 17:27:29 +00:00
import ReactModal from 'react-modal';
2018-05-03 04:51:39 +00:00
import { CloseIcon } from 'outline-icons';
2017-10-27 05:42:08 +00:00
import { fadeAndScaleIn } from 'shared/styles/animations';
import Flex from 'shared/components/Flex';
2017-07-09 17:27:29 +00:00
2017-07-10 06:53:35 +00:00
type Props = {
2018-05-05 23:16:08 +00:00
children?: React.Node,
2017-07-10 06:53:35 +00:00
isOpen: boolean,
title?: string,
2018-05-05 23:16:08 +00:00
onRequestClose: () => *,
2017-07-10 06:53:35 +00:00
};
2017-07-09 17:27:29 +00:00
2018-11-07 05:58:32 +00:00
const GlobalStyles = createGlobalStyle`
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 (
2018-11-07 05:58:32 +00:00
<React.Fragment>
<GlobalStyles />
<StyledModal
contentLabel={title}
onRequestClose={onRequestClose}
isOpen={isOpen}
{...rest}
>
<Content column>
{title && <h1>{title}</h1>}
<Close onClick={onRequestClose}>
<CloseIcon size={32} />
</Close>
{children}
</Content>
</StyledModal>
</React.Fragment>
2017-07-10 06:53:35 +00:00
);
};
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: 16px;
right: 16px;
2017-11-10 22:14:30 +00:00
opacity: 0.5;
2018-06-10 02:10:30 +00:00
color: ${props => props.theme.text};
2017-07-10 03:02:10 +00:00
&:hover {
opacity: 1;
}
${breakpoint('tablet')`
top: 3rem;
right: 3rem;
`};
2017-07-09 17:27:29 +00:00
`;
2017-09-04 21:48:56 +00:00
export default observer(Modal);