forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonGroup.js
More file actions
60 lines (50 loc) · 1.45 KB
/
Copy pathButtonGroup.js
File metadata and controls
60 lines (50 loc) · 1.45 KB
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
import classNames from 'classnames';
import React from 'react';
import all from 'react-prop-types/lib/all';
import Button from './Button';
import { bsClass, getClassSet, prefix, splitBsProps }
from './utils/bootstrapUtils';
const propTypes = {
vertical: React.PropTypes.bool,
justified: React.PropTypes.bool,
/**
* Display block buttons; only useful when used with the "vertical" prop.
* @type {bool}
*/
block: all(
React.PropTypes.bool,
({ block, vertical }) => (
block && !vertical ?
new Error('`block` requires `vertical` to be set to have any effect') :
null
),
),
};
const defaultProps = {
block: false,
justified: false,
vertical: false,
};
class ButtonGroup extends React.Component {
render() {
const { block, justified, vertical, className, ...props } = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const classes = {
...getClassSet(bsProps),
[prefix(bsProps)]: !vertical,
[prefix(bsProps, 'vertical')]: vertical,
[prefix(bsProps, 'justified')]: justified,
// this is annoying, since the class is `btn-block` not `btn-group-block`
[prefix(Button.defaultProps, 'block')]: block,
};
return (
<div
{...elementProps}
className={classNames(className, classes)}
/>
);
}
}
ButtonGroup.propTypes = propTypes;
ButtonGroup.defaultProps = defaultProps;
export default bsClass('btn-group', ButtonGroup);