DocSpring / craco-antd

A craco plugin to use Ant Design with create-react-app
MIT License
234 stars 49 forks source link

Using Ant Design Variables in Styled Components #71

Open hshoja opened 2 years ago

hshoja commented 2 years ago

I would like to be able to access the Ant Design variables (which are written in Less) within a styled component. Something like this:

const StyledButton = styled(Button)`
  background-color: @primary-color
`

how can I achieve this?

floatrx commented 2 years ago

Try use native css variable instead.

Map with less variables:

:root {
   --primary-color: var(@primary-color);
   // other global variables
}
const StyledButton = styled(Button)`
  background-color: --primary-color;
`
hshoja commented 2 years ago

Try use native css variable instead.

Map with less variables:

:root {
   --primary-color: var(@primary-color);
   // other global variables
}
const StyledButton = styled(Button)`
  background-color: --primary-color;
`

I used this approach, but we have to define it twice.