Typography
The Typography component is a wrapper for Material-UI's Typography that provides an easy way to render text with different styles and variants.
This component wraps Material-UI’s Typography component and allows you to easily control the text's style by specifying the variant you need.
Importing
Each component in this boilerplate can be imported from the components project as a named reference.
Example:
jsx
import { Typography } from "components";Ensure your package.json references the components project and that the version matches.
json
"dependencies": {
"components": "1.0.0"
}Usage
Example
Here’s a simple example of using the Typography wrapper:
jsx
import { Typography } from "components";
function MyApp() {
return <Typography variant="h4">This is a heading</Typography>;
}
export default MyApp;Component API
Props
variant: (optional) The typography variant to apply to the text. It can be one of the following:"h1","h2","h3","h4","h5","h6": Heading variants."subtitle1","subtitle2": Subtitle variants."body1","body2": Body text variants."caption","overline","button","inherit": Other text styles (e.g., captions, overlines, or inherited styles).
children: (required) The text content to render inside theTypographycomponent.props: Any other props passed to theTextwill be forwarded to the Material-UITypographycomponent.
Example with Custom Variant
jsx
import { Typography } from "components";
function MyApp() {
return (
<div>
<Typography variant="h2">Main Title</Typography>
<Typography variant="body1">
This is a paragraph of body text, styled with the "body1" variant.
</Typography>
</div>
);
}
export default MyApp;In this example, different typography variants are used for the title and body text.
Notes
- Typography Variants: The
variantprop determines the style of the text. You can choose from a variety of predefined Material-UI typography styles. - Custom Content: The
childrenprop is required and represents the content to be displayed inside theTypographycomponent.
For more details, check out the Material-UI Typography documentation.