Upload

NPM
v0.0.117

#Installation

npm install @solid-primitives/upload
yarn add @solid-primitives/upload
pnpm add @solid-primitives/upload

#Readme

Primitive to make uploading files and making dropzones easier.

#How to use it

#createFileUploader

// single files
const { files, selectFiles } = createFileUploader();
selectFiles([file] => console.log(file));

// multiple files
const { files, selectFiles } = createFileUploader({ multiple: true, accept: "image/*" });
selectFiles(files => files.forEach(file => console.log(file)));

#use:fileUploader directive

const [files, setFiles] = createSignal<UploadFile[]>([]);

<input
  type="file"
  multiple
  use:fileUploader={{
    userCallback: fs => fs.forEach(f => console.log(f)),
    setFiles,
  }}
/>;

#createDropzone

<div
  ref={dropzoneRef}
  style={{ width: "100px", height: "100px", background: "red" }}>
  Dropzone
</div>
const { setRef: dropzoneRef, files: droppedFiles } = createDropzone({
  onDrop: async files => {
    await doStuff(2);
    files.forEach(f => console.log(f));
  },
  onDragStart: files => files.forEach(f => console.log(f)),
  onDragOver: files => console.log("drag over"),
});

#Demo

Live Site

Working example: https://primitives.solidjs.community Source code: https://github.com/solidjs-community/solid-primitives/blob/main/packages/upload/dev/index.tsx

#Changelog

See CHANGELOG.md