Merge pull request #38 from metonym/copy

refactor(copy): inline handleClick, remove dispatcher
This commit is contained in:
Eric Liu 2019-12-18 08:53:37 -08:00 committed by GitHub
commit 29bd9a080e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,27 +3,16 @@
export { className as class };
export let feedback = 'Copied!';
export let feedbackTimeout = 2000;
export let props = {};
import { createEventDispatcher, onDestroy } from 'svelte';
import { onDestroy } from 'svelte';
import { cx } from '../../lib';
const dispatch = createEventDispatcher();
let timeoutId = undefined;
let showFeedback = false;
function handleClick(event) {
showFeedback = true;
timeoutId = setTimeout(() => {
showFeedback = false;
}, feedbackTimeout);
}
onDestroy(() => {
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
window.clearTimeout(timeoutId);
timeoutId = undefined;
}
});
@ -32,11 +21,15 @@
</script>
<button
{...props}
type="button"
class={className}
on:click
on:click={handleClick}
on:click={() => {
showFeedback = true;
timeoutId = window.setTimeout(() => {
showFeedback = false;
}, feedbackTimeout);
}}
on:mouseover
on:mouseenter
on:mouseleave>