mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
refactor(copy): inline handleClick, remove dispatcher
This commit is contained in:
parent
5ca9f35286
commit
7a7fd93121
1 changed files with 8 additions and 15 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue