@orangesk/orange-design-system 2.0.0-beta.27 → 2.0.0-beta.28
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/build/components/index.js +1 -1
- package/build/components/index.js.map +1 -1
- package/build/components/tsconfig.tsbuildinfo +1 -1
- package/build/components/types/src/components/Modal/Modal.static.d.ts +2 -0
- package/build/lib/scripts.js +1 -1
- package/build/lib/scripts.js.map +1 -1
- package/build/search-index.json +418 -0
- package/package.json +2 -2
- package/src/components/Modal/Modal.static.ts +14 -3
- package/src/components/Modal/Modal.tsx +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orangesk/orange-design-system",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.28",
|
|
4
4
|
"private": false,
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.x"
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"eslint-config-prettier": "^10.1.8",
|
|
105
105
|
"eslint-plugin-unused-imports": "^4.3.0",
|
|
106
106
|
"fs-extra": "^11.3.3",
|
|
107
|
-
"glob": "13.0.
|
|
107
|
+
"glob": "13.0.1",
|
|
108
108
|
"html-validate": "10.7.0",
|
|
109
109
|
"husky": "^9.1.7",
|
|
110
110
|
"identity-obj-proxy": "^3.0.0",
|
|
@@ -10,6 +10,8 @@ interface ModalConfig {
|
|
|
10
10
|
root: string;
|
|
11
11
|
/** Move modal into this element selector (must be unique in DOM) */
|
|
12
12
|
modalsRoot: string;
|
|
13
|
+
/** Disable moving modal to #root-modals (for React controlled mode) */
|
|
14
|
+
disablePortal?: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
const defaultConfig = (): ModalConfig => ({
|
|
@@ -111,7 +113,7 @@ export default class Modal {
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
init(): void {
|
|
114
|
-
if (this.config.modalsRoot) {
|
|
116
|
+
if (this.config.modalsRoot && !this.config.disablePortal) {
|
|
115
117
|
Modal.moveToModalRoot(
|
|
116
118
|
this.element,
|
|
117
119
|
document.querySelector(this.config.modalsRoot),
|
|
@@ -180,11 +182,15 @@ export default class Modal {
|
|
|
180
182
|
const scrollY = window.scrollY;
|
|
181
183
|
document.body.setAttribute("data-lock-scrolltop", scrollY.toString());
|
|
182
184
|
|
|
185
|
+
const scrollbarWidth =
|
|
186
|
+
window.innerWidth - document.documentElement.clientWidth;
|
|
187
|
+
|
|
183
188
|
// Lock body with position fixed and offset
|
|
184
189
|
document.body.style.position = "fixed";
|
|
185
190
|
document.body.style.top = `-${scrollY}px`;
|
|
186
191
|
document.body.style.left = "0";
|
|
187
192
|
document.body.style.right = "0";
|
|
193
|
+
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
188
194
|
|
|
189
195
|
// add modal class
|
|
190
196
|
document.body.classList.add(actualClassName);
|
|
@@ -203,12 +209,17 @@ export default class Modal {
|
|
|
203
209
|
document.body.style.top = "";
|
|
204
210
|
document.body.style.left = "";
|
|
205
211
|
document.body.style.right = "";
|
|
212
|
+
document.body.style.paddingRight = "";
|
|
206
213
|
|
|
207
214
|
// remove modal class
|
|
208
215
|
document.body.classList.remove(actualClassName);
|
|
209
216
|
|
|
210
|
-
// Restore scroll position
|
|
211
|
-
window.scrollTo(
|
|
217
|
+
// Restore scroll position instantly (ignore scroll-behavior: smooth)
|
|
218
|
+
window.scrollTo({
|
|
219
|
+
top: parseInt(scrollTop, 10),
|
|
220
|
+
left: 0,
|
|
221
|
+
behavior: "instant",
|
|
222
|
+
});
|
|
212
223
|
Modal.isLocked = false;
|
|
213
224
|
}
|
|
214
225
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import React, { useEffect } from "react";
|
|
3
|
+
import React, { useEffect, useMemo } from "react";
|
|
4
4
|
import cx from "classnames";
|
|
5
5
|
|
|
6
6
|
import { useStatic } from "../../utils/hooks";
|
|
@@ -80,7 +80,16 @@ const Modal: React.FC<ModalProps> = ({
|
|
|
80
80
|
disableFooterSpacing,
|
|
81
81
|
...other
|
|
82
82
|
}) => {
|
|
83
|
-
|
|
83
|
+
// In React controlled mode (using isActive), we skip data-modal
|
|
84
|
+
// so vanilla JS won't initialize and move modal to #root-modals
|
|
85
|
+
// onHide alone works in uncontrolled mode - it's just a callback
|
|
86
|
+
const isReactControlled = isActive !== undefined;
|
|
87
|
+
|
|
88
|
+
const modalConfig = useMemo(
|
|
89
|
+
() => (isReactControlled ? { disablePortal: true } : {}),
|
|
90
|
+
[isReactControlled],
|
|
91
|
+
);
|
|
92
|
+
const [modalRef, instance] = useStatic(ModalStatic, modalConfig);
|
|
84
93
|
|
|
85
94
|
useEffect(() => {
|
|
86
95
|
if (!instance.current || !onHide) return;
|
|
@@ -128,7 +137,7 @@ const Modal: React.FC<ModalProps> = ({
|
|
|
128
137
|
return (
|
|
129
138
|
<div
|
|
130
139
|
id={id}
|
|
131
|
-
data-modal
|
|
140
|
+
{...(!isReactControlled && { "data-modal": true })}
|
|
132
141
|
className={CLASS_ROOT}
|
|
133
142
|
ref={modalRef}
|
|
134
143
|
role="dialog"
|