Skip to content

Commit af3f73f

Browse files
committed
fix: #1240
docs: copy contact details and copy button with modal to clipboard page
1 parent 00a76c9 commit af3f73f

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

src/routes/docs/components/clipboard.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,85 @@ Add a `Clipboard` to your `Textarea` using the `addon` snippet. The button appea
305305
</Textarea>
306306
```
307307

308+
## Copy contact details
309+
This example can be used to copy the text content (ie. contact details) inside of the `<address>` field by clicking on the copy to clipboard button positioned inside of the address card.
310+
311+
Make sure that you set the `id` to the trigger element to specify the source of the content that is to be copied.
312+
313+
```svelte example class="flex justify-center items-center"
314+
<script lang="ts">
315+
import { Card, Clipboard, Tooltip } from "$lib";
316+
import { CheckOutline, ClipboardCleanSolid } from "flowbite-svelte-icons";
317+
318+
let value = $state("");
319+
320+
function onclick(ev: MouseEvent): void {
321+
const target = ev.target as HTMLElement;
322+
const codeBlock = target.ownerDocument.querySelector("#contact-details");
323+
if (codeBlock) {
324+
value = codeBlock.textContent || "";
325+
}
326+
}
327+
</script>
328+
329+
<Card class="relative p-5">
330+
<h2 class="mb-2 text-lg font-semibold text-gray-900 dark:text-white">Contact details</h2>
331+
<address class="relative grid grid-cols-2 rounded-lg border border-gray-200 bg-gray-50 p-4 not-italic dark:border-gray-600 dark:bg-gray-700">
332+
<div class="hidden space-y-2 leading-loose text-gray-500 sm:block dark:text-gray-400">
333+
Name <br />
334+
Email
335+
<br />
336+
Phone Number
337+
</div>
338+
<div id="contact-details" class="space-y-2 leading-loose font-medium text-gray-900 dark:text-white">
339+
Bonnie Green <br />
340+
name@flowbite.com
341+
<br />
342+
+ 12 345 67890
343+
</div>
344+
</address>
345+
<Clipboard {onclick} bind:value embedded class="absolute end-2 top-2 h-8 px-2.5 font-medium focus:ring-0">
346+
{#snippet children(success)}
347+
<Tooltip isOpen={success}>{success ? "Copied" : "Copy to clipboard"}</Tooltip>
348+
{#if success}<CheckOutline />{:else}<ClipboardCleanSolid />{/if}
349+
{/snippet}
350+
</Clipboard>
351+
</Card>
352+
```
353+
354+
## Copy button with modal
355+
Use this example to show an input field where you can copy the URL of the current page and also show a modal with the copied URL when the copy button is clicked.
356+
357+
```svelte example class="flex justify-center" hideResponsiveButtons
358+
<script>
359+
import { Clipboard, Input, Tooltip, Modal, Button, Label } from "flowbite-svelte";
360+
import { CheckOutline, ClipboardCleanSolid, ShareNodesOutline } from "flowbite-svelte-icons";
361+
362+
let value = $state("npm install flowbite-svelte");
363+
let copyModal = $state(false);
364+
</script>
365+
366+
<Button color="alternative" onclick={() => (copyModal = true)}><ShareNodesOutline class="me-2"/> Share course</Button>
367+
368+
<Modal title="Share course" bind:open={copyModal} autoclose class="divide-y-0" headerClass="text-lg text-gray-500 dark:text-gray-400" footerClass="px-5 pb-5">
369+
<Label for="course-url" class="text-sm font-medium mb-2 block">Share the course link below with your friends:</Label>
370+
371+
<Input bind:value id="course-url">
372+
{#snippet right()}
373+
<Clipboard bind:value embedded>
374+
{#snippet children(success)}
375+
<Tooltip isOpen={success}>{success ? "Copied" : "Copy to clipboard"}</Tooltip>
376+
{#if success}<CheckOutline />{:else}<ClipboardCleanSolid />{/if}
377+
{/snippet}
378+
</Clipboard>
379+
{/snippet}
380+
</Input>
381+
{#snippet footer()}
382+
<Button onclick={() => copyModal = false} >Close</Button>
383+
{/snippet}
384+
</Modal>
385+
```
386+
308387
## Component data
309388

310389
The component has the following props, type, and default values. See [types page](/docs/pages/typescript) for type information.

0 commit comments

Comments
 (0)