UNPKG

1.35 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5
6const propTypes = {
7 /** Aria label */
8 'aria-label': PropTypes.string,
9 /** Add custom class */
10 className: PropTypes.string,
11 /** Change underlying component's CSS base class name */
12 cssModule: PropTypes.object,
13 /** In order for assistive technologies (such as screen readers) to convey that a series of buttons is grouped, an appropriate role attribute needs to be provided. For button groups, this would be role="group", while toolbars should have a role="toolbar". */
14 role: PropTypes.string,
15 /** Make the button bigger or smaller */
16 size: PropTypes.string,
17 /** Set a custom element for this component */
18 tag: tagPropType,
19 /** Make button group vertical */
20 vertical: PropTypes.bool,
21};
22
23function ButtonGroup(props) {
24 const {
25 className,
26 cssModule,
27 size,
28 vertical,
29 tag: Tag = 'div',
30 ...attributes
31 } = props;
32
33 const classes = mapToCssModules(
34 classNames(
35 className,
36 size ? 'btn-group-' + size : false,
37 vertical ? 'btn-group-vertical' : 'btn-group',
38 ),
39 cssModule,
40 );
41
42 return <Tag {...{ role: 'group', ...attributes }} className={classes} />;
43}
44
45ButtonGroup.propTypes = propTypes;
46
47export default ButtonGroup;
48
\No newline at end of file