From 5e03e474e92077e6b7c17531b16dbf6bbd74bc28 Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Tue, 30 Jun 2020 13:08:58 +0100 Subject: [PATCH] Colorpicker - Portal and Centering --- .../Colorpicker/Colorpicker.svelte | 146 ++++++++++-------- .../Colorpicker/Colorpreview.svelte | 116 ++++++-------- .../userInterface/Colorpicker/Portal.svelte | 37 +++++ .../[application]/frontend/_layout.svelte | 1 - 4 files changed, 168 insertions(+), 132 deletions(-) create mode 100644 packages/builder/src/components/userInterface/Colorpicker/Portal.svelte diff --git a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte index 2ae31385aa..27b5e20b5b 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte @@ -13,16 +13,18 @@ import Palette from "./Palette.svelte" import ButtonGroup from "./ButtonGroup.svelte" import Input from "./Input.svelte" + import Portal from "./Portal.svelte" export let value = "#3ec1d3ff" + export let open = false; export let swatches = [] //TODO: Safe swatches - limit to 12. warn in console export let disableSwatches = false export let format = "hexa" - export let open = false - + export let style = "" export let pickerHeight = 0 export let pickerWidth = 0 + let colorPicker = null let adder = null let h = null @@ -38,6 +40,10 @@ getRecentColors() } + if(colorPicker) { + colorPicker.focus() + } + if (format) { convertAndSetHSVA() } @@ -50,6 +56,12 @@ } } + function handleEscape(e) { + if(open && e.key === "Escape") { + open = false + } + } + function setRecentColor(color) { if (swatches.length === 12) { swatches.splice(0, 1) @@ -145,85 +157,97 @@ } $: border = v > 90 && s < 5 ? "1px dashed #dedada" : "" - $: style = buildStyle({ background: value, border }) + $: selectedColorStyle = buildStyle({ background: value, border }) $: shrink = swatches.length > 0 + -
-
- -
+ +
-
-
-
- -
- -
-
- setHue(hue.detail)} - on:dragend={dispatchValue} /> +
+ +
- +
+
+
+ +
+ +
+
setAlpha(alpha.detail, isDrag)} + type="hue" + value={h} + on:change={hue => setHue(hue.detail)} on:dragend={dispatchValue} /> - + + 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)} + on:change={dispatchInputChange} />
- {#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)} - on:change={dispatchInputChange} /> -
- -
+