← @mortar-kit/core

BrickDefinitioninterface

import { BrickDefinition } from '@mortar-kit/core'

interface BrickDefinition<F extends Fields, L = undefined, R = undefined>

What a developer passes to defineBrick.

Properties

name: string

Stable identifier stored in entries. Lowercase, e.g. hero or feature-grid.

label?: string

Human-readable name for the admin panel. Defaults to name.

schema: F

The editable fields, built with fields.*.

load?: (data: InferFields<F>, content: ContentReader) => L | Promise<L>

Loads what the brick shows besides its own data, e.g. the latest posts. Runs on the server when the page renders (pages without JavaScript included) and in the browser in the admin preview, where it reads saved content (not unsaved edits to other documents), again after each save. Read the data fields it depends on before the first await: changing those loads again, changing others doesn't. Return plain JSON. Write it before component, so props.loaded gets its type.

action?: (input: ActionInput<InferFields<F>>) => R | Promise<R>

Handles a post of the brick's form (<ActionForm> in its component). Runs on the server only, through the app's runner (Content.runAction), which reads the entry's stored data; what it returns (plain JSON) reaches the component as props.submission.result. Without JavaScript the post reloads the page with the result; with it, only the brick updates. The brick's module also reaches the browser, so take server-only services from context, not from imports. Write it before component, so the result gets its type.

interactive?: boolean

Runs the brick in the browser (an island) on pages that are otherwise plain HTML: the page loads JavaScript only when it shows a brick like this, and only this brick hydrates; the rest of the page stays static. Its form (<ActionForm>) then posts in the background and updates only the brick. Its data, what load returned and its latest submission are sent along in the HTML (plain JSON), and load doesn't run again in the browser. Default false: the brick is server-rendered HTML. Pages that hydrate as a whole (the admin) render it like any other brick.

component: Component<BrickProps<InferFields<F>, L, R>>

Renders the brick. Read props.data.x (and props.loaded, props.submission); don't destructure props.