Modal.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled from 'styled-components';
  4. import Button from '../Button';
  5. const Wrapper = styled.div`
  6. position: fixed;
  7. width: 100%;
  8. height: 100%;
  9. top: 0;
  10. left: 0;
  11. display: flex;
  12. justify-content: center;
  13. align-items: center;
  14. background-color: rgba(50, 50, 50, 0.8);
  15. z-index: 1000;
  16. `;
  17. const Content = styled.div`
  18. padding: 48px 64px;
  19. text-align: center;
  20. border-radius: 8px;
  21. background-color: white;
  22. @media only screen and (max-width: 768px) {
  23. width: 90%;
  24. padding: 32px;
  25. }
  26. `;
  27. const ButtonsWrapper = styled.div`
  28. display: flex;
  29. justify-content: center;
  30. margin-top: 40px;
  31. button {
  32. margin: 0 16px;
  33. }
  34. `;
  35. const Modal = ({ children, handler, show, close }) =>
  36. show ? (
  37. <Wrapper>
  38. <Content>
  39. {children}
  40. <ButtonsWrapper>
  41. <Button color="gray" onClick={close}>
  42. No
  43. </Button>
  44. <Button onClick={handler}>Yes</Button>
  45. </ButtonsWrapper>
  46. </Content>
  47. </Wrapper>
  48. ) : null;
  49. Modal.propTypes = {
  50. children: PropTypes.node.isRequired,
  51. close: PropTypes.func.isRequired,
  52. handler: PropTypes.func.isRequired,
  53. show: PropTypes.bool,
  54. };
  55. Modal.defaultProps = {
  56. show: false,
  57. };
  58. export default Modal;