2021-10-01 18:07:48 +01:00
|
|
|
import Label from '@/components/elements/Label';
|
2020-02-23 04:07:56 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Field, FieldProps } from 'formik';
|
2020-07-05 00:26:07 +01:00
|
|
|
import Input from '@/components/elements/Input';
|
2021-10-01 18:07:48 +01:00
|
|
|
import tw from 'twin.macro';
|
2020-02-23 04:07:56 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
name: string;
|
2021-10-01 18:07:48 +01:00
|
|
|
label?: string;
|
2020-07-11 23:37:59 +01:00
|
|
|
className?: string;
|
2020-02-23 04:07:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 18:07:48 +01:00
|
|
|
type OmitFields = 'ref' | 'name' | 'value' | 'type';
|
2020-02-23 04:07:56 +00:00
|
|
|
|
2020-07-05 00:26:07 +01:00
|
|
|
type InputProps = Omit<JSX.IntrinsicElements['input'], OmitFields>;
|
2020-02-23 04:07:56 +00:00
|
|
|
|
2021-10-01 18:07:48 +01:00
|
|
|
const Checkbox = ({ name, label, className, ...props }: Props & InputProps) => (
|
2020-02-23 04:07:56 +00:00
|
|
|
<Field name={name}>
|
2021-10-01 18:07:48 +01:00
|
|
|
{({ field }: FieldProps) => {
|
2020-02-23 04:07:56 +00:00
|
|
|
return (
|
2021-10-01 18:07:48 +01:00
|
|
|
<div css={tw`flex flex-row`} className={className}>
|
|
|
|
<Input
|
|
|
|
{...field}
|
|
|
|
{...props}
|
|
|
|
css={tw`w-5 h-5 mr-2`}
|
|
|
|
type={'checkbox'}
|
|
|
|
/>
|
|
|
|
{label &&
|
|
|
|
<div css={tw`flex-1`}>
|
|
|
|
<Label noBottomSpacing>{label}</Label>
|
|
|
|
</div>}
|
|
|
|
</div>
|
2020-02-23 04:07:56 +00:00
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Field>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Checkbox;
|