Properties

  1. active: PropTypes.bool,
  2. 'aria-label': PropTypes.string,
  3. block: PropTypes.bool,
  4. color: PropTypes.string, // default: 'secondary'
  5. disabled: PropTypes.bool,
  6. outline: PropTypes.bool,
  7. // Pass in a Component to override default button element
  8. // example: react-router Link
  9. // default: 'button'
  10. tag: PropTypes.oneOfType([
  11. PropTypes.func,
  12. PropTypes.string,
  13. PropTypes.shape({ $$typeof: PropTypes.symbol, render: PropTypes.func }),
  14. PropTypes.arrayOf(PropTypes.oneOfType([
  15. PropTypes.func,
  16. PropTypes.string,
  17. PropTypes.shape({ $$typeof: PropTypes.symbol, render: PropTypes.func }),
  18. ]))
  19. ]),
  20. // ref will only get you a reference to the Button component, use innerRef to get a reference to the DOM element (for things like focus management).
  21. innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  22. onClick: PropTypes.func,
  23. size: PropTypes.string,
  24. children: PropTypes.node,
  25. className: PropTypes.string,
  26. cssModule: PropTypes.object,
  27. // use close prop for BS4 close icon utility
  28. }
  29. Button.defaultProps = {
  30. color: 'secondary',
  31. tag: 'button',

  1. import React from 'react';
  2. import { Button } from 'reactstrap';
  3. export default class Example extends React.Component {
  4. render() {
  5. return (
  6. <div>
  7. <Button outline color="primary">primary</Button>{' '}
  8. <Button outline color="secondary">secondary</Button>{' '}
  9. <Button outline color="success">success</Button>{' '}
  10. <Button outline color="info">info</Button>{' '}
  11. <Button outline color="warning">warning</Button>{' '}
  12. <Button outline color="danger">danger</Button>
  13. </div>
  14. );
  15. }
  16. }

Sizes

Large ButtonLarge Button Small ButtonSmall Button
  1. <Button color="primary" size="sm">Small Button</Button>{' '}
  2. <Button color="secondary" size="sm">Small Button</Button>
Block level buttonBlock level button
  1. <Button color="primary" size="lg" block>Block level button</Button>
  2. <Button color="secondary" size="lg" block>Block level button</Button>
Primary linkLink

Disabled State

Primary buttonButton
  1. <Button color="primary" size="lg" disabled>Primary button</Button>{' '}
  2. <Button color="secondary" size="lg" disabled>Button</Button>

Buttons - 图1

  1. import React, { Component } from 'react';
  2. import { Button, ButtonGroup } from 'reactstrap';
  3. class Example extends Component {
  4. constructor (props) {
  5. super(props);
  6. this.state = { cSelected: [] };
  7. this.onRadioBtnClick = this.onRadioBtnClick.bind(this);
  8. }
  9. onRadioBtnClick(rSelected) {
  10. }
  11. onCheckboxBtnClick(selected) {
  12. const index = this.state.cSelected.indexOf(selected);
  13. if (index < 0) {
  14. this.state.cSelected.push(selected);
  15. } else {
  16. this.state.cSelected.splice(index, 1);
  17. }
  18. this.setState({ cSelected: [...this.state.cSelected] });
  19. }
  20. render() {
  21. return (
  22. <div>
  23. <h5>Radio Buttons</h5>
  24. <ButtonGroup>
  25. <Button color="primary" onClick={() => this.onRadioBtnClick(1)} active={this.state.rSelected === 1}>One</Button>
  26. <Button color="primary" onClick={() => this.onRadioBtnClick(2)} active={this.state.rSelected === 2}>Two</Button>
  27. <Button color="primary" onClick={() => this.onRadioBtnClick(3)} active={this.state.rSelected === 3}>Three</Button>
  28. </ButtonGroup>
  29. <p>Selected: {this.state.rSelected}</p>
  30. <h5>Checkbox Buttons</h5>
  31. <ButtonGroup>
  32. <Button color="primary" onClick={() => this.onCheckboxBtnClick(1)} active={this.state.cSelected.includes(1)}>One</Button>
  33. <Button color="primary" onClick={() => this.onCheckboxBtnClick(2)} active={this.state.cSelected.includes(2)}>Two</Button>
  34. <Button color="primary" onClick={() => this.onCheckboxBtnClick(3)} active={this.state.cSelected.includes(3)}>Three</Button>
  35. </ButtonGroup>
  36. <p>Selected: {JSON.stringify(this.state.cSelected)}</p>
  37. </div>
  38. );
  39. }
  40. }

Close icon