React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. DateRangePicker component allows the user to quickly select a date range. We can use the following approach in ReactJS to use the React Suite DateRangePicker Component.
DateRangePicker Props:
- appearance: It is used for the component appearance.
- block: It is used to block an entire row.
- cleanable: It is used to indicate whether the option can be emptied or not.
- container: It is used to set the rendering container.
- defaultCalendarValue: It is used to denote the default calendar panel date.
- defaultOpen: It is used to denote the default value of the open property.
- defaultValue: It is used to denote the default value.
- disabled: It is used to indicate whether the component is disabled or not.
- disabledDate: It is used to disable the date.
- hoverRange: It is used to select the date range when you click on the date.
- isoWeek: It is a boolean value denoting the ISO 8601 standard set or not.
- limitEndYear: It is used to set the lower limit of the available year relative to the currently selected date.
- onChange: It is a callback function that is triggered when the value changes.
- onClean: It is a callback function that is triggered when value clean.
- onClose: It is a callback function that is triggered on a close event.
- onEnter: It is a callback function that is triggered before the overlay transitions in.
- onEntered: It is a callback function that is triggered after the overlay finishes transitioning in.
- onEntering: It is a callback function that is triggered as the overlay begins to transition in.
- onExit: It is a callback function that is triggered right before the overlay transitions out.
- onExited: It is a callback function that is triggered after the overlay finishes transitioning out.
- onExiting: It is a callback function that is triggered as the overlay begins to transition out.
- onOk: It is a callback function that is triggered on click ok the Ok button.
- onOpen: It is a callback function that is triggered on open of the component.
- onSelect: It is a callback function that is triggered on the selection of date or time.
- oneTap: It is used to indicate whether to enable One-click to complete the selection date or not.
- open: It is used to indicate whether open the component or not.
- placeholder: It is used to denote the placeholder.
- placement: It is used for the placement of component.
- preventOverflow: It is used to prevent floating element overflow.
- ranges: It is used for the shortcut config.
- renderValue: It is used for the custom render selected date range.
- showOneCalendar: It is used to indicate whether to show only one calendar or not.
- showWeekNumbers: It is used to indicate whether to show week numbers or not.
- size: It is used to denote the picker size.
- toggleComponentClass: It can be used for the custom element for this component.
- value: It is used to denote the value (Controlled).
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 rsuite
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 'rsuite/dist/styles/rsuite-default.css' ; import { DateRangePicker } from 'rsuite' ; export default function App() { return ( <div style={{ display: 'block' , width: 600, paddingLeft: 30 }}> <h4>React Suite DateRangePicker Component</h4> <DateRangePicker style={{ width: 300 }} placeholder= "Select Date Range" /> </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://rsuitejs.com/components/date-range-picker/