Palette Drag, Debounce and Tidyup

This commit is contained in:
cmack 2020-07-10 11:40:53 +01:00
parent 39ee12c390
commit 4d11f9c25c
3 changed files with 8 additions and 5 deletions

View File

@ -1,8 +1,10 @@
<script> <script>
import FlatButton from "./FlatButton.svelte" import FlatButton from "./FlatButton.svelte"
import { createEventDispatcher } from "svelte"
const dispatch = createEventDispatcher()
export let format = "hex" export let format = "hex"
export let onclick = format => {}
let colorFormats = ["hex", "rgb", "hsl"] let colorFormats = ["hex", "rgb", "hsl"]
</script> </script>
@ -12,7 +14,7 @@
<FlatButton <FlatButton
selected={format === text} selected={format === text}
{text} {text}
on:click={() => onclick(text)} /> on:click={() => dispatch('click', text)} />
{/each} {/each}
</div> </div>

View File

@ -120,7 +120,7 @@
} }
function changeFormatAndConvert(f) { function changeFormatAndConvert(f) {
format = f format = f.detail
value = convertHsvaToFormat([h, s, v, a], format) value = convertHsvaToFormat([h, s, v, a], format)
} }
@ -251,7 +251,7 @@
{/if} {/if}
<div class="format-input-panel"> <div class="format-input-panel">
<ButtonGroup {format} onclick={changeFormatAndConvert} /> <ButtonGroup {format} on:click={changeFormatAndConvert} />
<Input <Input
{value} {value}
on:input={event => handleColorInput(event.target.value)} on:input={event => handleColorInput(event.target.value)}

View File

@ -47,7 +47,8 @@
function onColorChange(color) { function onColorChange(color) {
value = color.detail value = color.detail
dispatch("change", color.detail) const fn = debounce(() => dispatch("change", color.detail), 300)
fn()
} }
function calculateDimensions() { function calculateDimensions() {