Components

CodesparkEditor

A flexible code editor component supporting Monaco Editor and CodeMirror.

CodesparkEditor is a standalone code editor component that supports both Monaco Editor and CodeMirror as the underlying editor engine. It integrates with the Workspace for file management and automatic compilation.

import { CodesparkEditor } from '@codespark/react';

Basic Usage

<CodesparkEditor value="some code..." />

Props

value

Initial code content for the editor.

TypeDefaultSince
string-v1.0.0
< ="export default () => <div>Hello</div>" />

theme

Theme mode for the editor.

TypeDefaultSince
'light' | 'dark'Inherited from contextv1.0.0
< ="dark" />

editor

Editor engine component to use.

TypeDefaultSince
typeof Monaco | typeof CodeMirrorCodeMirrorv1.0.0
import {  } from '@codespark/react';
import {  } from '@codespark/react/Monaco';

< ={} />

height

Height of the editor. For CodeMirror, pass a CSS string. For Monaco, pass a number (pixels).

TypeDefaultSince
string | number200 / '100%'v1.0.0
// CodeMirror (default)
< ="300px" />

// Monaco
< ={Monaco} ={300} />

width

Width of the editor.

TypeDefaultSince
string | number-v1.0.0
< ="100%" />

toolbox

Toolbar configuration. Set to false to hide, true to show default tools, or pass a custom array.

TypeDefaultSince
boolean | (ToolboxItemId | ToolboxItemConfig | ReactElement)[]['reset', 'format', 'copy']v1.0.0

Built-in tool IDs:

  • 'reset' - Reset code to initial state
  • 'format' - Format the code
  • 'copy' - Copy code to clipboard
import {  } from '@codespark/react';
// Hide toolbar
< ={false} />

// Custom toolbar
< ={['copy', 'format']} />

// Custom tool item
<
  ={[
    'copy',
    {
      : 'My Custom Action',
      : <MyIcon />,
      :  => .(?.)
    }
  ]}
/>

workspace

Workspace instance to use for file management.

TypeDefaultSince
WorkspaceInherited from contextv1.0.0
import { ,  } from '@codespark/react';

const  = new ({
  : './App.tsx',
  : { './App.tsx': 'export default () => <div>Hello</div>' }
});

< ={} />

className

CSS class name for the editor element.

TypeDefaultSince
string-v1.0.0
< ="my-editor" />

containerProps

Props to pass to the container div element.

TypeDefaultSince
ComponentProps<'div'>-v1.0.0
<CodesparkEditor containerProps={{ className: 'h-full' }} />

debounceWait

Debounce wait time in milliseconds for triggering workspace updates on code changes.

TypeDefaultSince
number500v1.0.0
< ={300} />

id

Unique identifier for the editor instance.

TypeDefaultSince
stringAuto-generatedv1.0.0
< ="main-editor" />

CodeMirror-specific Props

These props only apply when using the default CodeMirror editor:

readOnly

Whether the editor is read-only.

TypeDefaultSince
booleanfalsev1.0.0
<  />

fontFamily

Font family for the editor.

TypeDefaultSince
string'Fira Code'v1.0.0
< ="JetBrains Mono" />

extensions

Additional CodeMirror extensions.

TypeDefaultSince
Extension[]-v1.0.0
import { javascript } from '@codemirror/lang-javascript';

<CodesparkEditor extensions={[javascript()]} />

basicSetup

CodeMirror basic setup configuration.

TypeDefaultSince
BasicSetupOptions-v1.0.0
< ={{ : false }} />

onChange

Callback fired when the editor content changes.

TypeDefaultSince
(value: string, viewUpdate: ViewUpdate) => void-v1.0.0
< ={ => .()} />

onMount

Callback fired when the editor is mounted.

TypeDefaultSince
(editor: EditorView) => void-v1.0.0
< ={ => .focus()} />

Monaco-specific Props

These props only apply when using Monaco Editor:

options

Monaco editor options.

TypeDefaultSince
IStandaloneEditorConstructionOptions-v1.0.0
import {  } from '@codespark/react';
import {  } from '@codespark/react/Monaco';

<
  ={}
  ={{
    : true,
    : { : true },
    : true,
    : 'off'
  }}
/>

wrapperProps

Props for the Monaco editor wrapper element.

TypeDefaultSince
HTMLAttributes<HTMLDivElement>-v1.0.0
< ={} ={{ : '...' }} />

onChange

Callback fired when the editor content changes.

TypeDefaultSince
(value: string, event: IModelContentChangedEvent) => void-v1.0.0
< ={} ={(, ) => ...} />

onMount

Callback fired when the editor is mounted.

TypeDefaultSince
(editor: IStandaloneCodeEditor, monaco: Monaco) => void-v1.0.0
< ={} ={(, ) => ...} />

Last updated on