1 | import _Object$values from 'babel-runtime/core-js/object/values';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _extends from 'babel-runtime/helpers/extends';
|
4 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
5 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
6 | import _inherits from 'babel-runtime/helpers/inherits';
|
7 | import classNames from 'classnames';
|
8 | import React from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 | import elementType from 'prop-types-extra/lib/elementType';
|
11 |
|
12 | import { bsClass, bsSizes, bsStyles, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils';
|
13 | import { Size, State, Style } from './utils/StyleConfig';
|
14 |
|
15 | import SafeAnchor from './SafeAnchor';
|
16 |
|
17 | var propTypes = {
|
18 | active: PropTypes.bool,
|
19 | disabled: PropTypes.bool,
|
20 | block: PropTypes.bool,
|
21 | onClick: PropTypes.func,
|
22 | componentClass: elementType,
|
23 | href: PropTypes.string,
|
24 | |
25 |
|
26 |
|
27 |
|
28 | type: PropTypes.oneOf(['button', 'reset', 'submit'])
|
29 | };
|
30 |
|
31 | var defaultProps = {
|
32 | active: false,
|
33 | block: false,
|
34 | disabled: false
|
35 | };
|
36 |
|
37 | var Button = function (_React$Component) {
|
38 | _inherits(Button, _React$Component);
|
39 |
|
40 | function Button() {
|
41 | _classCallCheck(this, Button);
|
42 |
|
43 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
44 | }
|
45 |
|
46 | Button.prototype.renderAnchor = function renderAnchor(elementProps, className) {
|
47 | return React.createElement(SafeAnchor, _extends({}, elementProps, {
|
48 | className: classNames(className, elementProps.disabled && 'disabled')
|
49 | }));
|
50 | };
|
51 |
|
52 | Button.prototype.renderButton = function renderButton(_ref, className) {
|
53 | var componentClass = _ref.componentClass,
|
54 | elementProps = _objectWithoutProperties(_ref, ['componentClass']);
|
55 |
|
56 | var Component = componentClass || 'button';
|
57 |
|
58 | return React.createElement(Component, _extends({}, elementProps, {
|
59 | type: elementProps.type || 'button',
|
60 | className: className
|
61 | }));
|
62 | };
|
63 |
|
64 | Button.prototype.render = function render() {
|
65 | var _extends2;
|
66 |
|
67 | var _props = this.props,
|
68 | active = _props.active,
|
69 | block = _props.block,
|
70 | className = _props.className,
|
71 | props = _objectWithoutProperties(_props, ['active', 'block', 'className']);
|
72 |
|
73 | var _splitBsProps = splitBsProps(props),
|
74 | bsProps = _splitBsProps[0],
|
75 | elementProps = _splitBsProps[1];
|
76 |
|
77 | var classes = _extends({}, getClassSet(bsProps), (_extends2 = {
|
78 | active: active
|
79 | }, _extends2[prefix(bsProps, 'block')] = block, _extends2));
|
80 | var fullClassName = classNames(className, classes);
|
81 |
|
82 | if (elementProps.href) {
|
83 | return this.renderAnchor(elementProps, fullClassName);
|
84 | }
|
85 |
|
86 | return this.renderButton(elementProps, fullClassName);
|
87 | };
|
88 |
|
89 | return Button;
|
90 | }(React.Component);
|
91 |
|
92 | Button.propTypes = propTypes;
|
93 | Button.defaultProps = defaultProps;
|
94 |
|
95 | export default bsClass('btn', bsSizes([Size.LARGE, Size.SMALL, Size.XSMALL], bsStyles([].concat(_Object$values(State), [Style.DEFAULT, Style.PRIMARY, Style.LINK]), Style.DEFAULT, Button))); |
\ | No newline at end of file |