Javascript 将材质UI排版更改为样式化组件
是否可以转换材质UI元素Javascript 将材质UI排版更改为样式化组件,javascript,reactjs,typescript,material-ui,styled-components,Javascript,Reactjs,Typescript,Material Ui,Styled Components,是否可以转换材质UI元素 <Container component="main" maxWidth="XS"> 另一个例子:我尝试使用这个,但是mt:8也不起作用。我也无法从材质ui系统导入Box,所以在看到一个示例后尝试了这种方法 import Box from '@material-ui/core/Box'; export const StyledBox = styled(Box)` mt: 8; 使用 @material ui/system为构建强大的设计系统提供了称为样
<Container component="main" maxWidth="XS">
另一个例子:我尝试使用这个,但是mt:8也不起作用。我也无法从材质ui系统导入Box,所以在看到一个示例后尝试了这种方法
import Box from '@material-ui/core/Box';
export const StyledBox = styled(Box)`
mt: 8;
使用
@material ui/system为构建强大的设计系统提供了称为样式功能的低级实用程序功能
将其与样式化组件一起使用
import styled from 'styled-components';
import { palette, spacing, typography } from '@material-ui/system';
const Box = styled.div`${palette}${spacing}${typography}`;
排版
请参阅此处的演示:
使现代化
如果我们只想用样式化组件来设置材质ui组件的样式
从普通@material ui/核心导入即可
import { Typography } from '@material-ui/core';
const StyledTyppgraphy = styled(Typography)`
...
`;
请参阅@keikai已经指出的样式化组件文档,您可以 我已经用几个例子做了一个总结。 您只需导入组件并按如下方式使用它:
import { Typography } from "@material-ui/core";
const StyledTypography = styled(Typography)``;
<StyledTypography variant="h5" component="h1"></StyledTypography>
请注意,我提供了一种处理材质UI间距变量的可选方法
如中所述,还可以通过从@material ui/system导入间距来使用间距道具。这样,您就可以应用这些间距道具,而无需扩展材质UI组件。
您也可以在样式化组件中直接使用间距函数,但我认为这超出了这个问题的范围 我不太明白。这种排版的样式是否与普通材质UI核心排版的样式相同?那么,我应该只在其中填写组件/变量值吗?我找不到这样的例子。另外,请查看qs中提到的更新qsAs,我已经尝试过了,但它不能正常工作。即使我使用相同的样式属性,结果也有点不同。也许我需要在样式化组件中使用除变量和组件之外的其他东西
import styled from 'styled-components';
import { palette, spacing, typography } from '@material-ui/system';
const Box = styled.div`${palette}${spacing}${typography}`;
import { Typography } from '@material-ui/core';
const StyledTyppgraphy = styled(Typography)`
...
`;
import { Typography } from "@material-ui/core";
const StyledTypography = styled(Typography)``;
<StyledTypography variant="h5" component="h1"></StyledTypography>
import { Box } from "@material-ui/core";
const StyledBox = styled(Box)``;
<StyledBox mt={8}></StyledBox>