dwysokinski.me/src/components/Section.js

65 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-01-17 08:31:50 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
2021-01-17 08:31:50 +00:00
import { makeStyles } from '@material-ui/core/styles';
2020-07-13 17:04:46 +00:00
export const BG_COLOR = {
2021-01-17 08:31:50 +00:00
TRANSPARENT: 'transparent',
BLACK: 'black',
PRIMARY: 'primary',
};
2020-07-13 17:04:46 +00:00
export const SIZE = {
2021-01-17 08:31:50 +00:00
SMALL: 'small',
MEDIUM: 'medium',
};
function Section({ children, className, bgColor, component, size, ...rest }) {
2021-01-17 08:31:50 +00:00
const classes = useStyles();
const Component = component || 'section';
2020-07-13 17:04:46 +00:00
return (
<Component
2020-07-13 17:04:46 +00:00
className={classnames(classes.section, className, {
2021-01-17 08:31:50 +00:00
'is-primary': bgColor === BG_COLOR.PRIMARY,
'is-black': bgColor === BG_COLOR.BLACK,
'is-small': size === SIZE.SMALL,
2020-07-13 17:04:46 +00:00
})}
{...rest}
2020-07-13 17:04:46 +00:00
>
{children}
</Component>
2021-01-17 08:31:50 +00:00
);
2020-07-13 17:04:46 +00:00
}
Section.defaultProps = {
bgColor: BG_COLOR.TRANSPARENT,
size: SIZE.MEDIUM,
2021-01-17 08:31:50 +00:00
};
2020-07-13 17:04:46 +00:00
Section.propTypes = {
bgColor: PropTypes.oneOf(Object.values(BG_COLOR)).isRequired,
size: PropTypes.oneOf(Object.values(SIZE)).isRequired,
2021-01-17 08:31:50 +00:00
};
const useStyles = makeStyles(theme => ({
section: {
padding: '3rem 0',
'&.is-primary': {
backgroundColor: theme.palette.primary.main,
},
'&.is-black': {
backgroundColor: '#000',
color: '#fff',
},
[theme.breakpoints.up('md')]: {
padding: '6rem 0',
},
'&.is-small': {
padding: '3rem 0',
},
},
}));
2021-01-17 08:31:50 +00:00
export default Section;