Skip to content

Instantly share code, notes, and snippets.

@mohammed-atif
Last active November 1, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohammed-atif/934052691c58b29af18f582f9f680d12 to your computer and use it in GitHub Desktop.
Save mohammed-atif/934052691c58b29af18f582f9f680d12 to your computer and use it in GitHub Desktop.
Typography Component
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