Skip to content

Commit 2e0e02c

Browse files
committed
docs: clipboard
1 parent 197ed5d commit 2e0e02c

File tree

9 files changed

+131
-0
lines changed

9 files changed

+131
-0
lines changed

packages/react/src/components/clipboard/clipboard.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default meta
99
export { Basic } from './examples/basic'
1010
export { Context } from './examples/context'
1111
export { Controlled } from './examples/controlled'
12+
export { CopyStatus } from './examples/copy-status'
1213
export { CustomTimeout } from './examples/custom-timeout'
1314
export { Programmatic } from './examples/programmatic'
1415
export { RootProvider } from './examples/root-provider'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Clipboard } from '@ark-ui/react/clipboard'
2+
import { CheckIcon, ClipboardCopyIcon } from 'lucide-react'
3+
import { useState } from 'react'
4+
5+
export const CopyStatus = () => {
6+
const [copyCount, setCopyCount] = useState(0)
7+
8+
return (
9+
<Clipboard.Root
10+
value="https://ark-ui.com"
11+
onStatusChange={(details) => {
12+
if (details.copied) {
13+
setCopyCount((prev) => prev + 1)
14+
}
15+
}}
16+
>
17+
<Clipboard.Trigger>
18+
<Clipboard.Indicator copied={<CheckIcon />}>
19+
<ClipboardCopyIcon />
20+
</Clipboard.Indicator>
21+
Copy
22+
</Clipboard.Trigger>
23+
<p>Copied {copyCount} times</p>
24+
</Clipboard.Root>
25+
)
26+
}

packages/solid/src/components/clipboard/clipboard.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default meta
99
export { Basic } from './examples/basic'
1010
export { Context } from './examples/context'
1111
export { Controlled } from './examples/controlled'
12+
export { CopyStatus } from './examples/copy-status'
1213
export { CustomTimeout } from './examples/custom-timeout'
1314
export { Programmatic } from './examples/programmatic'
1415
export { RootProvider } from './examples/root-provider'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Clipboard } from '@ark-ui/solid/clipboard'
2+
import { CheckIcon, ClipboardCopyIcon } from 'lucide-solid'
3+
import { Show, createSignal } from 'solid-js'
4+
5+
export const CopyStatus = () => {
6+
const [copyCount, setCopyCount] = createSignal(0)
7+
8+
return (
9+
<Clipboard.Root
10+
value="https://ark-ui.com"
11+
onStatusChange={(details) => {
12+
if (details.copied) {
13+
setCopyCount((prev) => prev + 1)
14+
}
15+
}}
16+
>
17+
<Clipboard.Trigger>
18+
<Clipboard.Indicator>
19+
<Show when={false} fallback={<ClipboardCopyIcon />}>
20+
<CheckIcon />
21+
</Show>
22+
</Clipboard.Indicator>
23+
Copy
24+
</Clipboard.Trigger>
25+
<p>Copied {copyCount()} times</p>
26+
</Clipboard.Root>
27+
)
28+
}

packages/svelte/src/lib/components/clipboard/clipboard.stories.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Meta } from '@storybook/svelte'
22
import BasicExample from './examples/basic.svelte'
33
import ContextExample from './examples/context.svelte'
44
import ControlledExample from './examples/controlled.svelte'
5+
import CopyStatusExample from './examples/copy-status.svelte'
56
import CustomTimeoutExample from './examples/custom-timeout.svelte'
67
import ProgrammaticExample from './examples/programmatic.svelte'
78
import RootProviderExample from './examples/root-provider.svelte'
@@ -31,6 +32,12 @@ export const Controlled = {
3132
}),
3233
}
3334

35+
export const CopyStatus = {
36+
render: () => ({
37+
Component: CopyStatusExample,
38+
}),
39+
}
40+
3441
export const CustomTimeout = {
3542
render: () => ({
3643
Component: CustomTimeoutExample,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts">
2+
import { CheckIcon, ClipboardCopyIcon } from 'lucide-svelte'
3+
import { Clipboard } from '@ark-ui/svelte/clipboard'
4+
5+
let copyCount = $state(0)
6+
</script>
7+
8+
<Clipboard.Root
9+
value="https://ark-ui.com"
10+
onStatusChange={(details) => {
11+
if (details.copied) {
12+
copyCount += 1
13+
}
14+
}}
15+
>
16+
<Clipboard.Trigger>
17+
<Clipboard.Indicator>
18+
<ClipboardCopyIcon />
19+
{#snippet copied()}
20+
<CheckIcon />
21+
{/snippet}
22+
</Clipboard.Indicator>
23+
Copy
24+
</Clipboard.Trigger>
25+
<p>Copied {copyCount} times</p>
26+
</Clipboard.Root>

packages/vue/src/components/clipboard/clipboard.stories.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Basic from './examples/basic.vue'
33
import Context from './examples/context.vue'
44
import Controlled from './examples/controlled.vue'
5+
import CopyStatus from './examples/copy-status.vue'
56
import CustomTimeout from './examples/custom-timeout.vue'
67
import Programmatic from './examples/programmatic.vue'
78
import RootProvider from './examples/root-provider.vue'
@@ -18,6 +19,9 @@ import ValueText from './examples/value-text.vue'
1819
<Variant title="Controlled">
1920
<Controlled />
2021
</Variant>
22+
<Variant title="CopyStatus">
23+
<CopyStatus />
24+
</Variant>
2125
<Variant title="CustomTimeout">
2226
<CustomTimeout />
2327
</Variant>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script setup lang="ts">
2+
import { Clipboard } from '@ark-ui/vue/clipboard'
3+
import { CheckIcon, ClipboardCopyIcon } from 'lucide-vue-next'
4+
import { ref } from 'vue'
5+
6+
const copyCount = ref(0)
7+
</script>
8+
9+
<template>
10+
<Clipboard.Root
11+
default-value="https://ark-ui.com"
12+
@status-change="
13+
(details) => {
14+
if (details.copied) {
15+
copyCount += 1
16+
}
17+
}
18+
"
19+
>
20+
<Clipboard.Trigger>
21+
<Clipboard.Indicator>
22+
<ClipboardCopyIcon />
23+
<template #copied>
24+
<CheckIcon />
25+
</template>
26+
</Clipboard.Indicator>
27+
Copy
28+
</Clipboard.Trigger>
29+
<p>Copied {{ copyCount }} times</p>
30+
</Clipboard.Root>
31+
</template>

website/src/content/pages/components/clipboard.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ Access the clipboard state and methods using `Clipboard.Context`. This provides
2929
3030
<Example id="context" />
3131

32+
### Copy Status
33+
34+
Use the `onStatusChange` prop to listen for copy operations. It exposes a `copied` property that you can use to display
35+
a success message.
36+
37+
<Example id="copy-status" />
38+
3239
### Controlled
3340

3441
Control the clipboard value externally by managing the state yourself and using `onValueChange` to handle updates.

0 commit comments

Comments
 (0)