@skatteetaten/ds-overlays 0.8.0 → 1.1.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/Modal/index.esm.js +30 -19
- package/package.json +8 -8
package/Modal/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../es.string.trim-9652bb40.js';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { forwardRef, useId, useRef, useImperativeHandle
|
|
3
|
+
import { forwardRef, useId, useRef, useImperativeHandle } from 'react';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { IconButton } from '@skatteetaten/ds-buttons';
|
|
6
6
|
import { dsI18n, SkatteetatenLogo, Separator, getCommonClassNameDefault } from '@skatteetaten/ds-core-utils';
|
|
@@ -31,6 +31,7 @@ const Modal = /*#__PURE__*/forwardRef(({
|
|
|
31
31
|
padding: _padding = getModalPaddingDefault(),
|
|
32
32
|
title,
|
|
33
33
|
variant: _variant = getModalVariantDefault(),
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
35
|
shadowRootNode,
|
|
35
36
|
onClose,
|
|
36
37
|
children
|
|
@@ -42,29 +43,35 @@ const Modal = /*#__PURE__*/forwardRef(({
|
|
|
42
43
|
} = useTranslation('ds_overlays', {
|
|
43
44
|
i18n: dsI18n
|
|
44
45
|
});
|
|
46
|
+
const statusFlagRef = useRef({
|
|
47
|
+
mouseDownCaptured: false
|
|
48
|
+
});
|
|
45
49
|
const modalRef = useRef(null);
|
|
46
50
|
useImperativeHandle(ref, () => modalRef == null ? void 0 : modalRef.current);
|
|
47
|
-
|
|
48
|
-
if (!
|
|
51
|
+
const isClickOutside = event => {
|
|
52
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const rect = event.target.getBoundingClientRect();
|
|
56
|
+
return rect.left > event.clientX || rect.right < event.clientX || rect.top > event.clientY || rect.bottom < event.clientY;
|
|
57
|
+
};
|
|
58
|
+
const handleMouseEvent = event => {
|
|
59
|
+
if (!_dismissOnOutsideClick || !(event.target instanceof HTMLElement)) {
|
|
49
60
|
return;
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const rect = event.target.getBoundingClientRect();
|
|
57
|
-
if (rect.left > event.clientX || rect.right < event.clientX || rect.top > event.clientY || rect.bottom < event.clientY) {
|
|
62
|
+
if (event.type === 'mousedown') {
|
|
63
|
+
statusFlagRef.current.mouseDownCaptured = false;
|
|
64
|
+
}
|
|
65
|
+
if (isClickOutside(event)) {
|
|
66
|
+
if (event.type === 'mouseup' && statusFlagRef.current.mouseDownCaptured) {
|
|
58
67
|
var _modalRef$current;
|
|
59
68
|
onClose == null || onClose();
|
|
60
69
|
(_modalRef$current = modalRef.current) == null || _modalRef$current.close();
|
|
70
|
+
} else {
|
|
71
|
+
statusFlagRef.current.mouseDownCaptured = true;
|
|
61
72
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return () => {
|
|
65
|
-
document.removeEventListener('click', onClickOutside, true);
|
|
66
|
-
};
|
|
67
|
-
}, [modalRef, _dismissOnOutsideClick, onClose, shadowRootNode]);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
68
75
|
const hideTitleClassName = hideTitle ? styles.srOnly : '';
|
|
69
76
|
const hideOutlineClassName = _variant === 'plain' || _variant === 'important' ? styles.modalNoBorder : '';
|
|
70
77
|
const paddingClassName = styles[`modalPadding${_padding.toUpperCase()}`];
|
|
@@ -78,12 +85,16 @@ const Modal = /*#__PURE__*/forwardRef(({
|
|
|
78
85
|
"data-testid": dataTestId,
|
|
79
86
|
"aria-labelledby": headingId,
|
|
80
87
|
autoFocus: true,
|
|
81
|
-
onCancel
|
|
82
|
-
|
|
88
|
+
/* Merk at onCancel kan ikke brukes til å hindre lukking fordi to trykk på esc lukker allikevel i chrome */
|
|
89
|
+
onKeyDown: e => {
|
|
90
|
+
if (!_dismissOnEsc && e.key === 'Escape') {
|
|
83
91
|
e.preventDefault();
|
|
92
|
+
} else {
|
|
93
|
+
onClose == null || onClose();
|
|
84
94
|
}
|
|
85
|
-
onClose == null || onClose();
|
|
86
95
|
},
|
|
96
|
+
onMouseUp: handleMouseEvent,
|
|
97
|
+
onMouseDown: handleMouseEvent,
|
|
87
98
|
children: jsxs("div", {
|
|
88
99
|
tabIndex: -1,
|
|
89
100
|
className: styles.modalContainer,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skatteetaten/ds-overlays",
|
|
3
3
|
"groupId": "no.skatteetaten.aurora",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"main": "./index.esm.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "./index.esm.js",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"i18next": "^23",
|
|
15
15
|
"react": "^18",
|
|
16
|
-
"react-i18next": "^
|
|
17
|
-
"@skatteetaten/ds-core-utils": "
|
|
18
|
-
"@skatteetaten/ds-buttons": "
|
|
19
|
-
"@skatteetaten/ds-icons": "
|
|
20
|
-
"@skatteetaten/ds-typography": "
|
|
21
|
-
"@skatteetaten/ds-progress": "
|
|
22
|
-
"@floating-ui/react": "0.26.
|
|
16
|
+
"react-i18next": "^14",
|
|
17
|
+
"@skatteetaten/ds-core-utils": "1.1.0",
|
|
18
|
+
"@skatteetaten/ds-buttons": "1.1.0",
|
|
19
|
+
"@skatteetaten/ds-icons": "1.1.0",
|
|
20
|
+
"@skatteetaten/ds-typography": "1.1.0",
|
|
21
|
+
"@skatteetaten/ds-progress": "1.1.0",
|
|
22
|
+
"@floating-ui/react": "0.26.17"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {}
|
|
25
25
|
}
|