Open In App

React.js Blueprint Variables Grids & dimensions

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

In this article, we will learn about the Grids & dimensions 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.

Grids & dimensions Variables These variables are used to control the sizes of custom components. They are available to use by the developers in the Sass or Less variables files.

Grids & dimensions Variables

  • $pt-grid-size: It corresponds to the following value in CSS 
$pt-grid-size: 10px
  • $pt-border-radius: It corresponds to the following value in CSS 
$pt-border-radius: 2px
  • $pt-button-height: It corresponds to the following value in CSS 
$pt-button-height: 30px
  • $pt-button-height-large: It corresponds to the following value in CSS 
$pt-button-height-large: 40px
  • $pt-input-height: It corresponds to the following value in CSS 
$pt-input-height: 30px
  • $pt-input-height-large: It corresponds to the following value in CSS 
$pt-input-height-large: 40px
  • $pt-navbar-height: It corresponds to the following value in CSS 
$pt-navbar-height: 50px

 

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 Grid and Sizing 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'
  
export default function App() {
    return (
        <div>
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    GeeksforGeeks
                </h1>
                <strong>
                    React blueprint Variables Grids & dimensions
                </strong>
                <br />
                <br />
            </div>
            <div className="container">
                <div className="box box-1"></div>
                <div className="box box-2"></div>
                <div className="box box-3"></div>
                <div className="box box-4"></div>
                <div className="box box-5"></div>
            </div>
        </div>
    );
}


Create a new file, App.scss, and assign different Grid and Sizing variables to different boxes.

Filename: App.scss

CSS




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    display: flex;
    margin: 0 auto;
    justify-content: center;
    gap: 5px;
}
  
.box {
    width: 100px;
    background-color: red;
}
  
.box-1 {
    height: $pt-grid-size;
}
  
.box-2 {
    height: $pt-border-radius;
}
  
.box-3 {
    height: $pt-button-height;
}
  
.box-4 {
    height: $pt-button-height-large;
}
  
.box-5 {
    height: $pt-navbar-height;
}


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 Grids and Sizing variables, used by BlueprintJS, but with slight modification by using the calc utility function in CSS.

Filename: App.js

Javascript




import './App.scss'
  
export default function App() {
    return (
        <div>
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    GeeksforGeeks
                </h1>
                <strong>
                    React blueprint Variables Grids & dimensions
                </strong>
                <br />
                <br />
            </div>
            <div className="container">
                <div className="box box-1"></div>
                <div className="box box-2"></div>
                <div className="box box-3"></div>
                <div className="box box-4"></div>
                <div className="box box-5"></div>
            </div>
        </div>
    );
}


Filename: App.scss

CSS




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    display: flex;
    margin: 0 auto;
    justify-content: center;
    gap: 5px;
}
  
.box {
    width: 100px;
    background-color: red;
}
  
.box-1 {
    height: calc(2 * $pt-grid-size);
}
  
.box-2 {
    height: $pt-border-radius;
}
  
.box-3 {
    height: calc(2 * $pt-input-height);
}
  
.box-4 {
    height: $pt-input-height-large;
}
  
.box-5 {
    height: $pt-navbar-height;
}


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.grids—dimensions



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads