Contracts
The @nizivo/react/contracts entry.
Import
import { STATE_ATTR_NAMES, details, mergeProps, renderElement, stateAttrs, toRenderFn } from '@nizivo/react/contracts';Exports
Aligntypeimport type { Align } from '@nizivo/react/contracts'type Align = (typeof ALIGNS)[number]ChangeDetailstypeimport type { ChangeDetails } from '@nizivo/react/contracts'The second argument of every
on<X>Change(value, details).reasonis Nizivo-owned: where the engine reports no cause, it is'unknown', never a guess.Name Type Default Description eventEvent– reasonrequiredR | "unknown"– OpenReasontypeimport type { OpenReason } from '@nizivo/react/contracts'Why an overlay opened or closed (§12.2).
type OpenReason = "trigger" | "escape" | "outside-press" | "close-part" | "item-press" | "hidden" | "programmatic"Orientationtypeimport type { Orientation } from '@nizivo/react/contracts'type Orientation = (typeof ORIENTATIONS)[number]RenderProptypeimport type { RenderProp } from '@nizivo/react/contracts'Composition without
asChildor a polymorphicas: - element form:render={<Link href="/orders" />}, serializable from Server Components; - function form:render={(props, state) => <a {...props} />}, client code only.type RenderProp<S> = ReactElement | ((props: Record<string, unknown>, state: S) => ReactElement)STATE_ATTR_NAMESconstantimport { STATE_ATTR_NAMES } from '@nizivo/react/contracts'Every attribute name
stateAttrs()can emit.const STATE_ATTR_NAMES: readonly string[]Sidetypeimport type { Side } from '@nizivo/react/contracts'type Side = (typeof SIDES)[number]StateAttrstypeimport type { StateAttrs } from '@nizivo/react/contracts'data-*attributes keyed by name; presence attributes carry"".type StateAttrs = Record<`data-${string}`, string>StateInputtypeimport type { StateInput } from '@nizivo/react/contracts'Engine-independent state, as adapters derive it from the engine's render state.
Name Type Default Description alignAlign"start""center""end"– checkedboolean– disabledboolean– emptyboolean– enteringboolean– errorboolean– exitingboolean– focusVisibleboolean– highlightedboolean– indeterminateboolean– invalidboolean– loadingboolean– mirror(typeof MIRRORS)[number]"rtl"– nestedOpenboolean– openboolean– orientationOrientation"horizontal""vertical"– pendingboolean– placeholderboolean– pressedboolean– readOnlyboolean– requiredboolean– selectedboolean– sideSide"top""right""bottom""left"– detailsfunctionimport { details } from '@nizivo/react/contracts'function details<R extends string = never>(reason: NoInfer<R> | "unknown", event?: Event): ChangeDetails<R>mergePropsfunctionimport { mergeProps } from '@nizivo/react/contracts'Merges prop objects from left ("ours") to right ("theirs"): -
classNameis concatenated, ours first, without repeating a class; -styleis shallow-merged, theirs winning; -on*handlers are chained theirs-first, and ours skip when the event wasdefaultPrevented; - refs are merged into one callback ref; - any other key: the right-most defined value wins, andundefinednever overrides.A function is created only when both sides supply one, so a server component that merges a consumer element never synthesises a handler or ref (functions cannot cross the RSC boundary).
function mergeProps(...sources: ReadonlyArray<Props | undefined>): PropsrenderElementfunctionimport { renderElement } from '@nizivo/react/contracts'Renders
tagwithprops, or the consumer's element/function withpropsmerged in (ours first). Element form:mergePropssemantics (the element's props win), except that the part's ownPART_OWNEDattributes win over the element's.function renderElement<S>(tag: string, render: RenderProp<S> | undefined, state: S, props: Record<string, unknown>): ReactElementstateAttrsfunctionimport { stateAttrs } from '@nizivo/react/contracts'Maps state to vocabulary attributes. False and absent states emit nothing.
function stateAttrs(state: StateInput): StateAttrstoRenderFnfunctionimport { toRenderFn } from '@nizivo/react/contracts'Normalises any render prop to the function form that engine adapters receive.
function toRenderFn<S>(render: RenderProp<S> | undefined, tag: string): (props: Record<string, unknown>, state: S) => ReactElement