diff --git a/src/components/common/code-editor.tsx b/src/components/common/code-editor.tsx new file mode 100644 index 0000000..62e06b4 --- /dev/null +++ b/src/components/common/code-editor.tsx @@ -0,0 +1,76 @@ +"use client"; + +import dynamic from "next/dynamic"; +import { useEffect, useState } from "react"; +import { Code2 } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { useUiStore } from "@/stores/ui-store"; + +const MonacoEditor = dynamic(() => import("@monaco-editor/react"), { + ssr: false, + loading: () =>
, +}); + +export function CodeEditor({ + title, + language, + value, + autoLoad = false, +}: { + title: string; + language: string; + value: string; + autoLoad?: boolean; +}) { + const themePref = useUiStore((state) => state.theme); + const [dark, setDark] = useState(true); + const [open, setOpen] = useState(autoLoad); + + useEffect(() => { + const frame = requestAnimationFrame(() => { + setDark(document.documentElement.classList.contains("dark")); + }); + return () => cancelAnimationFrame(frame); + }, [themePref]); + + return ( +
+ {value}
+
+
+ >
+ )}
+