React Suite DateRangePicker Show One Calendar
React Suite is a front-end UI framework that has a set of React components that developers can use in their react app to fasten the development process. It supports all the major browsers like Chrome, Safari, Firefox, Brave, etc. In this example, we will see React Suite DateRangePicker Show One Calendar.
The DateRangePicker component is used to take the input of the date range from the users. By default, it shows two calendars when opened to select starting date and end date but we can use the showOneCalendar property to show only one calendar which can be used to select both starting and ending date.
React Suite DateRangePicker Show One Calendar Components:
- DateRangePicker: This component is used to take the input of the date range from the user.
React Suite DateRangePicker Show One Calendar Attributes/Props:
- showOneCalendar: This is a boolean property used to show only one calendar when opening the DateRangePicker.
- size: This attribute is used on the DateRangePicker component to specify its size. It takes four values: “lg“, “md“, “sm” and “xs“.
Creating React Application and Installing React Suite in the Project:
Step 1: Create the React application using the npx command:
npx create-react-app foldername
Step 2: After creating the project folder, move to it using the cd command:
Step 3: After creating the ReactJS application, Install the rsuite module so that we can use the DateRangePicker component using the following command:
npm install rsuite
Project Structure: After following the above steps, the project structure will look like this:
Let’s see some examples to understand how to use the React Suite DateRangePicker showOneCalendar attribute/prop.
Example 1: Now replace the code in the App.js file with the code below. In this example, we used the showOneCalendar property of the DateRangePicker component to show only one calendar.
Run the Application: Run your app using the following command from the root directory of the project.
Output: Go to http://localhost:3000/ in your browser to see the output.
Example 2: In the example below we used the showOneCalendar property of the DateRangePicker along with the size property to show variation in the sizes of the component.
Please Login to comment...