Open In App

React.js Blueprint Button group Component Flex layout

Last Updated : 01 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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. ButtonGroup Component provides a way for users to arrange multiple buttons in a horizontal or vertical group.

Button group Component props for flex layout:

  • fill: It is used to indicate whether the button group should take up the full width of its container or not.
  • vertical: It is used to indicate whether the button group should appear with vertical styling or not.

You can either give fill prop to the whole button group or the individual buttons according to your need. If you give the fill and vertical prop it will expand vertically. You can also set the individual button sizes through CSS.

Approach: Let us create a React project and install React Blueprint module. Then we will create a UI that will showcase the Button group Component Flex layout.

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 Button group Component Flex layout in the horizontal direction.

App.js




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button, ButtonGroup } from "@blueprintjs/core";
export default function App() {
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: "green" }}>
               GeeksforGeeks
            </h1>
            <h3>
              React.js Blueprint Button group Component Flex layout
            </h3>
            <p>Applying no fill prop.</p>
            <ButtonGroup>
                <Button intent="primary">
                    Button One
                </Button>
                <Button intent="success">
                    Button Two
                </Button>
                <Button intent="warning">
                    Button Three
                </Button>
            </ButtonGroup>
            <br /><br />
            <p>Applying fill prop to the button group. </p>
            <ButtonGroup fill>
                <Button intent="primary">
                    Button One
                </Button>
                <Button intent="success">
                    Button Two
                </Button>
                <Button intent="warning">
                    Button Three
                </Button>
            </ButtonGroup>
            <br />
            <p>Applying custom CSS.</p>
            <ButtonGroup>
                <Button intent="primary" 
                    style={{ width:"200px"}}>
                    Button One
                </Button>
                <Button intent="success" 
                    style={{ width:"250px"}}>
                    Button Two
                </Button>
                <Button intent="warning" 
                    style={{ width:"350px"}}>
                    Button Three
                </Button>
            </ButtonGroup>
            <br /><br />
            <p>Applying fill prop to the individual button.</p>
            <Button fill intent="success">
                Button One
            </Button>
        </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 the Button group Component Flex layout in the vertical direction.

App.js




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button, ButtonGroup } from "@blueprintjs/core";
export default function App() {
    return (
        <div style={{ margin: 100 }}>
            <h1 style={{ color: "green" }}>
              GeeksforGeeks
             </h1>
            <h3>
              React.js Blueprint Button group 
              Component Flex layout
            </h3>
            <p>Applying no fill prop. </p>
            <ButtonGroup vertical>
                <Button intent="primary">
                  Button One
                 </Button>
                <Button intent="success">
                  Button Two
                 </Button>
                <Button intent="warning">
                  Button Three
                </Button>
            </ButtonGroup>
            <br /><br />
            <p>Applying fill prop to the button group. </p>
            <ButtonGroup fill vertical>
                <Button intent="primary">
                  Button One
                </Button>
                <Button intent="success">
                  Button Two
                </Button>
                <Button intent="warning">
                  Button Three
                </Button>
            </ButtonGroup>
            <br />
            <p>Applying custom CSS. </p>
            <ButtonGroup vertical>
                <Button intent="primary" 
                    style={{width:"200px"}}>
                   Button One
                </Button>
                <Button intent="success" 
                    style={{width:"250px"}}>
                    Button Two
                </Button>
                <Button intent="warning" 
                    style={{width:"350px"}}>
                    Button Three
                </Button>
            </ButtonGroup>
            <br /><br /> 
            <p>Applying fill prop to the 
                individual button.</p>
  
            <Button vertical intent="primary">
               Button One
            </Button>
            <Button vertical fill intent="success">
               Button Two
             </Button>
            <Button vertical intent="warning">
               Button Three
             </Button>
        </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/button-group.flex-layout



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads