Fix popover clipping
This commit is contained in:
parent
ac2b8ad13f
commit
8d7d021594
2 changed files with 65 additions and 54 deletions
|
|
@ -1,16 +1,11 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Snippet} from "svelte"
|
import type {Snippet} from "svelte"
|
||||||
import {deriveProfile} from "@welshman/app"
|
import type {Instance} from "tippy.js"
|
||||||
import MenuDots from "@assets/icons/menu-dots.svg?dataurl"
|
import MenuDots from "@assets/icons/menu-dots.svg?dataurl"
|
||||||
import Code2 from "@assets/icons/code-2.svg?dataurl"
|
|
||||||
import ShareCircle from "@assets/icons/share-circle.svg?dataurl"
|
|
||||||
import {fly} from "@lib/transition"
|
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
|
import Tippy from "@lib/components/Tippy.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Popover from "@lib/components/Popover.svelte"
|
import ProfileMenuList from "@app/components/ProfileMenuList.svelte"
|
||||||
import ProfileInfo from "@app/components/ProfileInfo.svelte"
|
|
||||||
import ProfileQrCode from "@app/components/ProfileQrCode.svelte"
|
|
||||||
import {pushModal} from "@app/modal"
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
pubkey: string
|
pubkey: string
|
||||||
|
|
@ -20,54 +15,19 @@
|
||||||
|
|
||||||
const {pubkey, url, customActions}: Props = $props()
|
const {pubkey, url, customActions}: Props = $props()
|
||||||
|
|
||||||
const profile = deriveProfile(pubkey)
|
const showPopover = () => popover?.show()
|
||||||
|
|
||||||
let showMenu = $state(false)
|
const hidePopover = () => popover?.hide()
|
||||||
|
|
||||||
const toggleMenu = () => {
|
let popover: Instance | undefined = $state()
|
||||||
showMenu = !showMenu
|
|
||||||
}
|
|
||||||
|
|
||||||
const closeMenu = () => {
|
|
||||||
showMenu = false
|
|
||||||
}
|
|
||||||
|
|
||||||
const showInfo = () => {
|
|
||||||
closeMenu()
|
|
||||||
pushModal(ProfileInfo, {event: $profile!.event, url})
|
|
||||||
}
|
|
||||||
|
|
||||||
const showShare = () => {
|
|
||||||
closeMenu()
|
|
||||||
pushModal(ProfileQrCode, {pubkey})
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative">
|
<Button onclick={showPopover} class="button button-circle button-ghost button-sm">
|
||||||
<Button class="button button-circle button-ghost button-sm" onclick={toggleMenu}>
|
<Tippy
|
||||||
|
bind:popover
|
||||||
|
component={ProfileMenuList}
|
||||||
|
props={{pubkey, url, customActions, onClick: hidePopover}}
|
||||||
|
params={{trigger: "manual", interactive: true, placement: "bottom-end"}}>
|
||||||
<Icon icon={MenuDots} />
|
<Icon icon={MenuDots} />
|
||||||
</Button>
|
</Tippy>
|
||||||
{#if showMenu}
|
</Button>
|
||||||
<Popover hideOnClick onClose={closeMenu}>
|
|
||||||
<ul
|
|
||||||
transition:fly
|
|
||||||
class="menu bg-surface absolute right-0 z-popover w-48 gap-1 rounded-2xl p-2">
|
|
||||||
<li>
|
|
||||||
<Button onclick={showShare}>
|
|
||||||
<Icon icon={ShareCircle} />
|
|
||||||
Share
|
|
||||||
</Button>
|
|
||||||
</li>
|
|
||||||
{#if $profile}
|
|
||||||
<li>
|
|
||||||
<Button onclick={showInfo}>
|
|
||||||
<Icon icon={Code2} />
|
|
||||||
Profile Info
|
|
||||||
</Button>
|
|
||||||
</li>
|
|
||||||
{/if}
|
|
||||||
{@render customActions?.()}
|
|
||||||
</ul>
|
|
||||||
</Popover>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
|
||||||
51
src/app/components/ProfileMenuList.svelte
Normal file
51
src/app/components/ProfileMenuList.svelte
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import {onMount} from "svelte"
|
||||||
|
import type {Snippet} from "svelte"
|
||||||
|
import {deriveProfile} from "@welshman/app"
|
||||||
|
import Code2 from "@assets/icons/code-2.svg?dataurl"
|
||||||
|
import ShareCircle from "@assets/icons/share-circle.svg?dataurl"
|
||||||
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import ProfileInfo from "@app/components/ProfileInfo.svelte"
|
||||||
|
import ProfileQrCode from "@app/components/ProfileQrCode.svelte"
|
||||||
|
import {pushModal} from "@app/modal"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
pubkey: string
|
||||||
|
url?: string
|
||||||
|
onClick: () => void
|
||||||
|
customActions?: Snippet
|
||||||
|
}
|
||||||
|
|
||||||
|
const {pubkey, url, onClick, customActions}: Props = $props()
|
||||||
|
|
||||||
|
const profile = deriveProfile(pubkey)
|
||||||
|
|
||||||
|
const showInfo = () => pushModal(ProfileInfo, {event: $profile!.event, url})
|
||||||
|
|
||||||
|
const showShare = () => pushModal(ProfileQrCode, {pubkey})
|
||||||
|
|
||||||
|
let ul: Element
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
ul.addEventListener("click", onClick)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ul class="menu whitespace-nowrap rounded-2xl bg-surface p-2" bind:this={ul}>
|
||||||
|
<li>
|
||||||
|
<Button onclick={showShare}>
|
||||||
|
<Icon size={4} icon={ShareCircle} />
|
||||||
|
Share
|
||||||
|
</Button>
|
||||||
|
</li>
|
||||||
|
{#if $profile}
|
||||||
|
<li>
|
||||||
|
<Button onclick={showInfo}>
|
||||||
|
<Icon size={4} icon={Code2} />
|
||||||
|
Profile Info
|
||||||
|
</Button>
|
||||||
|
</li>
|
||||||
|
{/if}
|
||||||
|
{@render customActions?.()}
|
||||||
|
</ul>
|
||||||
Loading…
Reference in a new issue