@canonical/react-components 3.8.1 → 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.
- package/dist/components/ActionButton/ActionButton.d.ts +6 -2
- package/dist/components/ActionButton/ActionButton.js +5 -1
- package/dist/components/Modal/Modal.js +4 -5
- package/dist/esm/components/ActionButton/ActionButton.d.ts +6 -2
- package/dist/esm/components/ActionButton/ActionButton.js +6 -2
- package/dist/esm/components/Modal/Modal.js +4 -5
- package/package.json +2 -2
|
@@ -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")
|
|
@@ -35,11 +35,11 @@ const Modal = _ref => {
|
|
|
35
35
|
const shouldClose = (0, _react.useRef)(false);
|
|
36
36
|
const modalRef = (0, _react.useRef)(null);
|
|
37
37
|
const closeButtonRef = (0, _react.useRef)(null);
|
|
38
|
-
const focusableModalElements = (0, _react.useRef)(null);
|
|
39
38
|
const handleTabKey = event => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
39
|
+
const focusableModalElements = modalRef.current.querySelectorAll(focusableElementSelectors);
|
|
40
|
+
if (focusableModalElements.length > 0) {
|
|
41
|
+
const firstElement = focusableModalElements[0];
|
|
42
|
+
const lastElement = focusableModalElements[focusableModalElements.length - 1];
|
|
43
43
|
if (!event.shiftKey && document.activeElement === lastElement) {
|
|
44
44
|
firstElement.focus();
|
|
45
45
|
event.preventDefault();
|
|
@@ -70,7 +70,6 @@ const Modal = _ref => {
|
|
|
70
70
|
} else {
|
|
71
71
|
modalRef.current.focus();
|
|
72
72
|
}
|
|
73
|
-
focusableModalElements.current = modalRef.current.querySelectorAll(focusableElementSelectors);
|
|
74
73
|
}, [focusRef]);
|
|
75
74
|
(0, _react.useEffect)(() => {
|
|
76
75
|
const keyListenersMap = new Map([["Escape", handleEscKey], ["Tab", handleTabKey]]);
|
|
@@ -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")
|
|
@@ -29,11 +29,11 @@ export var Modal = _ref => {
|
|
|
29
29
|
var shouldClose = useRef(false);
|
|
30
30
|
var modalRef = useRef(null);
|
|
31
31
|
var closeButtonRef = useRef(null);
|
|
32
|
-
var focusableModalElements = useRef(null);
|
|
33
32
|
var handleTabKey = event => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var
|
|
33
|
+
var focusableModalElements = modalRef.current.querySelectorAll(focusableElementSelectors);
|
|
34
|
+
if (focusableModalElements.length > 0) {
|
|
35
|
+
var firstElement = focusableModalElements[0];
|
|
36
|
+
var lastElement = focusableModalElements[focusableModalElements.length - 1];
|
|
37
37
|
if (!event.shiftKey && document.activeElement === lastElement) {
|
|
38
38
|
firstElement.focus();
|
|
39
39
|
event.preventDefault();
|
|
@@ -64,7 +64,6 @@ export var Modal = _ref => {
|
|
|
64
64
|
} else {
|
|
65
65
|
modalRef.current.focus();
|
|
66
66
|
}
|
|
67
|
-
focusableModalElements.current = modalRef.current.querySelectorAll(focusableElementSelectors);
|
|
68
67
|
}, [focusRef]);
|
|
69
68
|
useEffect(() => {
|
|
70
69
|
var keyListenersMap = new Map([["Escape", handleEscKey], ["Tab", handleTabKey]]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/react-components",
|
|
3
|
-
"version": "3.8.
|
|
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.
|
|
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",
|