BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/tool-ui/code-diff

Code Diff

tool-ui/code-diff
FreeBlock

Code Diff component for AI interfaces.

See it running

Open the demo on tool-ui

www.tool-ui.com/components/code-diff
Open
This registry sends X-Frame-Options, so its page cannot be embedded here. The link is the same page the frame would have shown.

Install it

npx shadcn@latest add https://www.tool-ui.com/r/code-diff.json

Source

components/tool-ui/code-diff/code-diff.tsxwww.tool-ui.com/r/code-diff.json · first 6 KB
1"use client";
2
3import {
4 useState,
5 useCallback,
6 useEffect,
7 useMemo,
8 createContext,
9 use,
10 type ReactNode,
11} from "react";
12import {
13 FileDiff as PierreFileDiff,
14 PatchDiff as PierrePatchDiff,
15} from "@pierre/diffs/react";
16import { parseDiffFromFile, RegisteredCustomThemes } from "@pierre/diffs";
17import type { FileDiffMetadata, ThemesType } from "@pierre/diffs";
18import { Copy, Check, ChevronDown, ChevronUp } from "lucide-react";
19import type { CodeDiffProps } from "./schema";
20import { useCopyToClipboard } from "../shared/use-copy-to-clipboard";
21import { Button, cn, Collapsible, CollapsibleTrigger } from "./_adapter";
22
23/*
24 * Pierre's shared_highlighter registers custom themes with dynamic imports
25 * (`import("../themes/pierre-dark.js")`) that fail under Turbopack because the
26 * package `exports` field doesn't include those subpaths. We override the
27 * RegisteredCustomThemes map entries with loaders that point to local vendored
28 * theme files in `components/tool-ui/shared`, which Turbopack can resolve.
29 */
30RegisteredCustomThemes.set("pierre-dark", () =>
31 import("../shared/pierre-dark-theme.js").then((m) => m.default as never),
32);
33RegisteredCustomThemes.set("pierre-light", () =>
34 import("../shared/pierre-light-theme.js").then((m) => m.default as never),
35);
36
37const COPY_ID = "codediff-code";
38
39/* ── Theme detection (mirrors CodeBlock) ────────────────────────── */
40
41function getSystemTheme(): "light" | "dark" {
42 if (typeof window === "undefined") return "light";
43 return window.matchMedia?.("(prefers-color-scheme: dark)").matches
44 ? "dark"
45 : "light";
46}
47
48function getDocumentTheme(): "light" | "dark" | null {
49 if (typeof document === "undefined") return null;
50 const root = document.documentElement;
51 const dataTheme = root.getAttribute("data-theme")?.toLowerCase();
52 if (dataTheme === "dark") return "dark";
53 if (dataTheme === "light") return "light";
54 if (root.classList.contains("dark")) return "dark";
55 if (root.classList.contains("light")) return "light";
56 return null;
57}
58
59function useResolvedTheme(): "light" | "dark" {
60 const [theme, setTheme] = useState<"light" | "dark">(() => {
61 return getDocumentTheme() ?? getSystemTheme();
62 });
63
64 useEffect(() => {
65 if (typeof window === "undefined" || typeof document === "undefined") {
66 return;
67 }
68
69 const update = () => setTheme(getDocumentTheme() ?? getSystemTheme());
70
71// … truncated

What it pulls in

npm packages

  • @pierre/diffs
  • lucide-react
  • zod

Other registry items

  • button
  • collapsible

Files it writes

  • components/tool-ui/code-diff/_adapter.tsx
  • components/tool-ui/code-diff/code-diff.tsx
  • components/tool-ui/code-diff/index.tsx
  • components/tool-ui/code-diff/schema.ts
  • components/tool-ui/shared/contract.ts
  • components/tool-ui/shared/parse.ts
  • components/tool-ui/shared/pierre-dark-theme.js
  • components/tool-ui/shared/pierre-light-theme.js
  • components/tool-ui/shared/schema.ts
  • components/tool-ui/shared/use-copy-to-clipboard.ts

Facts

Registry
tool-ui
Type
registry:block
Access
Free
Files written
10
Licence
the repository states none
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

Docs on tool-ui www.tool-ui.com Raw registry item This item as JSON

More from tool-ui

All 27 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Approval Cardapproval-cardtool-uiBlocksFree2 deps · 11 files
Audioaudiotool-uiBlocksFree2 deps · 9 files
Chartcharttool-uiBlocksFree2 deps · 8 files
Citationcitationtool-uiBlocksFree2 deps · 15 files
Code Blockcode-blocktool-uiBlocksFree3 deps · 11 files
Data Tabledata-tabletool-uiBlocksFree1 dep · 17 files
Geo Mapgeo-maptool-uiBlocksFree4 deps · 12 files
Imageimagetool-uiBlocksFree1 dep · 14 files
BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex