|
| 1 | +import React from 'react'; |
| 2 | +import styled, { css } from 'styled-components'; |
| 3 | +import PropTypes from 'prop-types'; |
| 4 | +import Text from './Text'; |
| 5 | + |
| 6 | +const Content = styled.div` |
| 7 | + background-color: ${({ theme }) => theme.colors.modalColor}; |
| 8 | + border-radius: 5px; |
| 9 | + max-width: 360px; |
| 10 | + transition: transform 0.3s ease-out; |
| 11 | + z-index: 9999; |
| 12 | +`; |
| 13 | + |
| 14 | +const Overlay = styled.div` |
| 15 | + background-color: rgba(0, 0, 0, 0.8); |
| 16 | + bottom: 0; |
| 17 | + dsplay: flex; |
| 18 | + left: 0; |
| 19 | + opacity: 0; |
| 20 | + position: fixed; |
| 21 | + right: 0; |
| 22 | + top: 0; |
| 23 | + transition: all 0.3s; |
| 24 | +`; |
| 25 | + |
| 26 | +const Wrapper = styled.div` |
| 27 | + align-items: center; |
| 28 | + bottom: 0; |
| 29 | + dsplay: flex; |
| 30 | + justify-content: center; |
| 31 | + left: 0; |
| 32 | + opacity: 0; |
| 33 | + pointer-events: none; |
| 34 | + position: fixed; |
| 35 | + right: 0; |
| 36 | + top: 0; |
| 37 | + transition: all 0.3s; |
| 38 | + visibility: hidden; |
| 39 | + z-index: 9; |
| 40 | +
|
| 41 | + ${Content} { |
| 42 | + transform: translate(0, -50px); |
| 43 | + } |
| 44 | +
|
| 45 | + ${({ isOpen }) => |
| 46 | + isOpen && |
| 47 | + css` |
| 48 | + display: flex; |
| 49 | + opacity: 1; |
| 50 | + pointer-events: auto; |
| 51 | + visibility: visible; |
| 52 | +
|
| 53 | + ${Content} { |
| 54 | + transform: translate(0, 0); |
| 55 | + } |
| 56 | +
|
| 57 | + ${Overlay} { |
| 58 | + opacity: 1; |
| 59 | + } |
| 60 | + `} |
| 61 | +`; |
| 62 | + |
| 63 | +const HeaderWrapper = styled.div` |
| 64 | + align-items: center; |
| 65 | + border-bottom: 1px solid ${({ theme }) => theme.colors.outlineColor}; |
| 66 | + display: flex; |
| 67 | + justify-content: center; |
| 68 | + padding: 20px; |
| 69 | +`; |
| 70 | + |
| 71 | +const Body = styled.div` |
| 72 | + padding: 15px; |
| 73 | + position: relative; |
| 74 | +`; |
| 75 | + |
| 76 | +const Footer = styled.div` |
| 77 | + display: flex; |
| 78 | + justify-content: center; |
| 79 | + padding: 0 15px 15px 15px; |
| 80 | +`; |
| 81 | + |
| 82 | +const Header = ({ children, ...props }) => { |
| 83 | + return ( |
| 84 | + <HeaderWrapper {...props}> |
| 85 | + <Text align="center">{children}</Text> |
| 86 | + </HeaderWrapper> |
| 87 | + ); |
| 88 | +}; |
| 89 | + |
| 90 | +const Modal = ({ children, isOpen, toggle }) => ( |
| 91 | + <Wrapper isOpen={isOpen}> |
| 92 | + <Overlay onClick={toggle} /> |
| 93 | + <Content>{children}</Content> |
| 94 | + </Wrapper> |
| 95 | +); |
| 96 | + |
| 97 | +Modal.Header = Header; |
| 98 | +Modal.Body = Body; |
| 99 | +Modal.Footer = Footer; |
| 100 | + |
| 101 | +Modal.propTypes = { |
| 102 | + children: PropTypes.node.isRequired, |
| 103 | + isOpen: PropTypes.bool.isRequired, |
| 104 | + toggle: PropTypes.func.isRequired |
| 105 | +}; |
| 106 | + |
| 107 | +export default Modal; |
0 commit comments