5

i need to override the default blue (primary color) on Antd Switch Component when checked and change it to red color. is there a way i can do this?

i have tried using style attribute but it didnt work.

Chisom Maxwell
  • 149
  • 2
  • 7

4 Answers4

10

You can change the backgroundColor using inline styles like this.

<Switch style={{backgroundColor: permission.enabled ? 'green' : 'orange'}}
        checked={permission.enabled}
        checkedChildren={'ENABLED'}
        unCheckedChildren={'DISABLED'}
        onChange={(e) => onPermissionChanged(e, permission)} />
jqIndy
  • 414
  • 5
  • 11
2

You can override the .ant-switch-checked class like so

.ant-switch-checked {
   background-color: red;
}
Caleb Smith
  • 131
  • 3
0

you can change switch styling by overriding default class (you will get all the element classes from developer tool) for switch class

.ant-switch-checked{
   background:#fdfdfd !important;
}

as a result it will override the color globally, to override the color for specific element only just wrap the element in some div by giving class "test" and override the css like

.test .ant-switch-checked{
   background:#fdfdfd !important;
}

and it will update the color for specific elemet only.

Siddharth Bagal
  • 499
  • 4
  • 7
0

In your main/themefile, you can just override the variable like so:

@switch-color: red; // @primary-color

or

@switch-bg: red; // @component-background;

You can actually override any variables to your use: reference

danyhiol
  • 594
  • 2
  • 7
  • 26