Open In App

React.js Blueprint Variables Color Aliases

In this article, we will learn about the Color Aliases 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.

Variables Color Aliases: These variables are semantic aliases of the colors used by the BlueprintJS library to maintain consistency in the color usages among different internal components. They are available to use by the developers in the Sass or Less variables files.



Color aliases:

 



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: Below example demonstrates the usage of different intent colors 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




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 
                    color aliases</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>
        </div>
    );
}

Create a new file, App.scss, and assign different intent colors to different boxes.

Filename: App.scss




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    display: flex;
    margin: 0 auto;
    justify-content: center;
    gap: 5px;
}
  
.box {
    height: 100px;
    width: 100px;
}
  
.box-1 {
    background-color: $pt-intent-primary;
}
  
.box-2 {
    background-color: $pt-intent-success;
}
  
.box-3 {
    background-color: $pt-intent-warning;
}
  
.box-4 {
    background-color: $pt-intent-danger;
}

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: Below example demonstrates the usage of different text colors used by BlueprintJS.

Filename: App.js




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 color aliases
                </strong>
                <br />
                <br />
            </div>
            <div className="container">
                <p className='p p-1'>default text color</p>
                <p className='p p-2'>muted text color</p>
                <p className='p p-3'>disabled text color</p>
            </div>
        </div>
    );
}

Create a new file, App.scss, and assign different text colors to different paragraphs.

Filename: App.scss




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    align-items: center;
    gap: 5px;
}
  
.p-1 {
    color: $pt-text-color;
}
  
.p-2 {
    color: $pt-text-color-muted;
}
  
.p-3 {
    color: $pt-text-color-disabled;
}

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.color-aliasesIt denotes the primary intent color


Article Tags :