2021-04-12 17:10:55 +02:00
|
|
|
<script>
|
2021-04-27 11:48:47 +02:00
|
|
|
import { setContext } from "svelte"
|
2021-04-23 09:41:49 +02:00
|
|
|
import Popover from "../Popover/Popover.svelte"
|
|
|
|
import Menu from "../Menu/Menu.svelte"
|
2021-04-26 17:34:28 +02:00
|
|
|
|
2021-04-27 11:48:47 +02:00
|
|
|
export let disabled = false
|
2021-05-06 16:00:35 +02:00
|
|
|
export let align = "left"
|
2021-06-08 09:00:54 +02:00
|
|
|
export let portalTarget
|
2022-04-20 13:51:44 +02:00
|
|
|
export let dataCy
|
2021-04-26 17:34:28 +02:00
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
let anchor
|
|
|
|
let dropdown
|
2021-04-12 17:10:55 +02:00
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
// This is needed because display: contents is considered "invisible".
|
|
|
|
// It should only ever be an action button, so should be fine.
|
|
|
|
function getAnchor(node) {
|
|
|
|
anchor = node.firstChild
|
|
|
|
}
|
|
|
|
|
|
|
|
export const hide = () => {
|
|
|
|
dropdown.hide()
|
|
|
|
}
|
|
|
|
export const show = () => {
|
|
|
|
dropdown.show()
|
|
|
|
}
|
2021-04-26 14:14:05 +02:00
|
|
|
|
2021-08-18 00:04:54 +02:00
|
|
|
const openMenu = event => {
|
2021-08-17 23:57:11 +02:00
|
|
|
if (!disabled) {
|
|
|
|
event.stopPropagation()
|
|
|
|
show()
|
|
|
|
}
|
2021-04-26 14:14:05 +02:00
|
|
|
}
|
2021-04-27 11:48:47 +02:00
|
|
|
|
|
|
|
setContext("actionMenu", { show, hide })
|
2021-04-12 17:10:55 +02:00
|
|
|
</script>
|
|
|
|
|
2021-04-28 14:42:17 +02:00
|
|
|
<div use:getAnchor on:click={openMenu}>
|
2021-04-27 15:34:17 +02:00
|
|
|
<slot name="control" />
|
2021-04-12 17:10:55 +02:00
|
|
|
</div>
|
2022-04-20 13:51:44 +02:00
|
|
|
<Popover bind:this={dropdown} {anchor} {align} {portalTarget} {dataCy}>
|
2021-04-23 09:41:49 +02:00
|
|
|
<Menu>
|
2021-04-27 11:48:47 +02:00
|
|
|
<slot />
|
2021-04-23 09:41:49 +02:00
|
|
|
</Menu>
|
2021-04-21 16:03:12 +02:00
|
|
|
</Popover>
|