import React, { useContext } from 'react' import type { ButtonCheckboxProps } from '@toptal/picasso-button' import { ButtonCheckbox as PicassoButtonCheckbox } from '@toptal/picasso-button' import type { FieldRenderProps as FinalFormFieldProps } from 'react-final-form' import { Field } from 'react-final-form' import type { FieldProps } from '../Field' import PicassoField from '../Field' import { CheckboxGroupContext } from '../CheckboxGroup' type CheckboxValue = | ButtonCheckboxProps['value'] | ButtonCheckboxProps['checked'] type CheckboxFormProps = Omit & { required?: boolean } type CheckboxWithoutGroup = CheckboxFormProps & FieldProps type CheckboxInGroup = CheckboxFormProps & { name?: string } export type Props = CheckboxWithoutGroup | CheckboxInGroup const ButtonCheckbox = ({ name, value, required, ...restProps }: Props) => { const groupName = useContext(CheckboxGroupContext) const isCheckboxInGroup = Boolean(groupName) if (isCheckboxInGroup) { return ( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion {({ // eslint-disable-next-line @typescript-eslint/no-unused-vars input: { value: inputValue, type, ...restInput }, }: FinalFormFieldProps) => { return }} ) } return ( {({ // omit 'highlight' as it is used only for classic inputs // eslint-disable-next-line @typescript-eslint/no-unused-vars highlight, ...input }: ButtonCheckboxProps & { highlight?: 'autofill' }) => ( )} ) } ButtonCheckbox.displayName = 'ButtonCheckbox' export default ButtonCheckbox