Open In App

React.js Blueprint DateInput2 Props

Blueprint is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex and data-dense for desktop applications.

In this article, we’ll discuss React.js Blueprint DateInput2 Props. The DateInput2 component is a type of InputGroup that allows the users to pick the date as per choice and also the timezones. It shows a DatePicker inside a Popover2 when focused.



React.js BluePrint DateInput2 Props:

 



Syntax:

<DateInput2
    value={...}
    formatDate={...}
/>

Creating React Application And Installing Module:

Step 1: Create a React application using the following command:

npm create-react-app appname

Step 2: After creating your project folder i.e. appname, move to it using the following command:

cd appname

Step 3: After creating the ReactJS application, Install the required module using the following command:

npm install @blueprintjs/core

Step 4: Installing @blueprintjs datetime2 component.

npm install @blueprintjs/datetime2

Project Structure:

 

Step 5: Run the project as follows:

npm start

Example 1: The below example demonstrates the usage of the formatDate, onChange, parseData, placeholder, and value props of DateInput2 component.




import React, { useCallback, useState } from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import "@blueprintjs/datetime/lib/css/blueprint-datetime.css";
import { DateInput2 } from "@blueprintjs/datetime2";
  
function App() {
    const [dateVal, setDateVal] = useState(null);
    const handleChange = useCallback(setDateVal, []);
    const formatDate = useCallback((Date) => 
        Date.toLocaleString(), []);
    const parseDate = useCallback((string) => 
        new Date(string), []);
  
    return (
        <center>
            <div style={{ textAlign: "center", color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJs Blueprint DateInput2 Props</h2>
            </div>
            <div style={{ width: 500 }}>
                <DateInput2
                    formatDate={formatDate}
                    onChange={handleChange}
                    parseDate={parseDate}
                    placeholder="MM/DD/YYYY"
                    value={dateVal}
                />
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Example 2: The below example demonstrates the usage of the shortcuts and highlightCurrentDay props of DateInput2 component.




import React, { useCallback, useState } from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import "@blueprintjs/datetime/lib/css/blueprint-datetime.css";
import { DateInput2 } from "@blueprintjs/datetime2";
  
function App() {
    const [dateVal, setDateVal] = useState(null);
    const handleChange = useCallback(setDateVal, []);
    const formatDate = useCallback((Date) => Date.toLocaleString(), []);
    const parseDate = useCallback((string) => new Date(string), []);
  
    return (
        <center>
            <div style={{ textAlign: "center", color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJs Blueprint DateInput2 Props</h2>
            </div>
            <div style={{ width: 500 }}>
                <DateInput2
                    formatDate={formatDate}
                    onChange={handleChange}
                    parseDate={parseDate}
                    placeholder="MM/DD/YYYY"
                    value={dateVal}
                    highlightCurrentDay={true}
                    shortcuts
                />
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Reference: https://blueprintjs.com/docs/#datetime2/date-input2.props-interface


Article Tags :