mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
chore: lift components folder
This commit is contained in:
parent
76df51674d
commit
2200b29b92
301 changed files with 57 additions and 76 deletions
51
src/Copy/Copy.svelte
Normal file
51
src/Copy/Copy.svelte
Normal file
|
@ -0,0 +1,51 @@
|
|||
<script>
|
||||
export let feedback = "Copied!";
|
||||
export let feedbackTimeout = 2000;
|
||||
export let ref = null;
|
||||
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
$: animation = undefined;
|
||||
$: timeoutId = undefined;
|
||||
$: showFeedback = timeoutId !== undefined;
|
||||
|
||||
onDestroy(() => {
|
||||
window.clearTimeout(timeoutId);
|
||||
timeoutId = undefined;
|
||||
});
|
||||
</script>
|
||||
|
||||
<button
|
||||
bind:this={ref}
|
||||
type="button"
|
||||
aria-live="polite"
|
||||
class:bx--copy={true}
|
||||
class:bx--copy-btn--animating={animation}
|
||||
aria-label={animation ? feedback : undefined}
|
||||
{...$$restProps}
|
||||
class="{$$restProps.class}
|
||||
{animation && `bx--copy-btn--${animation}`}"
|
||||
on:click
|
||||
on:click={() => {
|
||||
if (animation === 'fade-in') return;
|
||||
animation = 'fade-in';
|
||||
timeoutId = setTimeout(() => {
|
||||
animation = 'fade-out';
|
||||
}, feedbackTimeout);
|
||||
}}
|
||||
on:animationend
|
||||
on:animationend={({ animationName }) => {
|
||||
if (animationName === 'hide-feedback') {
|
||||
animation = undefined;
|
||||
}
|
||||
}}>
|
||||
<slot>
|
||||
{#if animation}{feedback || $$restProps['aria-label']}{/if}
|
||||
</slot>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class:bx--assistive-text={true}
|
||||
class:bx--copy-btn__feedback={true}>
|
||||
{feedback}
|
||||
</span>
|
||||
</button>
|
1
src/Copy/index.js
Normal file
1
src/Copy/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default as Copy } from "./Copy.svelte";
|
Loading…
Add table
Add a link
Reference in a new issue