BrickDefinitioninterface
import { BrickDefinition } from '@mortar-kit/core'
interface BrickDefinition<F extends Fields, L = undefined, R = undefined>What a developer passes to defineBrick.
Properties
name: stringStable identifier stored in entries. Lowercase, e.g.
heroorfeature-grid.label?: stringHuman-readable name for the admin panel. Defaults to
name.schema: FThe 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
datafields it depends on before the firstawait: changing those loads again, changing others doesn't. Return plain JSON. Write it beforecomponent, soprops.loadedgets 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 storeddata; what it returns (plain JSON) reaches the component asprops.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 fromcontext, not from imports. Write it beforecomponent, so the result gets its type.interactive?: booleanRuns 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. Itsdata, whatloadreturned and its latest submission are sent along in the HTML (plain JSON), andloaddoesn'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(andprops.loaded,props.submission); don't destructure props.