formik-alfalab-core-components
v1.0.0
Published
Bindings for Formik and Alfalab's Core Components
Downloads
1,939
Readme
formik-alfalab-core-components
Bindings for formik and @alfalab/core-components.
Usage
Just use the components from formik-alfalab-core-components
as a drop-in replacement of the components
from @alfalab/core-components
, but with one required prop name
. Available components are:
- AmountInput
- Input
- InputAutocomplete
- MaskedInput
- PhoneInput
- RadioGroup
- Select
- Switch
- Textarea
Consider the example:
import React from 'react';
import { Formik, Form } from 'formik';
import { Input } from 'formik-alfalab-core-components/Input';
export const MyForm: FC = () => {
return (
<Formik
initialValues={{ name: '' }}
onSubmit={(values) => { console.log(values) }}
>
<Form>
<Input name="name" />
<button type="submit">Submit</button>
</Form>
</Formik>
);
};
Exports
Each component can be imported from the subdirectory:
import { Input } from 'formik-alfalab-core-components/Input';
This library also exposes some utility hooks which are used under the hood by components:
useFieldBlurState
— useful for handlingblur
event inside formik context;useFieldOkState
— provideserror
andsuccess
props using formik state;useInputFieldState
— providesprops: InputProps
using formik state;useSelectFieldState
— providesprops: BaseSelectProps
using formik state.
These hooks are available under formik-alfalab-core-components/hooks
and can be used
to bind your custom components to formik.
How does it work?
Under the hood it connects to the Formik's state via useField
hook and name
prop.
Then the given state is passed to original component from @alfalab/core-components
.