Skip to content
Related Articles

Related Articles

React Suite Button group

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Jun, 2022
View Discussion
Improve Article
Save Article

React Suite is a front-end library that consists of a set of React components that makes it easier for developers to build beautiful and responsive websites faster. In this article, we will be discussing React Suite Button group. The ButtonGroup component is used to group the buttons together in a group. 

React Suite Button Group Components:

  • Button: This is the most basic button component.
  • ButtonGroup: This component is used to group the Buttons together.

React Suite Button Groups Props:

  • size: This property of the ButtonGroup component is used to change the size of all buttons in the group. It accepts four values: xs, sm, md and lg.

Syntax:

<ButtonGroup>
      <Button>...</Button>
      <Button>...</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: Move to the newly created project folder using the following command:

cd foldername

Step 3: After creating the ReactJS application, Install the required modules ( rsuite in this case ) using the following command:

npm install rsuite

Project Structure: After completing the above steps, the project structure will look like the following:

Project Structure

Example 1: Now write down the following code in the App.js file. Here, App is our default component. In this example, we made two button groups using the ButtonGroup component provided by the rsuite library.

Javascript




import React from "react";
import { ButtonGroup, Button } from "rsuite";
// Default CSS
import "rsuite/dist/rsuite.min.css";
  
  
function App() {
    return (
  
        <div className="App" style={{ textAlign: "center" }}>
            <header style={{ display: "block"
                             marginBottom: "20px" }}>
                <h3 style={{ color: "green" }}>
                    GeeksforGeeks</h3>
                <h5>React Suite Button Group</h5>
            </header>
  
            {/* Button Group 1 */}
            <ButtonGroup>
                <Button>Button 1</Button>
                <Button>Button 2</Button>
                <Button>Button 3</Button>
            </ButtonGroup>
  
            <br />
            {/* Button Group 2 */}
            <ButtonGroup style={{ marginTop: "20px" }}>
                <Button appearance="primary">
                    Button 1</Button>
                <Button appearance="primary">
                    Button 2</Button>
                <Button appearance="primary">
                    Button 3</Button>
                <Button appearance="primary">
                    Button 4</Button>
                <Button appearance="primary">
                    Button 5</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 used the size property of the ButtonGroup component to change the size of all buttons in the group.

Javascript




import React from "react";
import { ButtonGroup, Button } from "rsuite";
// Default CSS
import "rsuite/dist/rsuite.min.css";
  
  
function App() {
    return (
  
        <div className="App" style={{ textAlign: "center" }}>
            <header style={{ display: "block"
                             marginBottom: "20px" }}>
                <h3 style={{ color: "green" }}>
                    GeeksforGeeks</h3>
                <h5>React Suite Button Group - Size Variation</h5>
            </header>
  
            {/* Button Group 1 - Small in Size */}
            <ButtonGroup size="sm">
                <Button>Button 1</Button>
                <Button>Button 2</Button>
                <Button>Button 3</Button>
            </ButtonGroup>
  
            <br />
            {/* Button Group 2 - Large in Size*/}
            <ButtonGroup size="lg" style={{ marginTop: "20px" }} >
                <Button appearance="primary">
                    Button 1</Button>
                <Button appearance="primary">
                    Button 2</Button>
                <Button appearance="primary">
                    Button 3</Button>
                <Button appearance="primary">
                    Button 4</Button>
                <Button appearance="primary">
                    Button 5</Button>
            </ButtonGroup>
  
        </div>
  
    );
}
  
export default App;

Output:

 

Reference: https://rsuitejs.com/components/button/#button-group


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!