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. Icon Component provides a way for users to easily render SVG icons in the application. It is used to display icons in our application. There are different props available to render icons properly.
Icon Props:
- children: It is used to pass the children component to the underlying element.
- className: It is used to denote a space-delimited list of class names to pass along to a child element.
- color: It is used to denote the color of icon.
- htmlTitle: It is used to denote the string for the title attribute on the rendered element.
- icon: It is used to denote the name of a Blueprint UI icon, or an icon element, to render.
- size: It is used to denote the size of the icon, in pixels.
- intent: It is used for the visual intent color to apply to elements.
- style: It is used to pass the CSS style properties.
- tagName: It is used to denote the HTML tag to use for the rendered element.
- title: It is used to denote the description string.
Approach: Let us create a React project and install React Blueprint module. Then we will create a UI that will showcase React.js BluePrint Icon Component Props.
Creating React Project:
Step 1: To create a react app, you need to install react modules through npx command. “npx” is used instead of “npm” because you will be needing this command in your app’s lifecycle only once.
npx create-react-app project_name
Step 2: After creating your react project, move into the folder to perform different operations.
cd project_name
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install @blueprintjs/core
Project Structure: After running the commands mentioned in the above steps, if you open the project in an editor you can see a similar project structure as shown below. The new component user makes or the code changes, we will be performing will be done in the source folder.
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Example 1: We are creating a UI that shows different React BluePrint Icon props.
App.js
import React from "react" ; import "@blueprintjs/core/lib/css/blueprint.css" ; import { Icon } from "@blueprintjs/core" ; export default function App() { return ( <div style={{ margin: 100, textAlign: "center" }}> <h1 style={{ color: "green" }}> neveropen </h1> <h3>React.js BluePrint Icon Component Props</h3> <br /> <Icon icon= "globe" size={30} intent= "primary" title= "Primary Icon" style={{ marginRight: 30 }} /> <Icon icon= "user" size={30} intent= "success" title= "Success Icon" style={{ marginRight: 30 }} /> <Icon icon= "offline" size={30} intent= "danger" title= "Danger Icon" style={{ marginRight: 30 }} /> <Icon icon= "refresh" size={30} intent= "warning" title= "warning Icon" /> </div> ); } |
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Example 2: We are creating a UI that shows React BluePrint Icon props.
App.js
import React from "react" ; import "@blueprintjs/core/lib/css/blueprint.css" ; import { Icon } from "@blueprintjs/core" ; export default function App() { return ( <div style={{ margin: 100, textAlign: "center" }}> <h1 style={{ color: "green" }}>neveropen</h1> <h3>React.js BluePrint Icon Component Props</h3> <br /> <p>Graph Icon - <Icon icon= "graph" size={30} intent= "primary" /> </p> <p>Snowflake Icon - <Icon icon= "snowflake" size={30} intent= "success" /> </p> <p>Filter Remove Icon - <Icon icon= "filter-remove" size={30} intent= "danger" /> </p> <p>Full Stacked Chart Icon - <Icon icon= "full-stacked-chart" size={30} intent= "warning" /> </p> </div> ); } |
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Reference: https://blueprintjs.com/docs/#core/components/icon.props