Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GuideFileDiff.tsx

41 lines1.3 KB

1import {
2 cloneFileDiffMetadata,
3 type FileDiffContentsLoader,
4 type FileDiffMetadata,
5} from "@pierre/diffs";
6import { FileDiff } from "@pierre/diffs/react";
7​
8import { useRenderedAppearance } from "~/hooks/useTheme";
9import { resolveDiffThemeName } from "~/lib/diffRendering";
10import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
11​
12import { DIFF_VIEW_UNSAFE_CSS } from "../../diffs/StyledDiffCodeView";
13​
14export function GuideFileDiff({
15 file,
16 loadDiffFiles,
17}: {
18 file: FileDiffMetadata;
19 loadDiffFiles: FileDiffContentsLoader;
20}) {
21 const resolvedTheme = useRenderedAppearance();
22 // Loading the unchanged lines rewrites the diff it is given; the excerpts read the same file
23 // as a patch, so this view expands a copy of its own.
24 const expandable = cloneFileDiffMetadata(file);
25 const options = {
26 diffStyle: "unified" as const,
27 lineDiffType: "none" as const,
28 overflow: "scroll" as const,
29 disableFileHeader: true,
30 theme: resolveDiffThemeName(resolvedTheme),
31 themeType: resolvedTheme,
32 preferredHighlighter: PREFERRED_HIGHLIGHTER,
33 unsafeCSS: DIFF_VIEW_UNSAFE_CSS,
34 loadDiffFiles,
35 };
36 return (
37 <div className="border-t border-border/60">
38 <FileDiff fileDiff={expandable} options={options} />
39 </div>
40 );