References:
- https://ant.design/docs/react/customize-theme
- https://github.com/santospatrick/cra-antd-theme
- https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less
Signin Form | Signin Form as components |
---|---|
![]() |
![]() |
Bad:
import styled from 'styled-components';
const LoginButton = styled.button`
background-color: #FF377B;
width: 100%;
font-family: Poppins;
`
function SigninForm() {
return (
<form>
// ...
<LoginButton />
</form>
)
}
- Recreating an existing component Ant Design already implements.
- Setting
width: 100%
in styles, but Ant Design's button already has a prop for that. - Setting font-family locally, instead of globally
Good:
// SigninForm.js
import { Button } from 'antd';
function SigninForm() {
return (
<form>
// ...
<Button block>Sign In</Button>
</form>
)
}
// theme.js
module.exports = {
"@font-family": "Poppins",
"@primary-color": "#FF377B"
}
- Using Ant Design's
<Button />
component - Using
<Button />
propblock
to fulfill needed width - Customizing all components primary color (#FF377B), not only
<Button />
local styles - Setting variables in
theme.js
makes them reusable in all components, even third parties that sometimes we need.