-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathButtonGroup.js
More file actions
42 lines (38 loc) · 1.19 KB
/
ButtonGroup.js
File metadata and controls
42 lines (38 loc) · 1.19 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
import React, { PropTypes, Component, Children } from 'react';
import classnames from 'classnames';
import DropdownButton from './DropdownButton';
export default class ButtonGroup extends Component {
constructor() {
super();
this.renderButton = this.renderButton.bind(this);
}
renderButton(button, index) {
if (!React.isValidElement(button)) return null;
const cnt = React.Children.count(this.props.children);
if (button.type && (button.type === DropdownButton || button.type.isGroupable)) {
return React.cloneElement(button, {
key: index,
grouped: true,
isFirstInGroup: index === 0,
isLastInGroup: index === cnt - 1,
});
}
return button;
}
render() {
const { className, children, ...props } = this.props;
const btnGrpClassNames = classnames(className, 'slds-button-group');
const pprops = Object.assign({}, props);
delete pprops.component;
delete pprops.items;
return (
<div className={ btnGrpClassNames } role='group' { ...props }>
{ Children.map(children, this.renderButton) }
</div>
);
}
}
ButtonGroup.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
};