forked from cms/tibi-svelte-starter
✨ feat: add loading bar and toast notification system with responsive design
This commit is contained in:
18
frontend/src/lib/actions/portal.ts
Normal file
18
frontend/src/lib/actions/portal.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Portal action — teleports an element to document.body.
|
||||
* Usage: <div use:portal>…</div>
|
||||
* SSR-safe: only runs when document is available.
|
||||
*/
|
||||
export function portal(node: HTMLElement) {
|
||||
if (typeof document === "undefined") return
|
||||
|
||||
document.body.appendChild(node)
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
if (node.parentNode) {
|
||||
node.parentNode.removeChild(node)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user