Function: defineBlock()
defineBlock<
Schema,Component>(block):Block<Schema,Component>
Defined in: packages/core/src/defineBlock.ts:45
Declares a block — the name documents resolve through, the schema its props are validated
against, the component that renders it, and the slots it accepts children in. The block comes
back unchanged, with Schema and Component pinned at the call site so InferProps derives
the component's props from the schema.
Type Parameters
Schema
Schema extends StandardSchemaV1<unknown, unknown>
The block's Standard Schema. Inferred from
block.schema; validation always runs its ~standard.validate, which must answer
synchronously.
Component
Component
Whatever the consumer's renderer accepts. core never inspects it.
Parameters
block
Block<Schema, Component>
The block to declare. version must be an integer of 1 or more, and every slot
declaring both bounds must keep min at or below max. Names in a slot's allow are not
resolved here — createRegistry resolves them once every sibling is present.
Returns
Block<Schema, Component>
The same object, typed Block<Schema, Component>.
Throws
block-version when version is not an integer of 1 or more.
Throws
slot-bounds when a slot's min exceeds its max, naming the block and
the slot in at.
Example
import { defineBlock } from "@nubbin/core";
import type { InferProps } from "@nubbin/core";
import { z } from "zod";
const heroSchema = z.object({
headline: z.string(),
tone: z.enum(["light", "dark"]),
});
const Hero = (props: InferProps<typeof heroSchema>) => null;
export const heroBlock = defineBlock({
name: "Hero",
schema: heroSchema,
component: Hero,
version: 1,
slots: { actions: { allow: ["CtaBanner"], max: 2 } },
});