Open In App

React .js Blueprint Popover2 Interactions

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 Popover2 Interactions. Popovers help in displaying the floating content next to the target element. Interactions tell how a popover should open & close in response to the interactions of users. There are 4 kinds of interactions provided by Blueprint and those are discussed below.



React.js Blueprint Popover2 InteractionKinds:

 



React.js Blueprint Popover2 Props:

Syntax:

<Popover2
    interactionKind="hover || hover-target || click || click-target"
    ...
/>

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

Project Structure:

 

Step 4: Run the project as follows:

npm start

Example 1: The below example demonstrates the usage of ‘Hover’ interaction in popover2.




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button } from "@blueprintjs/core";
import { Popover2 } from "@blueprintjs/popover2";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
  
function App() {
    return (
        <center>
            <div style={{
                padding: 20, textAlign: "center",
                color: "green"
            }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJS BluePrint Popover2 Interactions</h2>
            </div>
            <div>
                <Popover2
                    interactionKind="hover"
                    position="bottom"
                    content={
                        <div style={{
                            backgroundColor: "#F0EFEF",
                            padding: 20
                        }}>
                            <h3>This is Hover interaction.</h3>
                        </div>
                    }
                    renderTarget={({ isOpen, ref, ...targetProps }) 
                    => (
                        <Button
                            {...targetProps}
                            elementRef={ref}
                            text="Hover"
                            intent="success"
                        />
                    )}
                />
            </div>
        </center>
    );
}
  
export default App;

Output: 

 

Example 2: The below example demonstrates the usage of ‘Hover_Target_Only’ interaction in popover2.




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button } from "@blueprintjs/core";
import { Popover2 } from "@blueprintjs/popover2";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
  
function App() {
    return (
        <center>
            <div style={{ padding: 20, textAlign: "center"
                 color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJS BluePrint Popover2 Interactions</h2>
            </div>
            <div>
                <Popover2
                    interactionKind="hover-target"
                    position="bottom"
                    content={
                        <div style={{
                            backgroundColor: "#F0EFEF",
                            padding: 20
                        }}>
                            <h3>
                              This is Hover_Target_Only interaction.
                             </h3>
                        </div>
                    }
                    renderTarget={({ isOpen, ref, ...targetProps }) 
                    => (
                        <Button
                            {...targetProps}
                            elementRef={ref}
                            text="Hover_Target"
                            intent="success"
                        />
                    )}
                />
            </div>
        </center>
    );
}
  
export default App;

Output: 

 

Example 3: The below example demonstrates the usage of ‘Click’ interaction in popover2.




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button } from "@blueprintjs/core";
import { Popover2 } from "@blueprintjs/popover2";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
  
function App() {
    return (
        <center>
            <div style={{ padding: 20, textAlign: "center"
            color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJS BluePrint Popover2 Interactions</h2>
            </div>
            <div>
                <Popover2
                    interactionKind="click"
                    position="bottom"
                    content={
                        <div style={{ backgroundColor: "#F0EFEF",
                             padding: 20 }}>
                            <h3>This is click interaction.</h3>
                        </div>
                    }
                    renderTarget={({ isOpen, ref, ...targetProps }) 
                     => (
                        <Button
                            {...targetProps}
                            elementRef={ref}
                            text="click"
                            intent="success"
                        />
                    )}
                />
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Example 4: The below example demonstrates the usage of ‘Click_Target_Only’ interaction in popover2.




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button } from "@blueprintjs/core";
import { Popover2 } from "@blueprintjs/popover2";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
  
function App() {
    return (
        <center>
            <div style={{ padding: 20, textAlign: "center"
                   color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJS BluePrint Popover2 Interactions</h2>
            </div>
            <div>
                <Popover2
                    interactionKind="click-target"
                    position="bottom"
                    content={
                        <div style={{ backgroundColor: 
                        "#F0EFEF", padding: 20 }}>
                            <h3>This is click-target interaction.</h3>
                        </div>
                    }
                    renderTarget={({ isOpen, ref, ...targetProps })
                    => (
                        <Button
                            {...targetProps}
                            elementRef={ref}
                            text="click-target"
                            intent="success"
                        />
                    )}
                />
            </div>
        </center>
    );
}
  
export default App;

Output: 

 

Reference: https://blueprintjs.com/docs/#popover2-package/popover2.interactions


Article Tags :