The schema property
Each brick should have a schema
static property, which has the following TypeScript interface:
Properties
interface IBlockType { name: string label: string // for the Add menu getDefaultProps: () => object hideFromAddMenu?: boolean sideEditProps?: Array<ISideEditProp | ISideGroup> repeaterItems?: IRepeaterItem[] playgroundLinkUrl?: string playgroundLinkLabel?: string}
The ISideEditProp
/ ISideGroup
interface is explained in the Side edit props page.
The Repeater
interface is explained in the Repeater page.
Properties definition
Property | Definition |
---|---|
name | The unique name for this block type (for example "hero-unit"). |
label | The name displayed in the Sidebar when you want to add a new block (for example "Hero Unit"). |
getDefaultProps | A function returning the default props for new added blocks. |
hideFromAddMenu | If 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 /> . |
sideEditProps | The 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. |
repeaterItems | Array to specify behaviour of the bricks used in the <Repeater> components. See Repeater. |
playgroundLinkUrl | Url to link in the Playground, for example to link docs, guidelines, etc. |
playgroundLinkLabel | Text for the link in the Playground, for example to link docs, guidelines, etc. |
Usage example
HeroUnit.schema = { name: 'hero-unit', label: 'Hero Unit', // Defaults when a new brick is added getDefaultProps: () => ({ background: { color: '#fff', className: 'bg-white' }, title: 'Thick as a React Brick', }), // Sidebar Edit props sideEditProps: [ { name: 'background', label: 'Background', type: types.SideEditPropType.Select, selectOptions: { display: types.OptionsDisplay.Color, options: [ // The color is the unique mandatory property for a "color" select { value: { color: '#fff', className: 'bg-white' }, label: 'White' }, { value: { color: '#f3f4f6', className: 'bg-gray-100' }, label: 'Gray', }, ], }, }, ],}