UNPKG

@dvcol/neo-svelte

Version:

Neomorphic ui library for svelte 5

41 lines (40 loc) 1.63 kB
import type { HTMLInputTypeAttribute } from 'svelte/elements'; import type { NeoValidationState } from '../inputs/common/neo-validation.model.js'; export type NeoFormContextFieldHTMLElement<Element extends HTMLElement = HTMLElement> = Element & { /** * Check the input validity. * @param update whether to check the input dirty and/or valid state. */ validate?: (update?: { dirty?: boolean; valid?: boolean; }) => NeoValidationState<unknown>; }; export type NeoFormType = HTMLInputTypeAttribute | 'range' | 'switch' | null; export type NeoFormContextField<Value = unknown, Element extends NeoFormContextFieldHTMLElement = NeoFormContextFieldHTMLElement> = { id: string; ref?: Element; name?: string | null; form?: string | null; type?: NeoFormType; state: NeoValidationState<Value>; error?: unknown | string; message?: unknown | string; }; export declare class NeoFormContext { #private; get fields(): Record<string, NeoFormContextField<unknown, NeoFormContextFieldHTMLElement<HTMLElement>>>; get values(): Record<string, unknown>; get initials(): Record<string, unknown>; get touched(): boolean; get dirty(): boolean; get valid(): boolean; get messages(): Record<string, unknown>; get errors(): Record<string, unknown>; constructor(id?: string); register(field: NeoFormContextField): void; remove(id: NeoFormContextField['id']): void; validate(): NeoValidationState; } export declare const getNeoFormContext: () => NeoFormContext; export declare const setNeoFormContext: (id?: string) => NeoFormContext;