mirror of
https://github.com/ershisan99/DevToysWeb.git
synced 2025-12-16 20:49:23 +00:00
feat: implement text diff tool
This commit is contained in:
30
components/ui/diff-editor.tsx
Normal file
30
components/ui/diff-editor.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
"use client";
|
||||
|
||||
import { ComponentPropsWithoutRef, forwardRef } from "react";
|
||||
import { DiffEditor as MonacoDiffEditor } from "@monaco-editor/react";
|
||||
import { useTheme } from "next-themes";
|
||||
|
||||
export type EditorProps = ComponentPropsWithoutRef<typeof MonacoDiffEditor>;
|
||||
|
||||
export const DiffEditor = forwardRef<HTMLTextAreaElement, EditorProps>(
|
||||
({ options, theme, ...props }, ref) => {
|
||||
const { theme: appTheme } = useTheme();
|
||||
const themeToUse = theme ?? (appTheme === "light" ? "light" : "vs-dark");
|
||||
|
||||
return (
|
||||
<MonacoDiffEditor
|
||||
{...{ ref }}
|
||||
theme={themeToUse}
|
||||
options={{
|
||||
tabFocusMode: true,
|
||||
automaticLayout: true,
|
||||
scrollBeyondLastLine: false,
|
||||
...options, // NOTE: merge shallowly
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
DiffEditor.displayName = "Editor";
|
||||
Reference in New Issue
Block a user