2021-03-31 11:59:07 +02:00
< script >
2021-04-21 16:03:12 +02:00
import "@spectrum-css/popover/dist/index-vars.css"
2021-03-31 11:59:07 +02:00
import Portal from "svelte-portal"
import { createEventDispatcher } from "svelte"
import positionDropdown from "../Actions/position_dropdown"
import clickOutside from "../Actions/click_outside"
2021-04-21 16:03:12 +02:00
2021-03-31 11:59:07 +02:00
const dispatch = createEventDispatcher()
export let anchor
export let align = "right"
2021-06-08 09:00:54 +02:00
export let portalTarget
2022-04-20 13:51:44 +02:00
export let dataCy
2022-08-30 11:16:15 +02:00
export let maxWidth
2021-03-31 11:59:07 +02:00
2022-04-26 13:04:07 +02:00
export let direction = "bottom"
export let showTip = false
let tipSvg =
'< svg xmlns = "http://www.w3.org/svg/2000" width = "23" height = "12" class = "spectrum-Popover-tip" > < path class = "spectrum-Popover-tip-triangle" d = "M 0.7071067811865476 0 L 11.414213562373096 10.707106781186548 L 22.121320343559645 0" / > < / svg > '
$: tooltipClasses = showTip
? `spectrum-Popover--withTip spectrum-Popover--${ direction } `
: ""
2022-04-19 15:38:09 +02:00
2021-03-31 11:59:07 +02:00
export const show = () => {
2021-04-21 16:03:12 +02:00
dispatch("open")
2021-03-31 11:59:07 +02:00
open = true
}
export const hide = () => {
2021-04-21 16:03:12 +02:00
dispatch("close")
2021-03-31 11:59:07 +02:00
open = false
}
2021-04-21 16:03:12 +02:00
let open = null
2021-03-31 11:59:07 +02:00
function handleEscape(e) {
if (open && e.key === "Escape") {
hide()
}
}
< / script >
{ #if open }
2021-06-08 09:00:54 +02:00
< Portal target = { portalTarget } >
2021-03-31 11:59:07 +02:00
< div
tabindex="0"
2022-08-30 11:16:15 +02:00
use:positionDropdown={{ anchor , align , maxWidth }}
2021-03-31 11:59:07 +02:00
use:clickOutside={ hide }
on:keydown={ handleEscape }
2022-04-26 13:04:07 +02:00
class={ "spectrum-Popover is-open " + ( tooltipClasses || "" )}
2021-05-04 12:04:42 +02:00
role="presentation"
2022-04-20 13:51:44 +02:00
data-cy={ dataCy }
2021-05-04 12:04:42 +02:00
>
2022-04-26 13:04:07 +02:00
{ #if showTip }
{ @html tipSvg }
{ /if }
2021-03-31 11:59:07 +02:00
< slot / >
< / div >
< / Portal >
{ /if }
2021-04-23 11:48:19 +02:00
< style >
.spectrum-Popover {
2022-07-18 06:34:40 +02:00
min-width: var(--spectrum-global-dimension-size-2000);
2022-08-05 12:11:12 +02:00
border-color: var(--spectrum-global-color-gray-300);
2021-04-23 11:48:19 +02:00
}
2022-04-26 13:04:07 +02:00
.spectrum-Popover.is-open.spectrum-Popover--withTip {
margin-top: var(--spacing-xs);
margin-left: var(--spacing-xl);
}
:global(.spectrum-Popover--bottom .spectrum-Popover-tip),
:global(.spectrum-Popover--top .spectrum-Popover-tip) {
left: 90%;
margin-left: calc(var(--spectrum-global-dimension-size-150) * -1);
}
2021-04-23 11:48:19 +02:00
< / style >