mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 08:36:01 +00:00
28 lines
891 B
TypeScript
28 lines
891 B
TypeScript
import type { ReactCodeMirrorProps } from "@uiw/react-codemirror";
|
|
import { Suspense, lazy } from "react";
|
|
import { useBknd } from "ui/client/bknd";
|
|
const CodeMirror = lazy(() => import("@uiw/react-codemirror"));
|
|
|
|
export default function CodeEditor({ editable, basicSetup, ...props }: ReactCodeMirrorProps) {
|
|
const b = useBknd();
|
|
const theme = b.app.getAdminConfig().color_scheme;
|
|
const _basicSetup: Partial<ReactCodeMirrorProps["basicSetup"]> = !editable
|
|
? {
|
|
...(typeof basicSetup === "object" ? basicSetup : {}),
|
|
highlightActiveLine: false,
|
|
highlightActiveLineGutter: false
|
|
}
|
|
: basicSetup;
|
|
|
|
return (
|
|
<Suspense>
|
|
<CodeMirror
|
|
theme={theme === "dark" ? "dark" : "light"}
|
|
editable={editable}
|
|
basicSetup={_basicSetup}
|
|
{...props}
|
|
/>
|
|
</Suspense>
|
|
);
|
|
}
|