Open In App

React.js Blueprint Variables Font variables

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

Font Variables: These variables are used for custom styling different fonts. They are available to use by the developers in the Sass or less variables files.



Font Variables:

$pt-font-family: -apple-system, “BlinkMacSystemFont”, “Segoe UI”, “Roboto”,



  “Oxygen”, “Ubuntu”, “Cantarell”, “Open Sans”, “Helvetica Neue”,

  “blueprint-icons-16”, sans-serif

$pt-font-family-monospace: monospace
$pt-font-size: 14px
$pt-font-size-small: 12px
$pt-font-size-large: 16px
$pt-line-height: 1.28581 

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 different font 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




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 Font Variables:</strong>
                <br />
                <br />
            </div>
            <div className="container">
                <p className='p1'>text</p>
                <p className='p2'>text</p>
                <p className='p3'>text</p>
                <p className='p4'>text</p>
                <p className='p5'>text</p>
                <p className='p6'>text</p>
            </div>
        </div>
    );
}

Create a new file, App.scss, and assign different font variables to different paragraphs.

Filename: App.scss 




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    position: relative;
    margin-left: 300px;
}
.p1 {
    font-family: $pt-font-family;
}
.p2 {
    font-family: $pt-font-family-monospace;
}
.p3 {
    font-size: $pt-font-size;
}
.p4 {
    font-size: $pt-font-size-small;
}
.p5 {
    font-size: $pt-font-size-large;
}
.p6 {
    line-height: $pt-line-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 font variables, used by BlueprintJS, but with slight modification by using calc utility function in CSS.

Filename: App.js




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 Font Variables:</strong>
                <br />
                <br />
            </div>
            <div className="container">
                <p className='p1'>text</p>
                <p className='p2'>text</p>
                <p className='p3'>text</p>
                <p className='p4'>text</p>
                <p className='p5'>text</p>
                <p className='p6'>text</p>
            </div>
        </div>
    );
}

Create a new file, App.scss, and assign different font variables to different paragraphs.

Filename: App.scss




@import "@blueprintjs/core/lib/scss/variables";
  
.container {
    position: relative;
    margin-left: 300px;
}
.p1 {
    font-family: $pt-font-family;
}
.p2 {
    font-family: $pt-font-family-monospace;
}
.p3 {
    font-size: calc(2 * $pt-font-size);
}
.p4 {
    font-size: calc(2 * $pt-font-size-small);
}
.p5 {
    font-size: calc(2 * $pt-font-size-large);
}
.p6 {
    line-height: calc(2 * $pt-line-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.font-variables


Article Tags :