PHP 8.2.30
Preview: portal-utils.tsx Size: 1.18 KB
/home/byroehnu/.trash/node_modules11/@adminjs/design-system/src/utils/portal-utils.tsx

/* eslint-disable arrow-body-style */
import React, { FC, useEffect, useState } from 'react'
import ReactDOM from 'react-dom'

import generateId from './generate-id.js'

// TODO: handle iframe case with ref.current.ownerDocument
export const PortalUtils = {
  appendElement: (element: HTMLDivElement): void => {
    window.document.body.appendChild(element)
  },

  removeElement: (id: string): void => {
    const domElement = window.document.getElementById(id)
    domElement?.remove()
  },

  createPortalForKey: function createPortalForKey<Props>(
    idKey: string,
    Component: FC<Props>,
  ): FC<Props & JSX.IntrinsicAttributes> {
    const Portal: FC<Props & JSX.IntrinsicAttributes> = (props) => {
      const [id] = useState(generateId(idKey))
      const [portalElement] = useState<HTMLDivElement>(window.document.createElement('div'))

      useEffect(() => {
        portalElement.id = id
        PortalUtils.appendElement(portalElement)

        return () => {
          PortalUtils.removeElement(id)
        }
      })

      return ReactDOM.createPortal(
        (
          <Component {...props} />
        ), portalElement,
      )
    }
    return Portal
  },
}

export default PortalUtils

Directory Contents

Dirs: 0 × Files: 21

Name Size Perms Modified Actions
226 B lrw-r--r-- 2026-02-28 00:31:40
Edit Download
151 B lrw-r--r-- 2026-02-28 00:31:40
Edit Download
826 B lrw-r--r-- 2026-02-28 00:31:40
Edit Download
6.13 KB lrw-r--r-- 2026-02-28 00:31:40
Edit Download
930 B lrw-r--r-- 2026-02-28 00:31:40
Edit Download
1.51 KB lrw-r--r-- 2026-02-28 00:31:40
Edit Download
23.52 KB lrw-r--r-- 2026-02-28 00:31:40
Edit Download
638 B lrw-r--r-- 2026-02-28 00:31:40
Edit Download
65 B lrw-r--r-- 2026-02-28 00:31:40
Edit Download
287 B lrw-r--r-- 2026-02-28 00:31:42
Edit Download
394 B lrw-r--r-- 2026-02-28 00:31:42
Edit Download
1008 B lrw-r--r-- 2026-02-28 00:31:42
Edit Download
491 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
438 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
42.07 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.18 KB lrw-r--r-- 2026-02-28 00:31:58
Edit Download
2.02 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.24 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
518 B lrw-r--r-- 2026-02-28 00:32:00
Edit Download
236 B lrw-r--r-- 2026-02-28 00:31:50
Edit Download
1.53 KB lrw-r--r-- 2026-02-28 00:31:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).