Skip to contentSkip to navigationSkip to topbar
Paste assistant Assistant
Figma
Star

Code Editor

Version 3.0.1GithubStorybook

A library to display and make changes to large blocks of code.


About

About page anchor

The Code Editor library is the code editor that powers the stylized Editable Code Block component. It allows for full code-editing functionality on the web, including syntax highlighting and displaying line numbers.

This library is built on top of monaco-react(link takes you to an external page), which wraps the Monaco Editor(link takes you to an external page). The library exposes a theme for use in Twilio products, aptly called the PasteTheme. This theme is based on the Night Owl theme by Sarah Drasner(link takes you to an external page).

(information)

Are you looking for stylized UI components?

For fully styled components, use the Editable Code Block. Or if you don't need editing functionality, use the Code Block.

Installation

Installation page anchor
yarn add @twilio-paste/code-editor-library - or - yarn add @twilio-paste/core
<CodeEditor
  height="90vh"
  defaultLanguage="javascript"
  defaultValue={JavascriptExample}
/>

Code Editor with PasteTheme

Code Editor with PasteTheme page anchor

const handleEditorDidMount = (editor: Editor.IStandaloneCodeEditor, monaco: Monaco): void => {
  monaco.editor.defineTheme('paste', CodeEditorPasteTheme);
  monaco.editor.setTheme('paste');
};
const PasteThemeEditor = (): React.ReactNode => {
  return (
    <CodeEditor
      onMount={handleEditorDidMount}
      options={{
        scrollBeyondLastLine: false,
        readOnly: false,
        wordWrap: 'wordWrapColumn',
        wordWrapColumn: 120,
        scrollbar: {
          verticalScrollbarSize: 8,
          horizontalScrollbarSize: 8,
        },
      }}
      height="70vh"
      defaultLanguage="typescript"
      defaultValue={TypescriptExample}
    />
  );
};

See more examples on our Storybook(link takes you to an external page).