【发布时间】:2021-01-29 03:40:15
【问题描述】:
我已尝试完全按照此处记录的内容进行操作:
How to theme components with styled-components and Material-UI?
import React from "react";
import { withTheme } from "@material-ui/core/styles";
import styled from "styled-components";
const StyledDiv = withTheme(styled.div`
background: ${props => props.theme.palette.primary.main};
color: ${props => props.theme.palette.primary.contrastText};
`);
export default function App() {
return (
<StyledDiv>
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</StyledDiv>
);
}
但是,我没有像上面那样使用“标准”HTML 组件,而是尝试使用 Material-UI 按钮,但没有成功。有人可以帮我解决我做错了什么吗?
这就是我正在尝试的:
styles.ts
import styled from 'styled-components';
import { withTheme } from "@material-ui/core/styles";
import { Button } from '@material-ui/core';
export const StyledInnerSignInButton = withTheme(styled(Button)`
margin: ${props => props.theme.spacing(3, 0, 2)};
`)
index.tsx
import { StyledInnerSignInButton } from './styles';
[...]
<StyledInnerSignInButton
type="submit"
fullWidth
variant="contained"
color="primary"
>
Sign In
</StyledInnerSignInButton>
我被困在这里,仍然是 React 新手。非常感谢任何帮助!
【问题讨论】:
标签: javascript reactjs material-ui styled-components