import { BetweenHorizontalStart, Expand, FoldVertical, Hash, ImageOff, Rows3, Ruler, SquareSplitVertical, TextCursorInput, Type, UnfoldVertical, WholeWord, WrapText, } from "lucide-react"; import { type ComponentType, useMemo } from "react"; import { Label } from "@/components/ui/label"; import { NumberStepperInput } from "@/components/ui/number-stepper-input"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { getDetectedFontOptionFromValue, useDetectedMonospaceFontOptions } from "@/lib/detected-monospace-fonts"; import { type DiffOptions, useDiffOptions } from "@/lib/diff-options-context"; import { FONT_FAMILY_OPTIONS, type FontFamilyValue, isDetectedFontFamilyValue } from "@/lib/font-options"; type BooleanOptionKey = { [K in keyof DiffOptions]: DiffOptions[K] extends boolean ? K : never; }[keyof DiffOptions]; type NumberOptionKey = { [K in keyof DiffOptions]: DiffOptions[K] extends number ? K : never; }[keyof DiffOptions]; type IconComponent = ComponentType<{ className?: string }>; function SettingLabel({ label, icon: Icon, htmlFor }: { label: string; icon: IconComponent; htmlFor?: string }) { return ( ); } function OptionSelect({ label, icon, optionKey, values, }: { label: string; icon: IconComponent; optionKey: K; values: readonly DiffOptions[K][]; }) { const { options, setOption } = useDiffOptions(); return (
); } function OptionSwitch({ label, icon: Icon, optionKey }: { label: string; icon: IconComponent; optionKey: BooleanOptionKey }) { const { options, setOption } = useDiffOptions(); return (
setOption(optionKey, v)} size="sm" />
); } function OptionNumber({ label, icon, optionKey, min, max, step, disabled = false, }: { label: string; icon: IconComponent; optionKey: NumberOptionKey; min?: number; max?: number; step?: number; disabled?: boolean; }) { const { options, setOption } = useDiffOptions(); return (
setOption(optionKey, value)} min={min} max={max} step={step} disabled={disabled} className="w-full" />
); } export function DiffToolbar() { const { options, setOption } = useDiffOptions(); const detectedMonospaceFonts = useDetectedMonospaceFontOptions(); const resolvedDetectedFonts = useMemo(() => { if (!isDetectedFontFamilyValue(options.diffFontFamily)) return detectedMonospaceFonts; if (detectedMonospaceFonts.some((font) => font.value === options.diffFontFamily)) return detectedMonospaceFonts; const fallback = getDetectedFontOptionFromValue(options.diffFontFamily); return fallback ? [...detectedMonospaceFonts, fallback] : detectedMonospaceFonts; }, [detectedMonospaceFonts, options.diffFontFamily]); return (
setOption("diffUseCustomTypography", value)} size="sm" />
); }