Modal.tsx 1.2 KB

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