UNPKG

@mitcsutt/kiln-forms

Version:

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

111 lines (110 loc) • 4.43 kB
/** * Every piece of library copy (D15). Override per kit (`createFormKit({ messages })`) or per form * (`useAppForm({ messages })`). Rule messages use `{value}` placeholders. */ export interface FormMessages { errorSummaryTitle: string; errorCount: (n: number) => string; submitFailed: string; noChanges: string; unsavedChanges: string; saving: string; saved: string; saveFailed: string; validating: string; add: string; remove: (item: string) => string; moveUp: (item: string) => string; moveDown: (item: string) => string; item: (index: number) => string; itemAdded: (item: string) => string; itemRemoved: (item: string) => string; itemMoved: (item: string, pos: number) => string; maxItems: (max: number) => string; /** Repeater (table): the header of the trailing item-actions column. */ actions: string; /** * Repeater with `reorderable="drag"`: its drag handles and what is announced at each step of * a drag. `position` counts from 1, out of `count` items. Their defaults live in * `@mitcsutt/kiln-forms/dnd`, so forms without drag and drop don't carry them. */ drag: Partial<{ /** How to use a handle, linked to every handle with `aria-describedby`. */ instructions: string; /** A drag handle's accessible name. */ handle: (item: string) => string; lifted: (item: string, position: number, count: number) => string; moved: (item: string, position: number, count: number) => string; dropped: (item: string, position: number, count: number) => string; canceled: (item: string, position: number, count: number) => string; }>; stepOf: (index: number, count: number, title: string) => string; back: string; next: string; submit: string; /** ResetButton's default text. */ reset: string; /** Stepper: visually hidden suffix after a completed step's label. */ stepComplete: string; /** Stepper: visually hidden suffix after the label of a step with errors. */ stepError: string; /** Stepper compact mode (narrow screens), before the current step's title: "Step 2 of 4". */ stepCompact: (index: number, count: number) => string; /** FormReview: the default text of the button that goes back to edit a step. */ edit: string; optionsFailed: string; fileRejected: { type: string; size: string; count: string; }; /** * A JSON field whose text isn't valid JSON, or that its `validate` rejects: "Line 3, column 12: * Remove this comma: nothing follows it". Called with no error where there's no detail, as * `toStandardSchema` does on a server. */ invalidJson: (error?: { message: string; line?: number; column?: number; }) => string; /** A JSON field: the name of the button that copies its text. */ copyJson: string; rules: { required: string; minLength: string; maxLength: string; pattern: string; email: string; url: string; min: string; max: string; step: string; integer: string; minItems: string; maxItems: string; unique: string; minDate: string; maxDate: string; }; /** View mode: a checked boolean. */ yes: string; /** View mode: an unchecked boolean. */ no: string; /** View mode: an empty value. */ notProvided: string; /** View mode with `viewLines`: the toggle that shows the rest of a clamped value. */ showMore: string; /** View mode with `viewLines`: the toggle that clamps it again. */ showLess: string; } export declare const defaultMessages: FormMessages; /** Replaces `{key}` placeholders with `params[key]`. Unknown keys are left as written. */ export declare function interpolate(template: string, params?: Record<string, unknown>): string; /** Deep-merges message overrides (one level for `rules` / `fileRejected` / `drag`). */ export declare function mergeMessages(...layers: (Partial<FormMessages> | undefined)[]): FormMessages; /** * Resolves a `$`-prefixed message key (`'$rules.minLength'`) against `messages` and interpolates * `params`. Plain messages are interpolated as-is. */ export declare function resolveMessage(message: string, messages: FormMessages, params?: Record<string, unknown>): string;