import { type ValidationHelper } from "./validation-helper"; export interface WithValidation { readonly isAutoValidationDisabled: boolean; readonly validation: ValidationHelper; required: boolean; validationMessage: string; showValidationError: ShowValidationErrorCallback | ((error: string) => void); clearValidationError: ClearValidationErrorCallback; checkValidity: () => boolean; reportValidity: () => boolean; } export type ValidationResultSummary = { isValid: boolean | null; message: string | null; }; export type ValidationResultItem = { isValid: boolean | null; message: string | null; validation: ValidationItem; }; export type ValidationResult = { validationList: ValidationResultItem[]; isAllValid: boolean; }; export type ValidatorFunction = (value: ValidationValue) => boolean | string | Promise; export type ValidationItem = { /** * @property validation function or regex to match value with */ validator: RegExp | ValidatorFunction; /** * @property error message that will be shown if validator return false or regex failed */ message: string; /** * @property type of error (category) its optional */ stateType?: keyof ValidityStateFlags; /** * @property defer validator execution until all non-deferred validation executed.(good for async validator) */ defer?: boolean; }; export type checkValidityInput = { /** * @property showError determine if you want to show error in invalidate state or not. default is true */ showError?: boolean; /** * @property the value you want to check validation on its optional and if not set it will get from component value) */ value?: ValidationValue; }; export type ShowValidationErrorInput = { message: string; }; export type ShowValidationErrorCallback = (error: ShowValidationErrorInput) => void; export type ClearValidationErrorCallback = () => void; export type GetValueCallback = () => (ValidationValue | Promise); export type GetValueStringCallback = (value: ValidationValue) => string; export type GetValidationsCallback = () => ValidationItem[]; export type SetValidationResultCallback = (result: ValidationResult) => void; export type Callbacks = { getValue: GetValueCallback; getValueString: GetValueStringCallback; showValidationError: ShowValidationErrorCallback[]; clearValidationError: ClearValidationErrorCallback[]; getValidations: GetValidationsCallback[]; setValidationResult: SetValidationResultCallback[]; }; export type CallbacksInput = { [key in keyof Callbacks]?: Callbacks[key] extends Array ? Callbacks[key][0] : Callbacks[key]; };