I am using antd for my app. I need to change the color of a default Primary Button from Blue to Grey. It seems like antd doesn't provide such an option. How can I change the button color easily?
Using Batch Styler pluginSwitch to Color tab. You will see a list of color styles available in the project. Select color group. Click on Daybreak Blue / blue-1 style and then on Daybreak Blue / blue-10 while holding down Shift.
You can set the Spin Component Color by adapting the background-color of the ant-spin-dot-item in your component css file. Here is a CodeSandBox demo with a changed index. css .
If we decide to customize another component in the project, even a widely used one, we will just need to add a file with the wrapper and change the path of that component in the file with re-exports located at src/components/antd/index.
The formal solution by antd
is the style
props as mentioned on every component's API:
<Button type="primary" style={{ background: "red", borderColor: "yellow" }}>
Submit
</Button>;
Moreover, when you want to override the style for every component in your application, you should override the CSS class or Customize Theme as mentioned.
// Should be used for overriding all buttons.
// Import the css on entry point.
.ant-btn-primary {
background-color: red;
}
Also, note that you can style the button's container and target its color (Without affecting the whole application styling):
.button-container {
.ant-btn-primary {
background-color: palevioletred;
}
}
An example with CSS-in-JS:
const ButtonContainer = styled.div`
.ant-btn-primary {
background-color: red;
}
`;
const App = () => {
return (
<ButtonContainer>
<Button type="primary">My Button</Button>
</ButtonContainer>
);
};
I'm unfamiliar with Ant Design, but you can see in their docs (Customize Theme) that you're able to edit the primary color like so:
@primary-color: #1890ff; // primary color for all components
In case you want to change only the button's color, you can create a new var:
@button-color: #757575; // a custom variable
and then add a rule (which will override the source):
.ant-btn-primary {
background-color: @button-color;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With