@pepperi-addons/ngx-lib-react 0.5.5 → 0.5.6
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/elements/main.js +1 -1
- package/package.json +1 -1
- package/pep-dialog.js +52 -3
- package/elements/971.js +0 -1
package/package.json
CHANGED
package/pep-dialog.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useEffect, useRef } from 'react';
|
|
3
|
+
import * as ReactDOM from 'react-dom';
|
|
3
4
|
export const PepDialog = ({ title, showClose, showHeader, showFooter, onClose, children, ...rest }) => {
|
|
4
5
|
const ref = useRef(null);
|
|
6
|
+
const [contentHost, setContentHost] = React.useState(null);
|
|
7
|
+
const [actionsHost, setActionsHost] = React.useState(null);
|
|
5
8
|
// Sync inputs as properties on the custom element
|
|
6
9
|
useEffect(() => {
|
|
7
10
|
const el = ref.current;
|
|
@@ -16,6 +19,33 @@ export const PepDialog = ({ title, showClose, showHeader, showFooter, onClose, c
|
|
|
16
19
|
if (typeof showFooter !== 'undefined')
|
|
17
20
|
el.showFooter = !!showFooter;
|
|
18
21
|
}, [title, showClose, showHeader, showFooter]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const el = ref.current;
|
|
24
|
+
if (!el) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let destroyed = false;
|
|
28
|
+
const queryHosts = () => {
|
|
29
|
+
if (destroyed) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const content = el.querySelector('[mat-dialog-content], .mat-dialog-content');
|
|
33
|
+
const actions = el.querySelector('[mat-dialog-actions], .mat-dialog-actions');
|
|
34
|
+
if (content || actions) {
|
|
35
|
+
setContentHost(content);
|
|
36
|
+
setActionsHost(actions);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
requestAnimationFrame(queryHosts);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
queryHosts();
|
|
43
|
+
return () => {
|
|
44
|
+
destroyed = true;
|
|
45
|
+
setContentHost(null);
|
|
46
|
+
setActionsHost(null);
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
19
49
|
// Wire events
|
|
20
50
|
useEffect(() => {
|
|
21
51
|
const el = ref.current;
|
|
@@ -29,6 +59,25 @@ export const PepDialog = ({ title, showClose, showHeader, showFooter, onClose, c
|
|
|
29
59
|
handlers.forEach(([n, h]) => el.addEventListener(n, h));
|
|
30
60
|
return () => handlers.forEach(([n, h]) => el.removeEventListener(n, h));
|
|
31
61
|
}, [onClose]);
|
|
32
|
-
|
|
62
|
+
const allChildren = React.Children.toArray(children);
|
|
63
|
+
const contentChildren = allChildren.filter((child) => {
|
|
64
|
+
if (!React.isValidElement(child)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
const props = child.props || {};
|
|
68
|
+
const hasContentAttr = Object.prototype.hasOwnProperty.call(props, 'pep-dialog-content');
|
|
69
|
+
const hasActionsAttr = Object.prototype.hasOwnProperty.call(props, 'pep-dialog-actions');
|
|
70
|
+
return hasContentAttr || !hasActionsAttr;
|
|
71
|
+
});
|
|
72
|
+
const actionsChildren = allChildren.filter((child) => {
|
|
73
|
+
if (!React.isValidElement(child)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const props = child.props || {};
|
|
77
|
+
return Object.prototype.hasOwnProperty.call(props, 'pep-dialog-actions');
|
|
78
|
+
});
|
|
79
|
+
return (_jsxs(_Fragment, { children: [_jsx("pep-dialog-element", { ref: ref, ...rest }), contentHost && contentChildren.length > 0 &&
|
|
80
|
+
ReactDOM.createPortal(contentChildren, contentHost), actionsHost && actionsChildren.length > 0 &&
|
|
81
|
+
ReactDOM.createPortal(actionsChildren, actionsHost)] }));
|
|
33
82
|
};
|
|
34
83
|
//# sourceMappingURL=pep-dialog.js.map
|