forked from tsai/budibase
committed by
GitHub
3 changed files with 37 additions and 6 deletions
@ -1,7 +1,38 @@ |
|||||
<script> |
<script> |
||||
|
import { createEventDispatcher } from 'svelte' |
||||
import Colorpicker from "@budibase/colorpicker" |
import Colorpicker from "@budibase/colorpicker" |
||||
|
|
||||
|
const dispatch = createEventDispatcher(); |
||||
|
|
||||
export let value |
export let value |
||||
|
|
||||
|
const WAIT = 150; |
||||
|
|
||||
|
function throttle(callback, wait, immediate = false) { |
||||
|
let timeout = null |
||||
|
let initialCall = true |
||||
|
|
||||
|
return function() { |
||||
|
const callNow = immediate && initialCall |
||||
|
const next = () => { |
||||
|
callback.apply(this, arguments) |
||||
|
timeout = null |
||||
|
} |
||||
|
|
||||
|
if (callNow) { |
||||
|
initialCall = false |
||||
|
next() |
||||
|
} |
||||
|
|
||||
|
if (!timeout) { |
||||
|
timeout = setTimeout(next, wait) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const onChange = throttle(e => { |
||||
|
dispatch('change', e.detail) |
||||
|
}, WAIT, true) |
||||
</script> |
</script> |
||||
|
|
||||
<Colorpicker value={value || '#000'} on:change /> |
<Colorpicker value={value || '#C4C4C4'} on:change={onChange} /> |
||||
|
|||||
Loading…
Reference in new issue