Open In App

React.js Blueprint Variables Layering

Last Updated : 16 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn about the Layering Variables offered by the blueprint.js library. BlueprintJS is a React-based UI toolkit for the web. It is written in Typescript. This library is very optimized and popular for building interfaces that are complex and data-dense for desktop applications that run in a modern web browser.

Layering Variables These variables are used to replicate the stacking context used by BlueprintJS. They are available to use by the developers in the Sass or Less variables files.

Layering Variables

  • $pt-z-index-base:  It corresponds to the following value in CSS 
$pt-z-index-base: 0
  • $pt-z-index-content:  It corresponds to the following value in CSS 
$pt-z-index-content: 10
  • $pt-z-index-overlay:  It corresponds to the following value in CSS 
$pt-z-index-overlay: 20

 

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 @blueprint/datetime @blueprintjs/datetime2
npm install sass

Project Structure: It will look like the following.

 

Example 1: The below example demonstrates the usage of different Layering Variables used by BlueprintJS.

Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

Filename: App.js

Javascript




import './App.scss'
import "@blueprintjs/core/lib/css/blueprint.css";
  
export default function App() {
    return (
        <div>
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    GeeksforGeeks
                </h1>
                <strong>
                    React blueprint Layering Variables:
                </strong>
                <br />
                <br />
            </div>
            <div className="container">
                <div class="box box-1"></div>
                <div class="box box-2"></div>
                <div class="box box-3"></div>
            </div>
        </div>
    );
}


Create a new file, App.scss, and assign different z-index values to different boxes.

Filename: App.scss

CSS




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    position: relative;
    margin-left: 300px;
}
  
.box {
    width: 100px;
    height: 100px;
    position: absolute;
}
  
.box-1 {
    background-color: skyblue;
    z-index: $pt-z-index-base;
    left: 0;
}
  
.box-2 {
    background-color: limegreen;
    z-index: $pt-z-index-content;
    top: 50px;
    left: 50px;
}
  
.box-3 {
    background-color: orange;
    z-index: $pt-z-index-overlay;
    top: 100px;
    left: 100px;
}


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:

 

Example 2: The below example demonstrates the usage of different layering variables, used by BlueprintJS, but with the slight modification of doing some pre-defined calculations with the variables.

Filename: App.js

Javascript




import './App.scss'
import "@blueprintjs/core/lib/css/blueprint.css";
  
export default function App() {
    return (
        <div>
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    GeeksforGeeks
                </h1>
                <strong>
                    React blueprint Layering Variables:
                </strong>
                <br />
                <br />
            </div>
            <div className="container">
                <div class="box box-1"></div>
                <div class="box box-2"></div>
                <div class="box box-3"></div>
            </div>
        </div>
    );
}


Create a new file, App.scss, and assign different z-indexes to different boxes.

Filename: App.scss

CSS




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    position: relative;
    margin-left: 300px;
}
  
.box {
    width: 100px;
    height: 100px;
    position: absolute;
}
  
.box-1 {
    background-color: skyblue;
    z-index: $pt-z-index-base;
    left: 0;
}
  
.box-2 {
    background-color: limegreen;
    z-index: calc(3 * $pt-z-index-content);
    top: 50px;
    left: 50px;
}
  
.box-3 {
    background-color: orange;
    z-index: $pt-z-index-overlay;
    top: 100px;
    left: 100px;
}


Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output:

 

Reference: https://blueprintjs.com/docs/#core/variables.layering



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

Similar Reads