2022-05-06 06:51:20 +00:00
|
|
|
<script lang="ts">
|
2024-07-07 06:12:36 +00:00
|
|
|
const { children } = $props();
|
|
|
|
|
|
2022-05-06 06:51:20 +00:00
|
|
|
function portal(node: HTMLElement) {
|
|
|
|
|
let target;
|
|
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
target = document.querySelector('body');
|
|
|
|
|
if (target) target.appendChild(node);
|
|
|
|
|
node.hidden = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function destroy() {
|
|
|
|
|
if (node.parentNode) {
|
|
|
|
|
// Child will tell the parent to remove itself
|
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
update,
|
|
|
|
|
destroy
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div use:portal hidden>
|
2024-07-07 06:12:36 +00:00
|
|
|
{@render children()}
|
2022-05-06 06:51:20 +00:00
|
|
|
</div>
|