aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ContentSection/ContentSection.tsx
blob: f18684c41242af1e7ce66937f5ac9f7cba2da335 (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
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react';

import {
  Typography,
  Divider,
  makeStyles,
  useMediaQuery,
  Theme,
} from '@material-ui/core';


interface PropTypes {
  sectionName: string;
  level?: number;
}

const useStyles = makeStyles(theme => ({
  content: {
    [theme.breakpoints.up('md')]: {
      padding: theme.spacing(2, 2, 1, 3),
    },
    [theme.breakpoints.down('sm')]: {
      padding: theme.spacing(2, 0),
    },
    marginBottom: theme.spacing(1),
  },
}));

const ContentSection: React.FC<PropTypes> = ({ sectionName, children, level = 0 }) => {
  const classes = useStyles();
  const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm'));

  let adjustedLevel = level + 2; // Make everything smaller
  if (adjustedLevel > 6) adjustedLevel = 6;

  type Variant = 'h3' | 'h4' | 'h5' | 'h6';
  const variant: Variant = `h${adjustedLevel}` as Variant;

  return (
    <>
      <Typography variant={variant}>{sectionName}</Typography>
      <Divider variant={isMobile ? 'fullWidth' : 'middle'} />
      <Typography component="div" className={classes.content}>
        {children}
      </Typography>
    </>
  );
};


export default ContentSection;