diff --git a/packages/builder/src/components/userInterface/Colorpicker/CheckedBackground.svelte b/packages/builder/src/components/userInterface/Colorpicker/CheckedBackground.svelte index c6acd8f18a..19d54523b2 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/CheckedBackground.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/CheckedBackground.svelte @@ -1,12 +1,14 @@ @@ -18,6 +20,6 @@ } -
+
\ No newline at end of file diff --git a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte index 16f17ccc98..5989e6b3ed 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte @@ -1,5 +1,7 @@ -
+
@@ -139,21 +243,38 @@
- setHue(hue.detail)} /> + setHue(hue.detail)} on:dragend={dispatchValue} /> setAlpha(alpha.detail)} /> + on:change={(alpha, isDrag) => setAlpha(alpha.detail, isDrag)} + on:dragend={dispatchValue} + />
+ {#if !disableSwatches} +
+ {#if swatches.length > 0} + {#each swatches as color, idx} + applySwatch(color)} on:removeswatch={() => removeSwatch(idx)} /> + {/each} + {/if} + {#if swatches.length !== 12} +
+ + +
+ {/if} +
+ {/if} +
- handleColorInput(event.target.value)} /> + handleColorInput(event.target.value)} on:change={dispatchInputChange} />
diff --git a/packages/builder/src/components/userInterface/Colorpicker/Colorpreview.svelte b/packages/builder/src/components/userInterface/Colorpicker/Colorpreview.svelte index 8f5bf64f70..32a5e63ff3 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Colorpreview.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Colorpreview.svelte @@ -2,11 +2,14 @@ import Colorpicker from "./Colorpicker.svelte" import CheckedBackground from "./CheckedBackground.svelte" import {createEventDispatcher, afterUpdate, beforeUpdate} from "svelte" + import {buildStyle} from "./helpers.js" import { fade } from 'svelte/transition'; import {getColorFormat} from "./utils.js" export let value = "#3ec1d3ff" + export let swatches = [] + export let disableSwatches = false export let open = false; export let width = "25px" export let height = "25px" @@ -17,8 +20,8 @@ let previewHeight = null let previewWidth = null - let pickerWidth = 250 - let pickerHeight = 300 + let pickerWidth = 0 + let pickerHeight = 0 let anchorEl = null let parentNodes = []; @@ -61,30 +64,33 @@ function openColorpicker(event) { if(colorPreview) { - const {top: spaceAbove, width, bottom, right, left: spaceLeft} = colorPreview.getBoundingClientRect() - const {innerHeight, innerWidth} = window - - const {offsetLeft, offsetTop} = colorPreview - //get the scrollTop value for all scrollable parent elements - let scrollTop = parentNodes.reduce((scrollAcc, el) => scrollAcc += el.scrollTop, 0); - - const spaceBelow = (innerHeight - spaceAbove) - previewHeight - const top = spaceAbove > spaceBelow ? (offsetTop - pickerHeight) - scrollTop : (offsetTop + previewHeight) - scrollTop - - //TOO: Testing and Scroll Awareness for x Scroll - const spaceRight = (innerWidth - spaceLeft) + previewWidth - const left = spaceRight > spaceLeft ? (offsetLeft + previewWidth) : offsetLeft - pickerWidth - - dimensions = {top, left} - open = true; } } + $: if(open && colorPreview) { + const {top: spaceAbove, width, bottom, right, left: spaceLeft} = colorPreview.getBoundingClientRect() + const {innerHeight, innerWidth} = window + + const {offsetLeft, offsetTop} = colorPreview + //get the scrollTop value for all scrollable parent elements + let scrollTop = parentNodes.reduce((scrollAcc, el) => scrollAcc += el.scrollTop, 0); + + const spaceBelow = (innerHeight - spaceAbove) - previewHeight + const top = spaceAbove > spaceBelow ? (offsetTop - pickerHeight) - scrollTop : (offsetTop + previewHeight) - scrollTop + + //TOO: Testing and Scroll Awareness for x Scroll + const spaceRight = (innerWidth - spaceLeft) + previewWidth + const left = spaceRight > spaceLeft ? (offsetLeft + previewWidth) : offsetLeft - pickerWidth + + dimensions = {top, left} + } + function onColorChange(color) { value = color.detail; dispatch("change", color.detail) } +
@@ -94,8 +100,8 @@ {#if open} -
- +
+
open = false} class="overlay">
{/if} diff --git a/packages/builder/src/components/userInterface/Colorpicker/Input.svelte b/packages/builder/src/components/userInterface/Colorpicker/Input.svelte index 483fcd450d..811a51cea6 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Input.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Input.svelte @@ -24,5 +24,5 @@
- +
diff --git a/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte b/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte index 47736d7b69..edf0888432 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte @@ -10,7 +10,7 @@ let slider; let sliderWidth = 0; - function handleClick(mouseX) { + function onSliderChange(mouseX, isDrag = false) { const { left, width } = slider.getBoundingClientRect(); let clickPosition = mouseX - left; @@ -21,7 +21,8 @@ type === "hue" ? 360 * percentageClick : percentageClick; - dispatch("change", value); + + dispatch("change", {color: value, isDrag}); } } @@ -75,13 +76,14 @@
handleClick(event.clientX)} + on:click={event => onSliderChange(event.clientX)} class="color-format-slider" class:hue={type === 'hue'} class:alpha={type === 'alpha'}>
handleClick(e.detail)} + on:drag={e => onSliderChange(e.detail, true)} + on:dragend class="slider-thumb" {style} />
diff --git a/packages/builder/src/components/userInterface/Colorpicker/Swatch.svelte b/packages/builder/src/components/userInterface/Colorpicker/Swatch.svelte new file mode 100644 index 0000000000..e602b72d33 --- /dev/null +++ b/packages/builder/src/components/userInterface/Colorpicker/Swatch.svelte @@ -0,0 +1,53 @@ + + + + +
+ +
hovered = true} on:mouseleave={() => hovered = false}> + {#if hovered} +
dispatch("removeswatch")}> + dispatch("removeswatch")}>× +
+ {/if} +
+
+
\ No newline at end of file diff --git a/packages/builder/src/components/userInterface/Colorpicker/drag.js b/packages/builder/src/components/userInterface/Colorpicker/drag.js index 0d7a9c2481..54fa5e924b 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/drag.js +++ b/packages/builder/src/components/userInterface/Colorpicker/drag.js @@ -16,6 +16,7 @@ export default function(node) { function handleMouseUp() { window.removeEventListener("mousedown", handleMouseDown) window.removeEventListener("mousemove", handleMouseMove) + node.dispatchEvent(new CustomEvent("dragend")) } node.addEventListener("mousedown", handleMouseDown)