@purr-core/components.portal 0.0.8 → 0.0.9
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/index.cjs +1 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var react=require('react'),reactDom=require('react-dom');var E=({children:l,className:r="",...o})=>{let e=react.useRef(null),n=react.useCallback(t=>{t?.setAttribute("data-test-id","portal"),t?.setAttribute("class",`portal ${r}`),Object.entries(o).forEach(([u,c])=>{t?.setAttribute(u,String(c));});},[r,o]);return react.useEffect(()=>{let t=document.getElementById("portal-root");return t||(t=document.createElement("div"),t.setAttribute("id","portal-root")),e.current||(e.current=document.createElement("div"),n(e.current)),document.body.appendChild(t),t.appendChild(e.current),()=>{e.current&&t.removeChild(e.current);}},[n]),e.current?reactDom.createPortal(l,e.current):null};exports.Portal=E;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { IExtendable } from '@purr-core/utils.definitions';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The props for the Portal component.
|
|
6
|
+
*
|
|
7
|
+
* @interface IPortalProps
|
|
8
|
+
* @property {string} [className] - The class name of the component.
|
|
9
|
+
* @property {ReactNode} children - The children of the component.
|
|
10
|
+
*/
|
|
11
|
+
interface IPortalProps extends IExtendable {
|
|
12
|
+
className?: string;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The Portal component.
|
|
18
|
+
*
|
|
19
|
+
* @param {IPortalProps} props - The props for the component.
|
|
20
|
+
* @returns {ReactNode} The component.
|
|
21
|
+
*/
|
|
22
|
+
declare const Portal: ({ children, className, ...restProps }: IPortalProps) => ReactNode;
|
|
23
|
+
|
|
24
|
+
export { type IPortalProps, Portal };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { IExtendable } from '@purr-core/utils.definitions';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The props for the Portal component.
|
|
6
|
+
*
|
|
7
|
+
* @interface IPortalProps
|
|
8
|
+
* @property {string} [className] - The class name of the component.
|
|
9
|
+
* @property {ReactNode} children - The children of the component.
|
|
10
|
+
*/
|
|
11
|
+
interface IPortalProps extends IExtendable {
|
|
12
|
+
className?: string;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The Portal component.
|
|
18
|
+
*
|
|
19
|
+
* @param {IPortalProps} props - The props for the component.
|
|
20
|
+
* @returns {ReactNode} The component.
|
|
21
|
+
*/
|
|
22
|
+
declare const Portal: ({ children, className, ...restProps }: IPortalProps) => ReactNode;
|
|
23
|
+
|
|
24
|
+
export { type IPortalProps, Portal };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {useRef,useCallback,useEffect}from'react';import {createPortal}from'react-dom';var E=({children:l,className:r="",...o})=>{let e=useRef(null),n=useCallback(t=>{t?.setAttribute("data-test-id","portal"),t?.setAttribute("class",`portal ${r}`),Object.entries(o).forEach(([u,c])=>{t?.setAttribute(u,String(c));});},[r,o]);return useEffect(()=>{let t=document.getElementById("portal-root");return t||(t=document.createElement("div"),t.setAttribute("id","portal-root")),e.current||(e.current=document.createElement("div"),n(e.current)),document.body.appendChild(t),t.appendChild(e.current),()=>{e.current&&t.removeChild(e.current);}},[n]),e.current?createPortal(l,e.current):null};export{E as Portal};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purr-core/components.portal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "*",
|
|
25
25
|
"react-dom": "*",
|
|
26
|
-
"@purr-core/utils.definitions": "0.0.
|
|
26
|
+
"@purr-core/utils.definitions": "0.0.12"
|
|
27
27
|
},
|
|
28
28
|
"author": "@DinhThienPhuc",
|
|
29
29
|
"license": "ISC",
|