-
-
Save mohammed-atif/934052691c58b29af18f582f9f680d12 to your computer and use it in GitHub Desktop.
Typography Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import PropTypes from "prop-types"; | |
import Typography from "@material-ui/core/Typography"; | |
const getMappedVariant = (variant) => { | |
switch (variant) { | |
case "header": | |
return "h4"; | |
case "title": | |
return "subtitle1"; | |
case "subtitle": | |
return "subtitle2"; | |
default: | |
return "body1"; | |
} | |
}; | |
const TypographyComponent = (props) => ( | |
<Typography variant={getMappedVariant(props.variant)}> | |
{props.children} | |
</Typography> | |
); | |
TypographyComponent.propTypes = { | |
children: PropTypes.string.isRequired, | |
variant: PropTypes.oneOf(["header", "title", "subtitle", "body"]), | |
}; | |
TypographyComponent.defaultProps = { | |
variant: "body", | |
}; | |
export default TypographyComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment