Skip to content

Commit bddedfb

Browse files
docs: fix clipboard button respecting prefix on second use. closes: saadeghi#3545
1 parent 8ca8149 commit bddedfb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

packages/docs/src/components/Component.svelte

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { htmlToJsx, prefixClassNames } from "$lib/actions.svelte.js"
44
import { t } from "$lib/i18n.svelte.js"
55
import Clipboard from "$components/Clipboard.svelte"
6+
import { prefix } from "$lib/stores"
7+
68
let {
79
title = undefined,
810
desc = undefined,
@@ -18,6 +20,8 @@
1820
let wrapper = $state()
1921
let htmlSlot = $state()
2022
let jsxSlot = $state()
23+
let htmlContent = $state("")
24+
let jsxContent = $state("")
2125
2226
let titleStr = $derived(
2327
title
@@ -33,6 +37,20 @@
3337
document.getElementById(location.hash.slice(1)).click()
3438
}
3539
})
40+
41+
// Subscribe to prefix changes
42+
$effect(() => {
43+
const unsubscribe = prefix.subscribe((value) => {
44+
if (htmlSlot) {
45+
htmlContent = htmlSlot.firstChild.innerHTML
46+
}
47+
if (jsxSlot) {
48+
jsxContent = jsxSlot.firstChild.innerHTML
49+
}
50+
})
51+
52+
return () => unsubscribe()
53+
})
3654
</script>
3755

3856
<div
@@ -104,7 +122,7 @@
104122
{@render html()}
105123
</div>
106124
{#if onMount}
107-
<Clipboard strip={true} text={htmlSlot?.firstChild.innerHTML} />
125+
<Clipboard strip={true} text={htmlContent} />
108126
{/if}
109127
</div>
110128
</div>
@@ -136,7 +154,7 @@
136154
</div>
137155
</div>
138156
{#if onMount}
139-
<Clipboard strip={true} text={jsxSlot?.firstChild.innerHTML} />
157+
<Clipboard strip={true} text={jsxContent} />
140158
{/if}
141159
</div>
142160
</div>

0 commit comments

Comments
 (0)