@teste-ui/portal
TypeScript icon, indicating that this package has built-in type declarations

2.0.4 • Public • Published

@teste-ui/portal

A wrapper for rendering components in React Portals, with support for nested portals and stacking.

Installation

yarn add @teste-ui/portal

# or

npm i @teste-ui/portal

Import components

import { Portal, PortalManager } from "@teste-ui/portal"

Render the PortalManager once at the root of your application

function App() {
  return (
    <ThemeProvider>
      <CSSReset />
      <PortalManager>{/* Your app goes here  */}</PortalManager>
    </ThemeProvider>
  )
}

Basic usage

Portals are render into the portal manager's node by default not document.body.

<div>
  <p>Welcome</p>
  <Portal>This text has been portaled</Portal>
</div>

Nested portals

Nesting portal can be very useful to build complex widgets like nested menu, popovers, modal, etc.

<Portal>
  This is a portal.
  <Portal>This is a nested portal</Portal>
</Portal>

Custom container

You can also portal elements into a custom containers. Simply pass a containerRef prop that points to the node of that element.

<>
  <div ref={ref} />
  <Portal containerRef={ref}>
    <h1>Hello world</h1>
  </Portal>
</>

Dependencies (3)

Dev Dependencies (4)

Package Sidebar

Install

npm i @teste-ui/portal

Weekly Downloads

6

Version

2.0.4

License

MIT

Unpacked Size

49.9 kB

Total Files

14

Last publish

Collaborators

  • benits