UNPKG

envoc-form

Version:

Envoc form components

22 lines (21 loc) 1.08 kB
import { CustomFieldInputProps } from './CustomFieldInputProps'; import { CustomFieldMetaProps } from './CustomFieldMetaProps'; import { NormalizationFunction } from '../Normalization/NormalizationFunction'; import { ValidationFunction } from '../Validation/ValidationFunction'; export interface useStandardFieldProps<TValue> { /** Id of the field. */ id?: string; /** Name of the field. */ name: string; /** Whether the field should be disabled. */ disabled?: boolean; /** Function to validate the field. */ validate?: ValidationFunction<TValue> | ValidationFunction<TValue>[]; /** Function to modify the field value without making the form dirty. (e.g. phone number) */ normalize?: NormalizationFunction<TValue>; } /** Provides a consistent way to deal with all form fields (non array). */ export default function useStandardField<TValue>({ id: providedId, name: providedName, disabled, validate, normalize, }: useStandardFieldProps<TValue>): [ CustomFieldInputProps<TValue>, CustomFieldMetaProps<TValue> ];