Open In App

React Suite Button Justified

Last Updated : 18 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The Button component is used to fire an action when the user clicks the button.

Justified buttons are laid out horizontally in the button set and are equally wide.

Syntax:

<ButtonGroup justified>
      <Button>Some Text</Button>
</ButtonGroup>

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 rsuite

Project Structure: It will look like the following.

 

Example 1: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. In this example, we have created 4 justified buttons with 4 different colors. These colors show that all buttons are justified (equally wide).

Javascript




import React from "react";
import Button from 'rsuite/Button';
import "rsuite/dist/rsuite.min.css";
  
import ButtonGroup from 'rsuite/ButtonGroup';
function App() {
  
    return (
        <div style={{ padding: 10 }}>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
              
            <h3 >
                React Suite Button Justified
            </h3>
              
            <ButtonGroup justified>
                <Button color="orange" appearance="primary">
                    Button 1
                </Button>
                <Button appearance="primary" color="cyan">
                    Button 2
                </Button>
                <Button appearance="primary" color="violet">
                    Button 3
                </Button>
                <Button color="green" appearance="primary">
                    Button 4
                </Button>
            </ButtonGroup>
        </div>
    );
}
  
export default App;


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: In this example, we will learn how can we create justified iconButtons. We have taken icons from https://rsuitejs.com/resources/icons/

Javascript




import React from "react";
import ButtonGroup from 'rsuite/ButtonGroup';
  
import FileUploadIcon from '@rsuite/icons/FileUpload';
import OffRoundIcon from '@rsuite/icons/OffRound';
import SendIcon from '@rsuite/icons/Send';
import "rsuite/dist/rsuite.min.css";
import TrashIcon from '@rsuite/icons/Trash';
import IconButton from 'rsuite/IconButton';
function App() {
  
    return (
        <div style={{ padding: 10 }}>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
              
            <h3 >
                React Suite Button Justified
            </h3>
              
            <ButtonGroup justified>
                <IconButton icon={<SendIcon />} 
                    color="red" appearance="primary">
                    Red
                </IconButton>
                <IconButton icon={<OffRoundIcon />} 
                    appearance="primary" color="cyan">
                    Cyan
                </IconButton>
                <IconButton icon={<TrashIcon />} 
                    appearance="primary" color="blue">
                    Blue
                </IconButton>
                <IconButton icon={<FileUploadIcon />} 
                    color="yellow" appearance="primary">
                    Yellow
                </IconButton>
            </ButtonGroup>
        </div>
    );
}
  
export default App;


Output:

 

Reference: https://rsuitejs.com/components/button/#justified



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads