forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.js
More file actions
85 lines (72 loc) · 2 KB
/
Button.js
File metadata and controls
85 lines (72 loc) · 2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import classNames from 'classnames';
import React from 'react';
import elementType from 'react-prop-types/lib/elementType';
import { bsClass, bsSizes, bsStyles, getClassSet, prefix, splitBsProps }
from './utils/bootstrapUtils';
import { Size, State, Style } from './utils/StyleConfig';
import SafeAnchor from './SafeAnchor';
const propTypes = {
active: React.PropTypes.bool,
disabled: React.PropTypes.bool,
block: React.PropTypes.bool,
onClick: React.PropTypes.func,
componentClass: elementType,
href: React.PropTypes.string,
/**
* Defines HTML button type attribute
* @defaultValue 'button'
*/
type: React.PropTypes.oneOf(['button', 'reset', 'submit']),
};
const defaultProps = {
active: false,
block: false,
disabled: false,
};
class Button extends React.Component {
renderAnchor(elementProps, className) {
return (
<SafeAnchor
{...elementProps}
className={classNames(
className, elementProps.disabled && 'disabled'
)}
/>
);
}
renderButton({ componentClass, ...elementProps }, className) {
const Component = componentClass || 'button';
return (
<Component
{...elementProps}
type={elementProps.type || 'button'}
className={className}
/>
);
}
render() {
const { active, block, className, ...props } = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const classes = {
...getClassSet(bsProps),
active,
[prefix(bsProps, 'block')]: block,
};
const fullClassName = classNames(className, classes);
if (elementProps.href) {
return this.renderAnchor(elementProps, fullClassName);
}
return this.renderButton(elementProps, fullClassName);
}
}
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;
export default bsClass('btn',
bsSizes([Size.LARGE, Size.SMALL, Size.XSMALL],
bsStyles(
[...Object.values(State), Style.DEFAULT, Style.PRIMARY, Style.LINK],
Style.DEFAULT,
Button
)
)
);