refactor(code-snippet): pass required text prop to CopyButton (#1372)

This also passes the `copy` prop to `CopyButton` instead of wrapping it in another function.
This commit is contained in:
metonym 2022-06-25 16:26:27 -07:00 committed by GitHub
commit d5d6294b02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,11 +110,6 @@
if (height > 0) showMoreLess = ref.getBoundingClientRect().height > 255;
}
function copyCode() {
copy(code);
dispatch("copy");
}
$: expandText = expanded ? showLessText : showMoreText;
$: minHeight = expanded ? 16 * 15 : 48;
$: maxHeight = expanded ? "none" : 16 * 15 + "px";
@ -174,7 +169,8 @@
{...$$restProps}
on:click
on:click="{() => {
copyCode();
copy(code);
dispatch('copy');
if (animation === 'fade-in') return;
animation = 'fade-in';
timeout = setTimeout(() => {
@ -229,12 +225,14 @@
</div>
{#if !hideCopyButton}
<CopyButton
text="{code}"
copy="{copy}"
disabled="{disabled}"
feedback="{feedback}"
feedbackTimeout="{feedbackTimeout}"
iconDescription="{copyButtonDescription}"
on:click
on:click="{copyCode}"
on:copy
on:animationend
/>
{/if}