Skip to content

Commit

Permalink
[#41] Centering of the definitions
Browse files Browse the repository at this point in the history
Definitions are centred in the box, it looks better when the definition is short
  • Loading branch information
filip-kopecky committed Oct 15, 2021
1 parent 05d9adf commit 05e298c
Showing 1 changed file with 47 additions and 40 deletions.
87 changes: 47 additions & 40 deletions src/components/DefinitionWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
import React, {ReactElement} from "react";
import {Box, BoxProps, Container, Grid, Typography} from "@material-ui/core";
import {makeStyles} from "@material-ui/core/styles";
import React, { ReactElement } from "react";
import { Box, BoxProps, Container, Grid, Typography } from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles";

interface DefinitionWrapperProps {
definition?: string;
source?: string;
illustration: ReactElement;
definition?: string;
source?: string;
illustration: ReactElement;
}

const defaultProps = {
borderColor: "primary.main",
minHeight: 144,
px: 3,
py: 2,
border: 2,
borderRadius: 16,
borderColor: "primary.main",
minHeight: 144,
px: 3,
py: 2,
border: 2,
borderRadius: 16,
};

const useStyles = makeStyles((theme) => ({
definitionImageWrapper: {
[theme.breakpoints.down("xs")]: {
display: "none",
},
definitionImageWrapper: {
[theme.breakpoints.down("xs")]: {
display: "none",
},
},
}));

const DefinitionWrapper: React.FC<DefinitionWrapperProps & BoxProps> = (props) => {
const classes = useStyles();
const DefinitionWrapper: React.FC<DefinitionWrapperProps & BoxProps> = (
props
) => {
const classes = useStyles();

return (
<Container>
<Box px={2} mt={4}>
<Grid container>
<Grid item sm={10} xs={12}>
<Box {...defaultProps}>
<Box mb={2}>
<Typography variant="h6">{props.definition}</Typography>
</Box>
{props.source && (
<Box fontStyle="italic" color="text.disabled">
<Typography variant="body1">{props.source}</Typography>
</Box>
)}
</Box>
</Grid>
<Grid item sm={2} className={classes.definitionImageWrapper}>
{props.illustration}
</Grid>
</Grid>
return (
<Container>
<Box px={2} mt={4}>
<Grid container>
<Grid item sm={10} xs={12}>
<Box
{...defaultProps}
display="flex"
flexDirection="column"
justifyContent="center"
>
<Box mb={props.source ? 2 : 0}>
<Typography variant="h6">{props.definition}</Typography>
</Box>
{props.source && (
<Box fontStyle="italic" color="text.disabled">
<Typography variant="body1">{props.source}</Typography>
</Box>
)}
</Box>
</Container>
);
</Grid>
<Grid item sm={2} className={classes.definitionImageWrapper}>
{props.illustration}
</Grid>
</Grid>
</Box>
</Container>
);
};

export default DefinitionWrapper;

0 comments on commit 05e298c

Please sign in to comment.