@skatteetaten/ds-overlays 1.1.0 → 1.2.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 +117 -115
- package/Popover/index.esm.js +78 -1149
- package/PopoverContent/index.esm.js +1 -2
- package/PopoverContent-QCKf0esL.js +101 -0
- package/PopoverContext/index.esm.js +1 -1
- package/PopoverTrigger/index.esm.js +30 -47
- package/index.esm.js +18 -5
- package/package.json +7 -6
- package/PopoverContent-201ee636.js +0 -182
- package/es.string.trim-9652bb40.js +0 -1106
package/Modal/index.esm.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import '../es.string.trim-9652bb40.js';
|
|
2
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
2
|
import { forwardRef, useId, useRef, useImperativeHandle } from 'react';
|
|
4
3
|
import { useTranslation } from 'react-i18next';
|
|
@@ -9,123 +8,126 @@ import { Heading } from '@skatteetaten/ds-typography';
|
|
|
9
8
|
import './styles.css';
|
|
10
9
|
|
|
11
10
|
|
|
12
|
-
const getModalPaddingDefault = ()
|
|
13
|
-
const getModalVariantDefault = ()
|
|
14
|
-
const getModalDismissOnOutsideClickDefault = ()
|
|
15
|
-
const getModalDismissOnEscDefault = ()
|
|
11
|
+
const getModalPaddingDefault = ()=>'l';
|
|
12
|
+
const getModalVariantDefault = ()=>'outline';
|
|
13
|
+
const getModalDismissOnOutsideClickDefault = ()=>true;
|
|
14
|
+
const getModalDismissOnEscDefault = ()=>true;
|
|
16
15
|
|
|
17
|
-
var styles = {
|
|
16
|
+
var styles = {
|
|
17
|
+
"modal": "Modal-module_modal__Kyr-Y",
|
|
18
|
+
"modalContainer": "Modal-module_modalContainer__muf75",
|
|
19
|
+
"modalLogo": "Modal-module_modalLogo__Vaf6E",
|
|
20
|
+
"modalHeading": "Modal-module_modalHeading__uwT1R",
|
|
21
|
+
"modalHeadingNoPadding": "Modal-module_modalHeadingNoPadding__t2hkH",
|
|
22
|
+
"modalIllustration": "Modal-module_modalIllustration__jbA32",
|
|
23
|
+
"modalNoBorder": "Modal-module_modalNoBorder__ReNVP",
|
|
24
|
+
"modalPaddingNONE": "Modal-module_modalPaddingNONE__02HaX",
|
|
25
|
+
"modalPaddingS": "Modal-module_modalPaddingS__O93ax",
|
|
26
|
+
"modalPaddingM": "Modal-module_modalPaddingM__c5Wi2",
|
|
27
|
+
"modalPaddingL": "Modal-module_modalPaddingL__IbVyg",
|
|
28
|
+
"modalPaddingMEGA": "Modal-module_modalPaddingMEGA__wWHwS",
|
|
29
|
+
"modalNoPaddingTop": "Modal-module_modalNoPaddingTop__REBWr",
|
|
30
|
+
"closeButton": "Modal-module_closeButton__jgbDq",
|
|
31
|
+
"srOnly": "Modal-module_srOnly__W8dQv"
|
|
32
|
+
};
|
|
18
33
|
|
|
19
|
-
const Modal = /*#__PURE__*/forwardRef(({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
variant: _variant = getModalVariantDefault(),
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
|
-
shadowRootNode,
|
|
36
|
-
onClose,
|
|
37
|
-
children
|
|
38
|
-
}, ref) => {
|
|
39
|
-
var _classNames$container, _classNames$image;
|
|
40
|
-
const headingId = `modalHeadingId-${useId()}`;
|
|
41
|
-
const {
|
|
42
|
-
t
|
|
43
|
-
} = useTranslation('ds_overlays', {
|
|
44
|
-
i18n: dsI18n
|
|
45
|
-
});
|
|
46
|
-
const statusFlagRef = useRef({
|
|
47
|
-
mouseDownCaptured: false
|
|
48
|
-
});
|
|
49
|
-
const modalRef = useRef(null);
|
|
50
|
-
useImperativeHandle(ref, () => modalRef == null ? void 0 : modalRef.current);
|
|
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)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (event.type === 'mousedown') {
|
|
63
|
-
statusFlagRef.current.mouseDownCaptured = false;
|
|
64
|
-
}
|
|
65
|
-
if (isClickOutside(event)) {
|
|
66
|
-
if (event.type === 'mouseup' && statusFlagRef.current.mouseDownCaptured) {
|
|
67
|
-
var _modalRef$current;
|
|
68
|
-
onClose == null || onClose();
|
|
69
|
-
(_modalRef$current = modalRef.current) == null || _modalRef$current.close();
|
|
70
|
-
} else {
|
|
71
|
-
statusFlagRef.current.mouseDownCaptured = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const hideTitleClassName = hideTitle ? styles.srOnly : '';
|
|
76
|
-
const hideOutlineClassName = _variant === 'plain' || _variant === 'important' ? styles.modalNoBorder : '';
|
|
77
|
-
const paddingClassName = styles[`modalPadding${_padding.toUpperCase()}`];
|
|
78
|
-
const noPaddingTop = imageSource ? styles.modalNoPaddingTop : '';
|
|
79
|
-
const headingNoPaddingClassName = _padding === 'mega' ? styles.modalHeadingNoPadding : '';
|
|
80
|
-
return jsx("dialog", {
|
|
81
|
-
ref: modalRef,
|
|
82
|
-
id: id,
|
|
83
|
-
className: `${styles.modal} ${hideOutlineClassName} ${_className} ${(_classNames$container = classNames == null ? void 0 : classNames.container) != null ? _classNames$container : ''}`.trim(),
|
|
84
|
-
lang: lang,
|
|
85
|
-
"data-testid": dataTestId,
|
|
86
|
-
"aria-labelledby": headingId,
|
|
87
|
-
autoFocus: true,
|
|
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') {
|
|
91
|
-
e.preventDefault();
|
|
92
|
-
} else {
|
|
93
|
-
onClose == null || onClose();
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
onMouseUp: handleMouseEvent,
|
|
97
|
-
onMouseDown: handleMouseEvent,
|
|
98
|
-
children: jsxs("div", {
|
|
99
|
-
tabIndex: -1,
|
|
100
|
-
className: styles.modalContainer,
|
|
101
|
-
children: [!hideCloseButton && jsx(IconButton, {
|
|
102
|
-
className: styles.closeButton,
|
|
103
|
-
svgPath: CancelSVGpath,
|
|
104
|
-
title: t('modal.CloseModal'),
|
|
105
|
-
onClick: () => {
|
|
106
|
-
var _modalRef$current2;
|
|
107
|
-
onClose == null || onClose();
|
|
108
|
-
(_modalRef$current2 = modalRef.current) == null || _modalRef$current2.close();
|
|
34
|
+
const Modal = /*#__PURE__*/ forwardRef(({ id, className = getCommonClassNameDefault(), classNames, lang, 'data-testid': dataTestId, dismissOnEsc = getModalDismissOnEscDefault(), dismissOnOutsideClick = getModalDismissOnOutsideClickDefault(), hideCloseButton, hideTitle, imageSource, imageSourceAltText, padding = getModalPaddingDefault(), title, variant = getModalVariantDefault(), // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
|
+
shadowRootNode, onClose, children }, ref)=>{
|
|
36
|
+
const headingId = `modalHeadingId-${useId()}`;
|
|
37
|
+
const { t } = useTranslation('ds_overlays', {
|
|
38
|
+
i18n: dsI18n
|
|
39
|
+
});
|
|
40
|
+
const statusFlagRef = useRef({
|
|
41
|
+
mouseDownCaptured: false
|
|
42
|
+
});
|
|
43
|
+
const modalRef = useRef(null);
|
|
44
|
+
useImperativeHandle(ref, ()=>modalRef?.current);
|
|
45
|
+
const isClickOutside = (event)=>{
|
|
46
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
47
|
+
return true;
|
|
109
48
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
49
|
+
const rect = event.target.getBoundingClientRect();
|
|
50
|
+
return rect.left > event.clientX || rect.right < event.clientX || rect.top > event.clientY || rect.bottom < event.clientY;
|
|
51
|
+
};
|
|
52
|
+
const handleMouseEvent = (event)=>{
|
|
53
|
+
if (!dismissOnOutsideClick || !(event.target instanceof HTMLElement)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (event.type === 'mousedown') {
|
|
57
|
+
statusFlagRef.current.mouseDownCaptured = false;
|
|
58
|
+
}
|
|
59
|
+
if (isClickOutside(event)) {
|
|
60
|
+
if (event.type === 'mouseup' && statusFlagRef.current.mouseDownCaptured) {
|
|
61
|
+
onClose?.();
|
|
62
|
+
modalRef.current?.close();
|
|
63
|
+
} else {
|
|
64
|
+
statusFlagRef.current.mouseDownCaptured = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const hideTitleClassName = hideTitle ? styles.srOnly : '';
|
|
69
|
+
const hideOutlineClassName = variant === 'plain' || variant === 'important' ? styles.modalNoBorder : '';
|
|
70
|
+
const paddingClassName = styles[`modalPadding${padding.toUpperCase()}`];
|
|
71
|
+
const noPaddingTop = imageSource ? styles.modalNoPaddingTop : '';
|
|
72
|
+
const headingNoPaddingClassName = padding === 'mega' ? styles.modalHeadingNoPadding : '';
|
|
73
|
+
return /*#__PURE__*/ jsx("dialog", {
|
|
74
|
+
ref: modalRef,
|
|
75
|
+
id: id,
|
|
76
|
+
className: `${styles.modal} ${hideOutlineClassName} ${className} ${classNames?.container ?? ''}`.trim(),
|
|
77
|
+
lang: lang,
|
|
78
|
+
"data-testid": dataTestId,
|
|
79
|
+
"aria-labelledby": headingId,
|
|
80
|
+
autoFocus: true,
|
|
81
|
+
/* Merk at onCancel kan ikke brukes til å hindre lukking fordi to trykk på esc lukker allikevel i chrome */ onKeyDown: (e)=>{
|
|
82
|
+
if (e.key === 'Escape') {
|
|
83
|
+
if (dismissOnEsc) {
|
|
84
|
+
onClose?.();
|
|
85
|
+
} else {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
onMouseUp: handleMouseEvent,
|
|
91
|
+
onMouseDown: handleMouseEvent,
|
|
92
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
93
|
+
tabIndex: -1,
|
|
94
|
+
className: styles.modalContainer,
|
|
95
|
+
children: [
|
|
96
|
+
!hideCloseButton && /*#__PURE__*/ jsx(IconButton, {
|
|
97
|
+
className: styles.closeButton,
|
|
98
|
+
svgPath: CancelSVGpath,
|
|
99
|
+
title: t('modal.CloseModal'),
|
|
100
|
+
onClick: ()=>{
|
|
101
|
+
onClose?.();
|
|
102
|
+
modalRef.current?.close();
|
|
103
|
+
}
|
|
104
|
+
}),
|
|
105
|
+
imageSource && /*#__PURE__*/ jsx("img", {
|
|
106
|
+
src: imageSource,
|
|
107
|
+
alt: imageSourceAltText ?? '',
|
|
108
|
+
className: `${styles.modalIllustration} ${classNames?.image ?? ''}`.trim()
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ jsxs("div", {
|
|
111
|
+
className: `${paddingClassName} ${noPaddingTop}`.trim(),
|
|
112
|
+
children: [
|
|
113
|
+
variant === 'important' && /*#__PURE__*/ jsx(SkatteetatenLogo, {
|
|
114
|
+
className: styles.modalLogo
|
|
115
|
+
}),
|
|
116
|
+
/*#__PURE__*/ jsx(Heading, {
|
|
117
|
+
className: `${styles.modalHeading} ${headingNoPaddingClassName} ${hideTitleClassName}`.trim(),
|
|
118
|
+
id: headingId,
|
|
119
|
+
as: 'h1',
|
|
120
|
+
level: 3,
|
|
121
|
+
hasSpacing: true,
|
|
122
|
+
children: title
|
|
123
|
+
}),
|
|
124
|
+
children
|
|
125
|
+
]
|
|
126
|
+
}),
|
|
127
|
+
variant === 'important' && /*#__PURE__*/ jsx(Separator, {})
|
|
128
|
+
]
|
|
129
|
+
})
|
|
130
|
+
});
|
|
129
131
|
});
|
|
130
132
|
Modal.displayName = 'Modal';
|
|
131
133
|
|