@sb1/ffe-buttons-react 14.0.5 → 14.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/BaseButton.js CHANGED
@@ -1,4 +1,4 @@
1
- var _excluded = ["ariaLoadingMessage", "buttonType", "children", "className", "condensed", "disabled", "element", "innerRef", "isLoading", "leftIcon", "rightIcon"];
1
+ var _excluded = ["ariaLoadingMessage", "buttonType", "children", "className", "condensed", "element", "innerRef", "isLoading", "leftIcon", "rightIcon", "onClick"];
2
2
 
3
3
  function _extends() { _extends = Object.assign || 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); }
4
4
 
@@ -19,24 +19,32 @@ var BaseButton = function BaseButton(props) {
19
19
  children = props.children,
20
20
  className = props.className,
21
21
  condensed = props.condensed,
22
- disabled = props.disabled,
23
22
  Element = props.element,
24
23
  innerRef = props.innerRef,
25
24
  isLoading = props.isLoading,
26
25
  leftIcon = props.leftIcon,
27
26
  rightIcon = props.rightIcon,
27
+ _onClick = props.onClick,
28
28
  rest = _objectWithoutProperties(props, _excluded);
29
29
 
30
30
  var supportsSpinner = ['action', 'primary', 'secondary'].includes(buttonType);
31
31
  return /*#__PURE__*/React.createElement(Element, _extends({
32
32
  "aria-busy": isLoading && supportsSpinner,
33
- "aria-disabled": disabled || isLoading && supportsSpinner,
33
+ "aria-disabled": rest.disabled || isLoading && supportsSpinner,
34
34
  className: classNames('ffe-button', "ffe-button--".concat(buttonType), {
35
35
  'ffe-button--condensed': condensed
36
36
  }, {
37
37
  'ffe-button--loading': isLoading && supportsSpinner
38
38
  }, className),
39
- ref: innerRef
39
+ ref: innerRef,
40
+ onClick: function onClick(event) {
41
+ if (isLoading && supportsSpinner) {
42
+ event.preventDefault();
43
+ event.stopPropagation();
44
+ } else if (_onClick) {
45
+ _onClick(event);
46
+ }
47
+ }
40
48
  }, rest), /*#__PURE__*/React.createElement("span", {
41
49
  className: "ffe-button__label"
42
50
  }, leftIcon && /*#__PURE__*/React.cloneElement(leftIcon, {
@@ -87,7 +95,10 @@ BaseButton.propTypes = {
87
95
  leftIcon: node,
88
96
 
89
97
  /** Icon shown to the right of the label */
90
- rightIcon: node
98
+ rightIcon: node,
99
+
100
+ /** Called when button is clicked if not loading or disabled */
101
+ onClick: func
91
102
  };
92
103
  BaseButton.defaultProps = {
93
104
  ariaLoadingMessage: 'Vennligst vent',
package/lib/BaseButton.js CHANGED
@@ -11,7 +11,7 @@ var _propTypes = require("prop-types");
11
11
 
12
12
  var _classnames = _interopRequireDefault(require("classnames"));
13
13
 
14
- var _excluded = ["ariaLoadingMessage", "buttonType", "children", "className", "condensed", "disabled", "element", "innerRef", "isLoading", "leftIcon", "rightIcon"];
14
+ var _excluded = ["ariaLoadingMessage", "buttonType", "children", "className", "condensed", "element", "innerRef", "isLoading", "leftIcon", "rightIcon", "onClick"];
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
@@ -30,24 +30,32 @@ var BaseButton = function BaseButton(props) {
30
30
  children = props.children,
31
31
  className = props.className,
32
32
  condensed = props.condensed,
33
- disabled = props.disabled,
34
33
  Element = props.element,
35
34
  innerRef = props.innerRef,
36
35
  isLoading = props.isLoading,
37
36
  leftIcon = props.leftIcon,
38
37
  rightIcon = props.rightIcon,
38
+ _onClick = props.onClick,
39
39
  rest = _objectWithoutProperties(props, _excluded);
40
40
 
41
41
  var supportsSpinner = ['action', 'primary', 'secondary'].includes(buttonType);
42
42
  return /*#__PURE__*/_react.default.createElement(Element, _extends({
43
43
  "aria-busy": isLoading && supportsSpinner,
44
- "aria-disabled": disabled || isLoading && supportsSpinner,
44
+ "aria-disabled": rest.disabled || isLoading && supportsSpinner,
45
45
  className: (0, _classnames.default)('ffe-button', "ffe-button--".concat(buttonType), {
46
46
  'ffe-button--condensed': condensed
47
47
  }, {
48
48
  'ffe-button--loading': isLoading && supportsSpinner
49
49
  }, className),
50
- ref: innerRef
50
+ ref: innerRef,
51
+ onClick: function onClick(event) {
52
+ if (isLoading && supportsSpinner) {
53
+ event.preventDefault();
54
+ event.stopPropagation();
55
+ } else if (_onClick) {
56
+ _onClick(event);
57
+ }
58
+ }
51
59
  }, rest), /*#__PURE__*/_react.default.createElement("span", {
52
60
  className: "ffe-button__label"
53
61
  }, leftIcon && /*#__PURE__*/_react.default.cloneElement(leftIcon, {
@@ -98,7 +106,10 @@ BaseButton.propTypes = {
98
106
  leftIcon: _propTypes.node,
99
107
 
100
108
  /** Icon shown to the right of the label */
101
- rightIcon: _propTypes.node
109
+ rightIcon: _propTypes.node,
110
+
111
+ /** Called when button is clicked if not loading or disabled */
112
+ onClick: _propTypes.func
102
113
  };
103
114
  BaseButton.defaultProps = {
104
115
  ariaLoadingMessage: 'Vennligst vent',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-buttons-react",
3
- "version": "14.0.5",
3
+ "version": "14.0.6",
4
4
  "description": "React implementation of ffe-buttons",
5
5
  "keywords": [
6
6
  "ffe"
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "779a28007545ef4d26681b63d458f5d82a5abdfb"
56
+ "gitHead": "0fb5a2f3fc9b083939ed70ee4685aa1890d42af7"
57
57
  }