@@ -4,11 +4,15 @@ import {
44 type CodeViewHandle ,
55 type CodeViewProps ,
66 type ControlledCodeViewProps ,
7+ FileDiff ,
8+ type FileDiffProps ,
79 type UncontrolledCodeViewProps ,
810} from "@pierre/diffs/react" ;
911/* oxlint-enable eslint/no-restricted-imports */
1012import type { Ref } from "react" ;
13+ import type { DiffColorScheme } from "@t3tools/contracts/settings" ;
1114
15+ import { useClientSettings } from "~/hooks/useSettings" ;
1216import { DIFF_SURFACE_THEME_UNSAFE_CSS } from "~/lib/diffRendering" ;
1317
1418const DIFF_VIEW_UNSAFE_CSS = `${ DIFF_SURFACE_THEME_UNSAFE_CSS }
@@ -258,9 +262,29 @@ const DIFF_VIEW_UNSAFE_CSS = `${DIFF_SURFACE_THEME_UNSAFE_CSS}
258262}
259263` ;
260264
265+ const DIFF_COLOR_SCHEME_CLASSES : Record < DiffColorScheme , string > = {
266+ "red-green" :
267+ "[--t3-diff-addition-color:var(--success)] [--t3-diff-deletion-color:var(--destructive)]" ,
268+ "orange-blue" : "[--t3-diff-addition-color:var(--info)] [--t3-diff-deletion-color:var(--warning)]" ,
269+ } ;
270+
271+ export function getDiffColorSchemeClassName ( scheme : DiffColorScheme ) : string {
272+ return DIFF_COLOR_SCHEME_CLASSES [ scheme ] ;
273+ }
274+
275+ function getDiffSurfaceClassName ( colorScheme : DiffColorScheme , className ?: string ) : string {
276+ return [
277+ "diff-render-surface [--code-background:var(--background)] outline-none" ,
278+ getDiffColorSchemeClassName ( colorScheme ) ,
279+ className ,
280+ ]
281+ . filter ( Boolean )
282+ . join ( " " ) ;
283+ }
284+
261285export type StyledDiffCodeViewOptions < LAnnotation > = Omit <
262286 NonNullable < CodeViewProps < LAnnotation > [ "options" ] > ,
263- "unsafeCSS" | "itemMetrics" | "layout"
287+ "unsafeCSS" | "itemMetrics" | "layout" | "diffIndicators"
264288> ;
265289
266290type StyledDiffCodeViewProps < LAnnotation > = (
@@ -284,19 +308,19 @@ export function StyledDiffCodeView<LAnnotation = undefined>({
284308 unsafeCSSExtra,
285309 ...props
286310} : StyledDiffCodeViewProps < LAnnotation > ) {
311+ const diffColorScheme = useClientSettings ( ( settings ) => settings . diffColorScheme ) ;
312+ const diffIndicatorStyle = useClientSettings ( ( settings ) => settings . diffIndicatorStyle ) ;
313+
287314 return (
288315 < CodeView < LAnnotation >
289316 { ...props }
290317 { ...( viewerRef ? { ref : viewerRef } : { } ) }
291318 // The custom element itself is focusable for keyboard scrolling. Its native outline sits
292319 // outside the panel clipping boundary; actual controls inside retain their own indicators.
293- className = {
294- className
295- ? `diff-render-surface [--code-background:var(--background)] outline-none ${ className } `
296- : "diff-render-surface [--code-background:var(--background)] outline-none"
297- }
320+ className = { getDiffSurfaceClassName ( diffColorScheme , className ) }
298321 options = { {
299322 ...options ,
323+ diffIndicators : diffIndicatorStyle ,
300324 unsafeCSS : unsafeCSSExtra
301325 ? `${ DIFF_VIEW_UNSAFE_CSS } \n${ unsafeCSSExtra } `
302326 : DIFF_VIEW_UNSAFE_CSS ,
@@ -320,3 +344,34 @@ export function StyledDiffCodeView<LAnnotation = undefined>({
320344 />
321345 ) ;
322346}
347+
348+ export type StyledFileDiffOptions < LAnnotation > = Omit <
349+ NonNullable < FileDiffProps < LAnnotation > [ "options" ] > ,
350+ "unsafeCSS" | "diffIndicators"
351+ > ;
352+
353+ type StyledFileDiffProps < LAnnotation > = Omit < FileDiffProps < LAnnotation > , "options" > & {
354+ readonly options ?: StyledFileDiffOptions < LAnnotation > ;
355+ } ;
356+
357+ /** The non-virtualized counterpart used for compact inline review-comment diffs. */
358+ export function StyledFileDiff < LAnnotation = undefined > ( {
359+ options,
360+ className,
361+ ...props
362+ } : StyledFileDiffProps < LAnnotation > ) {
363+ const diffColorScheme = useClientSettings ( ( settings ) => settings . diffColorScheme ) ;
364+ const diffIndicatorStyle = useClientSettings ( ( settings ) => settings . diffIndicatorStyle ) ;
365+
366+ return (
367+ < FileDiff < LAnnotation >
368+ { ...props }
369+ className = { getDiffSurfaceClassName ( diffColorScheme , className ) }
370+ options = { {
371+ ...options ,
372+ diffIndicators : diffIndicatorStyle ,
373+ unsafeCSS : DIFF_SURFACE_THEME_UNSAFE_CSS ,
374+ } }
375+ />
376+ ) ;
377+ }
0 commit comments