1
0
Fork 0
mirror of synced 2024-09-12 23:43:09 +12:00

Fix multiple issue with colour selection for options

This commit is contained in:
Andrew Kingston 2024-05-20 14:50:39 +01:00
parent 387723f9cf
commit de13f4ea11

View file

@ -9,8 +9,8 @@
export let constraints export let constraints
export let optionColors = {} export let optionColors = {}
let options = []
let options = []
let colorPopovers = [] let colorPopovers = []
let anchors = [] let anchors = []
@ -64,9 +64,14 @@
delete optionColors[optionName] delete optionColors[optionName]
} }
const openColorPickerPopover = (optionIdx, target) => { const openColorPickerPopover = optionIdx => {
colorPopovers[optionIdx].show() for (let i = 0; i < colorPopovers.length; i++) {
anchors[optionIdx] = target if (i === optionIdx) {
colorPopovers[i].show()
} else {
colorPopovers[i]?.hide()
}
}
} }
onMount(() => { onMount(() => {
@ -94,7 +99,7 @@
on:consider={handleDndConsider} on:consider={handleDndConsider}
on:finalize={handleDndFinalize} on:finalize={handleDndFinalize}
> >
{#each options as option, idx (option.id)} {#each options as option, idx (`${option.id}-${idx}`)}
<div <div
class="no-border action-container" class="no-border action-container"
animate:flip={{ duration: flipDurationMs }} animate:flip={{ duration: flipDurationMs }}
@ -102,25 +107,24 @@
<div class="child drag-handle-spacing"> <div class="child drag-handle-spacing">
<Icon name="DragHandle" size="L" /> <Icon name="DragHandle" size="L" />
</div> </div>
<div class="child color-picker"> <div
bind:this={anchors[idx]}
class="child color-picker"
on:click={e => openColorPickerPopover(idx, e.target)}
>
<div <div
id="color-picker" class="circle"
bind:this={anchors[idx]}
style="--color:{optionColors?.[option.name] || style="--color:{optionColors?.[option.name] ||
'hsla(0, 1%, 50%, 0.3)'}" 'hsla(0, 1%, 50%, 0.3)'}"
class="circle"
on:click={e => openColorPickerPopover(idx, e.target)}
> >
<Popover <Popover
bind:this={colorPopovers[idx]} bind:this={colorPopovers[idx]}
anchor={anchors[idx]} anchor={anchors[idx]}
align="left" align="left"
offset={0} offset={0}
style=""
popoverTarget={document.getElementById(`color-picker`)}
animate={false} animate={false}
> >
<div class="colors"> <div class="colors" data-ignore-click-outside="true">
{#each colorsArray as color} {#each colorsArray as color}
<div <div
on:click={() => handleColorChange(option.name, color, idx)} on:click={() => handleColorChange(option.name, color, idx)}
@ -228,6 +232,10 @@
display: flex; display: flex;
} }
.color-picker:hover {
cursor: pointer;
}
.circle { .circle {
height: 20px; height: 20px;
width: 20px; width: 20px;