Modal.tsx 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { FC } from "react";
  2. import styled from "styled-components";
  3. import { Flex } from "reflexbox/styled-components";
  4. interface Props {
  5. show: boolean;
  6. id?: string;
  7. closeHandler?: () => unknown;
  8. }
  9. const Wrapper = styled.div`
  10. position: fixed;
  11. width: 100%;
  12. height: 100%;
  13. top: 0;
  14. left: 0;
  15. display: flex;
  16. justify-content: center;
  17. align-items: center;
  18. background-color: rgba(50, 50, 50, 0.8);
  19. z-index: 1000;
  20. `;
  21. const Modal: FC<Props> = ({ children, id, show, closeHandler }) => {
  22. if (!show) return null;
  23. const onClickOutside = e => {
  24. if (e.target.id === id) closeHandler();
  25. };
  26. return (
  27. <Wrapper id={id} onClick={onClickOutside}>
  28. <Flex
  29. minWidth={[400, 450]}
  30. maxWidth={0.9}
  31. py={[32, 32, 48]}
  32. px={[24, 24, 32]}
  33. style={{ borderRadius: 8, backgroundColor: "white" }}
  34. flexDirection="column"
  35. >
  36. {children}
  37. </Flex>
  38. </Wrapper>
  39. );
  40. };
  41. Modal.defaultProps = {
  42. show: false
  43. };
  44. export default Modal;