@purr-core/components.portal 0.0.1

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.
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,7 @@
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
+ }
package/dist/index.cjs ADDED
@@ -0,0 +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;
@@ -0,0 +1,2 @@
1
+ export * from './_components';
2
+ export * from './_types';
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
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
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@purr-core/components.portal",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "peerDependencies": {
24
+ "react": "*",
25
+ "react-dom": "*",
26
+ "@purr-core/utils.definitions": "0.0.4"
27
+ },
28
+ "author": "@DinhThienPhuc",
29
+ "license": "ISC",
30
+ "description": "",
31
+ "sideEffects": false,
32
+ "scripts": {
33
+ "dev": "vite build --watch",
34
+ "build": "tsc && vite build",
35
+ "lint": "eslint . --ext ts,tsx --max-warnings 0"
36
+ }
37
+ }