BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/beui/code-block

Code Block

beui/code-block
FreeComponent

A syntax-highlighted code surface with stable streaming updates, line numbers, focused lines, smooth following, and copy feedback.

Install it

npx shadcn@latest add https://beui.dev/r/code-block.json

Source

components/agents/code-block.tsxbeui.dev/r/code-block.json · first 6 KB
1"use client";
2// beui.dev/components/agents/code-block
3
4import { Check, Copy, FileCode2, LoaderCircle } from "lucide-react";
5import { motion, useReducedMotion } from "motion/react";
6import {
7 type ReactNode,
8 useCallback,
9 useEffect,
10 useLayoutEffect,
11 useMemo,
12 useRef,
13 useState,
14} from "react";
15import {
16 type AgentCodeLanguage,
17 AgentCodeLine,
18 useAgentCodeTokens,
19} from "@/components/agents/agent-code";
20import { SPRING_PRESS } from "@/lib/ease";
21import { cn } from "@/lib/utils";
22
23export type CodeBlockStatus = "streaming" | "complete";
24
25export interface CodeBlockProps {
26 code: string;
27 language?: AgentCodeLanguage;
28 filename?: ReactNode;
29 status?: CodeBlockStatus;
30 showLineNumbers?: boolean;
31 highlightLines?: number[];
32 maxHeight?: number;
33 wrap?: boolean;
34 copyable?: boolean;
35 onCopy?: () => void | Promise<void>;
36 className?: string;
37}
38
39export function CodeBlock({
40 code,
41 language = "typescript",
42 filename,
43 status = "complete",
44 showLineNumbers = true,
45 highlightLines = [],
46 maxHeight = 280,
47 wrap = false,
48 copyable = true,
49 onCopy,
50 className,
51}: CodeBlockProps) {
52 const reduce = useReducedMotion() ?? false;
53 const viewportRef = useRef<HTMLDivElement>(null);
54 const copyTimer = useRef<number | undefined>(undefined);
55 const [copied, setCopied] = useState(false);
56 const streaming = status === "streaming";
57 const tokens = useAgentCodeTokens(code, language);
58 const highlighted = useMemo(
59 () => new Set(highlightLines),
60 [highlightLines],
61 );
62 let offset = 0;
63 const lines = code.split("\n").map((content) => {
64 const line = { content, offset };
65 offset += content.length + 1;
66 return line;
67 });
68
69 useEffect(
70 () => () => {
71 if (copyTimer.current) window.clearTimeout(copyTimer.current);
72 },
73 [],
74 );
75
76 useLayoutEffect(() => {
77 const viewport = viewportRef.current;
78 if (!viewport || !streaming) return;
79
80 const frame = requestAnimationFrame(() => {
81 if (viewport.scrollHeight <= viewport.clientHeight) return;
82 if (typeof viewport.scrollTo === "function") {
83 viewport.scrollTo({
84 top: viewport.scrollHeight,
85 behavior: reduce ? "auto" : "smooth",
86 });
87 } else {
88 viewport.scrollTop = viewport.scrollHeight;
89 }
90 });
91 return () => cancelAnimationFrame(frame);
92 });
93
94 const handleCopy = useCallback(async () => {
95 if (onCopy) await onCopy();
96 else await navigator.clipboard?.writeText(code);
97
98 setCopied(true);
99// … truncated

What it pulls in

npm packages

  • clsx
  • lucide-react
  • motion
  • shiki
  • tailwind-merge

Files it writes

  • components/agents/code-block.tsx
  • components/agents/agent-code.tsx
  • lib/ease.ts
  • lib/utils.ts

Facts

Registry
beui
Type
registry:component
Access
Free
Files written
4
Licence
the repository states none
First indexed
2026-08-12
Last confirmed
today

Go to the source

beui.dev Raw registry item This item as JSON

More from beui

All 104 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Action Swap Bluraction-swap-blurbeuiComponentsFree3 deps · 4 files
Action Swap Cascadeaction-swap-cascadebeuiComponentsFree3 deps · 4 files
Action Swap Rollaction-swap-rollbeuiComponentsFree3 deps · 4 files
Agent Activityagent-activitybeuiComponentsFree4 deps · 9 files
Agent Loading States Agent Progressagent-progressbeuiComponentsFree3 deps · 3 files
AI Sidebarai-sidebarbeuiComponentsFree4 deps · 5 files
Animated Badgeanimated-badgebeuiComponentsFree4 deps · 3 files
Number Animation Animated Numberanimated-numberbeuiComponentsFree3 deps · 3 files
BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex