// @flow import * as React from 'react'; import CheckboxTooltip from './CheckboxTooltip'; import './Checkbox.scss'; type Props = { className?: string, /** Description to the checkbox */ description?: React.Node, /** Label for the field shown on top of the checkbox */ fieldLabel?: React.Node, /** Hides the checkbox label when true */ hideLabel?: boolean, /** Unique `id` for the input */ id?: string, /** Checkbox checked state */ isChecked?: boolean, // @TODO: eventually call this `checked` /** Checkbox disabled state */ isDisabled?: boolean, // @TODO: eventually call this `disabled` /** Label displayed for the input */ label: React.Node, /** Name of the input */ name: string, /** blur callback function called with event as the argument */ onBlur?: (e: SyntheticInputEvent) => any, /** change callback function called with event as the argument */ onChange?: (e: SyntheticInputEvent) => any, /** Subsection below the checkbox */ subsection?: React.Node, /** Info tooltip text next to the checkbox label */ tooltip?: string, /** optional value for the checkbox */ value?: any, }; const Checkbox = ({ className = '', description, fieldLabel, hideLabel, id, isChecked, isDisabled, label, name, onChange, subsection, tooltip, ...rest // @TODO: eventually remove `rest` in favor of explicit props }: Props) => { const checkboxLabel = ( // eslint-disable-next-line jsx-a11y/label-has-for ); return (
{fieldLabel &&
{fieldLabel}
} {tooltip ? : checkboxLabel} {description ?
{description}
: null} {subsection ?
{subsection}
: null}
); }; export type CheckboxProps = Props; export default Checkbox;