For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign in
DocsAPI ReferenceChangelog
DocsAPI ReferenceChangelog
  • Get started
    • Quickstart
    • Concepts
  • Guides
    • Environments
  • Reference
        • Checkbox
        • Code
        • Color
        • Combobox
        • Group
        • Image
        • Font
        • Link
        • List
        • Number
        • Rich Text
        • Select
        • Slot
        • Style
        • Text Area
        • Text Input
      • Makeswift API Handler
    • Product docs
    • Blog
    • Support
Sign in
LogoLogo
On this page
  • Params
  • Prop type
  • Editor
  • Example
Reference@makeswift/runtimeControls

Code

Was this page helpful?
Previous

Checkbox

Next

Color

Built with

Adds a Code editor in the Makeswift builder to visually edit a string of source code, with syntax highlighting.

A Code panel editing an HTML snippet

Params

label
stringDefaults to Code

Text for the panel label in the Makeswift builder.

description
string

The description shown in the Panel of the Makeswift builder. This can be written in Markdown format. Added in v0.24.8.

defaultValue
string

The value passed to your component when nothing is set in the Makeswift builder.

Prop type

The Code control passes an object of shape { value: string } to your component, where value contains the source code as a string. If you don’t set a defaultValue and no value is set in the builder, your component receives undefined.

Editor

The Code panel opens a full-screen editor powered by Monaco (the editor used in VS Code). Syntax highlighting is applied automatically — the editor detects the language from the content rather than exposing a language picker. Detection covers common languages including JavaScript, TypeScript, HTML, CSS, JSON, YAML, Markdown, Python, Ruby, Go, Rust, Java, PHP, SQL, shell, and others. When the language can’t be confidently detected, the editor falls back to plaintext.

Example

The following example adds a Code control to the snippet prop of a CodeBlock component.

1import { Code, Style } from "@makeswift/runtime/controls";
2
3import { runtime } from "../../../../../makeswift/runtime";
4
5import { CodeBlock } from "./CodeBlock";
6
7runtime.registerComponent(CodeBlock, {
8 type: "code-block",
9 label: "Code Block",
10 props: {
11 className: Style(),
12 snippet: Code({
13 label: "Snippet",
14 defaultValue: 'console.log("Hello, world!");',
15 }),
16 },
17});

.makeswift.ts is a naming convention for organizing Makeswift registration code. Learn more.