UNPKG

@mitcsutt/kiln-forms

Version:

Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui

32 lines (31 loc) • 1.84 kB
import type { FieldLayout } from '@mitcsutt/kiln-ui'; import { type ReactNode } from 'react'; /** How fields under a layout render (§9.0). Bindings merge it under the field's own props. */ export interface FieldPresentationValue { layout?: FieldLayout; labelHidden?: boolean; /** `external`: the field keeps its invalid state but its message renders elsewhere (sentence, table). */ errorPlacement?: 'inline' | 'external'; /** `view` renders each field's display value, no control (FormReview, `Form mode="view"`). */ mode?: 'edit' | 'view'; /** * View mode: clamp each field's value to about this many lines, with a toggle that shows the * rest (kiln-ui's `ShowMore`). Values that fit show no toggle. */ viewLines?: number; /** Cascades; a nested `false` cannot re-enable. */ disabled?: boolean; /** Cascades; a nested `false` cannot make it editable. */ readOnly?: boolean; /** For `errorPlacement: 'external'`: the id of the element showing a field's message. */ describedBy?: (name: string) => string | undefined; } export type FieldPresentationProps = Partial<FieldPresentationValue> & { children: ReactNode; }; /** Merges two presentation layers: inner wins, except `disabled` / `readOnly`, which only add. */ export declare function mergePresentation(outer: FieldPresentationValue, inner: Partial<FieldPresentationValue>): FieldPresentationValue; /** Provides presentation hints to every field below, merged with any parent presentation. */ export declare function FieldPresentation({ children, layout, labelHidden, errorPlacement, mode, viewLines, disabled, readOnly, describedBy, }: FieldPresentationProps): import("react").JSX.Element; /** The merged presentation in effect here. */ export declare function useFieldPresentation(): FieldPresentationValue;