UNPKG

@dvcol/neo-svelte

Version:

Neomorphic ui library for svelte 5

43 lines (42 loc) 1.75 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. * @param update.dirty whether to mark the input dirty * @param update.valid whether to force a valid state */ validate?: (update?: { dirty?: boolean; valid?: boolean; }) => NeoValidationState<unknown>; }; export type NeoFormType = HTMLInputTypeAttribute | 'range' | 'switch' | null; export interface 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 function getNeoFormContext(): NeoFormContext; export declare function setNeoFormContext(id?: string): NeoFormContext;