Documentation
API: primitives (@fragiola/splitter-react)

Panel

Splitter.Panel is a flex item whose size comes from the group's layout, with its constraints in any unit, collapsing, and callbacks for every change.

Splitter.Panel is one entry of its group's layout: a flex item whose grow factor is its size in percent. Its order is its position in the document, so a panel rendered conditionally lands where the markup puts it. A Splitter.Group inside it nests in it. Its element's DOM id is its panel id, which the separators' aria-controls point at.

<Splitter.Panel
    id="sidebar"
    defaultSize="25%"
    minSize="10rem"
    maxSize="40%"
    collapsible
    collapsedSize="3rem"
    onCollapse={() => setCollapsed(true)}
    onExpand={() => setCollapsed(false)}
>
    …
</Splitter.Panel>

Panel is also a named export, the same component.

Props

PanelProps<T> extends the common primitive props, every div attribute but id and onResize, and UsePanelOptions<T> (the same options as usePanel). A size is a SizeValue: a number is pixels, a string carries its unit (%, px, em, rem, vh, vw), a string without one is a percentage.

proptypedefaultdescription
idPanelIdOf<T>generated (useId)the panel's id, as the saved layout names it, and its element's DOM id
defaultSizeSizeValuean equal share of what is leftthe size it starts with when no saved or given layout has one
minSizeSizeValue0the smallest size it takes when expanded
maxSizeSizeValue"100%"the largest size it takes
collapsiblebooleanfalseit can collapse below its minimum, to its collapsed size
collapsedSizeSizeValue0its size collapsed
collapsedThresholdSizeValuehalfwayhow far past its minimum a drag goes before it collapses
disabledbooleanfalseno separator resizes it (code still can)
groupResizeBehavior"preserve-relative-size" | "preserve-pixel-size""preserve-relative-size"when the group resizes, it keeps its percentage, or its pixels
onResize(size: PanelSize, previous: PanelSize | undefined) => voidnoneits size changed (percentage, and pixels once measured); previous is undefined the first time
onCollapse() => voidnoneit collapsed
onExpand() => voidnoneit expanded
childrenReactNodenoneits content

State

PanelPartState, what className, style and render receive (also returned by usePanel):

fieldtypedescription
idstringthe panel's id
sizenumber | undefinedits size in percent; undefined until known
collapsedbooleanit is collapsed
collapsiblebooleanit can collapse
disabledbooleanno separator resizes it
pathstring | undefinedits path (/g0/p1); undefined until it registers

Data attributes

attributevalue
data-splitter-part"panel"
data-splitter-path<group path>/p<index> (see Paths)
data-collapsedpresent while collapsed
data-collapsiblepresent when it can collapse
data-disabledpresent when disabled
idits panel id

Structural style

flex: <size> 1 0 and overflow: hidden. Before its size is known (no saved, given or default layout), flex: 0 1 <defaultSize> when it declares one, else flex: 1 1 0: the same on the server and in the hydration render. Scrolling its content is yours.

Commands

It registers with panel.add (with its group's registration, or on its own when it mounts later); a changed constraint runs panel.update, unmounting panel.remove. A drag runs separator.move; code resizes it with panel.resize, panel.collapse and panel.expand.