Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to change Antd internal button's color?

Tags:

css

button

antd

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?

like image 670
Dong Avatar asked Jun 22 '19 18:06

Dong


People also ask

How do I change the color of my ANTD switch?

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.

How do I change the color of my spinner on my ANTD?

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 .

How do I customize my ANTD components?

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.


2 Answers

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>
  );
};

Edit quizzical-chatterjee-8vp4v

like image 129
Dennis Vash Avatar answered Sep 18 '22 20:09

Dennis Vash


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;
}
like image 32
Eliya Cohen Avatar answered Sep 20 '22 20:09

Eliya Cohen