import * as React from "react"; import styled from "styled-components"; import { useField } from "formik"; import { BaseLabel, Label, ErrorLabel, Checkbox, Box, Col } from "./index"; import { StructureProps } from "./system/unions"; type ManagedCheckboxFieldProps = StructureProps & { caption?: string; label: string; id: string; disabled?: boolean; }; // Hide this input completely const HiddenInput = styled.input` position: absolute; opacity: 0; height: 0; width: 0; margin: 0px; `; export const ManagedCheckboxField = ({ label, caption, id, disabled, ...props }: ManagedCheckboxFieldProps) => { const [field, meta, { setTouched }] = useField({ name: id, type: "checkbox", }); // Chrome and Safari do not send blur events properly const onChange = React.useCallback( (e: React.ChangeEvent) => { setTouched(true); field.onChange(e); }, [field.onChange, setTouched] ); return ( {caption ? ( ) : null} {meta.error} ); };