aboutsummaryrefslogtreecommitdiff
path: root/src/components/ModalScreen/ModalScreen.tsx
blob: 6b7c52c809469b94ad17e934e0a6321778ecc282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { useCallback } from 'react';
import { useHistory } from 'react-router-dom';
import {
  Dialog,
  Toolbar,
  Typography,
  IconButton,
  useMediaQuery,
  useTheme
} from '@material-ui/core';
import CloseIcon from '@material-ui/icons/Close';

interface PropTypes {
  title: string;
}

const ModalScreen: React.FC<PropTypes> = ({ title, children }) => {
  const theme = useTheme();
  const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
  const history = useHistory();

  const handleClose = useCallback(() => history.goBack(), [history]);

  return (
    <Dialog fullScreen={isMobile} fullWidth open>
      <Toolbar color="primary">
        <IconButton edge="start" onClick={handleClose}>
          <CloseIcon />
        </IconButton>
        <Typography variant="h6">
          { title }
        </Typography>
      </Toolbar>
      { children }
    </Dialog>
  );
};

export default ModalScreen;