Skip to content

Core package

Here you can find a list of interfaces and types used in the core package.

Global

All types and interfaces that you have to know to use the useConfig, and the faivform contexts.

ContextForm

A wrapper type of Readable<FaivFormStore> that defines the form context.

PropertyTypeDescription
loadingWritable<boolean>Whether the form is loading or not.
errorsWritable<Errors<Data>>The errors of the fields.
dataWritable<Data>The values of the fields.
stylesWritable<ContextStyles>The styles of the form.
reset(clear?: boolean, starting?: Data) => voidResets the form.
setError(field: Keys, error?: string | null) => Promise<void>Sets the error of a field.
setField(field: Keys, value: Data[Keys], validate?: boolean) => Promise<void>Sets the value of a field.
check(event: UserEvent<HTMLInputElement | HTMLTextAreaElement, FocusEvent | Event>) => Promise<void>Checks the value of a field.
submitsubmit<T = Data>(action: SubmitAction<T>, config?: SubmitConfig<T>) => Submit`Submits the form.

ContextStyles

An interface that defines the field styles.

PropertyTypeDescription
replaceboolean | undefinedWhether the styles should replace the default styles or not.
fieldFieldStyles | undefinedThe styles of the Field.
selectSelectStyles | undefinedThe styles of the Select.
optionOptionStyles | undefinedThe styles of the Option.
fileFileStyles | undefinedThe styles of the File.
errorsErrorsStyles | undefinedThe styles of the Errors.

Faivform

All types and interfaces that you have to know to use the core package.

FaivFormConfig

An interface that defines the config of the form.

PropertyTypeDescription
fieldsFieldsSchema | AdapterThe fields of the form.
stylesContextStyles | undefinedThe styles of the form.
contextstring | undefinedThe context of the form.

FaivFormStore

An interface that defines the store of the form.

PropertyTypeDescription
loadingWritable<boolean>Whether the form is loading or not.
errorsWritable<Errors<Data>>The errors of the fields.
dataWritable<Data>The values of the fields.
stylesWritable<ContextStyles>The styles of the form.
reset(clear?: boolean, starting?: Data) => voidResets the form.
setError(field: Keys, error?: string | null) => Promise<void>Sets the error of a field.
setField(field: Keys, value: Data[Keys], validate?: boolean) => Promise<void>Sets the value of a field.
check(event: UserEvent<HTMLInputElement | HTMLTextAreaElement, FocusEvent | Event>) => Promise<void>Checks the value of a field.
submitsubmit<T = Data>(action: SubmitAction<T>, config?: SubmitConfig<T>) => Submit`Submits the form.

Adapter

An abstract class that defines the methods that an adapter must implement.

MethodDescription
initial(): { fields: Data; errors: Errors<Data>; }Returns the initial values of the fields and errors.
validate<T = Data>(data: T): Promise<void>Validates the data.
field(field: keyof Data, value: Data[keyof Data], errors: Writable<Errors<Data>>): Promise<void>Validates a field.
errors(error: unknown, errors: Writable<Errors<Data>>, handle?: (error: unknown) => (void | Promise<void>)): Promise<void>Handles an error.

SubmitAction

An type that defines the submit action.

PropertyTypeDescription
valuesDataThe values of the form.

SubmitConfig

An interface that defines the submit config.

PropertyTypeDescription
error((error: unknown) => (void | Promise<void>)) | undefinedA function that handles the error.
finishVoidFunction | undefinedA function that is called when the submit action is finished whether it was successful or not.
resetboolean | undefinedWhether the form should be reset or not.
initialData | undefinedThe initial values of the form.

Submit

An type that defines the function that is called when the form is submitted.

PropertyTypeDescription
eventUserEvent<HTMLFormElement, SubmitEvent>The submit event.

UserEvent

An object type that defines the user event. It extends the native event to safely access the current target.

PropertyTypeDescription
currentTargetEventTarget & ElementThe current target of the event.
EventAll the properties of the event used.

