1
0
Fork 0
mirror of synced 2024-09-28 15:21:28 +12:00
budibase/packages/client/src/components/preview/HoverIndicator.svelte

38 lines
924 B
Svelte
Raw Normal View History

<script>
import { onMount, onDestroy } from "svelte"
import IndicatorSet from "./IndicatorSet.svelte"
import { builderStore } from "../../store"
let componentId
$: zIndex = componentId === $builderStore.selectedComponentId ? 900 : 920
const onMouseOver = e => {
const element = e.target.closest("[data-type='component']")
const newId = element?.dataset?.id
if (newId !== componentId) {
componentId = newId
}
}
const onMouseLeave = () => {
componentId = null
}
onMount(() => {
document.addEventListener("mouseover", onMouseOver)
document.body.addEventListener("mouseleave", onMouseLeave)
})
onDestroy(() => {
document.removeEventListener("mouseover", onMouseOver)
document.body.removeEventListener("mouseleave", onMouseLeave)
})
</script>
2021-07-01 08:23:55 +12:00
<IndicatorSet
{componentId}
color="var(--spectrum-global-color-static-blue-200)"
2021-07-01 08:23:55 +12:00
transition
{zIndex}
/>