2020-04-26 00:37:03 +00:00
|
|
|
import React from 'react';
|
|
|
|
import FormikFieldWrapper from '@/components/elements/FormikFieldWrapper';
|
|
|
|
import { Field, FieldProps } from 'formik';
|
|
|
|
import Switch, { SwitchProps } from '@/components/elements/Switch';
|
|
|
|
|
|
|
|
const FormikSwitch = ({ name, label, ...props }: SwitchProps) => {
|
|
|
|
return (
|
|
|
|
<FormikFieldWrapper name={name}>
|
|
|
|
<Field name={name}>
|
|
|
|
{({ field, form }: FieldProps) => (
|
|
|
|
<Switch
|
|
|
|
name={name}
|
|
|
|
label={label}
|
|
|
|
onChange={() => {
|
|
|
|
form.setFieldTouched(name);
|
|
|
|
form.setFieldValue(field.name, !field.value);
|
|
|
|
}}
|
2021-09-16 20:59:22 +00:00
|
|
|
defaultChecked={ field.value}
|
2020-04-26 00:37:03 +00:00
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Field>
|
|
|
|
</FormikFieldWrapper>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FormikSwitch;
|