Open In App

ReactJS Blueprint Tooltip2 Component

Last Updated : 10 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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

Tooltip2 Component provides a way for users to show additional information during hover interactions as it is a lightweight popover. We can use the following approach in ReactJS to use the ReactJS Blueprint Tooltip2 Component.

Tooltip2 Props:

  • autoFocus: It is used to indicate whether the overlay should acquire application focus when it first opens.
  • boundary: It is used to denote a boundary element supplied to the flip and preventOverflow modifiers.
  • canEscapeKeyClose: It is used to indicate whether pressing the ESC key should invoke onClose.
  • captureDismiss: When a user clicks inside a Classes.POPOVER_DISMISS element will only close the current popover and not the outer popovers when this prop is enabled.
  • className: It is used to denote a space-delimited list of class names to pass along to a child element.
  • content: It is used to denote the content that will be displayed inside the tooltip.
  • defaultIsOpen: It is used to denote the initial opened state when uncontrolled.
  • disabled: It is used to prevent the popover from appearing when true.
  • enforceFocus: It is used to indicate whether the overlay should prevent focus from leaving itself.
  • hoverCloseDelay: It is used to denote the amount of time in milliseconds the tooltip should remain open after the user hovers off the trigger.
  • hoverOpenDelay: It is used to denote the amount of time in milliseconds the tooltip should wait before opening after the user hovers over the trigger.
  • inheritDarkTheme: It is used to indicate whether a popover that uses a Portal should automatically inherit the dark theme from its parent.
  • intent: It is used to denote the visual intent color to apply to element.
  • interactionKind: It is used to denote the kind of hover interaction that triggers the display of the tooltip.
  • isOpen: It is used to indicate whether the popover is visible.
  • lazy: The Portal containing the children is created and attached to the DOM when the overlay is opened for the first time when this is set to true and usePortal is true.
  • minimal: It is used to indicate whether to apply minimal styling to this popover or tooltip.
  • modifiers: It is used to override for Popper.js built-in modifiers.
  • onClose: It is a callback that is triggered when user interaction causes the overlay to close.
  • onClosed: It is used to denote a lifecycle method invoked just after the CSS close transition ends but before the child has been removed from the DOM.
  • onClosing: It is used to denote a lifecycle method invoked just before CSS close transition begins on a child.
  • onInteraction: It is a callback function that is triggered in controlled mode when the popover open state would change due to user interaction.
  • onOpened: It is used to denote a lifecycle method invoked just after the CSS open transition ends.
  • onOpening: It is used to denote a lifecycle method invoked just after mounting the child in the DOM but just before the CSS open transition begins.
  • openOnTargetFocus: It is used to indicate whether the popover should open when its target is focused.
  • placement: It is used to denote the placement at which the popover should appear.
  • popoverClassName: It is used to denote a space-delimited string of class names applied to the popover element.
  • portalClassName: It is used to denote a space-delimited string of class names applied to the Portal element if usePortal is true.
  • portalContainer: It is used to denote the container element into which the overlay renders its contents when usePortal is true.
  • position: It is used to denote the position at which the popover should appear. Mutually exclusive with placement prop.
  • renderTarget: It is used to denote the target renderer which receives props injected by Popover2 which should be spread onto the rendered element.
  • rootBoundary: It is used to denote a root boundary element supplied to the flip and preventOverflow modifiers.
  • targetTagName: It is used to denote the HTML tag name for the target element.
  • transitionDuration: It is used to indicate how long the tooltip appears/disappears transition takes in milliseconds.
  • usePortal: It is used to indicate whether the popover should be rendered inside a Portal attached to portalContainer prop.

 

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 @blueprintjs/core
    npm install @blueprintjs/popover2

Project Structure: It will look like the following.

Project Structure

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 '@blueprintjs/core/lib/css/blueprint.css';
import { Button, mergeRefs } from "@blueprintjs/core";
import { Popover2, Tooltip2 } from "@blueprintjs/popover2";
  
function App() {
  
    return (
        <div style={{
            display: 'block', width: 400, padding: 30
        }}>
            <h4>ReactJS Blueprint Tooltip2 Component</h4>
            <Popover2
                content={<h1>Popover!</h1>}
                renderTarget={({ isOpen: isPopoverOpen,
                    ref: ref1, ...popoverProps }) => (
                    <Tooltip2
                        content="Sample Tooltip 2 Content"
                        disabled={isPopoverOpen}
                        renderTarget={({ isOpen: isTooltipOpen,
                            ref: ref2, ...tooltipProps }) => (
                            <Button
                                active={isPopoverOpen}
                                {...popoverProps}
                                {...tooltipProps}
                                text="Hover Me to see ToolTip!"
                                elementRef={mergeRefs(ref1, ref2)}
                            />
                        )}
                    />
                )}
            />
        </div >
    );
}
  
export default App;


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://blueprintjs.com/docs/#popover2-package/tooltip2



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads