Skip to content

Commit eb1efb2

Browse files
committed
feat: add CopyCodeInput component for easy code copying
1 parent 39863fc commit eb1efb2

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
source: string
4+
}>()
5+
6+
const copied = ref(false)
7+
8+
function copy() {
9+
navigator.clipboard.writeText(props.source)
10+
copied.value = true
11+
12+
setTimeout(() => {
13+
copied.value = false
14+
}, 2000)
15+
}
16+
</script>
17+
18+
<template>
19+
<UInput
20+
:model-value="props.source"
21+
aria-label="Copy code to get started"
22+
size="xl"
23+
class="w-88"
24+
disabled
25+
:ui="{ base: 'disabled:cursor-default' }"
26+
>
27+
<template #leading>
28+
<UIcon name="i-ph-terminal" />
29+
</template>
30+
<template
31+
v-if="props.source?.length"
32+
#trailing
33+
>
34+
<UTooltip
35+
text="Copy to clipboard"
36+
:content="{ side: 'right' }"
37+
>
38+
<UButton
39+
:color="copied ? 'success' : 'neutral'"
40+
variant="link"
41+
:icon="copied ? 'i-lucide-copy-check' : 'i-lucide-copy'"
42+
aria-label="Copy to clipboard"
43+
@click="copy"
44+
/>
45+
</UTooltip>
46+
</template>
47+
</UInput>
48+
</template>

docs/content/index.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,7 @@ Build Shopify Apps with Nuxt
3434
Get started
3535
:::
3636

37-
:::u-button
38-
---
39-
color: neutral
40-
icon: i-lucide-github
41-
size: xl
42-
target: _blank
43-
to: https://github.com/kiriminaja/shopify-app-nuxt
44-
variant: subtle
45-
---
46-
Give a star
37+
:::copy-code-input{source="npx nuxt module add color-mode"}
4738
:::
4839
::
4940

0 commit comments

Comments
 (0)