UNPKG

emr-types

Version:

Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation

296 lines 7.53 kB
/** * Form Utility Types for EMR Application * * Provides comprehensive form-related types for building type-safe forms * with validation, state management, and user interaction handling. * * @package emr-types */ import { z } from 'zod'; /** * Base form field configuration */ export interface FormField<T = unknown> { name: string; label: string; type: FormFieldType; value: T; required?: boolean; disabled?: boolean; placeholder?: string; helpText?: string; validation?: z.ZodSchema<T>; error?: string; touched?: boolean; dirty?: boolean; } /** * Supported form field types */ export declare enum FormFieldType { TEXT = "text", EMAIL = "email", PASSWORD = "password", NUMBER = "number", TEL = "tel", DATE = "date", DATETIME = "datetime-local", TIME = "time", SELECT = "select", MULTISELECT = "multiselect", CHECKBOX = "checkbox", RADIO = "radio", TEXTAREA = "textarea", FILE = "file", HIDDEN = "hidden", CUSTOM = "custom" } /** * Form field with validation state */ export interface ValidatedFormField<T = unknown> extends FormField<T> { isValid: boolean; validationErrors: string[]; isTouched: boolean; isDirty: boolean; isFocused: boolean; } /** * Form field options for select/multiselect fields */ export interface FormFieldOption<T = string> { value: T; label: string; disabled?: boolean; group?: string; } /** * Form state management */ export interface FormState<T extends Record<string, unknown> = Record<string, unknown>> { values: T; errors: Partial<Record<keyof T, string>>; touched: Partial<Record<keyof T, boolean>>; dirty: Partial<Record<keyof T, boolean>>; focused: Partial<Record<keyof T, boolean>>; isValid: boolean; isDirty: boolean; isSubmitting: boolean; isSubmitted: boolean; submitCount: number; } /** * Form validation result */ export interface FormValidationResult<T = unknown> { isValid: boolean; errors: Record<string, string[]>; fieldErrors: Record<string, string>; globalErrors: string[]; data?: T; } /** * Form submission state */ export interface FormSubmissionState<T = unknown> { isSubmitting: boolean; isSubmitted: boolean; isSuccess: boolean; error?: string; data?: T; submitCount: number; } /** * Form validation schema */ export type FormValidationSchema<T> = Record<keyof T, z.ZodSchema>; /** * Form validation function */ export type FormValidator<T> = (values: T) => FormValidationResult<T>; /** * Field validation function */ export type FieldValidator<T> = (value: T, allValues?: Record<string, unknown>) => string | undefined; /** * Async form validation function */ export type AsyncFormValidator<T> = (values: T) => Promise<FormValidationResult<T>>; /** * Form change event */ export interface FormChangeEvent<T = unknown> { name: string; value: T; type: 'change' | 'blur' | 'focus'; field: string; } /** * Form submit event */ export interface FormSubmitEvent<T = unknown> { values: T; isValid: boolean; errors: Record<string, string[]>; preventDefault: () => void; } /** * Form reset event */ export interface FormResetEvent<T = unknown> { values: T; isDirty: boolean; } /** * Form configuration */ export interface FormConfig<T extends Record<string, unknown> = Record<string, unknown>> { initialValues: T; validationSchema?: FormValidationSchema<T>; validateOnChange?: boolean; validateOnBlur?: boolean; validateOnSubmit?: boolean; enableReinitialize?: boolean; keepDirtyOnReinitialize?: boolean; updateUnregisteredFields?: boolean; destroyOnUnmount?: boolean; } /** * Form field configuration */ export interface FormFieldConfig<T = unknown> { name: string; label: string; type: FormFieldType; required?: boolean; disabled?: boolean; placeholder?: string; helpText?: string; validation?: z.ZodSchema<T>; options?: FormFieldOption[]; defaultValue?: T; transform?: (value: unknown) => T; format?: (value: T) => string; parse?: (value: string) => T; } /** * Extract form field names from a type */ export type FormFieldNames<T> = keyof T; /** * Extract form field values from a type */ export type FormFieldValues<T> = T[keyof T]; /** * Make all form fields optional */ export type PartialFormState<T> = Partial<T>; /** * Make all form fields required */ export type RequiredFormState<T> = Required<T>; /** * Form field with specific value type */ export type TypedFormField<T, K extends keyof T> = FormField<T[K]> & { name: K; }; /** * Form state with specific field types */ export type TypedFormState<T> = { [K in keyof T]: ValidatedFormField<T[K]>; }; /** * Form field group */ export interface FormFieldGroup { name: string; label: string; fields: string[]; collapsed?: boolean; collapsible?: boolean; } /** * Form section */ export interface FormSection { title: string; description?: string; fields: FormFieldConfig[]; groups?: FormFieldGroup[]; } /** * Form layout */ export interface FormLayout { sections: FormSection[]; columns?: number; responsive?: boolean; } /** * Form accessibility */ export interface FormAccessibility { ariaLabel?: string; ariaDescribedBy?: string; ariaInvalid?: boolean; role?: string; } /** * Create a form validator from Zod schema */ export declare function createFormValidator<T>(schema: z.ZodSchema<T>): FormValidator<T>; /** * Create a field validator from Zod schema */ export declare function createFieldValidator<T>(schema: z.ZodSchema<T>): FieldValidator<T>; /** * Combine multiple field validators */ export declare function combineFieldValidators<T>(validators: FieldValidator<T>[]): FieldValidator<T>; /** * Create initial form state */ export declare function createInitialFormState<T extends Record<string, unknown>>(initialValues: T): FormState<T>; /** * Check if form is valid */ export declare function isFormValid<T extends Record<string, unknown>>(state: FormState<T>): boolean; /** * Check if form is dirty */ export declare function isFormDirty<T extends Record<string, unknown>>(state: FormState<T>): boolean; /** * Get form field value */ export declare function getFieldValue<T extends Record<string, unknown>, K extends keyof T>(state: FormState<T>, field: K): T[K]; /** * Get form field error */ export declare function getFieldError<T extends Record<string, unknown>, K extends keyof T>(state: FormState<T>, field: K): string | undefined; /** * Check if field is touched */ export declare function isFieldTouched<T extends Record<string, unknown>, K extends keyof T>(state: FormState<T>, field: K): boolean; /** * Check if field is dirty */ export declare function isFieldDirty<T extends Record<string, unknown>, K extends keyof T>(state: FormState<T>, field: K): boolean; /** * Type guard for form field */ export declare function isFormField(value: unknown): value is FormField; /** * Type guard for validated form field */ export declare function isValidatedFormField(value: unknown): value is ValidatedFormField; /** * Type guard for form state */ export declare function isFormState(value: unknown): value is FormState; /** * Type guard for form validation result */ export declare function isFormValidationResult(value: unknown): value is FormValidationResult; //# sourceMappingURL=form.d.ts.map