Skip to main content

BnLayoutItem

Namespace: BlazorNative.Components

The parameters every component can carry as an item inside its parent's layout — how it aligns itself, how it grows and shrinks, its own box, and its position insets.

public abstract class BnLayoutItem : Microsoft.AspNetCore.Components.ComponentBase, Microsoft.AspNetCore.Components.IComponent, Microsoft.AspNetCore.Components.IHandleEvent, Microsoft.AspNetCore.Components.IHandleAfterRender

Inheritance ObjectComponentBaseBnLayoutItem
Implements IComponent, IHandleEvent, IHandleAfterRender
Attributes NullableContextAttribute, NullableAttribute

Remarks:

This is the single declaration of the item surface. Previously these seventeen parameters were copy-pasted across eight components and absent from four more, so a BnText could not take a margin and a BnButton could take nothing at all. Any component that participates in layout derives from this type; LayoutSurfacePinTests reds if one does not, and LayoutSurfaceSequenceBandTests reds if one derives it and then fails to EMIT it — declaring a parameter and dropping it every frame is the defect this type exists to make impossible, not a lesser version of it.

You do not derive from this yourself. It is public and abstract because the components in this package derive from it across their own file boundaries, not as an extension point: the shells map a fixed vocabulary of element names, so a component of your own opening an element they do not know would produce a node neither shell can create — and the pins that keep this surface honest scan only this assembly, so nothing would tell you. Compose the components here instead.

Sequence-number bands are normative, and there are two ways to take this surface. A component that writes its own render tree calls EmitItemAttributes, which occupies 1–17; BnLayoutContainer owns 50–99; the component's own attributes start at 100 and ChildContent is 200. Keeping to those bands matters because a collision does not throw — it produces a wrong diff, silently. LayoutSurfaceSequenceBandTests enforces both halves for every component that writes its own render tree: no two attributes in one region share a sequence, and each attribute sits in the band its name belongs to. The splat form described next is exempt from the band half, and necessarily so — the Razor compiler assigns those numbers, not the author.

A component written as markup cannot do that: its render tree is generated for it and every sequence number is assigned by the compiler, so there is no point at which EmitItemAttributes could run. Those components splat ItemAttributes instead, and all seventeen then share a single sequence number rather than spanning 1–17. That is still correct, and not by luck: repeated sequence numbers inside a run of attributes make the diff match them by name instead of by position, so a value that changes updates, and a value that goes null still emits its reset. It costs a dictionary per render, which is why the numbered form remains the default wherever it is reachable.

Lengths are typed.BnLength and BnAutoLength carry the shells' grammar (a bare number, N%, or auto where allowed), so a malformed value is a compile error rather than a log line. They are nullable on every parameter: null is unset, and a bare default would be a real value.

Properties

BackgroundColor

Fill colour behind the component. Null leaves it transparent.

public string? BackgroundColor { get; set; }

Property Value

String

Margin

Space outside the component, between it and its siblings. Null = none.

public BnAutoLength? Margin { get; set; }

Property Value

BnAutoLength?

Remarks:

auto is legal here and absorbs free space, which re-centres the node.

AlignSelf

Cross-axis alignment for this item alone, overriding the parent's. Null = inherit.

public FlexAlign? AlignSelf { get; set; }

Property Value

FlexAlign?

Grow

Share of leftover space this item takes (unitless ratio). Null = Yoga's default (0).

public float? Grow { get; set; }

Property Value

Single?

Shrink

Share of overflow this item gives up (unitless ratio). Null = Yoga's default (1).

public float? Shrink { get; set; }

Property Value

Single?

Basis

Starting main-axis size before grow/shrink. Null = auto.

public BnAutoLength? Basis { get; set; }

Property Value

BnAutoLength?

Width

Box width. Null = auto.

public BnAutoLength? Width { get; set; }

Property Value

BnAutoLength?

Height

Box height. Null = auto.

public BnAutoLength? Height { get; set; }

Property Value

BnAutoLength?

MinWidth

Lower bound on width. Null = unset.

public BnLength? MinWidth { get; set; }

Property Value

BnLength?

MaxWidth

Upper bound on width. Null = unset.

public BnLength? MaxWidth { get; set; }

Property Value

BnLength?

MinHeight

Lower bound on height. Null = unset.

public BnLength? MinHeight { get; set; }

Property Value

BnLength?

MaxHeight

Upper bound on height. Null = unset.

public BnLength? MaxHeight { get; set; }

Property Value

BnLength?

Position

Positioning scheme. Null = Yoga's default (relative).

public FlexPosition? Position { get; set; }

Property Value

FlexPosition?

Top

Top inset. Null = unset.

public BnLength? Top { get; set; }

Property Value

BnLength?

Right inset. Null = unset.

public BnLength? Right { get; set; }

Property Value

BnLength?

Bottom

Bottom inset. Null = unset.

public BnLength? Bottom { get; set; }

Property Value

BnLength?

Left

Left inset. Null = unset.

public BnLength? Left { get; set; }

Property Value

BnLength?