Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

ReactJS Blueprint Drawer Component

  • Last Updated : 10 Jul, 2021

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.

The Drawer component is a panel that slides in from the edge of the screen. It overlay content over existing parts of the UI. We can use the following approach in ReactJS to use the ReactJS Blueprint Drawer Component.

Drawer Props:

  • autoFocus: It is used to indicate whether the overlay should acquire application focus when it first opens.
  • 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 the 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.
  • icon: It is used to denote the name of an icon or an icon element to render in the drawer’s header.
  • isCloseButtonShown: It is used to indicate whether to show the close button in the dialog’s header or not.
  • isOpen: It is used to denote the visibility of the overlay and its children.
  • lazy: It is used to denote the portal containing the children is created and attached to the DOM when the overlay is opened for the first time if this is set to true and usePortal={true}.
  • onClose: It is used to denote 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 the 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 the lifecycle method invoked just before the CSS close transition begins on a child. Receives the DOM element of the child being closed.
  • onOpened: It is used to denote the lifecycle method invoked just after the CSS open transition ends.
  • onOpening: It is used to denote the 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 the space-delimited string of class names applied to the Portal element if usePortal={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 for the Position of a drawer.
  • shouldReturnFocusOnClose: It is used to indicate whether the application should return focus to the last active element in the document after this drawer closes.
  • size: It is used to denote the CSS size of the drawer.
  • style: It is used to denote the CSS styles to apply to the dialog.
  • title: It is used to denote the title of the dialog.
  • 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.
  • vertical: It is used to indicate whether the drawer should appear with vertical styling.

 



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 { Drawer, Classes } from "@blueprintjs/core";
  
function App() {
    return (
        <div style={{
            display: 'block', width: 400, padding: 30
        }}>
            <h4>ReactJS Blueprint Drawer Component</h4>
            <Drawer
                isOpen={true}
                icon="info-sign"
                title="Drawer Title"
            >
                <div className={Classes.DRAWER_BODY}>
                    <div className={Classes.DIALOG_BODY}>
                        <p>I am sample body text!!</p>
  
                    </div>
                </div>
                <div className={Classes.DRAWER_FOOTER}>Drawer Footer</div>
            </Drawer>
        </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/drawer




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!