Skip to content

Commit a2aeb6b

Browse files
authored
Merge pull request #17 from cwandev/refactor/code-block
refactor: rewrite code-block component
2 parents 1419a7a + 7e2f436 commit a2aeb6b

File tree

16 files changed

+740
-218
lines changed

16 files changed

+740
-218
lines changed

apps/test/app/examples/code-block.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { CodeBlock } from '@repo/elements/code-block'
2+
import { CodeBlock, CodeBlockCopyButton } from '@repo/elements/code-block'
33
44
const code = `<template>
55
<div>
@@ -15,8 +15,22 @@ interface Props {
1515
1616
defineProps<Props>()
1717
<\/script>`
18+
19+
function handleCopy() {
20+
// eslint-disable-next-line no-console
21+
console.log('Copied code to clipboard')
22+
}
23+
24+
function handleError(error: Error) {
25+
console.error('Failed to copy code to clipboard', error)
26+
}
1827
</script>
1928

2029
<template>
21-
<CodeBlock :code="code" lang="vue" />
30+
<CodeBlock :code="code" language="vue">
31+
<CodeBlockCopyButton
32+
@copy="handleCopy"
33+
@error="handleError"
34+
/>
35+
</CodeBlock>
2236
</template>

apps/www/assets/css/tailwind.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,11 @@
119119
}
120120
}
121121

122-
122+
@layer components {
123+
/* Override shadcn-docs-nuxt's .shiki code span.line styles
124+
to prevent conflicts with code-block component preview */
125+
.docs-component-preview .shiki code span.line {
126+
min-height: 0 !important;
127+
line-height: 0 !important;
128+
}
129+
}

apps/www/components/ComponentViewer.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ defineProps<Props>()
1111
<ClientOnly>
1212
<Suspense>
1313
<template #default>
14-
<component :is="componentName" />
14+
<div class="docs-component-preview">
15+
<component :is="componentName" />
16+
</div>
1517
</template>
1618
<template #fallback>
1719
<div class="p-4" />

apps/www/content/1.overview/1.Introduction.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,7 @@ You can install it with:
6363
:::ComponentLoader{label="InlineCitation" componentName="InlineCitation"}
6464
:::
6565

66+
:::ComponentLoader{label="CodeBlock" componentName="CodeBlock"}
67+
:::
68+
6669
View the [source code](https://github.com/cwandev/ai-elements-vue) for all components on GitHub.

0 commit comments

Comments
 (0)