@papernote/ui
Version:
A modern React component library with a paper notebook aesthetic - minimal, professional, and expressive
44 lines • 1.43 kB
TypeScript
import React from 'react';
export type ValidationRule<T = unknown> = {
required?: boolean | string;
min?: number | {
value: number;
message: string;
};
max?: number | {
value: number;
message: string;
};
minLength?: number | {
value: number;
message: string;
};
maxLength?: number | {
value: number;
message: string;
};
pattern?: RegExp | {
value: RegExp;
message: string;
};
validate?: (value: T) => boolean | string | Promise<boolean | string>;
};
export type FieldErrors = Record<string, string>;
export interface FormProps {
children: React.ReactNode;
onSubmit: (data: Record<string, unknown>) => void | Promise<void>;
validationRules?: Record<string, ValidationRule>;
className?: string;
}
export interface FormContextValue {
errors: FieldErrors;
touched: Record<string, boolean>;
isSubmitting: boolean;
registerField: (name: string, value: unknown) => void;
setFieldError: (name: string, error: string) => void;
setFieldTouched: (name: string) => void;
}
export declare const FormContext: React.Context<FormContextValue | null>;
export declare function useFormContext(): FormContextValue;
export default function Form({ children, onSubmit, validationRules, className, }: FormProps): import("react/jsx-runtime").JSX.Element;
//# sourceMappingURL=Form.d.ts.map