1.0.0 • Published 10 months ago
astro-teleport v1.0.0
Astro Portal Component
A lightweight Astro component for rendering content in a different part of the DOM using a Web Component.
Installation
npm install astro-teleportor with Yarn:
yarn add astro-teleportor with pnpm:
pnpm add astro-teleportUsage
Basic Example
---
import Portal from "astro-teleport";
---
<Portal data-target="#modal" data-open={true}>
<div>
<h2>This is inside the portal!</h2>
</div>
</Portal>Props
| 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. |
How It Works
- 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.
License
MIT