Amount
1 month ago
Consent
1 year ago
utils
1 year ago
Checkbox.tsx
1 year ago
Date.tsx
1 year ago
Email.tsx
1 year ago
File.tsx
1 year ago
Gateways.tsx
1 year ago
Hidden.tsx
2 years ago
Honeypot.tsx
1 year ago
MultiSelect.tsx
2 years ago
Password.tsx
2 years ago
Phone.tsx
1 year ago
Radio.tsx
2 years ago
Select.tsx
1 year ago
Text.tsx
1 year ago
TextArea.tsx
2 years ago
Url.tsx
2 years ago
Checkbox.tsx
24 lines
| 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 |