javascript - 将 Material UI Typography 更改为样式组件

标签 javascript reactjs typescript material-ui styled-components

是否可以转换 Material UI 元素

<Container component="main" maxWidth="XS">
<Typography component="h1" variant="h5">
          Sign in
        </Typography>

进入样式组件?

我尝试使用此方法进行排版,但文本似乎小得多。

export const Typo = styled.h5`
export const Typo = styled(Typography)`
component: h1; 
variant: h5;
`

另一个例子:我尝试使用这个,但 mt: 8 也不起作用。我也无法从 Material ui 系统导入 Box,所以在看到示例后尝试了此方法。

import Box from '@material-ui/core/Box';

export const StyledBox = styled(Box)`
mt: 8;

最佳答案

使用@material-ui/system

@material-ui/system provides low-level utility functions called "style functions" for building powerful design systems.

将其与样式组件一起使用

import styled from 'styled-components';
import { palette, spacing, typography } from '@material-ui/system';

const Box = styled.div`${palette}${spacing}${typography}`;

对于排版

请参阅此处的演示:https://material-ui.com/system/typography/#typography

<小时/>

更新

如果我们只想使用styled-components来设置material-ui组件的样式

从正常的@material-ui/core导入就可以了

import { Typography } from '@material-ui/core';

const StyledTyppgraphy = styled(Typography)`
  ...
`;

引用:styled-components文档Extending Styles

关于javascript - 将 Material UI Typography 更改为样式组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61059715/

相关文章:

javascript - React useCallback 设置对回调内调用的函数的依赖

javascript - 将脚本写入 DOM 并在 DOM 完成渲染之前让它运行

reactjs - 无法在Docker上运行React应用程序

javascript - 如何为内存游戏的 if/else if/else 语句创建获胜条件

reactjs - 指定 axios 响应数据类型

javascript - 可使用(或不带)_references.ts 自动解析和排序 TypeScript 依赖项的工具?

javascript - Jasmine 测试 toEqual 是正确的值,但测试仍然失败

javascript - 向 div 添加 onclick 事件

javascript - 用于 PhoneGap/cordova 的条形码扫描器

javascript - 如何在 React 中集中处理 API 调用的错误(使用 Axios)