flotilla/src/app/components/IconPickerButton.svelte

47 lines
1.2 KiB
Svelte
Raw Normal View History

<script lang="ts">
2026-08-29 17:20:39 +00:00
import type {Maybe} from "@welshman/lib"
import {isMobile} from "@lib/html"
import Button from "@lib/components/Button.svelte"
import Tippy from "@lib/components/Tippy.svelte"
2026-08-29 17:20:39 +00:00
import type {TippyController} from "@lib/components/Tippy.svelte"
2026-03-11 23:15:37 +00:00
import IconPickerModal from "@app/components/IconPickerModal.svelte"
import IconPickerPopover from "@app/components/IconPickerPopover.svelte"
2026-06-08 21:14:40 +00:00
import {pushModal, popModal} from "@app/modal"
const {...props} = $props()
const open = () => {
if (isMobile) {
2026-03-11 23:29:24 +00:00
pushModal(IconPickerModal, {onSelect: onClick}, {nested: true})
} else {
2026-08-29 17:20:39 +00:00
tippy?.show()
}
}
const close = () => {
if (isMobile) {
2026-03-11 23:29:24 +00:00
popModal()
} else {
2026-08-29 17:20:39 +00:00
tippy?.hide()
}
}
const onClick = (iconUrl: string) => {
props.onSelect(iconUrl)
close()
}
2026-08-29 17:20:39 +00:00
let tippy: Maybe<TippyController> = $state()
</script>
<Tippy
2026-08-29 17:20:39 +00:00
bind:controller={tippy}
2026-03-11 23:15:37 +00:00
component={IconPickerPopover}
strayMargin={50}
props={{onSelect: onClick}}
2026-02-10 01:40:10 +00:00
params={{trigger: "manual", interactive: true, placement: "top-end"}}>
<Button onclick={open} class={props.class}>
{@render props.children?.()}
</Button>
</Tippy>