Ant Design Library has this component pre-built, and it is very easy to integrate as well. ConfigProvider Component is used to provide uniform configuration support for components. We can use the following approach in ReactJS to use the Ant Design ConfigProvider Component.
ConfigProvider Props:
- autoInsertSpaceInButton: When it is set to false, it removes space between 2 Chinese characters on the Button.
- componentSize: It is used to config the antd component size.
- csp: It is used to set the Content Security Policy config.
- direction: It is used to set the direction of the layout.
- dropdownMatchSelectWidth: It is used to determine whether the dropdown menu and the select input are the same widths or not.
- form: It is used to set Form common props.
- getPopupContainer: It is used to set the container of the popup element.
- getTargetContainer: It is used for the Config Affix, Anchor scroll target container.
- iconPrefixCls: It is used to set icon prefix className.
- input: It is used to set Input common props.
- locale: It is used to denote the language package setting.
- pageHeader: It is used to unify the ghost of PageHeader.
- prefixCls: It is used to set the prefix className.
- renderEmpty: It is used to set the empty content of the components.
- space: It is used to set the Space size.
- virtual: It is used to disable the virtual scroll when set it is set to false.
Creating React Application And Installing Module:
-
Step 1: Create a React application using the following command:
npx create-react-app foldername
-
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
-
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install antd
Project Structure: It will look like the following.
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
App.js
import React from 'react' import "antd/dist/antd.css" ; import { ConfigProvider } from 'antd' ; export default function App() { return ( <div style={{ display: 'block' , width: 700, padding: 30 }}> <h4>ReactJS Ant-Design ConfigProvider Component</h4> <ConfigProvider componentSize={ "small" }> <label> It provides a uniform configuration support for components </label> </ConfigProvider> </div> ); } |
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Reference: https://ant.design/components/config-provider/