Features
Libraries
A multi-file code editor that keeps the open files and the active one in context, and routes each file to a code, Markdown, image or font view.
Installation#
bash
pnpm dlx shadcn@latest add @zui/code-editorUsage#
tsx
import { CodeEditor, CodeEditorContent, type RoutedFile } from '@/components/editor/code';tsx
function Project({ files }: { files: RoutedFile[] }) {
return (
<CodeEditor files={files} defaultValue="README.md" onFileTextChange={save}>
<CodeEditorContent>Pick a file.</CodeEditorContent>
</CodeEditor>
);
}CodeEditor holds the open files and the active path and draws nothing; lay out a tree, a menu and CodeEditorContent inside it, and read the selection with useCodeEditor. It keeps no text of its own, so the host stores each file and reacts to onFileTextChange. A file's view says how it is shown: code, markdown, image, font or binary, and fileView classifies a path by its extension.
API reference#
CodeEditor#
| Prop | Type | Default |
|---|---|---|
files | RoutedFile[] | - |
value | string | - |
defaultValue | string | - |
onValueChange | (path: string) => void | - |
onFileTextChange | (path: string, text: string) => void | - |
readOnly | boolean | false |