react-signal-forms
Version:
A forms library focusing on performance and modular extensibility.
32 lines • 1.84 kB
TypeScript
/// <reference types="react" />
import { ExpandFieldContextProperties, FieldContextExtension, FieldExtension, PropertyDescriptors, SignalFormPlugin } from "@/plugins/types";
import { KeyOf } from "@/utils";
import { Signal } from "@preact/signals-react";
import { Field } from "./fields";
export type FieldContextCollection<TForm = any, TPlugins extends SignalFormPlugin[] = []> = unknown extends TForm ? Record<string, IFieldContext<any, TPlugins>> : {
[Key in KeyOf<TForm>]: IFieldContext<TForm[Key], TPlugins>;
};
export type IFieldContext<TValue = any, TPlugins extends SignalFormPlugin[] = []> = {
name: string;
value: TValue | null;
setValue(value: TValue | null): void;
peekValue(): TValue;
handleBlur(event: React.FocusEvent<HTMLElement, Element>): void;
} & ExpandFieldContextProperties<TPlugins>;
export declare class FieldContext<TValue = any> implements IFieldContext<TValue> {
protected __field: Field;
protected __valueSignal: Signal<TValue>;
private __extensions;
private __blurEffects;
constructor(field: Field, initialValue?: TValue);
get name(): string;
get value(): TValue;
addBlurEffect: (effect: (event: React.FocusEvent<HTMLElement, Element>) => void) => void;
peekValue: () => TValue;
setValue: (value: TValue) => void;
handleBlur: (event: React.FocusEvent<HTMLElement, Element>) => void;
addExtension: <TExtension extends FieldContextExtension, TContext>(name: string, fieldExtension: TExtension, fieldContextProperties: PropertyDescriptors<TContext> | undefined) => void;
getExtension: <TPlugin extends SignalFormPlugin<FieldContextExtension, import("@/plugins/types").ContextProperties, import("@/plugins/types").ContextProperties>>(name: string) => FieldExtension<TPlugin>;
toJSON(): any;
}
//# sourceMappingURL=fieldContext.d.ts.map