UNPKG

3.13 kBJavaScriptView Raw
1import _Object$values from 'babel-runtime/core-js/object/values';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _extends from 'babel-runtime/helpers/extends';
4import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
5import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
6import _inherits from 'babel-runtime/helpers/inherits';
7import classNames from 'classnames';
8import React from 'react';
9import PropTypes from 'prop-types';
10import elementType from 'prop-types-extra/lib/elementType';
11
12import { bsClass, bsSizes, bsStyles, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils';
13import { Size, State, Style } from './utils/StyleConfig';
14
15import SafeAnchor from './SafeAnchor';
16
17var 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 * Defines HTML button type attribute
26 * @defaultValue 'button'
27 */
28 type: PropTypes.oneOf(['button', 'reset', 'submit'])
29};
30
31var defaultProps = {
32 active: false,
33 block: false,
34 disabled: false
35};
36
37var 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
92Button.propTypes = propTypes;
93Button.defaultProps = defaultProps;
94
95export 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