📜  ReactJS Reactstrap ButtonGroup 组件(1)

📅  最后修改于: 2023-12-03 15:04:50.831000             🧑  作者: Mango

ReactJS Reactstrap ButtonGroup Component

Reactstrap is a popular library of Bootstrap 4 components, ported to React. One of the components included in Reactstrap is the ButtonGroup component, which allows you to group a number of buttons together.

Installation

If you haven't already done so, you will need to install Reactstrap into your project. You can do this using NPM, by running the following command in your project directory:

npm install --save reactstrap
Usage

To use the ButtonGroup component, you need to import it into your React component:

import { ButtonGroup } from 'reactstrap';

Then, you can use the component in your JSX code. Here's a simple example:

<ButtonGroup>
  <Button>One</Button>
  <Button>Two</Button>
  <Button>Three</Button>
</ButtonGroup>

This will create a group of three buttons. By default, the buttons are rendered vertically. If you want them to be rendered horizontally, you can add the vertical prop to the ButtonGroup component:

<ButtonGroup vertical={false}>
  <Button>One</Button>
  <Button>Two</Button>
  <Button>Three</Button>
</ButtonGroup>
Props

The ButtonGroup component accepts a number of props that allow you to customize its behavior and appearance:

  • vertical: A boolean that determines whether the buttons should be rendered vertically (default) or horizontally.
  • size: The size of the buttons. Can be "sm" for small, "lg" for large, or null for the default size.
  • className: A string of additional class names to apply to the ButtonGroup component.
  • tag: The HTML tag to use for the ButtonGroup component (default is "div").
  • role: The ARIA role for the ButtonGroup component (default is "group").
Conclusion

The ButtonGroup component provided by Reactstrap is a handy way to group a number of buttons together. It allows you to customize the layout, size, and appearance of the buttons, as well as provide additional accessibility features through the use of ARIA roles. If you're building a React application and need to group buttons, be sure to give the ButtonGroup component a try!