MonacoJsonField

Shows a JSON value in a read-only Monaco editor.

Installation

pnpm dlx shadcn@latest add @chelone/monaco
Loading preview…

<MonacoJsonField> shows a JSON value, or a string of JSON, in a read-only Monaco editor with syntax highlighting and folding. Use it where the value is long enough to want a real editor, such as a show view.

It is an add-on installed from the registry, with Monaco as an optional peer dependency. The MonacoJsonInput page covers installing it and how Monaco loads.

In a show view

import { RecordField, Show } from "@chelone/react";
import { MonacoJsonField } from "@/components/monaco/monaco-json-field";
 
export const IntegrationShow = () => (
  <Show>
    <RecordField source="settings">
      <MonacoJsonField source="settings" maxHeight={320} />
    </RecordField>
  </Show>
);

The editor grows with the content up to maxHeight. Set autoHeight={false} to use a fixed height instead.

For a list cell, use JsonField. It renders plain text in a <pre> and loads no editor, so a datagrid of many rows stays light.

Props

PropTypeDefaultDescription
autoHeightboolean—Grow with the content up to `maxHeight`. Defaults to true.
cellClassNamestring—A class name to apply to the cell element when used inside `<DataTable>`.
classNamestring—A class name to apply to the root element.
defaultValueSourceValue<RecordType, SourceProp<RecordType>>—Shown when the record has no value at `source`.
emptyReactNode—The node to display when the field value is empty. Defaults to nothing. A string is translated; a ReactNode renders as-is.
headerClassNamestring—A class name to apply to the header cell element when used inside `<DataTable>`.
heightnumber—Editor height in pixels when `autoHeight` is false. Defaults to 200.
labelReactNode—Label to use as column header when using `<DataTable>` or `<SimpleShowLayout>`. Defaults to the capitalized field name. Set to `false` to disable the label.
maxHeightnumber—Tallest the editor grows to when `autoHeight` is on. Defaults to 400.
monacoOptionsIStandaloneEditorConstructionOptions—Merged over the read-only defaults, so it can override any of them.
recordRecordType—The record to render. Defaults to the ambient `RecordContext` value.
resourcestring—The resource name. Defaults to the ambient `ResourceContext` value.
sortableboolean—Disable the header click handler when used inside `<DataTable>`.
sortBystring—The field to sort by when this column head is clicked, if sortable.
sortByOrderSortOrder—The order used for sorting when this column head is clicked, if sortable.
sourceSourceProp<RecordType>—Name of the property to display (dot/bracket path).
textAlignTextAlign—The text alignment for the cell content, when used inside `<DataTable>`.