1 | var _excluded = ["active", "aria-label", "block", "className", "close", "cssModule", "color", "outline", "size", "tag", "innerRef"];
|
2 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
3 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
4 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
5 | import React, { useCallback } from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import classNames from 'classnames';
|
8 | import { mapToCssModules, tagPropType } from './utils';
|
9 | import CloseButton from './CloseButton';
|
10 | var propTypes = {
|
11 |
|
12 | active: PropTypes.bool,
|
13 |
|
14 | 'aria-label': PropTypes.string,
|
15 | block: PropTypes.bool,
|
16 |
|
17 | children: PropTypes.node,
|
18 |
|
19 | className: PropTypes.string,
|
20 |
|
21 | cssModule: PropTypes.object,
|
22 |
|
23 | close: PropTypes.bool,
|
24 |
|
25 | color: PropTypes.string,
|
26 |
|
27 | disabled: PropTypes.bool,
|
28 | innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
|
29 |
|
30 | onClick: PropTypes.func,
|
31 |
|
32 | outline: PropTypes.bool,
|
33 |
|
34 | size: PropTypes.string,
|
35 |
|
36 | tag: tagPropType
|
37 | };
|
38 | function Button(props) {
|
39 | var onClick = useCallback(function (e) {
|
40 | if (props.disabled) {
|
41 | e.preventDefault();
|
42 | return;
|
43 | }
|
44 | if (props.onClick) {
|
45 | return props.onClick(e);
|
46 | }
|
47 | }, [props.onClick, props.disabled]);
|
48 | var active = props.active,
|
49 | ariaLabel = props['aria-label'],
|
50 | block = props.block,
|
51 | className = props.className,
|
52 | close = props.close,
|
53 | cssModule = props.cssModule,
|
54 | _props$color = props.color,
|
55 | color = _props$color === void 0 ? 'secondary' : _props$color,
|
56 | outline = props.outline,
|
57 | size = props.size,
|
58 | _props$tag = props.tag,
|
59 | Tag = _props$tag === void 0 ? 'button' : _props$tag,
|
60 | innerRef = props.innerRef,
|
61 | attributes = _objectWithoutProperties(props, _excluded);
|
62 | if (close) {
|
63 | return React.createElement(CloseButton, attributes);
|
64 | }
|
65 | var btnOutlineColor = "btn".concat(outline ? '-outline' : '', "-").concat(color);
|
66 | var classes = mapToCssModules(classNames(className, 'btn', btnOutlineColor, size ? "btn-".concat(size) : false, block ? 'd-block w-100' : false, {
|
67 | active: active,
|
68 | disabled: props.disabled
|
69 | }), cssModule);
|
70 | if (attributes.href && Tag === 'button') {
|
71 | Tag = 'a';
|
72 | }
|
73 | return React.createElement(Tag, _extends({
|
74 | type: Tag === 'button' && attributes.onClick ? 'button' : undefined
|
75 | }, attributes, {
|
76 | className: classes,
|
77 | ref: innerRef,
|
78 | onClick: onClick,
|
79 | "aria-label": ariaLabel
|
80 | }));
|
81 | }
|
82 | Button.propTypes = propTypes;
|
83 | export default Button; |
\ | No newline at end of file |