@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
47 lines (46 loc) • 1.79 kB
TypeScript
import type { ReactNode } from 'react';
import { type ChoiceCardsFieldProps as UiChoiceCardsFieldProps } from '@mitcsutt/kiln-ui';
import type { ControlledKeys } from '../internal/controlledKeys.js';
import { type CommonFieldProps } from '../../../hooks/useFieldBinding.js';
import { type FieldOption } from '../../../kit/contracts.js';
/** The base value of a choice-card option (§7.2 `choiceCards`: no booleans). */
export type ChoiceCardValue = string | number;
type UiSingleProps = Extract<UiChoiceCardsFieldProps, {
type: 'single';
}>;
export interface FormChoiceCardsFieldProps extends Omit<UiSingleProps, ControlledKeys | 'options' | 'type'>, CommonFieldProps<ChoiceCardValue | null> {
options?: readonly FieldOption<ChoiceCardValue>[];
/** A figure or short fact at the foot of an option's card, keyed by its value. */
optionMeta?: (value: ChoiceCardValue) => ReactNode;
}
/**
* One choice from a handful of cards, for options that need a sentence or a price each.
*
* @remarks
* It renders kiln-ui's {@link ChoiceCardsField | ChoiceCardsField} with `type="single"`.
*
* @example In a schema
* ```json
* {
* "kind": "choiceCards",
* "name": "plan",
* "label": "Pass",
* "options": [
* {
* "value": "month",
* "label": "Month",
* "description": "Renews automatically"
* }
* ]
* }
* ```
*
* @value the options' value type, or `null`
* @empty `null`
*
* @privateRemarks
* One choice from a handful of cards (§7.2 `choiceCards`, ui `type="single"`). Option values
* keep their primitive type; empty is `null`.
*/
export declare const FormChoiceCardsField: import("../../../kit/contracts.js").FieldDef<import("../../../kit/contracts.js").OptionContract<ChoiceCardValue>, FormChoiceCardsFieldProps>;
export {};