Skip to content

Schema

Each brick requires a schema property, which defines the brick name, default props, sidebar controls and other things.

Required props

Th required props are just two:

  • name: a name for this brick. It must be unique within the bricks configured for an App
  • label: the name displayed for this brick in the editing interface

Let’s see a first simple example of a brick’s schema:

Usage Example

TextImage.tsx
const TextImage: types.Brick<TextImageProps> = ({...}) => {
return (
...
)
}
TextImage.schema = {
name: 'text-image',
label: 'Text Image',
previewImageUrl: imgPreview.src,
getDefaultProps: () => ({
title: 'Thick as a brick',
description: 'Another brick in the wall',
imageSide: 'right',
}),
sideEditProps: [
{
name: 'imageSide',
label: 'Image Side',
type: types.SideEditPropType.Select,
selectOptions: {
display: types.OptionsDisplay.Radio,
options: [
{ value: 'left', label: 'Left' },
{ value: 'right', label: 'Right' },
],
},
},
],
}

Schema Properties

Let’s analyze the schema properties dividing them in 3 groups:

1. Key Properties

Apart from name and label, there are other key properties defined in the schema.

Click on the property to access the dedicated page in the documentation:

3. UI and Categorization

PropertyDescription
hideFromAddMenuHide this brick from the “Add new brick” menu. Useful to prevent editors to add directly to a page bricks that are meant to be used only when repeated within another brick.
previewImageUrlImage of the brick shown in the “Add new brick” selection on the right sidebar.
tagsA set of tags to help content editors find this brick with the search function (for example, add “cta”, “call to action”, “link” to a “CallToAction” brick)
playgroundLinkUrlShow a link in the Playground for this brick: for example to an external design guideline.
playgroundLinkLabelLabel for the Playground link.

Typings for Schema

Schema interface
interface IBlockType<T = Props> {
name: string
label: string
getDefaultProps?: () => Partial<T>
hideFromAddMenu?: boolean
sideEditProps?: Array<ISideEditProp<T> | ISideGroup<T>>
repeaterItems?: IRepeaterItem[]
newItemMenuOpen?: boolean
groupByRepeater?: boolean
getExternalData?: (
page: Page,
brickProps?: T,
args?: any
) => Promise<Partial<T>>
mapExternalDataToProps?: (externalData: Props, brickProps?: T) => Partial<T>
playgroundLinkUrl?: string
playgroundLinkLabel?: string
theme?: string
category?: string
tags?: string[]
previewImageUrl?: string
previewIcon?: React.ReactElement
stories?: BrickStory<Partial<T>>[]
}

Properties definition

PropertyDefinition
nameThe unique name for this block type (for example “hero-unit”). The “RB_PAGE_EMBED” name is reserved and should be used only for an embed brick.
labelThe name displayed in the Sidebar when you want to add a new block (for example “Hero Unit”).
getDefaultPropsA function returning the default props for new added blocks.
hideFromAddMenuIf true, the component isn’t shown in the list of components available in the “add block” menu. For example, you may want to hide a block that can be used only inside of a <Repeater />.
sideEditPropsThe array of objects representing the props the user will be able to modify in the right Sidebar, with their display properties. See Side Edit Props.
repeaterItemsArray to specify behaviour of the bricks used in the <Repeater> components. See Repeater.
newItemMenuOpenIf true the “Add new…” accordion menu is open by default; if false it is closed by default; otherwise, by default it is open when the number of repeaterItems is less than or equal to 4 and closed otherwise.
groupByRepeaterfalse by default. If set to true the items that can be repeated are grouped by repeater (if you set the positionLabel the title of each collapsible section is the positionLabel).
getExternalDataFunction to fetch external data. It has the page, the brick’s props and a third argument as arguments and should return (async) an object which is merged to the brick’s props. See External content.
mapExternalDataToPropsFunction that gets as first argument the external data (from the getExternalData function specified on the pageType) and as second argument the props on this brick. It should return the new props for this brick. See External content.
playgroundLinkUrlUrl to link in the Playground, for example to link docs, guidelines, etc.
playgroundLinkLabelText for the link in the Playground, for example to link docs, guidelines, etc.
categoryUsed to categorize bricks. Bricks will be shown grouped by category.
tagsTags are used to search bricks in the Admin interface.
previewImageUrlImage URL to be used as preview image for this brick. You can create easily a “screenshot image” of a brick from the Playground. It is shown only if you set the enablePreviewImage flag to true in the React Bricks configuration.
storiesYou may define default stories on a brick. Editors will be able to add their own stories saved on the React Bricks APIs. This feature is available only for “Pro” and upper plans. See Stories and the BrickStory type