Files
archie/ui/src/base/CodeView.vue
T

39 lines
1.1 KiB
Vue

<script setup lang="ts">
import { cn } from "@/lib/utils";
import {
CodeBlock,
CodeBlockActions,
CodeBlockContent,
CodeBlockCopyButton,
CodeBlockLine,
CodeBlockToken,
useHighlightedCode,
} from "@/components/ui/code-block";
/**
* Code or a payload with a copy button that appears on hover or focus. The
* text is shown verbatim and wrapped: stored payloads are mostly long unbroken
* tokens (URLs, hashes, base64), which must not push the panel past its edge.
* A language the highlighter does not know renders plain.
*/
const props = defineProps<{ code: string; lang?: string; class?: string }>();
const lines = useHighlightedCode(
() => props.code,
() => props.lang || "text",
);
</script>
<template>
<CodeBlock :class="cn('bg-muted', props.class)">
<CodeBlockActions>
<CodeBlockCopyButton :value="code" />
</CodeBlockActions>
<CodeBlockContent wrap class="max-h-[60vh] pe-10 text-xs">
<CodeBlockLine v-for="(line, index) in lines" :key="index">
<CodeBlockToken v-for="(token, i) in line" :key="i" :token="token" />
</CodeBlockLine>
</CodeBlockContent>
</CodeBlock>
</template>