@canonical/react-components 1.9.1 → 1.10.0
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/Modal/Modal.d.ts +5 -1
- package/dist/components/Modal/Modal.js +2 -1
- package/dist/components/Modal/Modal.stories.js +8 -1
- package/dist/esm/components/Modal/Modal.d.ts +5 -1
- package/dist/esm/components/Modal/Modal.js +4 -3
- package/dist/esm/components/Modal/Modal.stories.js +8 -1
- package/package.json +1 -1
|
@@ -26,11 +26,15 @@ export type Props = PropsWithSpread<{
|
|
|
26
26
|
* Whether the button click event should propagate.
|
|
27
27
|
*/
|
|
28
28
|
shouldPropagateClickEvent?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the modal should close when clicking outside the modal.
|
|
31
|
+
*/
|
|
32
|
+
closeOnOutsideClick?: boolean;
|
|
29
33
|
}, HTMLProps<HTMLDivElement>>;
|
|
30
34
|
/**
|
|
31
35
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Modal](https://docs.vanillaframework.io/patterns/modal/).
|
|
32
36
|
*
|
|
33
37
|
* The modal component can be used to overlay an area of the screen which can contain a prompt, dialog or interaction.
|
|
34
38
|
*/
|
|
35
|
-
export declare const Modal: ({ buttonRow, children, className, close, title, shouldPropagateClickEvent, ...wrapperProps }: Props) => ReactElement;
|
|
39
|
+
export declare const Modal: ({ buttonRow, children, className, close, title, shouldPropagateClickEvent, closeOnOutsideClick, ...wrapperProps }: Props) => ReactElement;
|
|
36
40
|
export default Modal;
|
|
@@ -23,6 +23,7 @@ const Modal = _ref => {
|
|
|
23
23
|
close,
|
|
24
24
|
title,
|
|
25
25
|
shouldPropagateClickEvent = false,
|
|
26
|
+
closeOnOutsideClick = true,
|
|
26
27
|
...wrapperProps
|
|
27
28
|
} = _ref;
|
|
28
29
|
// list of focusable selectors is based on this Stack Overflow answer:
|
|
@@ -92,7 +93,7 @@ const Modal = _ref => {
|
|
|
92
93
|
shouldClose.current = false;
|
|
93
94
|
};
|
|
94
95
|
const handleOverlayOnMouseDown = event => {
|
|
95
|
-
if (event.target === modalRef.current) {
|
|
96
|
+
if (event.target === modalRef.current && closeOnOutsideClick) {
|
|
96
97
|
shouldClose.current = true;
|
|
97
98
|
}
|
|
98
99
|
};
|
|
@@ -31,12 +31,18 @@ const meta = {
|
|
|
31
31
|
control: {
|
|
32
32
|
disable: true
|
|
33
33
|
}
|
|
34
|
+
},
|
|
35
|
+
closeOnOutsideClick: {
|
|
36
|
+
control: "boolean"
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
};
|
|
37
40
|
var _default = exports.default = meta;
|
|
38
41
|
const Default = exports.Default = {
|
|
39
|
-
render:
|
|
42
|
+
render: _ref => {
|
|
43
|
+
let {
|
|
44
|
+
closeOnOutsideClick
|
|
45
|
+
} = _ref;
|
|
40
46
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
41
47
|
const [modalOpen, setModalOpen] = (0, _react.useState)(true);
|
|
42
48
|
const closeHandler = () => setModalOpen(false);
|
|
@@ -45,6 +51,7 @@ const Default = exports.Default = {
|
|
|
45
51
|
}, "Open modal"), modalOpen ? /*#__PURE__*/_react.default.createElement(_Modal.default, {
|
|
46
52
|
close: closeHandler,
|
|
47
53
|
title: "Confirm delete",
|
|
54
|
+
closeOnOutsideClick: closeOnOutsideClick,
|
|
48
55
|
buttonRow: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("button", {
|
|
49
56
|
className: "u-no-margin--bottom",
|
|
50
57
|
onClick: closeHandler
|
|
@@ -26,11 +26,15 @@ export type Props = PropsWithSpread<{
|
|
|
26
26
|
* Whether the button click event should propagate.
|
|
27
27
|
*/
|
|
28
28
|
shouldPropagateClickEvent?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the modal should close when clicking outside the modal.
|
|
31
|
+
*/
|
|
32
|
+
closeOnOutsideClick?: boolean;
|
|
29
33
|
}, HTMLProps<HTMLDivElement>>;
|
|
30
34
|
/**
|
|
31
35
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Modal](https://docs.vanillaframework.io/patterns/modal/).
|
|
32
36
|
*
|
|
33
37
|
* The modal component can be used to overlay an area of the screen which can contain a prompt, dialog or interaction.
|
|
34
38
|
*/
|
|
35
|
-
export declare const Modal: ({ buttonRow, children, className, close, title, shouldPropagateClickEvent, ...wrapperProps }: Props) => ReactElement;
|
|
39
|
+
export declare const Modal: ({ buttonRow, children, className, close, title, shouldPropagateClickEvent, closeOnOutsideClick, ...wrapperProps }: Props) => ReactElement;
|
|
36
40
|
export default Modal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["buttonRow", "children", "className", "close", "title", "shouldPropagateClickEvent"];
|
|
1
|
+
var _excluded = ["buttonRow", "children", "className", "close", "title", "shouldPropagateClickEvent", "closeOnOutsideClick"];
|
|
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; }
|
|
@@ -16,7 +16,8 @@ export var Modal = _ref => {
|
|
|
16
16
|
className,
|
|
17
17
|
close,
|
|
18
18
|
title,
|
|
19
|
-
shouldPropagateClickEvent = false
|
|
19
|
+
shouldPropagateClickEvent = false,
|
|
20
|
+
closeOnOutsideClick = true
|
|
20
21
|
} = _ref,
|
|
21
22
|
wrapperProps = _objectWithoutProperties(_ref, _excluded);
|
|
22
23
|
// list of focusable selectors is based on this Stack Overflow answer:
|
|
@@ -86,7 +87,7 @@ export var Modal = _ref => {
|
|
|
86
87
|
shouldClose.current = false;
|
|
87
88
|
};
|
|
88
89
|
var handleOverlayOnMouseDown = event => {
|
|
89
|
-
if (event.target === modalRef.current) {
|
|
90
|
+
if (event.target === modalRef.current && closeOnOutsideClick) {
|
|
90
91
|
shouldClose.current = true;
|
|
91
92
|
}
|
|
92
93
|
};
|
|
@@ -23,12 +23,18 @@ var meta = {
|
|
|
23
23
|
control: {
|
|
24
24
|
disable: true
|
|
25
25
|
}
|
|
26
|
+
},
|
|
27
|
+
closeOnOutsideClick: {
|
|
28
|
+
control: "boolean"
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
32
|
export default meta;
|
|
30
33
|
export var Default = {
|
|
31
|
-
render:
|
|
34
|
+
render: _ref => {
|
|
35
|
+
var {
|
|
36
|
+
closeOnOutsideClick
|
|
37
|
+
} = _ref;
|
|
32
38
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
33
39
|
var [modalOpen, setModalOpen] = useState(true);
|
|
34
40
|
var closeHandler = () => setModalOpen(false);
|
|
@@ -37,6 +43,7 @@ export var Default = {
|
|
|
37
43
|
}, "Open modal"), modalOpen ? /*#__PURE__*/React.createElement(Modal, {
|
|
38
44
|
close: closeHandler,
|
|
39
45
|
title: "Confirm delete",
|
|
46
|
+
closeOnOutsideClick: closeOnOutsideClick,
|
|
40
47
|
buttonRow: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
41
48
|
className: "u-no-margin--bottom",
|
|
42
49
|
onClick: closeHandler
|