@canonical/react-components 3.8.2 → 3.8.3

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.
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { MouseEventHandler } from "react";
2
2
  import type { ButtonHTMLAttributes, ReactNode } from "react";
3
3
  import type { ButtonProps } from "../Button";
4
4
  import type { ClassName, PropsWithSpread } from "../../types";
@@ -33,6 +33,10 @@ export type Props = PropsWithSpread<{
33
33
  * Whether the button should be in the loading state.
34
34
  */
35
35
  loading?: boolean;
36
+ /**
37
+ * Function for handling button click event.
38
+ */
39
+ onClick?: MouseEventHandler<HTMLButtonElement>;
36
40
  /**
37
41
  * Whether the button should be in the success state.
38
42
  */
@@ -45,5 +49,5 @@ export type Props = PropsWithSpread<{
45
49
  * [Button](?path=/docs/components-button--docs) in addition to those in the
46
50
  * props table:
47
51
  */
48
- declare const ActionButton: ({ appearance, children, className, disabled, inline, loading, success, ...buttonProps }: Props) => React.JSX.Element;
52
+ declare const ActionButton: ({ appearance, children, className, onClick, disabled, inline, loading, success, ...buttonProps }: Props) => React.JSX.Element;
49
53
  export default ActionButton;
@@ -30,6 +30,7 @@ const ActionButton = _ref => {
30
30
  appearance,
31
31
  children,
32
32
  className,
33
+ onClick,
33
34
  disabled = null,
34
35
  inline = false,
35
36
  loading = false,
@@ -108,8 +109,10 @@ const ActionButton = _ref => {
108
109
  "is-inline": inline
109
110
  });
110
111
  const showIcon = showLoader || showSuccess;
112
+ const isDisabled = disabled === null ? showLoader : disabled;
111
113
  const icon = showLoader && "spinner" || showSuccess && "success" || null;
112
114
  const iconLight = appearance === "positive" || appearance === "negative";
115
+ const onClickDisabled = e => e.preventDefault();
113
116
 
114
117
  // This component uses the base button element instead of the Button component
115
118
  // as the button requires a ref and Button would have to be updated to use
@@ -117,8 +120,9 @@ const ActionButton = _ref => {
117
120
  // typescript generics.
118
121
  return /*#__PURE__*/_react.default.createElement("button", _extends({
119
122
  className: buttonClasses,
120
- disabled: disabled === null ? showLoader : disabled,
121
123
  ref: ref,
124
+ onClick: isDisabled ? onClickDisabled : onClick,
125
+ "aria-disabled": isDisabled || undefined,
122
126
  style: height && width ? {
123
127
  height: "".concat(height, "px"),
124
128
  width: "".concat(width, "px")
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { MouseEventHandler } from "react";
2
2
  import type { ButtonHTMLAttributes, ReactNode } from "react";
3
3
  import type { ButtonProps } from "../Button";
4
4
  import type { ClassName, PropsWithSpread } from "../../types";
@@ -33,6 +33,10 @@ export type Props = PropsWithSpread<{
33
33
  * Whether the button should be in the loading state.
34
34
  */
35
35
  loading?: boolean;
36
+ /**
37
+ * Function for handling button click event.
38
+ */
39
+ onClick?: MouseEventHandler<HTMLButtonElement>;
36
40
  /**
37
41
  * Whether the button should be in the success state.
38
42
  */
@@ -45,5 +49,5 @@ export type Props = PropsWithSpread<{
45
49
  * [Button](?path=/docs/components-button--docs) in addition to those in the
46
50
  * props table:
47
51
  */
48
- declare const ActionButton: ({ appearance, children, className, disabled, inline, loading, success, ...buttonProps }: Props) => React.JSX.Element;
52
+ declare const ActionButton: ({ appearance, children, className, onClick, disabled, inline, loading, success, ...buttonProps }: Props) => React.JSX.Element;
49
53
  export default ActionButton;
@@ -1,4 +1,4 @@
1
- var _excluded = ["appearance", "children", "className", "disabled", "inline", "loading", "success"];
1
+ var _excluded = ["appearance", "children", "className", "onClick", "disabled", "inline", "loading", "success"];
2
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
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
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; }
@@ -25,6 +25,7 @@ var ActionButton = _ref => {
25
25
  appearance,
26
26
  children,
27
27
  className,
28
+ onClick,
28
29
  disabled = null,
29
30
  inline = false,
30
31
  loading = false,
@@ -103,8 +104,10 @@ var ActionButton = _ref => {
103
104
  "is-inline": inline
104
105
  });
105
106
  var showIcon = showLoader || showSuccess;
107
+ var isDisabled = disabled === null ? showLoader : disabled;
106
108
  var icon = showLoader && "spinner" || showSuccess && "success" || null;
107
109
  var iconLight = appearance === "positive" || appearance === "negative";
110
+ var onClickDisabled = e => e.preventDefault();
108
111
 
109
112
  // This component uses the base button element instead of the Button component
110
113
  // as the button requires a ref and Button would have to be updated to use
@@ -112,8 +115,9 @@ var ActionButton = _ref => {
112
115
  // typescript generics.
113
116
  return /*#__PURE__*/React.createElement("button", _extends({
114
117
  className: buttonClasses,
115
- disabled: disabled === null ? showLoader : disabled,
116
118
  ref: ref,
119
+ onClick: isDisabled ? onClickDisabled : onClick,
120
+ "aria-disabled": isDisabled || undefined,
117
121
  style: height && width ? {
118
122
  height: "".concat(height, "px"),
119
123
  width: "".concat(width, "px")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "3.8.2",
3
+ "version": "3.8.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {
@@ -81,7 +81,7 @@
81
81
  "sass": "1.85.0",
82
82
  "sass-loader": "16.0.5",
83
83
  "semantic-release": "25.0.2",
84
- "storybook": "8.5.6",
84
+ "storybook": "8.6.15",
85
85
  "strip-ansi": "7.1.0",
86
86
  "style-loader": "4.0.0",
87
87
  "stylelint": "16.14.1",