Open In App

ReactJS Blueprint Overlay Component

Last Updated : 08 Apr, 2022
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. Overlay Component provides a way for users to render the overlay content on top of its siblings, or above the entire application. We can use the following approach in ReactJS to use the ReactJS Blueprint Overlay Component.

Overlay Props:

  • autoFocus: It is used to indicate whether overlay should acquire application focus when it first opens or not.
  • backdropClassName: It is used to denote the CSS class names to apply to the backdrop element.
  • backdropProps: It is used to denote the HTML props for the backdrop element.
  • canEscapeKeyClose: It is used to indicate whether pressing the ESC key should invoke onClose or not.
  • canOutsideClickClose: It is used to indicate whether clicking outside the overlay element should invoke onClose or not.
  • className: It is used to denote a space-delimited list of class names to pass along to a child element.
  • enforceFocus: It is used to indicate whether the overlay should prevent focus from leaving itself or not.
  • hasBackdrop: It is used to indicate whether a container-spanning backdrop element should be rendered behind the contents or not.
  • isOpen: It is used to toggle the visibility of the overlay and its children.
  • 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={true}.
  • onClose: It is a callback function that is triggered when user interaction causes the overlay to close, such as clicking on the overlay or pressing the ESC key.
  • 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.
  • 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.
  • 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.
  • transitionDuration: It is used to indicate how long the overlay’s enter/leave transition takes in milliseconds.
  • transitionName: It is used to denote the name of the transition for internal CSSTransition.
  • usePortal: It is used to indicate whether the overlay should be wrapped in a Portal, which renders its contents in a new element 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

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 { Overlay, Classes, H3, Button } from "@blueprintjs/core";
  
function App() {
  
    // Open state
    const [isOpen, setIsOpen] = React.useState(false)
  
    return (
        <div style={{
            display: 'block', width: 400, padding: 30
        }}>
            <h4>ReactJS Blueprint Overlay Component</h4>
  
            <Button onClick={() => { setIsOpen(true) }}>Toggle Overlay</Button>
  
            <Overlay className={Classes.OVERLAY_SCROLL_CONTAINER}
                isOpen={isOpen}>
                <H3>I am sample Content of Overlay</H3>
            </Overlay>
        </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/#core/components/overlay



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

Similar Reads