Modal.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { FC } from 'react';
  2. import styled from 'styled-components';
  3. import { Flex } from 'reflexbox/styled-components';
  4. import Button from './Button';
  5. interface Props {
  6. close: any; // TODO: typing
  7. handler?: any; // TODO: typing
  8. show?: boolean;
  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 Content = styled.div`
  23. padding: 48px 64px;
  24. text-align: center;
  25. border-radius: 8px;
  26. background-color: white;
  27. @media only screen and (max-width: 768px) {
  28. width: 90%;
  29. padding: 32px;
  30. }
  31. `;
  32. const ButtonsWrapper = styled(Flex).attrs({
  33. justifyContent: 'center',
  34. mt: 40,
  35. })`
  36. button {
  37. margin: 0 16px;
  38. }
  39. `;
  40. const Modal: FC<Props> = ({ children, handler, show, close }) =>
  41. show ? (
  42. <Wrapper>
  43. <Content>
  44. {children}
  45. <ButtonsWrapper>
  46. <Button color="gray" onClick={close}>
  47. {handler ? 'No' : 'Close'}
  48. </Button>
  49. {handler && <Button onClick={handler}>Yes</Button>}
  50. </ButtonsWrapper>
  51. </Content>
  52. </Wrapper>
  53. ) : null;
  54. Modal.defaultProps = {
  55. show: false,
  56. handler: null,
  57. };
  58. export default Modal;