|
1 | | -## Welcome to GitHub Pages |
| 1 | +<img align="right" alt="traffic" src="https://pv-badge.herokuapp.com/total.svg?repo_id=olavoparno-react-use-downloader"/> |
2 | 2 |
|
3 | | -You can use the [editor on GitHub](https://github.com/olavoparno/react-use-downloader/edit/main/docs/index.md) to maintain and preview the content for your website in Markdown files. |
| 3 | +# react-use-downloader |
4 | 4 |
|
5 | | -Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files. |
| 5 | +> Creates a download handler function with its progress information and cancel ability. |
6 | 6 |
|
7 | | -### Markdown |
| 7 | +[](https://www.npmjs.com/package/react-use-downloader) |
8 | 8 |
|
9 | | -Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for |
| 9 | +--- |
10 | 10 |
|
11 | | -```markdown |
12 | | -Syntax highlighted code block |
| 11 | +## Table of Contents |
13 | 12 |
|
14 | | -# Header 1 |
15 | | -## Header 2 |
16 | | -### Header 3 |
| 13 | +- [Running example](#running-example) |
| 14 | +- [Install](#install) |
| 15 | +- [Usage](#usage) |
| 16 | +- [Documentation](#documentation) |
| 17 | +- [License](#license) |
17 | 18 |
|
18 | | -- Bulleted |
19 | | -- List |
| 19 | +--- |
20 | 20 |
|
21 | | -1. Numbered |
22 | | -2. List |
| 21 | +## Running example |
23 | 22 |
|
24 | | -**Bold** and _Italic_ and `Code` text |
| 23 | +| Plain | |
| 24 | +| ------------------------------- | |
| 25 | +|  | |
| 26 | +| [Preview!](https://codesandbox.io/s/react-use-downloader-0zzoq) | |
25 | 27 |
|
26 | | -[Link](url) and  |
| 28 | +--- |
| 29 | + |
| 30 | +## Install |
| 31 | + |
| 32 | +```bash |
| 33 | +npm install --save react-use-downloader |
| 34 | +``` |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +```jsx |
| 41 | +import React from "react"; |
| 42 | +import useDownloader from "react-use-downloader"; |
| 43 | + |
| 44 | +export default function App() { |
| 45 | + const { |
| 46 | + size, |
| 47 | + elapsed, |
| 48 | + percentage, |
| 49 | + download, |
| 50 | + cancel, |
| 51 | + error, |
| 52 | + isInProgress |
| 53 | + } = useDownloader(); |
| 54 | + |
| 55 | + const fileUrl = "https://olavoparno.github.io/saywololo/sounds/Wololo1.wav"; |
| 56 | + |
| 57 | + return ( |
| 58 | + <div className="App"> |
| 59 | + <p>Download is in {isInProgress ? 'in progress' : 'stopped'}</p> |
| 60 | + <button onClick={() => download(fileUrl, "filename")}> |
| 61 | + Click to download the file |
| 62 | + </button> |
| 63 | + <button onClick={() => cancel()}>Cancel the download</button> |
| 64 | + <p> |
| 65 | + Download size in bytes {size} |
| 66 | + </p> |
| 67 | + <label for="file">Downloading progress:</label> |
| 68 | + <progress id="file" value={percentage} max="100" /> |
| 69 | + <p>Elapsed time in seconds {elapsed}</p> |
| 70 | + {error && <p>possible error {JSON.stringify(error)}</p>} |
| 71 | + </div> |
| 72 | + ); |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Documentation |
| 79 | + |
| 80 | +`useDownloader()` returns: |
| 81 | + |
| 82 | +- An object with the following keys: |
| 83 | + |
| 84 | +| key | description | arguments | |
| 85 | +| ------------ | -------------------------------- | --------------------------------------- | |
| 86 | +| size | size in bytes | n/a | |
| 87 | +| elapsed | elapsed time in seconds | n/a | |
| 88 | +| percentage | percentage in string | n/a | |
| 89 | +| download | download function handler | (downloadUrl: string, filename: string) | |
| 90 | +| cancel | cancel function handler | n/a | |
| 91 | +| error | error object from the request | n/a | |
| 92 | +| isInProgress | boolean denoting download status | n/a | |
| 93 | + |
| 94 | +```jsx |
| 95 | +const { |
| 96 | + size, |
| 97 | + elapsed, |
| 98 | + percentage, |
| 99 | + download, |
| 100 | + cancel, |
| 101 | + error, |
| 102 | + isInProgress |
| 103 | + } = useDownloader(); |
27 | 104 | ``` |
28 | 105 |
|
29 | | -For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/). |
| 106 | +--- |
30 | 107 |
|
31 | | -### Jekyll Themes |
| 108 | +## License |
32 | 109 |
|
33 | | -Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/olavoparno/react-use-downloader/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file. |
| 110 | +react-use-downloader is [MIT licensed](./LICENSE). |
34 | 111 |
|
35 | | -### Support or Contact |
| 112 | +--- |
36 | 113 |
|
37 | | -Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://support.github.com/contact) and we’ll help you sort it out. |
| 114 | +This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook). |
0 commit comments