import React, { useContext } from 'react' import type { CheckboxProps } from '@toptal/picasso-checkbox' import { Checkbox as PicassoCheckbox } from '@toptal/picasso-checkbox' import { useFieldsLayoutContext } from '@toptal/picasso-form' 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' import { useFormConfig } from '../FormConfig' type CheckboxValue = CheckboxProps['value'] | CheckboxProps['checked'] type CheckboxFormProps = Omit & { required?: boolean } type CheckboxWithoutGroup = CheckboxFormProps & FieldProps type CheckboxInGroup = CheckboxFormProps & { name?: string } export type Props = CheckboxWithoutGroup | CheckboxInGroup export const Checkbox = ({ name, value, required, label, // eslint-disable-next-line @typescript-eslint/no-unused-vars defaultValue, ...restProps }: Props) => { const { layout } = useFieldsLayoutContext() const formConfig = useFormConfig() 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 }} ) } const showAsterisk = required && formConfig.requiredVariant === 'asterisk' const requiredDecoration = showAsterisk ? 'asterisk' : undefined return ( {({ // omit 'highlight' as it is used only for classic inputs // eslint-disable-next-line @typescript-eslint/no-unused-vars highlight, ...input }: CheckboxProps & { highlight?: 'autofill' }) => ( <> {layout === 'horizontal' &&
} )} ) } Checkbox.displayName = 'Checkbox' export default Checkbox