Skip to content
Redpanda UI
Esc
↑↓navigate↵open⌘Jpreview
Made by imskyleen
Edit on GitHub

Code Editor

A read-only code display with syntax highlighting, a file header, and optional copying.

Installation

bash
npx shadcn@latest add @redpanda/code-editor
bash
pnpm dlx shadcn@latest add @redpanda/code-editor
bash
yarn dlx shadcn@latest add @redpanda/code-editor
bash
bunx shadcn@latest add @redpanda/code-editor
bash
nubx shadcn@latest add @redpanda/code-editor
bash
aube dlx shadcn@latest add @redpanda/code-editor

Usage

tsx
<CodeEditor lang="tsx">  {`const a = 1;const b = 2;const c = a + b;`}</CodeEditor>

If you want to toggle between light and dark themes, you can use the theme prop.

tsx
<CodeEditor lang="tsx" theme="dark">  {`const a = 1;const b = 2;const c = a + b;`}</CodeEditor>

When to use

Use CodeEditor for a framed, read-only source example with a file title and optional copying. Use Code Comparison for side-by-side differences. CodeEditor does not edit text or animate typing.

Highlighting starts immediately by default. Set inView to defer it until the code enters the viewport. onDone runs after highlighting succeeds, not after a typing animation.

Props

PropType
childrenstring

The code to display in the editor.

Typestring
langstring

The language of the code.

Typestring
themes?{ light: string; dark: string }

The theme of the code editor (see https://shiki.style/themes).

Type{ light: string; dark: string }
Default{ light: "github-light-high-contrast"; dark: "github-dark-default" }
theme?"light" | "dark" | "system"

Select a palette explicitly, or follow the application theme.

Type"light" | "dark" | "system"
Default"system"
header?boolean

Whether to show the header.

Typeboolean
Defaulttrue
dots?boolean

Whether to show the top left dots.

Typeboolean
Defaulttrue
icon?React.ReactNode

The icon to display in the header.

TypeReact.ReactNode
inView?boolean

Defer highlighting until the code enters the viewport.

Typeboolean
Defaultfalse
inViewMargin?string

The intersection margin used to detect visibility.

Typestring
Default0px
inViewOnce?boolean

Stop observing visibility after the first viewport entry.

Typeboolean
Defaulttrue
copyButton?boolean

Whether to show the copy button.

Typeboolean
Defaultfalse
title?string

The file name.

Typestring
onDone?() => void

Callback after syntax highlighting succeeds.

Type() => void
onCopy?(content: string) => void

The function to call when copy is successful.

Type(content: string) => void

Credits

Recent changes

  • patchv1.2.0Pin shipped dependency floors to the version we develop against. Registry items now declare ranges like `^5.1.9` (the actual installed version) instead of collapsing to `^5.0.0`, so consumers start on the known-tested baseline while caret semantics still allow any compatible release within the same major.#133
  • minorv1.1.0Theme docs refresh, readability pass on semantic foregrounds, and consumer-facing Base UI regression fixes.#121
  • minorv1.0.0Post-Base-UI polish. Public API unchanged.#116
  • majorv1.0.0Migrate every Radix-based primitive to `@base-ui/react@^1.4.0` (Base UI).#114
  • minorv0.3.0Add theme-provider component to the registry with documentation and tests. Includes playground type improvements (export RegistryItem, remove as-const boilerplate) and docs site dark mode border color fix.#109
See full history →

Last updated on

Was this page helpful?