Ensure hover indicator is correctly hidden when using DND and improve DND labels

This commit is contained in:
Andrew Kingston 2021-09-16 16:02:45 +01:00
parent 601a4935a9
commit cb04b3fa7d
3 changed files with 20 additions and 7 deletions

View File

@ -1,7 +1,7 @@
<script> <script>
import { onMount } from "svelte" import { onMount } from "svelte"
import { get } from "svelte/store"
import IndicatorSet from "./IndicatorSet.svelte" import IndicatorSet from "./IndicatorSet.svelte"
import Indicator from "./Indicator.svelte"
import DNDPositionIndicator from "./DNDPositionIndicator.svelte" import DNDPositionIndicator from "./DNDPositionIndicator.svelte"
import { builderStore } from "stores" import { builderStore } from "stores"
@ -21,7 +21,6 @@
// Update state // Update state
dragTarget = e.target.dataset.componentId dragTarget = e.target.dataset.componentId
builderStore.actions.selectComponent(dragTarget) builderStore.actions.selectComponent(dragTarget)
builderStore.actions.showHoverIndicator(false)
// Highlight being dragged by setting opacity // Highlight being dragged by setting opacity
const child = getDOMNodeForComponent(e.target) const child = getDOMNodeForComponent(e.target)
@ -97,6 +96,13 @@
element.dataset.droppable && element.dataset.droppable &&
element.dataset.id !== dragTarget element.dataset.id !== dragTarget
) { ) {
// Disable hover selection again to ensure it's always disabled.
// There's a bit of a race condition between the app reinitialisation
// after selecting the DND component and setting this the first time
if (get(builderStore).showHoverIndicator) {
builderStore.actions.showHoverIndicator(false)
}
// Store target ID // Store target ID
dropTarget = element.dataset.id dropTarget = element.dataset.id

View File

@ -36,8 +36,7 @@
{zIndex} {zIndex}
{color} {color}
{transition} {transition}
flip={mode === "below"} line
rounded
/> />
{/if} {/if}
{/key} {/key}

View File

@ -9,9 +9,9 @@
export let color export let color
export let zIndex export let zIndex
export let transition = false export let transition = false
export let flip = false export let line = false
$: flipped = flip || top < 20 $: flipped = top < 20
</script> </script>
<div <div
@ -22,10 +22,11 @@
out:fade={{ duration: transition ? 130 : 0 }} out:fade={{ duration: transition ? 130 : 0 }}
class="indicator" class="indicator"
class:flipped class:flipped
class:line
style="top: {top}px; left: {left}px; width: {width}px; height: {height}px; --color: {color}; --zIndex: {zIndex};" style="top: {top}px; left: {left}px; width: {width}px; height: {height}px; --color: {color}; --zIndex: {zIndex};"
> >
{#if text} {#if text}
<div class="text" class:flipped> <div class="text" class:flipped class:line>
{text} {text}
</div> </div>
{/if} {/if}
@ -45,6 +46,9 @@
.indicator.flipped { .indicator.flipped {
border-top-left-radius: 4px; border-top-left-radius: 4px;
} }
.indicator.line {
border-radius: 4px !important;
}
.text { .text {
background-color: var(--color); background-color: var(--color);
color: white; color: white;
@ -70,4 +74,8 @@
transform: translateY(0%); transform: translateY(0%);
top: -2px; top: -2px;
} }
.text.line {
transform: translateY(-50%) !important;
border-radius: 4px !important;
}
</style> </style>