In Ant Design, the Spin component defaults to using the primary color of the current theme. If you want to change this color, there are several methods you can use:
1. Using CSS to Override Default Styles
You can directly use CSS to override the color of the Spin component. The Spin component uses the .ant-spin-dot class to control the style of the loading icon, so you can add the following CSS rule in your stylesheet to change the color:
css.ant-spin-dot i { background-color: #1DA57A; /* Replace with your desired color */ }
This method is straightforward but will affect the color of all Spin components. If you only want to change the color of a specific Spin component, you can add a custom class name to it:
jsx<Spin className="custom-spin"> {/* Your content here */} </Spin>
Then, set the color in your CSS for this class name:
css.custom-spin .ant-spin-dot i { background-color: #1DA57A; /* Replace with your desired color */ }
2. Using LESS Variables
If your project supports LESS, Ant Design provides a way to change the theme color by modifying LESS variables, including the color for the Spin component. You can modify the @primary-color variable in your global stylesheet file:
less@import "~antd/lib/style/themes/default.less"; @primary-color: #1DA57A; // Set to your preferred color @import "~antd/dist/antd.less"; // Import Ant Design styles
This will change the color of all components that use the primary color, including Spin.
3. Using Dynamic Theme
Ant Design also supports dynamically changing the theme. You can use the ConfigProvider component to set the theme color dynamically. This allows you to change the theme color via JavaScript without modifying LESS variables.
jsximport { ConfigProvider } from 'antd'; <ConfigProvider theme={{ primaryColor: '#1DA57A' }}> <Spin /> {/* Other components */} </ConfigProvider>
After this setup, the Spin component and all child components will use the new theme color.
The above are several methods to change the color of the Ant Design Spin component. These methods can be chosen based on your project's specific requirements and configuration.