Errors

An object type that defines the errors of the fields.

PropertyTypeDescription
[field]string | nullThe error of a field.

Schemas

All schemas are defined using TypeScript types. This means that you can use them to define the type of your data.

FieldsSchema

A object type that defines a schema for a set of fields.

PropertyTypeDescription
[field]Schema | FieldPropSchema | ArraySchema | FieldsSchemaA field schema.

Schema

A type that defines the type of a field.

ValueDescription
RegExpA regular expression.
"string"A string.
"number"A number.
"boolean"A boolean.
"date"A date.
"file"A file.

FieldPropSchema

A object type that defines the type of a field.

PropertyTypeDescription
typeSchemaThe type of the field.
requiredboolean | undefinedWhether the field is required or not.
minnumber | undefinedThe minimum value of the field.
maxnumber | undefinedThe maximum value of the field.

ArraySchema

A object type that defines the type of an array.

PropertyTypeDescription
type"array"Indicates that the field is an array.
itemSchema | FieldPropSchema | ArraySchema | FieldsSchemaThe type of the items in the array.
requiredboolean | undefinedWhether the array is required or not.
minnumber | undefinedThe minimum length of the array.
maxnumber | undefinedThe maximum length of the array.

Styles

All types and interfaces that you have to know to use the styles.

FieldStyles

An interface that defines the field styles.

PropertyTypeDescription
containerstring | undefinedField container class
labelstring | undefinedField label class
inputstring | undefinedField input class
areastring | undefinedField type textarea class
checkstring | undefinedField type checkbox class
actionstring | undefinedField type password action class
iconstring | undefinedField type password icon class
checkedstring | undefinedField type checkbox checked icon
errorstring | undefinedField error class

SelectStyles

An interface that defines the select styles.

PropertyTypeDescription
containerstring | undefinedSelect container class
labelstring | undefinedSelect label class
selectstring | undefinedSelect menu class
valuestring | undefinedSelect value class
itemstring | undefinedSelect item class
removestring | undefinedSelect remove class
searchablestring | undefinedSelect searchable class
nonsearchablestring | undefinedSelect nonsearchable class
clearstring | undefinedSelect clear class
arrowstring | undefinedSelect arrow class
iconstring | undefinedSelect icon class
optionsstring | undefinedSelect options class
optionstring | undefinedSelect option class
emptystring | undefinedSelect empty class
errorstring | undefinedSelect error class

OptionStyles

An interface that defines the option styles.

PropertyTypeDescription
containerstring | undefinedOptions container class
legendstring | undefinedOptions label class
optionstring | undefinedOption class
labelstring | undefinedOption label class
inputstring | undefinedOption input class
contentstring | undefinedOption content class
errorstring | undefinedOption error class

FileStyles

An interface that defines the file styles.

PropertyTypeDescription
containerstring | undefinedFile container class
itemstring | undefinedFile item class
coverstring | undefinedFile cover class
removestring | undefinedFile remove class
itemsstring | undefinedFile items class
retrystring | undefinedFile retry class
contentstring | undefinedFile content class
labelstring | undefinedFile label class
inputstring | undefinedFile input class
errorstring | undefinedFile error class

ErrorsStyles

An interface that defines the errors styles.

PropertyTypeDescription
containerstring | undefinedErrors list class
itemstring | undefinedErrors item class

Built-in components

All types and interfaces that you have to know to use the built-in components.

SelectOption

An interface that defines the select option.

PropertyTypeDescription
keystring | undefinedThe key of the option.
labelstringThe label of the option.
valuestringThe value of the option.
fixedboolean | undefinedWhether the option is fixed or not.
disabledboolean | undefinedWhether the option is disabled or not.

OptionItem

An interface that defines the option item.

PropertyTypeDescription
keystring | undefinedThe key of the option.
labelstring | undefinedThe label of the option.
valuestringThe value of the option.
disabledboolean | undefinedWhether the option is disabled or not.