A lightweight Astro component for rendering content in a different part of the DOM using a Web Component.
npm install astro-teleportor with Yarn:
yarn add astro-teleportor with pnpm:
pnpm add astro-teleport---
import Portal from "astro-teleport";
---
<Portal data-target="#modal" data-open={true}>
<div>
<h2>This is inside the portal!</h2>
</div>
</Portal>| Prop | Type | Description |
|---|---|---|
data-target |
string |
A CSS selector for the target container. Defaults to body. |
data-open |
boolean |
Controls whether the portal content is shown. |
- The
Portalcomponent moves its children to the specifieddata-targetelement. - If
data-targetis not provided, it defaults todocument.body. - When
data-openistrue, the portal content is mounted inside the target. - When
data-openisfalse, the content is removed from the target.
MIT