UploadUrlInput
Packageβ
Installationβ
- npm
- Yarn
- pnpm
npm install @rpldy/upload-url-input
OR
npm install @rpldy/uploady @rpldy/upload-url-input
yarn add @rpldy/upload-url-input
OR
yarn add @rpldy/uploady @rpldy/upload-url-input
pnpm add @rpldy/upload-url-input
OR
pnpm add @rpldy/uploady @rpldy/upload-url-input
note
Must be rendered inside (child/descendant) of an Uploady instance
Propsβ
Name (* = mandatory) | Type | Default | Description |
---|---|---|---|
id | string | undefined | id attribute to pass to the button element |
className | string | undefined | the class attribute to pass to the button element |
placeholder | string | undefined | input's placeholder text |
validate | ValidateMethod | undefined | function to validate input's value before its sent |
uploadRef | React Ref | undefined | ref will be set to the upload callback so it can be triggered from the outside (see example) |
ignoreKeyPress | boolean | false | by default pressing Enter will initiate the upload, set to true in order to disable this behavior |
In addition, most UploadOptions props can be passed to UploadButton, in order to override configuration passed to the parent Uploady component. See Uploady documentation for detailed list of upload options.
validateβ
type ValidateMethod = (value: string | undefined, input: HTMLInputElement | undefined) => boolean;
When specified, should return true (truthy) to indicate the input's value is valid. Should return false (falsy) in case the value isn't valid and to prevent the upload from taking place.
uploadRefβ
The value of the ref (current) will be set with a function that can be called when the input's value should be handed to the uploader. This is the equivalent of selecting a file of dropping a file in the drop-zone.
Exampleβ
import React, { useRef } from "react";
import Uploady from "@rpldy/uploady";
import UploadUrlInput from "@rpldy/upload-url-input";
const MyUrlUpload = () => {
const uploadRef = useRef(null);
const onClick = () => {
if (uploadRef && uploadRef.current) {
uploadRef.current(); //initiate upload
}
};
return <Uploady>
<UploadUrlInput placeholder="URL to upload"
uploadRef={uploadRef} />
<button onClick={onClick}>Upload</button>
</Uploady>;
};