# defineLayoutComponent

`defineLayoutComponent(describe)` defines reusable pure structure that a layout
parent can inspect before allocating it. It returns a [PibblComponent](/reference/types/elements-components/#pibblcomponent) for JSX
or `createElement`. Its result is [PibblNodeInput](/reference/types/elements-components/#pibblnodeinput):

```tsx
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](/playground/#/examples/layout/wasm-flex-nested-intrinsic)
shows width-dependent height moving a following target. Percentage feedback,
wrapping and aggregate structural paint reuse remain open.

## API details from source

<span id="api-defineLayoutComponent"></span>

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.

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

Related API: [defineLayoutComponent](/reference/functions/define-layout-component/), [PibblNodeInput](/reference/types/elements-components/#pibblnodeinput), [PibblComponent](/reference/types/elements-components/#pibblcomponent).

### Parameters

- **`describe`** — Pure synchronous description using authored readonly props.

### Returns

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

### Throws

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

### See also

[PibblComponent](/reference/types/elements-components/#pibblcomponent)

[PibblNodeInput](/reference/types/elements-components/#pibblnodeinput)

[View source — packages/core/src/lib/layout/define-layout-component.ts:29](/source/packages/core/src/lib/layout/define-layout-component-ts/#L29)

## Implementation guidance for agents

Read the [Drawing, layout, and effects companion](/agents/topics/layout/) for ownership, adaptation, failure modes, and verification. [Agent start](/agents/) provides the version-selection workflow.

## Complete minimal examples

- [Inspectable layout component](/minimal-examples/layout/layout-component/): Define a pure layout description that a Flex owner can inspect before allocation. [Plain source](/minimal/layout/layout-component.tsx)
## Documentation version

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