button-group

v1.0.0arrow_drop_down
v1.0.0
STATUS
Passing
DOWNLOADS
794
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
4 months ago
subject
Sets the size for all Buttons in the group.
1 contributor
Like
Use button-group in your project ?
Copied
npm i @bit/react-bootstrap.react-bootstrap.button-group
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
src/ButtonGroup.js
77 Lines(46 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { elementType } from 'prop-types-extra';

import { createBootstrapComponent } from './ThemeProvider';

class ButtonGroup extends React.Component {
  static propTypes = {
    /**
     * @default 'btn-group'
     */
    bsPrefix: PropTypes.string,

    /**
     * Sets the size for all Buttons in the group.
     *
     * @type ('sm'|'lg')
     */
    size: PropTypes.string,

    /** Make the set of Buttons appear vertically stacked. */
    vertical: PropTypes.bool,

    /**
     * Display as a button toggle group.
     *
     * (Generally it's better to use `ToggleButtonGroup` directly)
     */
    toggle: PropTypes.bool,

    /**
     * An ARIA role describing the button group. Usually the default
     * "group" role is fine. An `aria-label` or `aria-labelledby`
     * prop is also recommended.
     */
    role: PropTypes.string,

    as: elementType,
  };

  static defaultProps = {
    vertical: false,
    toggle: false,
    role: 'group',
    as: 'div',
  };

  render() {
    const {
      bsPrefix,
      size,
      toggle,
      vertical,
      className,
      as: Component,
      ...props
    } = this.props;

    let baseClass = bsPrefix;
    if (vertical) baseClass = `${bsPrefix}-vertical`;

    return (
      <Component
        {...props}
        className={classNames(
          className,
          baseClass,
          size && `${bsPrefix}-${size}`,
          toggle && `${bsPrefix}-toggle`,
        )}
      />
    );
  }
}

export default createBootstrapComponent(ButtonGroup, 'btn-group');