@sybilion/uilib 1.3.20 → 1.3.21
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/dist/esm/components/ui/Dialog/Dialog.js +10 -2
- package/dist/esm/constants/appMount.js +5 -0
- package/dist/esm/types/src/constants/appMount.d.ts +4 -0
- package/package.json +1 -1
- package/src/components/ui/Dialog/Dialog.tsx +19 -2
- package/src/constants/appMount.ts +5 -0
- package/src/docs/index.tsx +2 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
-
import React__default, { useState, useRef, useId, useEffect } from 'react';
|
|
3
|
+
import React__default, { useState, useRef, useId, useEffect, useLayoutEffect } from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
5
|
import { Card, CardHeader, CardContent, CardFooter } from '../Card/Card.js';
|
|
6
|
+
import { APP_MODAL_ID } from '../../../constants/appMount.js';
|
|
6
7
|
import { XIcon } from '@phosphor-icons/react';
|
|
7
8
|
import S from './Dialog.styl.js';
|
|
8
9
|
|
|
9
10
|
function Dialog({ open, onOpenChange, disabled, trigger, title, subtitle, disableCloseButton, icon, content, contentClassName, footer, footerClassName, footerAlignment = 'center', size = 'default', className, noScroll, maxHeight, autoScrollBottom, width, }) {
|
|
10
11
|
const [isMounted, setIsMounted] = useState(false);
|
|
12
|
+
const [modalContainer, setModalContainer] = useState(null);
|
|
11
13
|
const [isAnimating, setIsAnimating] = useState(false);
|
|
12
14
|
const dialogRef = useRef(null);
|
|
13
15
|
const triggerRef = useRef(null);
|
|
@@ -19,6 +21,9 @@ function Dialog({ open, onOpenChange, disabled, trigger, title, subtitle, disabl
|
|
|
19
21
|
setIsMounted(true);
|
|
20
22
|
return () => setIsMounted(false);
|
|
21
23
|
}, []);
|
|
24
|
+
useLayoutEffect(() => {
|
|
25
|
+
setModalContainer(document.getElementById(APP_MODAL_ID));
|
|
26
|
+
}, []);
|
|
22
27
|
// Handle open/close animations
|
|
23
28
|
useEffect(() => {
|
|
24
29
|
if (open) {
|
|
@@ -120,7 +125,10 @@ function Dialog({ open, onOpenChange, disabled, trigger, title, subtitle, disabl
|
|
|
120
125
|
: null,
|
|
121
126
|
}, children: [(title || subtitle || icon) && (jsx(CardHeader, { icon: icon, title: title, description: subtitle })), !disableCloseButton && (jsx("button", { className: S.dialogClose, onClick: handleCloseClick, "aria-label": "Close dialog", type: "button", children: jsx(XIcon, { size: 16 }) })), content && (jsx(CardContent, { className: contentClassName, noScroll: noScroll, autoScrollBottom: autoScrollBottom, children: content })), footer && (jsx(CardFooter, { className: cn(S.footer, S[`align-${footerAlignment}`], footerClassName), children: footer }))] })] }));
|
|
122
127
|
const onTriggerClick = !disabled ? () => onOpenChange(true) : undefined;
|
|
123
|
-
return (jsxs(Fragment, { children: [trigger && jsx("div", { onClick: onTriggerClick, children: trigger }), open &&
|
|
128
|
+
return (jsxs(Fragment, { children: [trigger && jsx("div", { onClick: onTriggerClick, children: trigger }), open &&
|
|
129
|
+
!disabled &&
|
|
130
|
+
modalContainer &&
|
|
131
|
+
createPortal(dialogContent, modalContainer)] }));
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
export { Dialog, S as DialogStyles };
|
package/package.json
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import cn from 'classnames';
|
|
2
|
-
import React, {
|
|
2
|
+
import React, {
|
|
3
|
+
useEffect,
|
|
4
|
+
useId,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
3
9
|
import { createPortal } from 'react-dom';
|
|
4
10
|
|
|
5
11
|
import {
|
|
@@ -8,6 +14,7 @@ import {
|
|
|
8
14
|
CardFooter,
|
|
9
15
|
CardHeader,
|
|
10
16
|
} from '#uilib/components/ui/Card/Card';
|
|
17
|
+
import { APP_MODAL_ID } from '#uilib/constants/appMount';
|
|
11
18
|
import { XIcon } from '@phosphor-icons/react';
|
|
12
19
|
|
|
13
20
|
import S from './Dialog.styl';
|
|
@@ -35,6 +42,9 @@ export function Dialog({
|
|
|
35
42
|
width,
|
|
36
43
|
}: DialogProps) {
|
|
37
44
|
const [isMounted, setIsMounted] = useState(false);
|
|
45
|
+
const [modalContainer, setModalContainer] = useState<HTMLElement | null>(
|
|
46
|
+
null,
|
|
47
|
+
);
|
|
38
48
|
const [isAnimating, setIsAnimating] = useState(false);
|
|
39
49
|
const dialogRef = useRef<HTMLDivElement>(null);
|
|
40
50
|
const triggerRef = useRef<HTMLElement | null>(null);
|
|
@@ -48,6 +58,10 @@ export function Dialog({
|
|
|
48
58
|
return () => setIsMounted(false);
|
|
49
59
|
}, []);
|
|
50
60
|
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
setModalContainer(document.getElementById(APP_MODAL_ID));
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
51
65
|
// Handle open/close animations
|
|
52
66
|
useEffect(() => {
|
|
53
67
|
if (open) {
|
|
@@ -228,7 +242,10 @@ export function Dialog({
|
|
|
228
242
|
return (
|
|
229
243
|
<>
|
|
230
244
|
{trigger && <div onClick={onTriggerClick}>{trigger}</div>}
|
|
231
|
-
{open &&
|
|
245
|
+
{open &&
|
|
246
|
+
!disabled &&
|
|
247
|
+
modalContainer &&
|
|
248
|
+
createPortal(dialogContent, modalContainer)}
|
|
232
249
|
</>
|
|
233
250
|
);
|
|
234
251
|
}
|
package/src/docs/index.tsx
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createRoot } from 'react-dom/client';
|
|
2
2
|
import { BrowserRouter } from 'react-router-dom';
|
|
3
3
|
|
|
4
|
+
import { APP_ROOT_ID } from '#uilib/constants/appMount';
|
|
4
5
|
import { DEFAULT_THEME_ACTIVE_COLOR } from '#uilib/docs/lib/theme';
|
|
5
6
|
|
|
6
7
|
import App from './App/App';
|
|
7
8
|
import { ThemeProvider } from './contexts/theme-context';
|
|
8
9
|
|
|
9
|
-
const elem = document.getElementById(
|
|
10
|
+
const elem = document.getElementById(APP_ROOT_ID) as HTMLElement;
|
|
10
11
|
const root = createRoot(elem);
|
|
11
12
|
|
|
12
13
|
root.render(
|