@purr-core/components.portal 0.0.7 → 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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),d=require("react-dom"),s=({children:a,className:u="",...c})=>{const r=o.useRef(null),e=o.useCallback(t=>{t==null||t.setAttribute("data-test-id","portal"),t==null||t.setAttribute("class",`portal ${u}`),Object.entries(c).forEach(([i,n])=>{t==null||t.setAttribute(i,String(n))})},[u,c]);return o.useEffect(()=>{let t=document.getElementById("portal-root");return t||(t=document.createElement("div"),t.setAttribute("id","portal-root")),r.current||(r.current=document.createElement("div"),e(r.current)),document.body.appendChild(t),t.appendChild(r.current),()=>{r.current&&t.removeChild(r.current)}},[e]),r.current?d.createPortal(a,r.current):null};exports.Portal=s;
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;
@@ -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 CHANGED
@@ -1,2 +1,24 @@
1
- export * from './_components';
2
- export * from './_types';
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 CHANGED
@@ -1,25 +1 @@
1
- import n, { useCallback as e, useEffect as s } from "react";
2
- import { createPortal as p } from "react-dom";
3
- const l = ({
4
- children: i,
5
- className: o = "",
6
- ...u
7
- }) => {
8
- const r = n.useRef(null), c = e(
9
- (t) => {
10
- t == null || t.setAttribute("data-test-id", "portal"), t == null || t.setAttribute("class", `portal ${o}`), Object.entries(u).forEach(([a, d]) => {
11
- t == null || t.setAttribute(a, String(d));
12
- });
13
- },
14
- [o, u]
15
- );
16
- return s(() => {
17
- let t = document.getElementById("portal-root");
18
- return t || (t = document.createElement("div"), t.setAttribute("id", "portal-root")), r.current || (r.current = document.createElement("div"), c(r.current)), document.body.appendChild(t), t.appendChild(r.current), () => {
19
- r.current && t.removeChild(r.current);
20
- };
21
- }, [c]), r.current ? p(i, r.current) : null;
22
- };
23
- export {
24
- l as Portal
25
- };
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.7",
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.10"
26
+ "@purr-core/utils.definitions": "0.0.12"
27
27
  },
28
28
  "author": "@DinhThienPhuc",
29
29
  "license": "ISC",
@@ -32,6 +32,8 @@
32
32
  "scripts": {
33
33
  "dev": "vite build --watch",
34
34
  "build": "tsc && vite build",
35
+ "build:vite": "tsc && vite build",
36
+ "build:tsup": "tsup",
35
37
  "lint": "eslint . --ext ts,tsx --max-warnings 0"
36
38
  }
37
39
  }
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
- import { IPortalProps } from './_types';
3
-
4
- export declare const Portal: ({ children, className, ...restProps }: IPortalProps) => React.ReactPortal | null;
package/dist/_types.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { IExtendable } from '@purr-core/utils.definitions';
3
-
4
- export interface IPortalProps extends IExtendable {
5
- className?: string;
6
- children: ReactNode;
7
- }