-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathSplitButton.js
75 lines (64 loc) · 1.56 KB
/
SplitButton.js
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
import React from 'react';
import PropTypes from 'prop-types';
import Button from './Button';
import Dropdown from './Dropdown';
import SplitToggle from './SplitToggle';
import splitComponentProps from './utils/splitComponentProps';
const propTypes = {
...Dropdown.propTypes,
// Toggle props.
bsStyle: PropTypes.string,
bsSize: PropTypes.string,
href: PropTypes.string,
onClick: PropTypes.func,
/**
* The content of the split button.
*/
title: PropTypes.node.isRequired,
/**
* Accessible label for the toggle; the value of `title` if not specified.
*/
toggleLabel: PropTypes.string,
// Override generated docs from <Dropdown>.
/**
* @private
*/
children: PropTypes.node
};
class SplitButton extends React.Component {
render() {
const {
bsSize,
bsStyle,
title,
toggleLabel,
children,
...props
} = this.props;
const [dropdownProps, buttonProps] = splitComponentProps(
props,
Dropdown.ControlledComponent
);
return (
<Dropdown {...dropdownProps} bsSize={bsSize} bsStyle={bsStyle}>
<Button
{...buttonProps}
disabled={props.disabled}
bsSize={bsSize}
bsStyle={bsStyle}
>
{title}
</Button>
<SplitToggle
aria-label={toggleLabel || title}
bsSize={bsSize}
bsStyle={bsStyle}
/>
<Dropdown.Menu>{children}</Dropdown.Menu>
</Dropdown>
);
}
}
SplitButton.propTypes = propTypes;
SplitButton.Toggle = SplitToggle;
export default SplitButton;