Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
  4. import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
  5. import React from 'react';
  6. import PropTypes from 'prop-types';
  7. import classNames from 'classnames';
  8. import { mapToCssModules, tagPropType } from './utils';
  9. var propTypes = {
  10. active: PropTypes.bool,
  11. 'aria-label': PropTypes.string,
  12. block: PropTypes.bool,
  13. color: PropTypes.string,
  14. disabled: PropTypes.bool,
  15. outline: PropTypes.bool,
  16. tag: tagPropType,
  17. innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  18. onClick: PropTypes.func,
  19. size: PropTypes.string,
  20. children: PropTypes.node,
  21. className: PropTypes.string,
  22. cssModule: PropTypes.object,
  23. close: PropTypes.bool
  24. };
  25. var defaultProps = {
  26. color: 'secondary',
  27. tag: 'button'
  28. };
  29. var Button =
  30. /*#__PURE__*/
  31. function (_React$Component) {
  32. _inheritsLoose(Button, _React$Component);
  33. function Button(props) {
  34. var _this;
  35. _this = _React$Component.call(this, props) || this;
  36. _this.onClick = _this.onClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
  37. return _this;
  38. }
  39. var _proto = Button.prototype;
  40. _proto.onClick = function onClick(e) {
  41. if (this.props.disabled) {
  42. e.preventDefault();
  43. return;
  44. }
  45. if (this.props.onClick) {
  46. this.props.onClick(e);
  47. }
  48. };
  49. _proto.render = function render() {
  50. var _this$props = this.props,
  51. active = _this$props.active,
  52. ariaLabel = _this$props['aria-label'],
  53. block = _this$props.block,
  54. className = _this$props.className,
  55. close = _this$props.close,
  56. cssModule = _this$props.cssModule,
  57. color = _this$props.color,
  58. outline = _this$props.outline,
  59. size = _this$props.size,
  60. Tag = _this$props.tag,
  61. innerRef = _this$props.innerRef,
  62. attributes = _objectWithoutPropertiesLoose(_this$props, ["active", "aria-label", "block", "className", "close", "cssModule", "color", "outline", "size", "tag", "innerRef"]);
  63. if (close && typeof attributes.children === 'undefined') {
  64. attributes.children = React.createElement("span", {
  65. "aria-hidden": true
  66. }, "\xD7");
  67. }
  68. var btnOutlineColor = "btn" + (outline ? '-outline' : '') + "-" + color;
  69. var classes = mapToCssModules(classNames(className, {
  70. close: close
  71. }, close || 'btn', close || btnOutlineColor, size ? "btn-" + size : false, block ? 'btn-block' : false, {
  72. active: active,
  73. disabled: this.props.disabled
  74. }), cssModule);
  75. if (attributes.href && Tag === 'button') {
  76. Tag = 'a';
  77. }
  78. var defaultAriaLabel = close ? 'Close' : null;
  79. return React.createElement(Tag, _extends({
  80. type: Tag === 'button' && attributes.onClick ? 'button' : undefined
  81. }, attributes, {
  82. className: classes,
  83. ref: innerRef,
  84. onClick: this.onClick,
  85. "aria-label": ariaLabel || defaultAriaLabel
  86. }));
  87. };
  88. return Button;
  89. }(React.Component);
  90. Button.propTypes = propTypes;
  91. Button.defaultProps = defaultProps;
  92. export default Button;