Search Documentation

Search for components, guides, and more.

Code Editor

A premium code editor component powered by Monaco Editor with syntax highlighting, language selection, and customizable action buttons.


Installation

pnpm dlx shadcn@latest add https://chatcn.me/c/code-editor


Props

CodeEditor

PropTypeDefaultDescription
valuestring""Initial code value
onValueChange(value: string) => void-Callback when value changes
languagestring"python"Programming language
onLanguageChange(language: string) => void-Callback when language changes
languagesLanguage[]DEFAULT_LANGUAGESCustom languages array
themestring"vs-dark"Monaco editor theme
disabledbooleanfalseDisable the editor
childrenReact.ReactNode-Header, Area, Footer components
classNamestring-Additional CSS classes

CodeEditorHeader

PropTypeDefaultDescription
childrenReact.ReactNode-Action buttons
classNamestring-Additional CSS classes
showLanguageSelectorbooleantrueShow/hide language dropdown

CodeEditorActions

Container for action buttons. Accepts standard div props.

PropTypeDefaultDescription
childrenReact.ReactNode-CodeEditorAction components
classNamestring-Additional CSS classes

CodeEditorAction

Wrapper for individual action buttons with tooltip and micro-interactions.

PropTypeDefaultDescription
tooltipReact.ReactNode-Tooltip content
childrenReact.ReactNode-Button element
animatebooleantrueEnable hover/tap animations
side"top" | "bottom" | "left" | "right""top"Tooltip position
classNamestring-Additional CSS classes

CodeEditorArea

PropTypeDefaultDescription
loaderReact.ReactNode-Custom loading component
classNamestring-Additional CSS classes
heightstring | number"400px"Editor height
widthstring | number"100%"Editor width

CodeEditorFooter

PropTypeDefaultDescription
childrenReact.ReactNode-Custom content
classNamestring-Additional CSS classes
showStatusbooleantrueShow status indicator
showLanguagebooleantrueShow language name with icon
showLineNumberbooleantrueShow cursor line/column
showCharCountbooleantrueShow character count
statusTextstring"Ready"Status indicator text

CodeEditorDivider

Visual separator between action buttons. No props.


Hooks

useCodeEditor

Access editor state and actions from within CodeEditor children.

const { value, setValue, language, setLanguage } = useCodeEditor()
PropertyTypeDescription
valuestringCurrent code value
setValue(v: string) => voidUpdate code value
languagestringCurrent language
setLanguage(l: string) => voidChange language
languagesLanguage[]Available languages
cursorLinenumberCurrent cursor line
cursorColumnnumberCurrent cursor column
disabledbooleanEditor disabled state

Animation Constants

Exported animation objects for customization:

import { ACTION_ANIMATION, SPINNER_ANIMATION, PULSE_ANIMATION } from "@/components/chatcn/ai/code-editor"
ConstantDescription
ACTION_ANIMATIONHover/tap scale effect for buttons
SPINNER_ANIMATIONLoading spinner rotation
PULSE_ANIMATIONStatus indicator pulse

Custom Languages

Pass your own languages array via the languages prop:

const MY_LANGUAGES: Language[] = [
  { value: "python", label: "Python", icon: "https://..." },
  { value: "rust", label: "Rust" }, // icon is optional
]
 
<CodeEditor languages={MY_LANGUAGES}>

Default Languages