@navikt/ds-react 6.1.0 → 6.1.1
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/cjs/modal/Modal.js +26 -8
- package/cjs/modal/Modal.js.map +1 -1
- package/cjs/modal/ModalHeader.js +1 -1
- package/cjs/modal/ModalHeader.js.map +1 -1
- package/cjs/modal/ModalUtils.d.ts +5 -0
- package/cjs/modal/ModalUtils.js +9 -1
- package/cjs/modal/ModalUtils.js.map +1 -1
- package/esm/modal/Modal.js +27 -9
- package/esm/modal/Modal.js.map +1 -1
- package/esm/modal/ModalHeader.js +1 -1
- package/esm/modal/ModalHeader.js.map +1 -1
- package/esm/modal/ModalUtils.d.ts +5 -0
- package/esm/modal/ModalUtils.js +7 -0
- package/esm/modal/ModalUtils.js.map +1 -1
- package/package.json +3 -4
- package/src/link/stories/link.stories.tsx +187 -96
- package/src/modal/Modal.tsx +47 -8
- package/src/modal/ModalHeader.tsx +1 -1
- package/src/modal/ModalUtils.ts +14 -0
package/cjs/modal/Modal.js
CHANGED
|
@@ -102,7 +102,7 @@ const dialog_polyfill_1 = __importStar(require("./dialog-polyfill"));
|
|
|
102
102
|
*/
|
|
103
103
|
exports.Modal = (0, react_2.forwardRef)((_a, ref) => {
|
|
104
104
|
var _b, _c;
|
|
105
|
-
var { header, children, open, onBeforeClose, onCancel, closeOnBackdropClick, width, portal, className, "aria-labelledby": ariaLabelledby, style, onClick } = _a, rest = __rest(_a, ["header", "children", "open", "onBeforeClose", "onCancel", "closeOnBackdropClick", "width", "portal", "className", "aria-labelledby", "style", "onClick"]);
|
|
105
|
+
var { header, children, open, onBeforeClose, onCancel, closeOnBackdropClick, width, portal, className, "aria-labelledby": ariaLabelledby, style, onClick, onMouseDown } = _a, rest = __rest(_a, ["header", "children", "open", "onBeforeClose", "onCancel", "closeOnBackdropClick", "width", "portal", "className", "aria-labelledby", "style", "onClick", "onMouseDown"]);
|
|
106
106
|
const modalRef = (0, react_2.useRef)(null);
|
|
107
107
|
const mergedRef = (0, useMergeRefs_1.useMergeRefs)(modalRef, ref);
|
|
108
108
|
const ariaLabelId = (0, hooks_1.useId)();
|
|
@@ -148,16 +148,30 @@ exports.Modal = (0, react_2.forwardRef)((_a, ref) => {
|
|
|
148
148
|
[`navds-modal--${width}`]: isWidthPreset,
|
|
149
149
|
});
|
|
150
150
|
const mergedStyle = Object.assign(Object.assign({}, style), (!isWidthPreset ? { width } : {}));
|
|
151
|
+
const mouseClickStart = (0, react_2.useRef)({
|
|
152
|
+
clientX: 0,
|
|
153
|
+
clientY: 0,
|
|
154
|
+
});
|
|
155
|
+
const handleModalMouseDown = (event) => {
|
|
156
|
+
mouseClickStart.current = event;
|
|
157
|
+
};
|
|
158
|
+
const shouldHandleModalClick = closeOnBackdropClick && !dialog_polyfill_1.needPolyfill;
|
|
151
159
|
/**
|
|
152
160
|
* @note `closeOnBackdropClick` has issues on polyfill when nesting modals (DatePicker)
|
|
153
161
|
*/
|
|
154
|
-
const handleModalClick = (
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
const handleModalClick = (endEvent) => {
|
|
163
|
+
if (endEvent.target !== modalRef.current) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const modalRect = modalRef.current.getBoundingClientRect();
|
|
167
|
+
if ((0, ModalUtils_1.coordsAreInside)(mouseClickStart.current, modalRect) ||
|
|
168
|
+
(0, ModalUtils_1.coordsAreInside)(endEvent, modalRect)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (onBeforeClose !== undefined && onBeforeClose() === false) {
|
|
172
|
+
return;
|
|
160
173
|
}
|
|
174
|
+
modalRef.current.close();
|
|
161
175
|
};
|
|
162
176
|
/**
|
|
163
177
|
* @note onCancel fires when you press `Esc`
|
|
@@ -170,7 +184,11 @@ exports.Modal = (0, react_2.forwardRef)((_a, ref) => {
|
|
|
170
184
|
: ariaLabelledby;
|
|
171
185
|
const component = (
|
|
172
186
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
|
173
|
-
react_2.default.createElement("dialog", Object.assign({}, rest, { ref: mergedRef, className: mergedClassName, style: mergedStyle, onCancel: (0, composeEventHandlers_1.composeEventHandlers)(onCancel, handleModalCancel), onClick:
|
|
187
|
+
react_2.default.createElement("dialog", Object.assign({}, rest, { ref: mergedRef, className: mergedClassName, style: mergedStyle, onCancel: (0, composeEventHandlers_1.composeEventHandlers)(onCancel, handleModalCancel), onClick: shouldHandleModalClick
|
|
188
|
+
? (0, composeEventHandlers_1.composeEventHandlers)(onClick, handleModalClick)
|
|
189
|
+
: onClick, onMouseDown: shouldHandleModalClick
|
|
190
|
+
? (0, composeEventHandlers_1.composeEventHandlers)(onMouseDown, handleModalMouseDown)
|
|
191
|
+
: onMouseDown, "aria-labelledby": mergedAriaLabelledBy }),
|
|
174
192
|
react_2.default.createElement(Modal_context_1.ModalContextProvider, { closeHandler: (0, ModalUtils_1.getCloseHandler)(modalRef, header, onBeforeClose), ref: modalRef },
|
|
175
193
|
header && (react_2.default.createElement(ModalHeader_1.default, null,
|
|
176
194
|
header.label && (react_2.default.createElement(typography_1.Detail, { className: "navds-modal__label" }, header.label)),
|
package/cjs/modal/Modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAA2D;AAC3D,gDAAsB;AACtB,+CAAyE;AACzE,yCAAyC;AACzC,6CAA8C;AAC9C,mDAAmD;AACnD,8CAAgD;AAChD,uEAAoE;AACpE,yCAAsC;AACtC,6DAA0D;AAC1D,mDAAwE;AACxE,4DAAoC;AACpC,gEAAwC;AACxC,gEAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src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AE,UAAU,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CACgB,CAAC;AAEpB,aAAK,CAAC,MAAM,GAAG,qBAAW,CAAC;AAC3B,aAAK,CAAC,IAAI,GAAG,mBAAS,CAAC;AACvB,aAAK,CAAC,MAAM,GAAG,qBAAW,CAAC;AAE3B,kBAAe,aAAK,CAAC"}
|
package/cjs/modal/ModalHeader.js
CHANGED
|
@@ -46,7 +46,7 @@ const ModalHeader = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
46
46
|
var { children, className, closeButton = true } = _a, rest = __rest(_a, ["children", "className", "closeButton"]);
|
|
47
47
|
const context = (0, Modal_context_1.useModalContext)();
|
|
48
48
|
return (react_1.default.createElement("div", Object.assign({}, rest, { ref: ref, className: (0, clsx_1.default)("navds-modal__header", className) }),
|
|
49
|
-
context.closeHandler && closeButton && (react_1.default.createElement(button_1.Button, { type: "button", className: "navds-modal__button", size: "small", variant: "tertiary-neutral", onClick: context.closeHandler, icon: react_1.default.createElement(aksel_icons_1.XMarkIcon, { title: "Lukk
|
|
49
|
+
context.closeHandler && closeButton && (react_1.default.createElement(button_1.Button, { type: "button", className: "navds-modal__button", size: "small", variant: "tertiary-neutral", onClick: context.closeHandler, icon: react_1.default.createElement(aksel_icons_1.XMarkIcon, { title: "Lukk" }) })),
|
|
50
50
|
children));
|
|
51
51
|
});
|
|
52
52
|
exports.default = ModalHeader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalHeader.js","sourceRoot":"","sources":["../../src/modal/ModalHeader.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAsB;AACtB,+CAA0C;AAC1C,qDAAgD;AAChD,sCAAmC;AACnC,mDAAkD;AAWlD,MAAM,WAAW,GAAG,IAAA,kBAAU,EAC5B,CAAC,EAAoD,EAAE,GAAG,EAAE,EAAE;QAA7D,E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,EAAE,OAAO,CAAC,YAAY,EAC7B,IAAI,EAAE,8BAAC,uBAAS,IAAC,KAAK,EAAC,MAAM,GAAG,GAChC,CACH;QACA,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,kBAAe,WAAW,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ModalProps } from "./types";
|
|
3
|
+
export interface MouseCoordinates {
|
|
4
|
+
clientX: number;
|
|
5
|
+
clientY: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const coordsAreInside: ({ clientX, clientY }: MouseCoordinates, { left, top, right, bottom }: DOMRect) => boolean;
|
|
3
8
|
export declare function getCloseHandler(modalRef: React.RefObject<HTMLDialogElement>, header: ModalProps["header"], onBeforeClose: ModalProps["onBeforeClose"]): (() => false | void | undefined) | undefined;
|
|
4
9
|
export declare const BODY_CLASS = "navds-modal__document-body";
|
|
5
10
|
export declare function useBodyScrollLock(modalRef: React.RefObject<HTMLDialogElement>, portalNode: HTMLElement | null, isNested: boolean): void;
|
package/cjs/modal/ModalUtils.js
CHANGED
|
@@ -3,8 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useBodyScrollLock = exports.BODY_CLASS = exports.getCloseHandler = void 0;
|
|
6
|
+
exports.useBodyScrollLock = exports.BODY_CLASS = exports.getCloseHandler = exports.coordsAreInside = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const coordsAreInside = ({ clientX, clientY }, { left, top, right, bottom }) => {
|
|
9
|
+
if (clientX < left || clientY < top)
|
|
10
|
+
return false;
|
|
11
|
+
if (clientX > right || clientY > bottom)
|
|
12
|
+
return false;
|
|
13
|
+
return true;
|
|
14
|
+
};
|
|
15
|
+
exports.coordsAreInside = coordsAreInside;
|
|
8
16
|
function getCloseHandler(modalRef, header, onBeforeClose) {
|
|
9
17
|
if (header && header.closeButton === false)
|
|
10
18
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalUtils.js","sourceRoot":"","sources":["../../src/modal/ModalUtils.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;
|
|
1
|
+
{"version":3,"file":"ModalUtils.js","sourceRoot":"","sources":["../../src/modal/ModalUtils.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAQnB,MAAM,eAAe,GAAG,CAC7B,EAAE,OAAO,EAAE,OAAO,EAAoB,EACtC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAW,EACrC,EAAE;IACF,IAAI,OAAO,GAAG,IAAI,IAAI,OAAO,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,OAAO,GAAG,KAAK,IAAI,OAAO,GAAG,MAAM;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B;AAEF,SAAgB,eAAe,CAC7B,QAA4C,EAC5C,MAA4B,EAC5B,aAA0C;IAE1C,IAAI,MAAM,IAAI,MAAM,CAAC,WAAW,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7D,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,GAAG,EAAE,WAAC,OAAA,aAAa,EAAE,KAAK,KAAK,KAAI,MAAA,QAAQ,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAA,CAAA,EAAA,CAAC;IACtE,CAAC;IACD,OAAO,GAAG,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAA,EAAA,CAAC;AACzC,CAAC;AAVD,0CAUC;AAEY,QAAA,UAAU,GAAG,4BAA4B,CAAC;AAEvD,SAAgB,iBAAiB,CAC/B,QAA4C,EAC5C,UAA8B,EAC9B,QAAiB;IAEjB,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,QAAQ;YAAE,OAAO;QACrB,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,UAAU;YAAE,OAAO,CAAC,kEAAkE;QAChH,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI;YAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAU,CAAC,CAAC,CAAC,mCAAmC;QAEvG,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE;;YACzC,IAAI,MAAA,QAAQ,CAAC,OAAO,0CAAE,IAAI;gBAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAU,CAAC,CAAC;;gBAC/D,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAU,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE;YACjC,UAAU,EAAE,IAAI;YAChB,eAAe,EAAE,CAAC,MAAM,CAAC;SAC1B,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAU,CAAC,CAAC,CAAC,gDAAgD;QAC9F,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvC,CAAC;AAvBD,8CAuBC"}
|
package/esm/modal/Modal.js
CHANGED
|
@@ -23,7 +23,7 @@ import { ModalContextProvider, useModalContext } from "./Modal.context.js";
|
|
|
23
23
|
import ModalBody from "./ModalBody.js";
|
|
24
24
|
import ModalFooter from "./ModalFooter.js";
|
|
25
25
|
import ModalHeader from "./ModalHeader.js";
|
|
26
|
-
import { getCloseHandler, useBodyScrollLock } from "./ModalUtils.js";
|
|
26
|
+
import { coordsAreInside, getCloseHandler, useBodyScrollLock, } from "./ModalUtils.js";
|
|
27
27
|
import dialogPolyfill, { needPolyfill } from "./dialog-polyfill.js";
|
|
28
28
|
/**
|
|
29
29
|
* A component that displays a modal dialog.
|
|
@@ -73,7 +73,7 @@ import dialogPolyfill, { needPolyfill } from "./dialog-polyfill.js";
|
|
|
73
73
|
*/
|
|
74
74
|
export const Modal = forwardRef((_a, ref) => {
|
|
75
75
|
var _b, _c;
|
|
76
|
-
var { header, children, open, onBeforeClose, onCancel, closeOnBackdropClick, width, portal, className, "aria-labelledby": ariaLabelledby, style, onClick } = _a, rest = __rest(_a, ["header", "children", "open", "onBeforeClose", "onCancel", "closeOnBackdropClick", "width", "portal", "className", "aria-labelledby", "style", "onClick"]);
|
|
76
|
+
var { header, children, open, onBeforeClose, onCancel, closeOnBackdropClick, width, portal, className, "aria-labelledby": ariaLabelledby, style, onClick, onMouseDown } = _a, rest = __rest(_a, ["header", "children", "open", "onBeforeClose", "onCancel", "closeOnBackdropClick", "width", "portal", "className", "aria-labelledby", "style", "onClick", "onMouseDown"]);
|
|
77
77
|
const modalRef = useRef(null);
|
|
78
78
|
const mergedRef = useMergeRefs(modalRef, ref);
|
|
79
79
|
const ariaLabelId = useId();
|
|
@@ -119,16 +119,30 @@ export const Modal = forwardRef((_a, ref) => {
|
|
|
119
119
|
[`navds-modal--${width}`]: isWidthPreset,
|
|
120
120
|
});
|
|
121
121
|
const mergedStyle = Object.assign(Object.assign({}, style), (!isWidthPreset ? { width } : {}));
|
|
122
|
+
const mouseClickStart = useRef({
|
|
123
|
+
clientX: 0,
|
|
124
|
+
clientY: 0,
|
|
125
|
+
});
|
|
126
|
+
const handleModalMouseDown = (event) => {
|
|
127
|
+
mouseClickStart.current = event;
|
|
128
|
+
};
|
|
129
|
+
const shouldHandleModalClick = closeOnBackdropClick && !needPolyfill;
|
|
122
130
|
/**
|
|
123
131
|
* @note `closeOnBackdropClick` has issues on polyfill when nesting modals (DatePicker)
|
|
124
132
|
*/
|
|
125
|
-
const handleModalClick = (
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
const handleModalClick = (endEvent) => {
|
|
134
|
+
if (endEvent.target !== modalRef.current) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const modalRect = modalRef.current.getBoundingClientRect();
|
|
138
|
+
if (coordsAreInside(mouseClickStart.current, modalRect) ||
|
|
139
|
+
coordsAreInside(endEvent, modalRect)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (onBeforeClose !== undefined && onBeforeClose() === false) {
|
|
143
|
+
return;
|
|
131
144
|
}
|
|
145
|
+
modalRef.current.close();
|
|
132
146
|
};
|
|
133
147
|
/**
|
|
134
148
|
* @note onCancel fires when you press `Esc`
|
|
@@ -141,7 +155,11 @@ export const Modal = forwardRef((_a, ref) => {
|
|
|
141
155
|
: ariaLabelledby;
|
|
142
156
|
const component = (
|
|
143
157
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
|
144
|
-
React.createElement("dialog", Object.assign({}, rest, { ref: mergedRef, className: mergedClassName, style: mergedStyle, onCancel: composeEventHandlers(onCancel, handleModalCancel), onClick:
|
|
158
|
+
React.createElement("dialog", Object.assign({}, rest, { ref: mergedRef, className: mergedClassName, style: mergedStyle, onCancel: composeEventHandlers(onCancel, handleModalCancel), onClick: shouldHandleModalClick
|
|
159
|
+
? composeEventHandlers(onClick, handleModalClick)
|
|
160
|
+
: onClick, onMouseDown: shouldHandleModalClick
|
|
161
|
+
? composeEventHandlers(onMouseDown, handleModalMouseDown)
|
|
162
|
+
: onMouseDown, "aria-labelledby": mergedAriaLabelledBy }),
|
|
145
163
|
React.createElement(ModalContextProvider, { closeHandler: getCloseHandler(modalRef, header, onBeforeClose), ref: modalRef },
|
|
146
164
|
header && (React.createElement(ModalHeader, null,
|
|
147
165
|
header.label && (React.createElement(Detail, { className: "navds-modal__label" }, header.label)),
|
package/esm/modal/Modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CA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AAE,MAAM,CAAC,IAAI,CAAQ;oBAC9D,MAAM,CAAC,OAAO,CACP,CACE,CACf;YAEA,QAAQ,CACY,CAChB,CACV,CAAC;IAEF,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,UAAU;YAAE,OAAO,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CACgB,CAAC;AAEpB,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC;AAC3B,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC;AACvB,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC;AAE3B,eAAe,KAAK,CAAC"}
|
package/esm/modal/ModalHeader.js
CHANGED
|
@@ -18,7 +18,7 @@ const ModalHeader = forwardRef((_a, ref) => {
|
|
|
18
18
|
var { children, className, closeButton = true } = _a, rest = __rest(_a, ["children", "className", "closeButton"]);
|
|
19
19
|
const context = useModalContext();
|
|
20
20
|
return (React.createElement("div", Object.assign({}, rest, { ref: ref, className: cl("navds-modal__header", className) }),
|
|
21
|
-
context.closeHandler && closeButton && (React.createElement(Button, { type: "button", className: "navds-modal__button", size: "small", variant: "tertiary-neutral", onClick: context.closeHandler, icon: React.createElement(XMarkIcon, { title: "Lukk
|
|
21
|
+
context.closeHandler && closeButton && (React.createElement(Button, { type: "button", className: "navds-modal__button", size: "small", variant: "tertiary-neutral", onClick: context.closeHandler, icon: React.createElement(XMarkIcon, { title: "Lukk" }) })),
|
|
22
22
|
children));
|
|
23
23
|
});
|
|
24
24
|
export default ModalHeader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalHeader.js","sourceRoot":"","sources":["../../src/modal/ModalHeader.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAA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,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;IAElC,OAAO,CACL,6CAAS,IAAI,IAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC;QACrE,OAAO,CAAC,YAAY,IAAI,WAAW,IAAI,CACtC,oBAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,qBAAqB,EAC/B,IAAI,EAAC,OAAO,EACZ,OAAO,EAAC,kBAAkB,EAC1B,OAAO,EAAE,OAAO,CAAC,YAAY,EAC7B,IAAI,EAAE,oBAAC,SAAS,IAAC,KAAK,EAAC,MAAM,GAAG,GAChC,CACH;QACA,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ModalProps } from "./types.js";
|
|
3
|
+
export interface MouseCoordinates {
|
|
4
|
+
clientX: number;
|
|
5
|
+
clientY: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const coordsAreInside: ({ clientX, clientY }: MouseCoordinates, { left, top, right, bottom }: DOMRect) => boolean;
|
|
3
8
|
export declare function getCloseHandler(modalRef: React.RefObject<HTMLDialogElement>, header: ModalProps["header"], onBeforeClose: ModalProps["onBeforeClose"]): (() => false | void | undefined) | undefined;
|
|
4
9
|
export declare const BODY_CLASS = "navds-modal__document-body";
|
|
5
10
|
export declare function useBodyScrollLock(modalRef: React.RefObject<HTMLDialogElement>, portalNode: HTMLElement | null, isNested: boolean): void;
|
package/esm/modal/ModalUtils.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
export const coordsAreInside = ({ clientX, clientY }, { left, top, right, bottom }) => {
|
|
3
|
+
if (clientX < left || clientY < top)
|
|
4
|
+
return false;
|
|
5
|
+
if (clientX > right || clientY > bottom)
|
|
6
|
+
return false;
|
|
7
|
+
return true;
|
|
8
|
+
};
|
|
2
9
|
export function getCloseHandler(modalRef, header, onBeforeClose) {
|
|
3
10
|
if (header && header.closeButton === false)
|
|
4
11
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalUtils.js","sourceRoot":"","sources":["../../src/modal/ModalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ModalUtils.js","sourceRoot":"","sources":["../../src/modal/ModalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,EAAE,OAAO,EAAE,OAAO,EAAoB,EACtC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAW,EACrC,EAAE;IACF,IAAI,OAAO,GAAG,IAAI,IAAI,OAAO,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,OAAO,GAAG,KAAK,IAAI,OAAO,GAAG,MAAM;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,UAAU,eAAe,CAC7B,QAA4C,EAC5C,MAA4B,EAC5B,aAA0C;IAE1C,IAAI,MAAM,IAAI,MAAM,CAAC,WAAW,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7D,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,GAAG,EAAE,WAAC,OAAA,aAAa,EAAE,KAAK,KAAK,KAAI,MAAA,QAAQ,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAA,CAAA,EAAA,CAAC;IACtE,CAAC;IACD,OAAO,GAAG,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAA,EAAA,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAEvD,MAAM,UAAU,iBAAiB,CAC/B,QAA4C,EAC5C,UAA8B,EAC9B,QAAiB;IAEjB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,QAAQ;YAAE,OAAO;QACrB,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,UAAU;YAAE,OAAO,CAAC,kEAAkE;QAChH,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI;YAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,mCAAmC;QAEvG,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE;;YACzC,IAAI,MAAA,QAAQ,CAAC,OAAO,0CAAE,IAAI;gBAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;;gBAC/D,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE;YACjC,UAAU,EAAE,IAAI;YAChB,eAAe,EAAE,CAAC,MAAM,CAAC;SAC1B,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,gDAAgD;QAC9F,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "React components from the Norwegian Labour and Welfare Administration.",
|
|
5
5
|
"author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -552,8 +552,8 @@
|
|
|
552
552
|
},
|
|
553
553
|
"dependencies": {
|
|
554
554
|
"@floating-ui/react": "0.25.4",
|
|
555
|
-
"@navikt/aksel-icons": "^6.1.
|
|
556
|
-
"@navikt/ds-tokens": "^6.1.
|
|
555
|
+
"@navikt/aksel-icons": "^6.1.1",
|
|
556
|
+
"@navikt/ds-tokens": "^6.1.1",
|
|
557
557
|
"@radix-ui/react-tabs": "1.0.0",
|
|
558
558
|
"@radix-ui/react-toggle-group": "1.0.0",
|
|
559
559
|
"clsx": "^2.1.0",
|
|
@@ -567,7 +567,6 @@
|
|
|
567
567
|
"@testing-library/user-event": "^14.2.0",
|
|
568
568
|
"@types/faker": "5.5.8",
|
|
569
569
|
"concurrently": "7.2.1",
|
|
570
|
-
"copyfiles": "^2.4.1",
|
|
571
570
|
"faker": "5.5.3",
|
|
572
571
|
"fast-glob": "3.2.11",
|
|
573
572
|
"jsdom": "24.0.0",
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import { Meta } from "@storybook/react";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { PlusCircleFillIcon } from "@navikt/aksel-icons";
|
|
3
4
|
import { Alert } from "../../alert";
|
|
4
5
|
import { ConfirmationPanel } from "../../form/confirmation-panel";
|
|
6
|
+
import { Box } from "../../layout/box";
|
|
7
|
+
import { VStack } from "../../layout/stack";
|
|
5
8
|
import { BodyLong } from "../../typography";
|
|
6
9
|
import Link from "../Link";
|
|
7
10
|
import { RandomIcon } from "./RandomIcon";
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
const meta: Meta<typeof Link> = {
|
|
10
13
|
title: "ds-react/Link",
|
|
11
14
|
component: Link,
|
|
15
|
+
parameters: {
|
|
16
|
+
chromatic: { disable: true },
|
|
17
|
+
},
|
|
12
18
|
};
|
|
19
|
+
export default meta;
|
|
13
20
|
|
|
14
21
|
const LinkWrapper = ({
|
|
15
22
|
children = "Ex aliqua incididunt",
|
|
@@ -27,53 +34,38 @@ const LinkWrapper = ({
|
|
|
27
34
|
variant={variant as "action" | "neutral" | "subtle"}
|
|
28
35
|
inlineText={inlineText}
|
|
29
36
|
>
|
|
30
|
-
{iconLeft &&
|
|
31
|
-
<>
|
|
32
|
-
<RandomIcon />{" "}
|
|
33
|
-
</>
|
|
34
|
-
)}
|
|
37
|
+
{iconLeft && <RandomIcon />}
|
|
35
38
|
{children}
|
|
36
|
-
{iconRight &&
|
|
37
|
-
<>
|
|
38
|
-
{" "}
|
|
39
|
-
<RandomIcon />
|
|
40
|
-
</>
|
|
41
|
-
)}
|
|
39
|
+
{iconRight && <RandomIcon />}
|
|
42
40
|
</Link>{" "}
|
|
43
41
|
</>
|
|
44
42
|
);
|
|
45
43
|
|
|
46
44
|
export const Default = {
|
|
47
|
-
render: ({ icon, inline }) => {
|
|
45
|
+
render: ({ icon, inline, underline }) => {
|
|
48
46
|
const LinkD = () => (
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{icon && <PlusCircleFillIcon />}
|
|
54
|
-
</Link>{" "}
|
|
55
|
-
</>
|
|
47
|
+
<Link href="#" underline={underline} inlineText={inline}>
|
|
48
|
+
{icon && <PlusCircleFillIcon />}Ex aliqua incididunt
|
|
49
|
+
{icon && <PlusCircleFillIcon />}
|
|
50
|
+
</Link>
|
|
56
51
|
);
|
|
57
52
|
|
|
58
53
|
if (inline) {
|
|
59
54
|
return (
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
borderRadius: "8px",
|
|
66
|
-
}}
|
|
55
|
+
<Box
|
|
56
|
+
borderWidth="1"
|
|
57
|
+
borderRadius="large"
|
|
58
|
+
padding="4"
|
|
59
|
+
style={{ maxWidth: "800px" }}
|
|
67
60
|
>
|
|
68
61
|
<BodyLong>
|
|
69
|
-
Incididunt laborum nisi nisi Lorem
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Lorem eu. Esse elit laboris aute commodo sint laborum fugiat aliqua.
|
|
62
|
+
Incididunt laborum nisi nisi Lorem <LinkD /> in. Laborum aute fugiat
|
|
63
|
+
officia adipisicing non veniam dolor nulla non ex consectetur fugiat
|
|
64
|
+
eiusmod aute. Culpa sit aute est duis minim in in voluptate velit
|
|
65
|
+
fugiat. Laboris est id deserunt ut ea Lorem eu. Esse elit laboris
|
|
66
|
+
aute commodo sint laborum fugiat aliqua.
|
|
75
67
|
</BodyLong>
|
|
76
|
-
</
|
|
68
|
+
</Box>
|
|
77
69
|
);
|
|
78
70
|
}
|
|
79
71
|
return <LinkD />;
|
|
@@ -82,22 +74,21 @@ export const Default = {
|
|
|
82
74
|
args: {
|
|
83
75
|
icon: false,
|
|
84
76
|
inline: false,
|
|
77
|
+
underline: true,
|
|
85
78
|
},
|
|
86
79
|
};
|
|
87
80
|
|
|
88
81
|
export const InlineInsideBodyLong = {
|
|
89
82
|
render: ({ iconLeft, iconRight }) => {
|
|
90
83
|
return (
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
borderRadius: "8px",
|
|
97
|
-
}}
|
|
84
|
+
<Box
|
|
85
|
+
borderWidth="1"
|
|
86
|
+
borderRadius="large"
|
|
87
|
+
padding="4"
|
|
88
|
+
style={{ width: "800px" }}
|
|
98
89
|
>
|
|
99
90
|
<style>{`.storybook-custom-spacing { white-space: pre;}`}</style>
|
|
100
|
-
<BodyLong>
|
|
91
|
+
<BodyLong spacing>
|
|
101
92
|
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight} />
|
|
102
93
|
Eiusmod aute.
|
|
103
94
|
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight} />
|
|
@@ -119,7 +110,7 @@ export const InlineInsideBodyLong = {
|
|
|
119
110
|
</LinkWrapper>
|
|
120
111
|
{" "}spacing.
|
|
121
112
|
</BodyLong>
|
|
122
|
-
</
|
|
113
|
+
</Box>
|
|
123
114
|
);
|
|
124
115
|
},
|
|
125
116
|
args: {
|
|
@@ -128,86 +119,186 @@ export const InlineInsideBodyLong = {
|
|
|
128
119
|
},
|
|
129
120
|
};
|
|
130
121
|
|
|
131
|
-
const
|
|
122
|
+
export const Varianter = {
|
|
123
|
+
render: ({ iconLeft, iconRight }) => {
|
|
124
|
+
return (
|
|
125
|
+
<VStack gap="3">
|
|
126
|
+
{["action", "neutral", "subtle"].map((variant) => (
|
|
127
|
+
<div key={variant}>
|
|
128
|
+
<LinkWrapper
|
|
129
|
+
iconLeft={iconLeft}
|
|
130
|
+
iconRight={iconRight}
|
|
131
|
+
variant={variant}
|
|
132
|
+
/>
|
|
133
|
+
</div>
|
|
134
|
+
))}
|
|
135
|
+
</VStack>
|
|
136
|
+
);
|
|
137
|
+
},
|
|
138
|
+
args: {
|
|
139
|
+
iconLeft: false,
|
|
140
|
+
iconRight: false,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const LinkWithIcon = () => (
|
|
132
145
|
<Link href="#">
|
|
133
|
-
<PlusCircleFillIcon aria-hidden />
|
|
146
|
+
<PlusCircleFillIcon aria-hidden />
|
|
147
|
+
Ex aliqua incididunt
|
|
134
148
|
<PlusCircleFillIcon aria-hidden />
|
|
135
149
|
</Link>
|
|
136
150
|
);
|
|
137
151
|
|
|
138
|
-
export const Icon = () => <
|
|
152
|
+
export const Icon = () => <LinkWithIcon />;
|
|
153
|
+
|
|
154
|
+
const Variants = () => (
|
|
155
|
+
<VStack gap="3">
|
|
156
|
+
{["action", "neutral", "subtle"].map((variant) => (
|
|
157
|
+
<div key={variant}>
|
|
158
|
+
<LinkWrapper variant={variant} />
|
|
159
|
+
</div>
|
|
160
|
+
))}
|
|
161
|
+
</VStack>
|
|
162
|
+
);
|
|
139
163
|
|
|
140
|
-
export const
|
|
141
|
-
|
|
164
|
+
export const Chromatic = () => (
|
|
165
|
+
<>
|
|
166
|
+
<h2>Default</h2>
|
|
167
|
+
<Link href="#">Ex aliqua incididunt</Link>
|
|
168
|
+
|
|
169
|
+
<h2>With icon</h2>
|
|
170
|
+
<LinkWithIcon />
|
|
171
|
+
|
|
172
|
+
<h2>Variants (no underline)</h2>
|
|
173
|
+
<Variants />
|
|
174
|
+
|
|
175
|
+
<h2>Inline</h2>
|
|
176
|
+
<BodyLong style={{ width: 500 }}>
|
|
177
|
+
Culpa sit aute est duis minim in in voluptate{" "}
|
|
178
|
+
<Link href="#" inlineText>
|
|
179
|
+
dette er en veldig lang lenke som brekker over flere linjer
|
|
180
|
+
<PlusCircleFillIcon aria-hidden />
|
|
181
|
+
</Link>{" "}
|
|
182
|
+
Culpa sit aute est duis minim in in voluptate velit Incididunt laborum
|
|
183
|
+
nisi nisi{" "}
|
|
184
|
+
<Link href="#" inlineText>
|
|
185
|
+
dette er en veldig lang lenke som brekker over flere linjer
|
|
186
|
+
</Link>{" "}
|
|
187
|
+
Lorem officia adipisicing non veniam occaecat commodo id ad aliquip.
|
|
188
|
+
</BodyLong>
|
|
189
|
+
|
|
190
|
+
<h2>In Alert</h2>
|
|
142
191
|
<div className="colgap">
|
|
143
192
|
<Alert variant="info">
|
|
144
|
-
<
|
|
193
|
+
<LinkWithIcon />
|
|
145
194
|
</Alert>
|
|
146
195
|
<Alert variant="success">
|
|
147
|
-
<
|
|
196
|
+
<LinkWithIcon />
|
|
148
197
|
</Alert>
|
|
149
198
|
<Alert variant="warning">
|
|
150
|
-
<
|
|
199
|
+
<LinkWithIcon />
|
|
151
200
|
</Alert>
|
|
152
201
|
<Alert variant="error">
|
|
153
|
-
<
|
|
202
|
+
<LinkWithIcon />
|
|
154
203
|
</Alert>
|
|
155
204
|
</div>
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
205
|
|
|
159
|
-
|
|
160
|
-
return (
|
|
206
|
+
<h2>In ConfirmationPanel</h2>
|
|
161
207
|
<div className="colgap">
|
|
162
208
|
<ConfirmationPanel label="demo">
|
|
163
|
-
<
|
|
209
|
+
<LinkWithIcon />
|
|
164
210
|
</ConfirmationPanel>
|
|
165
211
|
<ConfirmationPanel checked label="demo">
|
|
166
|
-
<
|
|
212
|
+
<LinkWithIcon />
|
|
167
213
|
</ConfirmationPanel>
|
|
168
214
|
<ConfirmationPanel error="demo" label="demo">
|
|
169
|
-
<
|
|
215
|
+
<LinkWithIcon />
|
|
216
|
+
</ConfirmationPanel>
|
|
217
|
+
</div>
|
|
218
|
+
</>
|
|
219
|
+
);
|
|
220
|
+
Chromatic.parameters = { chromatic: { disable: false } };
|
|
221
|
+
|
|
222
|
+
export const ChromaticHover = () => (
|
|
223
|
+
<>
|
|
224
|
+
<h2>With icon</h2>
|
|
225
|
+
<LinkWithIcon />
|
|
226
|
+
|
|
227
|
+
<h2>Variants (no underline)</h2>
|
|
228
|
+
<Variants />
|
|
229
|
+
|
|
230
|
+
<h2>In Alert</h2>
|
|
231
|
+
<div className="colgap">
|
|
232
|
+
<Alert variant="info">
|
|
233
|
+
<LinkWithIcon />
|
|
234
|
+
</Alert>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<h2>In ConfirmationPanel</h2>
|
|
238
|
+
<div className="colgap">
|
|
239
|
+
<ConfirmationPanel checked label="demo">
|
|
240
|
+
<LinkWithIcon />
|
|
170
241
|
</ConfirmationPanel>
|
|
171
242
|
</div>
|
|
172
|
-
|
|
243
|
+
</>
|
|
244
|
+
);
|
|
245
|
+
ChromaticHover.parameters = {
|
|
246
|
+
chromatic: { disable: false },
|
|
247
|
+
pseudo: { hover: true },
|
|
173
248
|
};
|
|
174
249
|
|
|
175
|
-
export const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
250
|
+
export const ChromaticFocusVisible = () => (
|
|
251
|
+
<>
|
|
252
|
+
<h2>With icon</h2>
|
|
253
|
+
<LinkWithIcon />
|
|
254
|
+
|
|
255
|
+
<h2>Variants (no underline)</h2>
|
|
256
|
+
<Variants />
|
|
257
|
+
|
|
258
|
+
<h2>In Alert</h2>
|
|
259
|
+
<div className="colgap">
|
|
260
|
+
<Alert variant="info">
|
|
261
|
+
<LinkWithIcon />
|
|
262
|
+
</Alert>
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
<h2>In ConfirmationPanel</h2>
|
|
266
|
+
<div className="colgap">
|
|
267
|
+
<ConfirmationPanel checked label="demo">
|
|
268
|
+
<LinkWithIcon />
|
|
269
|
+
</ConfirmationPanel>
|
|
270
|
+
</div>
|
|
271
|
+
</>
|
|
272
|
+
);
|
|
273
|
+
ChromaticFocusVisible.parameters = {
|
|
274
|
+
chromatic: { disable: false },
|
|
275
|
+
pseudo: { focusVisible: true },
|
|
197
276
|
};
|
|
198
277
|
|
|
199
|
-
export const
|
|
200
|
-
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
278
|
+
export const ChromaticActive = () => (
|
|
279
|
+
<>
|
|
280
|
+
<h2>With icon</h2>
|
|
281
|
+
<LinkWithIcon />
|
|
282
|
+
|
|
283
|
+
<h2>Variants (no underline)</h2>
|
|
284
|
+
<Variants />
|
|
285
|
+
|
|
286
|
+
<h2>In Alert</h2>
|
|
287
|
+
<div className="colgap">
|
|
288
|
+
<Alert variant="info">
|
|
289
|
+
<LinkWithIcon />
|
|
290
|
+
</Alert>
|
|
291
|
+
</div>
|
|
292
|
+
|
|
293
|
+
<h2>In ConfirmationPanel</h2>
|
|
294
|
+
<div className="colgap">
|
|
295
|
+
<ConfirmationPanel checked label="demo">
|
|
296
|
+
<LinkWithIcon />
|
|
297
|
+
</ConfirmationPanel>
|
|
298
|
+
</div>
|
|
299
|
+
</>
|
|
300
|
+
);
|
|
301
|
+
ChromaticActive.parameters = {
|
|
302
|
+
chromatic: { disable: false },
|
|
303
|
+
pseudo: { active: true },
|
|
213
304
|
};
|
package/src/modal/Modal.tsx
CHANGED
|
@@ -12,7 +12,12 @@ import { ModalContextProvider, useModalContext } from "./Modal.context";
|
|
|
12
12
|
import ModalBody from "./ModalBody";
|
|
13
13
|
import ModalFooter from "./ModalFooter";
|
|
14
14
|
import ModalHeader from "./ModalHeader";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
MouseCoordinates,
|
|
17
|
+
coordsAreInside,
|
|
18
|
+
getCloseHandler,
|
|
19
|
+
useBodyScrollLock,
|
|
20
|
+
} from "./ModalUtils";
|
|
16
21
|
import dialogPolyfill, { needPolyfill } from "./dialog-polyfill";
|
|
17
22
|
import { ModalProps } from "./types";
|
|
18
23
|
|
|
@@ -86,6 +91,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
|
|
|
86
91
|
"aria-labelledby": ariaLabelledby,
|
|
87
92
|
style,
|
|
88
93
|
onClick,
|
|
94
|
+
onMouseDown,
|
|
89
95
|
...rest
|
|
90
96
|
}: ModalProps,
|
|
91
97
|
ref,
|
|
@@ -146,18 +152,42 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
|
|
|
146
152
|
...(!isWidthPreset ? { width } : {}),
|
|
147
153
|
};
|
|
148
154
|
|
|
155
|
+
const mouseClickStart = useRef<MouseCoordinates>({
|
|
156
|
+
clientX: 0,
|
|
157
|
+
clientY: 0,
|
|
158
|
+
});
|
|
159
|
+
const handleModalMouseDown: React.MouseEventHandler<HTMLDialogElement> = (
|
|
160
|
+
event,
|
|
161
|
+
) => {
|
|
162
|
+
mouseClickStart.current = event;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const shouldHandleModalClick = closeOnBackdropClick && !needPolyfill;
|
|
166
|
+
|
|
149
167
|
/**
|
|
150
168
|
* @note `closeOnBackdropClick` has issues on polyfill when nesting modals (DatePicker)
|
|
151
169
|
*/
|
|
152
|
-
const handleModalClick = (
|
|
170
|
+
const handleModalClick = (
|
|
171
|
+
endEvent: React.MouseEvent<HTMLDialogElement>,
|
|
172
|
+
) => {
|
|
173
|
+
if (endEvent.target !== modalRef.current) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const modalRect = modalRef.current.getBoundingClientRect();
|
|
178
|
+
|
|
153
179
|
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
event.target === modalRef.current &&
|
|
157
|
-
(!onBeforeClose || onBeforeClose() !== false)
|
|
180
|
+
coordsAreInside(mouseClickStart.current, modalRect) ||
|
|
181
|
+
coordsAreInside(endEvent, modalRect)
|
|
158
182
|
) {
|
|
159
|
-
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (onBeforeClose !== undefined && onBeforeClose() === false) {
|
|
187
|
+
return;
|
|
160
188
|
}
|
|
189
|
+
|
|
190
|
+
modalRef.current.close();
|
|
161
191
|
};
|
|
162
192
|
|
|
163
193
|
/**
|
|
@@ -182,7 +212,16 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
|
|
|
182
212
|
className={mergedClassName}
|
|
183
213
|
style={mergedStyle}
|
|
184
214
|
onCancel={composeEventHandlers(onCancel, handleModalCancel)}
|
|
185
|
-
onClick={
|
|
215
|
+
onClick={
|
|
216
|
+
shouldHandleModalClick
|
|
217
|
+
? composeEventHandlers(onClick, handleModalClick)
|
|
218
|
+
: onClick
|
|
219
|
+
}
|
|
220
|
+
onMouseDown={
|
|
221
|
+
shouldHandleModalClick
|
|
222
|
+
? composeEventHandlers(onMouseDown, handleModalMouseDown)
|
|
223
|
+
: onMouseDown
|
|
224
|
+
}
|
|
186
225
|
aria-labelledby={mergedAriaLabelledBy}
|
|
187
226
|
>
|
|
188
227
|
<ModalContextProvider
|
package/src/modal/ModalUtils.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ModalProps } from "./types";
|
|
3
3
|
|
|
4
|
+
export interface MouseCoordinates {
|
|
5
|
+
clientX: number;
|
|
6
|
+
clientY: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const coordsAreInside = (
|
|
10
|
+
{ clientX, clientY }: MouseCoordinates,
|
|
11
|
+
{ left, top, right, bottom }: DOMRect,
|
|
12
|
+
) => {
|
|
13
|
+
if (clientX < left || clientY < top) return false;
|
|
14
|
+
if (clientX > right || clientY > bottom) return false;
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
17
|
+
|
|
4
18
|
export function getCloseHandler(
|
|
5
19
|
modalRef: React.RefObject<HTMLDialogElement>,
|
|
6
20
|
header: ModalProps["header"],
|