0.1.2 • Published 4 years ago

file-progress v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

file-progress

An extended HTML file input that looks like a progress bar.

Features

  • Lightweight, no dependencies.
  • Better HTML file input design.
  • Has option to upload file via ajax and show progress.
    • Use your own implementation for ajax file upload.

Installation

Using npm:

$ npm install file-progress

Using yarn:

$ yarn add file-progress

Cloning the repo:

$ git clone https://github.com/mrethical/file-progress

Usage

...
<body>
  <input type="file" id="file-progress-input">
  <script type="text/javascript" src="./dist/file-progress.js"></script>
</body>
...
const fileProgress = new FileProgress('file-progress-input');

If you installed the library via package manager, you can use the library by importing it.

import FileProgress from "file-progress";

const fileProgress = new FileProgress('file-progress-input');

Options

optiontypedescription
urlstringif set, will send selected file to the url via ajax
uploadfunction(File, FileProgress): voidfunction for implementing custom ajax call rather than built in
labelfunction(File?): voidfunction for setting custom label
onRemovefunction(): voidcallback when file was cleared/removed

To set options, provide them at class initialization.

const fileProgress = new FileProgress('file-progress-input', {
    url: 'https://example.com/upload'
});

Methods

nameparametersdescription
progresspercentage (number)set file progress bar (useful when using own ajax upload function)
prefillprefill (label)update the input label without updating the file
openopen file modal
setfileList (FileList)programatically set files of input
clearremove files

Screenshots

Imgur

Imgur

License

This library is open-sourced software licensed under the MIT license.