Friday, July 5, 2024
HomeLanguagesReactReact.js Blueprint HTML Component table CSS

React.js Blueprint HTML Component table CSS

BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex and data-dense for desktop applications. HTMLTable Component provides a way for users to add modifier props to apply styles to an HTML <table> element. 

HTMLTable Props:

  • bordered: It is used to enable the borders between rows and cells.
  • condensed: It is used for a small, condensed appearance.
  • elementRef: It is used to denote a ref handler or a ref object that receives the native HTML element rendered by this component.
  • interactive: It is used to enable the hover styles on rows.
  • striped: It is used for alternate background color on odd rows.

HTML Component table CSS:

  • bp4-html-table: It is used to denote an HTML Table. Apply this class with the table tag.
  • bp4-html-table-bordered: It is used to enable the borders between rows and cells.
  • bp4-html-table-condensed: It is used for a small, condensed appearance.
  • bp4-html-table-striped: It is used for alternate background color on odd rows.
  • bp4-interactive: It is used to enable the hover styles on a row.

Approach: Let us create a React project and install React Blueprint module. Then we will create a UI that will showcase React.js BluePrint HTML Component Table CSS.

Syntax:

<table class="bp4-html-table">
    <thead>
        <tr>
            <th>Table Row title</th>
            ...
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Table Column Content</td>
            ...
        </tr>
        ...
    </tbody>
</table>

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. 

Project Structure

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 HTML table Component CSS.

App.js




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import '@blueprintjs/icons/lib/css/blueprint-icons.css';
export default function App() {
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: "green" }}>neveropen</h1>
            <h3>React.js BluePrint HTML Component table CSS</h3>
            <table class="bp4-html-table bp4-html-table-bordered 
                bp4-html-table-condensed bp4-html-table-striped">
                <thead>
                    <tr>
                        <th>Data Structures</th>
                        <th>Access</th>
                        <th>Insertion</th>
                        <th>Deletion</th>
                        <th>Search</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Array</td>
                        <td>O(1)</td>
                        <td>O(n)</td>
                        <td>O(n)</td>
                        <td>O(n)</td>
                    </tr>
                    <tr>
                        <td>LinkedList</td>
                        <td>O(n)</td>
                        <td>O(1)</td>
                        <td>O(1)</td>
                        <td>O(n)</td>
                    </tr>
                    <tr>
                        <td>HashMap</td>
                        <td>N/A</td>
                        <td>O(1)</td>
                        <td>O(1)</td>
                        <td>O(1)</td>
                    </tr>
                </tbody>
            </table>
        </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 HTML table Component CSS.

App.js




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import '@blueprintjs/icons/lib/css/blueprint-icons.css';
export default function App() {
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: "green" }}>neveropen</h1>
            <h3>React.js BluePrint HTML Component table CSS</h3>
            <table class="bp4-html-table 
                bp4-html-table-bordered bp4-interactive">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Marks</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>1</td>
                        <td>Student 1</td>
                        <td>70%</td>
                        <td>Pass</td>
                    </tr>
                    <tr>
                        <td>2</td>
                        <td>Student 2</td>
                        <td>80%</td>
                        <td>Pass</td>
                    </tr>
                    <tr>
                        <td>3</td>
                        <td>Student 3</td>
                        <td>30%</td>
                        <td>Fail</td>
                    </tr>
                    <tr>
                        <td>4</td>
                        <td>Student 4</td>
                        <td>60%</td>
                        <td>Pass</td>
                    </tr>
                </tbody>
            </table>
        </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/html-table.css

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments