UNPKG

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