Skip to content

Commit

Permalink
add options to Copy_To_Clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Aug 4, 2024
1 parent 42ccc80 commit c4bd56e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-parrots-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ryanatkn/fuz': patch
---

add options to `Copy_To_Clipboard`
28 changes: 24 additions & 4 deletions src/lib/Copy_To_Clipboard.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
<script lang="ts">
import type {Snippet} from 'svelte';
import type {SvelteHTMLElements} from 'svelte/elements';
interface Props {
text: string;
classes?: string;
button_classes?: string;
button_attrs?: SvelteHTMLElements['button'];
attrs?: SvelteHTMLElements['div'];
children?: Snippet<[copied: boolean, failed: boolean]>;
}
// TODO add library entry
const {text}: Props = $props();
const {
text,
classes = '',
button_classes = 'icon_button',
button_attrs,
attrs,
children,
}: Props = $props();
let copied = $state(false);
let failed = $state(false);
Expand All @@ -23,9 +38,14 @@
};
</script>

<div class="copy_to_clipboard">
<button type="button" class="icon_button" style:font-size="var(--size_lg)" onclick={copy}
>📋</button
<div {...attrs} class="copy_to_clipboard {classes}">
<button
{...button_attrs}
type="button"
class={button_classes}
style:font-size="var(--size_lg)"
onclick={copy}
>{#if children}{@render children(copied, failed)}{:else}📋{/if}</button
>
{#if copied}<small class="color_b_5">copied!</small>{/if}
{#if failed}<small class="color_c_5">failed</small>{/if}
Expand Down

0 comments on commit c4bd56e

Please sign in to comment.