Button Dropdown

Button Dropdown - 图1

  1. import React from 'react';
  2. import { ButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
  3. export default class Example extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.toggle = this.toggle.bind(this);
  7. this.state = {
  8. dropdownOpen: false
  9. };
  10. }
  11. toggle() {
  12. this.setState({
  13. dropdownOpen: !this.state.dropdownOpen
  14. });
  15. }
  16. render() {
  17. return (
  18. <ButtonDropdown isOpen={this.state.dropdownOpen} toggle={this.toggle}>
  19. <DropdownToggle caret>
  20. Button Dropdown
  21. </DropdownToggle>
  22. <DropdownMenu>
  23. <DropdownItem header>Header</DropdownItem>
  24. <DropdownItem disabled>Action</DropdownItem>
  25. <DropdownItem>Another Action</DropdownItem>
  26. <DropdownItem divider />
  27. <DropdownItem>Another Action</DropdownItem>
  28. </DropdownMenu>
  29. </ButtonDropdown>
  30. );
  31. }
  32. }

Properties

  1. ButtonDropdown.propTypes = {
  2. disabled: PropTypes.bool,
  3. direction: PropTypes.oneOf(['up', 'down', 'left', 'right']),
  4. group: PropTypes.bool,
  5. isOpen: PropTypes.bool,
  6. tag: PropTypes.string,
  7. toggle: PropTypes.func
  8. };
  9. DropdownToggle.propTypes = {
  10. caret: PropTypes.bool,
  11. color: PropTypes.string,
  12. disabled: PropTypes.bool,
  13. onClick: PropTypes.func,
  14. 'data-toggle': PropTypes.string,
  15. 'aria-haspopup': PropTypes.bool
  16. };

Single button dropdowns

Button Dropdown - 图2

  1. <ButtonDropdown isOpen={isOpen} toggle={toggle}>
  2. <DropdownToggle caret color="primary">
  3. Text
  4. </DropdownToggle>
  5. <DropdownMenu>
  6. <DropdownItem header>Header</DropdownItem>
  7. <DropdownItem disabled>Action</DropdownItem>
  8. <DropdownItem>Another Action</DropdownItem>
  9. <DropdownItem divider/>
  10. <DropdownItem>Another Action</DropdownItem>
  11. </DropdownMenu>
  12. </ButtonDropdown>

Split button dropdowns

Button Dropdown - 图3

  1. <ButtonDropdown isOpen={isOpen} toggle={toggle}>
  2. <Button id="caret" color="primary">{this.props.text}</Button>
  3. <DropdownToggle caret color="primary" />
  4. <DropdownMenu>
  5. <DropdownItem header>Header</DropdownItem>
  6. <DropdownItem disabled>Action</DropdownItem>
  7. <DropdownItem>Another Action</DropdownItem>
  8. <DropdownItem divider/>
  9. <DropdownItem>Another Action</DropdownItem>
  10. </DropdownMenu>
  11. </ButtonDropdown>

Sizing

Button Dropdown - 图4

Button Dropdown - 图5

  1. <ButtonDropdown isOpen={isOpen} toggle={toggle}>
  2. <DropdownToggle caret size="lg">
  3. Large Button
  4. </DropdownToggle>
  5. <DropdownMenu>
  6. <DropdownItem>Another Action</DropdownItem>
  7. <DropdownItem>Another Action</DropdownItem>
  8. </DropdownMenu>
  9. </ButtonDropdown>
  10. <ButtonDropdown isOpen={isOpen} toggle={toggle}>
  11. <DropdownToggle caret size="sm">
  12. Small Button
  13. </DropdownToggle>
  14. <DropdownMenu>
  15. <DropdownItem>Another Action</DropdownItem>
  16. <DropdownItem>Another Action</DropdownItem>
  17. </DropdownMenu>
  18. </ButtonDropdown>

Uncontrolled Dropdown

Button Dropdown - 图6

  1. import React from 'react';
  2. import { UncontrolledButtonDropdown, DropdownMenu, DropdownItem, DropdownToggle } from 'reactstrap';
  3. export default function Example () => {
  4. return (
  5. <UncontrolledButtonDropdown>
  6. <DropdownToggle caret>
  7. Dropdown
  8. </DropdownToggle>
  9. <DropdownMenu>
  10. <DropdownItem header>Header</DropdownItem>
  11. <DropdownItem disabled>Action</DropdownItem>
  12. <DropdownItem>Another Action</DropdownItem>
  13. <DropdownItem divider />
  14. <DropdownItem>Another Action</DropdownItem>
  15. </DropdownMenu>
  16. </UncontrolledButtonDropdown>
  17. );
  18. }

Drop direction variations

Button Dropdown - 图7

  1. <ButtonDropdown direction="up" isOpen={isOpen} toggle={toggle}>
  2. <DropdownToggle caret>
  3. Dropup
  4. </DropdownToggle>
  5. <DropdownMenu>
  6. <DropdownItem>Another Action</DropdownItem>
  7. <DropdownItem>Another Action</DropdownItem>
  8. </DropdownMenu>
  9. </ButtonDropdown>
  10. <ButtonDropdown direction="left" isOpen={this.state.btnDropleft} toggle={() => { this.setState({ btnDropleft: !this.state.btnDropleft }); }}>
  11. <DropdownToggle caret>
  12. Dropleft
  13. </DropdownToggle>
  14. <DropdownMenu>
  15. <DropdownItem>Another Action</DropdownItem>
  16. <DropdownItem>Another Action</DropdownItem>
  17. </DropdownMenu>
  18. </ButtonDropdown>
  19. <ButtonDropdown direction="right" isOpen={this.state.btnDropright} toggle={() => { this.setState({ btnDropright: !this.state.btnDropright }); }}>
  20. <DropdownToggle caret>
  21. Dropright
  22. </DropdownToggle>
  23. <DropdownMenu>
  24. <DropdownItem>Another Action</DropdownItem>
  25. <DropdownItem>Another Action</DropdownItem>
  26. </DropdownMenu>
  27. </ButtonDropdown>