| 1 |
import type {CheckboxProps} from '@givewp/forms/propTypes'; |
| 2 |
|
| 3 |
/** |
| 4 |
* @since 4.0.0 updated inputProps and value to prevent checkbox from being a controlled component |
| 5 |
* @since 3.0.0 |
| 6 |
*/ |
| 7 |
export default function Checkbox({Label, ErrorMessage, value, helpText, fieldError, inputProps}: CheckboxProps) { |
| 8 |
const FieldDescription = window.givewp.form.templates.layouts.fieldDescription; |
| 9 |
|
| 10 |
const {checked, ...rest} = inputProps; |
| 11 |
const inputValue = value === null ? undefined : value; |
| 12 |
|
| 13 |
return ( |
| 14 |
<> |
| 15 |
<label> |
| 16 |
<input type="checkbox" value={inputValue} defaultChecked={checked} aria-invalid={fieldError ? 'true' : 'false'} {...rest} /> |
| 17 |
<Label /> |
| 18 |
</label> |
| 19 |
{helpText && <FieldDescription description={helpText} />} |
| 20 |
<ErrorMessage /> |
| 21 |
</> |
| 22 |
); |
| 23 |
} |
| 24 |
|