web/PopoverContainer: refactor & simplify code

why the fuck was it that way in the first place
This commit is contained in:
wukko
2025-03-07 20:47:43 +06:00
parent 3935396709
commit 714e71751e
3 changed files with 14 additions and 20 deletions

View File

@ -1,22 +1,15 @@
<script lang="ts">
export let id = "";
export let expanded = false;
export let popoverAction: () => void;
export let expandStart: "left" | "center" | "right" = "center";
/*
a popover isn't pre-rendered by default, because the user might never open it.
but if they do, we render only once, and then keep it the dom :3
*/
$: renderPopover = false;
export const showPopover = async () => {
const timeout = !renderPopover;
renderPopover = true;
// 10ms delay to let the popover render for the first time
if (timeout) {
setTimeout(popoverAction, 10);
} else {
popoverAction();
}
};
$: if (expanded && !renderPopover) renderPopover = true;
</script>
<div {id} class="popover {expandStart}" aria-hidden={!expanded} class:expanded>