@skatteetaten/ds-overlays 1.1.1 → 1.3.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.
@@ -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,125 +8,126 @@ import { Heading } from '@skatteetaten/ds-typography';
9
8
  import './styles.css';
10
9
 
11
10
 
12
- const getModalPaddingDefault = () => 'l';
13
- const getModalVariantDefault = () => 'outline';
14
- const getModalDismissOnOutsideClickDefault = () => true;
15
- const getModalDismissOnEscDefault = () => true;
11
+ const getModalPaddingDefault = ()=>'l';
12
+ const getModalVariantDefault = ()=>'outline';
13
+ const getModalDismissOnOutsideClickDefault = ()=>true;
14
+ const getModalDismissOnEscDefault = ()=>true;
16
15
 
17
- var styles = {"modal":"Modal-module_modal__Kyr-Y","modalContainer":"Modal-module_modalContainer__muf75","modalLogo":"Modal-module_modalLogo__Vaf6E","modalHeading":"Modal-module_modalHeading__uwT1R","modalHeadingNoPadding":"Modal-module_modalHeadingNoPadding__t2hkH","modalIllustration":"Modal-module_modalIllustration__jbA32","modalNoBorder":"Modal-module_modalNoBorder__ReNVP","modalPaddingNONE":"Modal-module_modalPaddingNONE__02HaX","modalPaddingS":"Modal-module_modalPaddingS__O93ax","modalPaddingM":"Modal-module_modalPaddingM__c5Wi2","modalPaddingL":"Modal-module_modalPaddingL__IbVyg","modalPaddingMEGA":"Modal-module_modalPaddingMEGA__wWHwS","modalNoPaddingTop":"Modal-module_modalNoPaddingTop__REBWr","closeButton":"Modal-module_closeButton__jgbDq","srOnly":"Modal-module_srOnly__W8dQv"};
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
- id,
21
- className: _className = getCommonClassNameDefault(),
22
- classNames,
23
- lang,
24
- 'data-testid': dataTestId,
25
- dismissOnEsc: _dismissOnEsc = getModalDismissOnEscDefault(),
26
- dismissOnOutsideClick: _dismissOnOutsideClick = getModalDismissOnOutsideClickDefault(),
27
- hideCloseButton,
28
- hideTitle,
29
- imageSource,
30
- imageSourceAltText,
31
- padding: _padding = getModalPaddingDefault(),
32
- title,
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 (e.key === 'Escape') {
91
- if (_dismissOnEsc) {
92
- onClose == null || onClose();
93
- } else {
94
- e.preventDefault();
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;
95
48
  }
96
- }
97
- },
98
- onMouseUp: handleMouseEvent,
99
- onMouseDown: handleMouseEvent,
100
- children: jsxs("div", {
101
- tabIndex: -1,
102
- className: styles.modalContainer,
103
- children: [!hideCloseButton && jsx(IconButton, {
104
- className: styles.closeButton,
105
- svgPath: CancelSVGpath,
106
- title: t('modal.CloseModal'),
107
- onClick: () => {
108
- var _modalRef$current2;
109
- onClose == null || onClose();
110
- (_modalRef$current2 = modalRef.current) == null || _modalRef$current2.close();
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;
111
55
  }
112
- }), imageSource && jsx("img", {
113
- src: imageSource,
114
- alt: imageSourceAltText != null ? imageSourceAltText : '',
115
- className: `${styles.modalIllustration} ${(_classNames$image = classNames == null ? void 0 : classNames.image) != null ? _classNames$image : ''}`.trim()
116
- }), jsxs("div", {
117
- className: `${paddingClassName} ${noPaddingTop}`.trim(),
118
- children: [_variant === 'important' && jsx(SkatteetatenLogo, {
119
- className: styles.modalLogo
120
- }), jsx(Heading, {
121
- className: `${styles.modalHeading} ${headingNoPaddingClassName} ${hideTitleClassName}`.trim(),
122
- id: headingId,
123
- as: 'h1',
124
- level: 3,
125
- hasSpacing: true,
126
- children: title
127
- }), children]
128
- }), _variant === 'important' && jsx(Separator, {})]
129
- })
130
- });
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
+ });
131
131
  });
132
132
  Modal.displayName = 'Modal';
133
133