Open In App

React Suite Vertical button group

Last Updated : 16 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. In this article, we will be learning about the React Suite Vertical button group. The ButtonGroup component along with the vertical property is used to group a set of buttons vertically.

React Suite Vertical Button Group Components:

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

React Suite Vertical Button Groups Props:

  • vertical: This is a boolean property used on the ButtonGroup component to make the button group vertical.
  • 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 vertical>
     <Button>...</Button>
     <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 vertical button groups using the ButtonGroup component along with the vertical property 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 Vertical Button Group</h5>
      </header>
 
      {/* Vertical - Button Group 1 */}
      <ButtonGroup vertical>
        <Button>Button 1</Button>
        <Button>Button 2</Button>
        <Button>Button 3</Button>
      </ButtonGroup>
 
      {/* Vertical - Button Group 2 */}
      <ButtonGroup style={{ margin: "20px" }} vertical>
        <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 control the size of the vertical button groups.

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 Vertical Button Group</h5>
            </header>
 
            {/*Small Vertical Button Group 2 */}
            <ButtonGroup style={{ margin: "20px" }}
                vertical size="sm">
                <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>
 
            {/*Medium Vertical Button Group 2 */}
            <ButtonGroup style={{ margin: "20px" }}
                vertical size="md">
                <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>
 
            {/*Large Vertical Button Group 2 */}
            <ButtonGroup style={{ margin: "20px" }}
                vertical size="lg">
                <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/#vertical-group



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

Similar Reads