FileWidget
This is a React component

Source
import { FileWidget } from "@prestojs/ui-antd";
FileWidget(props)

File upload widget that wraps the antd Upload component. Unlike that component this one never uploads immediately - the raw File object will be passed to onChange and it's expected the upload will happen externally (eg. on a form submit).

If multiple is true then the value passed to onChange will be an array of File objects or an empty array when clearing the value.

If multiple is false then the value passed to onChange will be a File object or null when clearing the value.

For very custom requirements consider using the useFileList in a custom component.

// TODO: Example: limit // TODO: Example: multiple // TODO: Example: custom children // TODO: Example: drag and drop // TODO: beforeUpload

ParameterTypeDescription
*props

The props from Upload. Note that data, method, headers and withCredentials are ignored as this component doesn't upload immediately.

*props.childrenReact.ReactNode

Contents to render (eg. upload button etc). If not provided renders default Icon or Button depending on listType

*props.inputUploadWidgetInputType
*props.limitnumber|null

Number of files to allow. null means unlimited.

If limit is 1 then after uploading a file the UI will change from an Add icon to an Edit icon and uploading a new file will replace the original.

If limit is > 1 then once the limit has been reached the UI will disallow adding new files. To add a new file an existing one must be removed.

If multiple is true then the value passed to onChange will be an array, otherwise it will be a File object or null. It is valid to set limit to 1 and multiple to true.

Defaults to 1.

*props.multipleboolean

Whether multiple values are accepted. In most cases you can set limit to null or a value greater than 1 instead of explicitly setting this. This can be set to true when limit is 1 in order to enforce the value being an array (eg. this could be useful if limit increases based on something else).

If true input.value must be an array when set and onChange will be passed an array of File objects, otherwise it will be passed a single value or null.

If multiple is true and limit is 1 then the only difference to multiple={false} is that the value will be an array.

Defaults to false if limit is 1 otherwise true.