Skip to content

defineLayoutComponent

Read as Markdown

defineLayoutComponent(describe) defines reusable pure structure that a layout parent can inspect before allocating it. It returns a PibblComponent for JSX or createElement. Its result is PibblNodeInput:

import {
Flex,
Rectangle,
Text,
defineLayoutComponent,
type FlexStyle,
} from "@pibbl/core";
type CardProps = { title: string; style: FlexStyle };
const Card = defineLayoutComponent(({ title, style }: CardProps) => (
<Flex style={{ ...style, flexDirection: "column", padding: 8 }}>
<Text style={{ minHeight: 0, flexShrink: 0, wrap: true }}>{title}</Text>
</Flex>
));
export function CardExample() {
return (
<Flex style={{ width: 240, height: 220, flexDirection: "column", gap: 12 }}>
<Card
title="A reusable title that can wrap"
style={{ maxWidth: 224, minHeight: 0, flexShrink: 0 }}
/>
<Rectangle
style={{
width: 240,
height: 24,
minHeight: 0,
flexShrink: 0,
fill: "#426b61",
}}
/>
</Flex>
);
}

The callback receives readonly authored props and returns one drawing or layout primitive root, optionally inside transparent fragments. Forward a style prop explicitly when your component exposes one. Existing signal reads are allowed; hooks, Canvas access, allocation reads, signal writes and resource creation are excluded. State and owned resources belong in an ordinary parent component.

One prepared description is shared by measurement and painting within the current render transaction. Later transactions prepare again, so nested mutable props are never assumed unchanged merely because their outer identity is stable. The Card and its returned root retain their ordinary type/key identity and cleanup rules. An ordinary component remains opaque to intrinsic measurement.

This initial capability uses existing measurement support: a finite-width nowrap column containing wrapped Text is supported by the default native layout engine. Nested Cards below known nowrap-column roots use that same settled-width path, with each description prepared once per receiver and transaction. Descriptor cycles retain the existing cyclic-measurement diagnostic. A finite LTR forward nowrap row may also query a described root with both measureIntrinsic and measure, using its content minimum as the automatic shrink floor. The query shares the description, receiver dependencies and bounded measurement cache with the current transaction; unrelated sibling paint can reuse a successful measurement. Ordinary components remain opaque. Other intrinsic structures retain contextual unsupported-measurement diagnostics; this does not enable general CSS sizing or switch the production layout engine.

A known forward LTR nowrap Flex row with definite numeric width can derive its automatic height from paired custom leaves after their native main allocation. Leaves require definite numeric bases and explicit minima; siblings need declared cross sizes. The nested intrinsic lesson shows width-dependent height moving a following target. Percentage feedback, wrapping and aggregate structural paint reuse remain open.

Defines pure reusable structure that a parent can inspect before allocation. The description returns one drawing or layout primitive root, optionally inside transparent fragments. Forward any authored style explicitly to that root. Signal reads are supported; hooks, Canvas/allocation reads, writes and resource creation are excluded. Descriptions are shared only within one transaction.

defineLayoutComponent: <P>(describe: (props: Readonly<P>) => PibblNodeInput) => PibblComponent<P>

Related API: defineLayoutComponent, PibblNodeInput, PibblComponent.

  • describe — Pure synchronous description using authored readonly props.

A component for JSX or createElement, preserving normal type/key identity.

When called directly, or when its description has no single primitive root.

PibblComponent

PibblNodeInput

View source — packages/core/src/lib/layout/define-layout-component.ts:29

Read the Drawing, layout, and effects companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.