@pepperi-addons/ngx-lib-react 0.5.5 → 0.5.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pepperi-addons/ngx-lib-react",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "Thin React wrappers for Pepperi Angular Elements (Web Components) to improve DX in React.",
5
5
  "license": "MIT",
6
6
  "author": "Pepperi",
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,18 @@ 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
- return (_jsx("pep-dialog-element", { ref: ref, ...rest, children: children }));
62
+ let primaryChildren = [];
63
+ if (React.isValidElement(children) && children.type === React.Fragment) {
64
+ primaryChildren = React.Children.toArray(children.props && children.props.children);
65
+ }
66
+ else {
67
+ primaryChildren = React.Children.toArray(children);
68
+ }
69
+ const flatChildren = primaryChildren.filter((child) => React.isValidElement(child));
70
+ const contentChildren = flatChildren[0] ? [flatChildren[0]] : [];
71
+ const actionsChildren = flatChildren[1] ? [flatChildren[1]] : [];
72
+ return (_jsxs(_Fragment, { children: [_jsx("pep-dialog-element", { ref: ref, ...rest }), contentHost && contentChildren.length > 0 &&
73
+ ReactDOM.createPortal(contentChildren, contentHost), actionsHost && actionsChildren.length > 0 &&
74
+ ReactDOM.createPortal(actionsChildren, actionsHost)] }));
33
75
  };
34
76
  //# sourceMappingURL=pep-dialog.js.map