Core package
Esta página aún no está disponible en tu idioma.
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.
Property | Type | Description |
---|---|---|
loading | Writable<boolean> | Whether the form is loading or not. |
errors | Writable< Errors <Data>> | The errors of the fields. |
data | Writable<Data> | The values of the fields. |
styles | Writable< ContextStyles > | The styles of the form. |
reset | (clear?: boolean, starting?: Data) => void | Resets 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. |
submit | submit<T = Data>(action: SubmitAction <T>, config?: SubmitConfig <T>) => Submit ` | Submits the form. |
ContextStyles
An interface that defines the field styles.
Property | Type | Description |
---|---|---|
replace | boolean | undefined | Whether the styles should replace the default styles or not. |
field | FieldStyles | undefined | The styles of the Field . |
select | SelectStyles | undefined | The styles of the Select . |
option | OptionStyles | undefined | The styles of the Option . |
file | FileStyles | undefined | The styles of the File . |
errors | ErrorsStyles | undefined | The 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.
Property | Type | Description |
---|---|---|
fields | FieldsSchema | Adapter | The fields of the form. |
styles | ContextStyles | undefined | The styles of the form. |
context | string | undefined | The context of the form. |
FaivFormStore
An interface that defines the store of the form.
Property | Type | Description |
---|---|---|
loading | Writable<boolean> | Whether the form is loading or not. |
errors | Writable< Errors <Data>> | The errors of the fields. |
data | Writable<Data> | The values of the fields. |
styles | Writable< ContextStyles > | The styles of the form. |
reset | (clear?: boolean, starting?: Data) => void | Resets 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. |
submit | submit<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.
Method | Description |
---|---|
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.
Property | Type | Description |
---|---|---|
values | Data | The values of the form. |
SubmitConfig
An interface that defines the submit config.
Property | Type | Description |
---|---|---|
error | ((error: unknown) => (void | Promise<void>)) | undefined | A function that handles the error. |
finish | VoidFunction | undefined | A function that is called when the submit action is finished whether it was successful or not. |
reset | boolean | undefined | Whether the form should be reset or not. |
initial | Data | undefined | The initial values of the form. |
Submit
An type that defines the function that is called when the form is submitted.
Property | Type | Description |
---|---|---|
event | UserEvent <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.
Property | Type | Description |
---|---|---|
currentTarget | EventTarget & Element | The current target of the event. |
… | Event | All the properties of the event used. |
Errors
An object type that defines the errors of the fields.
Property | Type | Description |
---|---|---|
[field] | string | null | The 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.
Property | Type | Description |
---|---|---|
[field] | Schema | FieldPropSchema | ArraySchema | FieldsSchema | A field schema. |
Schema
A type that defines the type of a field.
Value | Description |
---|---|
RegExp | A 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.
Property | Type | Description |
---|---|---|
type | Schema | The type of the field. |
required | boolean | undefined | Whether the field is required or not. |
min | number | undefined | The minimum value of the field. |
max | number | undefined | The maximum value of the field. |
ArraySchema
A object type that defines the type of an array.
Property | Type | Description |
---|---|---|
type | "array" | Indicates that the field is an array. |
item | Schema | FieldPropSchema | ArraySchema | FieldsSchema | The type of the items in the array. |
required | boolean | undefined | Whether the array is required or not. |
min | number | undefined | The minimum length of the array. |
max | number | undefined | The 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.
Property | Type | Description |
---|---|---|
container | string | undefined | Field container class |
label | string | undefined | Field label class |
input | string | undefined | Field input class |
area | string | undefined | Field type textarea class |
check | string | undefined | Field type checkbox class |
action | string | undefined | Field type password action class |
icon | string | undefined | Field type password icon class |
checked | string | undefined | Field type checkbox checked icon |
error | string | undefined | Field error class |
SelectStyles
An interface that defines the select styles.
Property | Type | Description |
---|---|---|
container | string | undefined | Select container class |
label | string | undefined | Select label class |
select | string | undefined | Select menu class |
value | string | undefined | Select value class |
item | string | undefined | Select item class |
remove | string | undefined | Select remove class |
searchable | string | undefined | Select searchable class |
nonsearchable | string | undefined | Select nonsearchable class |
clear | string | undefined | Select clear class |
arrow | string | undefined | Select arrow class |
icon | string | undefined | Select icon class |
options | string | undefined | Select options class |
option | string | undefined | Select option class |
empty | string | undefined | Select empty class |
error | string | undefined | Select error class |
OptionStyles
An interface that defines the option styles.
Property | Type | Description |
---|---|---|
container | string | undefined | Options container class |
legend | string | undefined | Options label class |
option | string | undefined | Option class |
label | string | undefined | Option label class |
input | string | undefined | Option input class |
content | string | undefined | Option content class |
error | string | undefined | Option error class |
FileStyles
An interface that defines the file styles.
Property | Type | Description |
---|---|---|
container | string | undefined | File container class |
item | string | undefined | File item class |
cover | string | undefined | File cover class |
remove | string | undefined | File remove class |
items | string | undefined | File items class |
retry | string | undefined | File retry class |
content | string | undefined | File content class |
label | string | undefined | File label class |
input | string | undefined | File input class |
error | string | undefined | File error class |
ErrorsStyles
An interface that defines the errors styles.
Property | Type | Description |
---|---|---|
container | string | undefined | Errors list class |
item | string | undefined | Errors 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.
Property | Type | Description |
---|---|---|
key | string | undefined | The key of the option. |
label | string | The label of the option. |
value | string | The value of the option. |
fixed | boolean | undefined | Whether the option is fixed or not. |
disabled | boolean | undefined | Whether the option is disabled or not. |
OptionItem
An interface that defines the option item.
Property | Type | Description |
---|---|---|
key | string | undefined | The key of the option. |
label | string | undefined | The label of the option. |
value | string | The value of the option. |
disabled | boolean | undefined | Whether the option is disabled or not. |