mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
refactor: use $$restProps API
- add ref prop for applicable components (#196) - add slot to Content Switcher `Switch` component (#183) - remove fillArray, css utilities
This commit is contained in:
parent
4e2959080b
commit
e886d772c7
288 changed files with 4681 additions and 4498 deletions
|
@ -1,52 +1,16 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let feedback = 'Copied!';
|
||||
export let feedbackTimeout = 2000;
|
||||
export let iconDescription = 'Copy to clipboard';
|
||||
export let style = undefined;
|
||||
export let iconDescription = "Copy to clipboard";
|
||||
|
||||
import { afterUpdate, onDestroy } from 'svelte';
|
||||
import Copy16 from 'carbon-icons-svelte/lib/Copy16';
|
||||
import { cx } from '../../lib';
|
||||
|
||||
let animation = undefined;
|
||||
let timeoutId = undefined;
|
||||
|
||||
afterUpdate(() => {
|
||||
if (animation === 'fade-in') {
|
||||
timeoutId = window.setTimeout(() => {
|
||||
animation = 'fade-out';
|
||||
}, feedbackTimeout);
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
window.clearTimeout(timeoutId);
|
||||
timeoutId = undefined;
|
||||
});
|
||||
import { Copy } from "../Copy";
|
||||
import Copy16 from "carbon-icons-svelte/lib/Copy16";
|
||||
</script>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
tabindex="0"
|
||||
<Copy
|
||||
class="bx--copy-btn"
|
||||
aria-label={iconDescription}
|
||||
title={iconDescription}
|
||||
class={cx('--copy-btn', animation && '--copy-btn--animating', animation && `--copy-btn--${animation}`, animation === 'fade-in' && '--btn--copy__feedback--displayed', className)}
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:click={() => {
|
||||
animation = 'fade-in';
|
||||
}}
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
on:animationend
|
||||
on:animationend={({ animationName }) => {
|
||||
if (animationName === 'hide-feedback') {
|
||||
animation = undefined;
|
||||
}
|
||||
}}
|
||||
{style}>
|
||||
<span class={cx('--assistive-text', '--copy-btn__feedback')}>{feedback}</span>
|
||||
<Copy16 class={cx('--snippet__icon')} />
|
||||
</button>
|
||||
on:animationend>
|
||||
<Copy16 class="bx--snippet__icon" />
|
||||
</Copy>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue