Amount
2 years ago
Consent
2 years ago
Checkbox.tsx
2 years ago
Date.tsx
2 years ago
Email.tsx
2 years ago
File.tsx
2 years ago
Gateways.tsx
2 years ago
Hidden.tsx
2 years ago
MultiSelect.tsx
2 years ago
Password.tsx
2 years ago
Phone.tsx
2 years ago
Radio.tsx
2 years ago
Select.tsx
2 years ago
Text.tsx
2 years ago
TextArea.tsx
2 years ago
Url.tsx
2 years ago
File.tsx
35 lines
| 1 | import {FileProps} from '@givewp/forms/propTypes'; |
| 2 | |
| 3 | export default function File({ |
| 4 | Label, |
| 5 | allowedMimeTypes, |
| 6 | ErrorMessage, |
| 7 | fieldError, |
| 8 | description, |
| 9 | inputProps, |
| 10 | }: FileProps) { |
| 11 | const FieldDescription = window.givewp.form.templates.layouts.fieldDescription; |
| 12 | const {setValue} = window.givewp.form.hooks.useFormContext(); |
| 13 | const {name} = inputProps; |
| 14 | |
| 15 | return ( |
| 16 | <label> |
| 17 | <Label /> |
| 18 | {description && <FieldDescription description={description} />} |
| 19 | |
| 20 | <input |
| 21 | type="file" |
| 22 | aria-invalid={fieldError ? 'true' : 'false'} |
| 23 | accept={allowedMimeTypes.join(',')} |
| 24 | onChange={(e) => { |
| 25 | setValue(name, e.target.files[0]); |
| 26 | }} |
| 27 | /> |
| 28 | |
| 29 | <input type="hidden" {...inputProps} /> |
| 30 | |
| 31 | <ErrorMessage /> |
| 32 | </label> |
| 33 | ); |
| 34 | } |
| 35 |