Skip to content

Commit 5df2930

Browse files
committed
Run prettier
1 parent 972d270 commit 5df2930

File tree

8 files changed

+123
-81
lines changed

8 files changed

+123
-81
lines changed

README.md

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
</a>
55
</h1>
66

7-
<p align="center"><b>React File & Image Uploader</b><br/> (React Wrapper for <a href="https://upload.io/uploader">Uploader</a>)</p>
7+
<p align="center"><b>React File Upload Component</b><br/> (React Wrapper for <a href="https://upload.io/uploader">Uploader</a>)</p>
88
<br/>
99
<p align="center">
10-
<a href="https://github.com/upload-js/uploader/">
10+
<a href="https://github.com/upload-io/uploader/">
1111
<img src="https://img.shields.io/badge/gzipped-29%20kb-4ba0f6" />
1212
</a>
1313

1414
<a href="https://www.npmjs.com/package/uploader">
1515
<img src="https://img.shields.io/badge/uploader-npm-4ba0f6" />
1616
</a>
1717

18-
<a href="https://github.com/upload-js/uploader/actions/workflows/ci.yml">
18+
<a href="https://github.com/upload-io/uploader/actions/workflows/ci.yml">
1919
<img src="https://img.shields.io/badge/build-passing-4ba0f6" />
2020
</a>
2121

@@ -28,7 +28,7 @@
2828
<img src="https://img.shields.io/badge/TypeScript-included-4ba0f6" />
2929
</a>
3030

31-
<a href="https://github.com/upload-js/uploader/actions/workflows/ci.yml">
31+
<a href="https://github.com/upload-io/uploader/actions/workflows/ci.yml">
3232
<img src="https://img.shields.io/npms-io/maintenance-score/upload-js?color=4ba0f6" />
3333
</a>
3434

@@ -38,6 +38,34 @@
3838

3939
</p>
4040

41+
# Quick Start
42+
43+
44+
```shell
45+
npm install react-uploader
46+
```
47+
48+
```javascript
49+
const { UploadButton } = require("react-uploader");
50+
const { Uploader } = require("uploader");
51+
52+
const uploader = new Uploader({
53+
apiKey: "free" // Get production API keys from Upload.io
54+
});
55+
56+
<UploadButton uploader={uploader}
57+
options={{multi: true}}
58+
onComplete={files => console.log(files)}>
59+
{({onClick}) =>
60+
<button onClick={onClick}>
61+
Upload a file...
62+
</button>
63+
}
64+
</UploadButton>
65+
```
66+
67+
# Documentation
68+
4169
## Installation
4270

4371
Install via NPM:
@@ -58,9 +86,7 @@ Or via a `<script>` tag:
5886
<script src="https://js.upload.io/react-uploader/v1"></script>
5987
```
6088

61-
## Usage
62-
63-
### Initialize
89+
## Initialization
6490

6591
Initialize once at the start of your application:
6692

@@ -74,9 +100,11 @@ const uploader = new Uploader({
74100
});
75101
```
76102

77-
### Render a File Upload Component
103+
## Using the File Upload Components
104+
105+
`react-uploader` provides two UI components:
78106

79-
#### Option 1: Render a File Upload Button
107+
### Option 1: Creating a File Upload Button
80108

81109
```javascript
82110
// Ignore if installed via a script tag.
@@ -93,7 +121,7 @@ const { UploadButton } = require("react-uploader");
93121
</UploadButton>
94122
```
95123

96-
#### Option 2: Render a Dropzone
124+
### Option 2: Creating a Dropzone
97125

98126
```javascript
99127
// Ignore if installed via a script tag.
@@ -106,7 +134,7 @@ const { UploadDropzone } = require("react-uploader");
106134
height="375px" />
107135
```
108136

109-
### The Result
137+
## The Result
110138

111139
The `onComplete` callback returns a `Array<UploaderResult>`:
112140

@@ -140,13 +168,13 @@ The `onComplete` callback returns a `Array<UploaderResult>`:
140168

141169
`react-uploader` is a wrapper for `uploader`.
142170

143-
Please see: **[Uploader Docs](https://github.com/upload-js/uploader#%EF%B8%8F-configuration)**.
171+
Please see: **[Uploader Docs](https://github.com/upload-io/uploader#%EF%B8%8F-configuration)**.
144172

145173
## Contribute
146174

147175
If you would like to contribute to Uploader:
148176

149-
1. Add a [GitHub Star](https://github.com/upload-js/uploader/stargazers) to the project (if you're feeling generous!).
177+
1. Add a [GitHub Star](https://github.com/upload-io/uploader/stargazers) to the project (if you're feeling generous!).
150178
2. Determine whether you're raising a bug, feature request or question.
151179
3. Raise your issue or PR.
152180

jest.config.pretest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ global.console = {
22
log: () => undefined, // console.log are ignored in tests
33

44
// Keep native behaviour for other methods, use those to print out things in your own tests, not `console.log`
5-
error: (e) => {
5+
error: e => {
66
if (e.includes("Rendering components directly into document.body")) {
77
// Silence React "render in body" warning.
8-
return
8+
return;
99
}
10-
console.error(e)
10+
console.error(e);
1111
},
1212
warn: console.warn,
1313
info: console.info,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"readmeFilename": "README.md",
1111
"repository": {
1212
"type": "git",
13-
"url": "git+https://github.com/upload-js/react-uploader.git"
13+
"url": "git+https://github.com/upload-io/react-uploader.git"
1414
},
1515
"bugs": {
16-
"url": "https://github.com/upload-js/react-uploader/issues"
16+
"url": "https://github.com/upload-io/react-uploader/issues"
1717
},
1818
"files": [
1919
"*"

src/UploadButton.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import {Uploader, UploaderResult, UploaderOptions} from "uploader";
1+
import { Uploader, UploaderResult, UploaderOptions } from "uploader";
22

33
interface MouseEventLite {
4-
preventDefault: () => void
4+
preventDefault: () => void;
55
}
66

77
interface Props {
8-
children: (props: {onClick: (event: MouseEventLite) => void}) => JSX.Element
9-
onComplete?: (files: UploaderResult[]) => void
10-
options?: UploaderOptions
11-
uploader: Uploader
8+
children: (props: { onClick: (event: MouseEventLite) => void }) => JSX.Element;
9+
onComplete?: (files: UploaderResult[]) => void;
10+
options?: UploaderOptions;
11+
uploader: Uploader;
1212
}
1313

14-
export const UploadButton = ({uploader, options, onComplete, children}: Props): JSX.Element => {
14+
export const UploadButton = ({ uploader, options, onComplete, children }: Props): JSX.Element => {
1515
const onClick = (e: MouseEventLite): void => {
16-
e.preventDefault()
16+
e.preventDefault();
1717

18-
uploader.open(options).then(files => {
19-
if (onComplete !== undefined) {
20-
onComplete(files)
21-
}
22-
}, error => console.error("Uploader error.", error))
23-
}
18+
uploader.open(options).then(
19+
files => {
20+
if (onComplete !== undefined) {
21+
onComplete(files);
22+
}
23+
},
24+
error => console.error("Uploader error.", error)
25+
);
26+
};
2427

25-
return children({onClick})
26-
}
28+
return children({ onClick });
29+
};

src/UploadDropzone.tsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1-
import {Uploader, UploaderResult, UploaderOptions} from "uploader";
2-
import React, {useLayoutEffect} from "react";
3-
import {useElementRef} from "react-uploader/Utils";
1+
import { Uploader, UploaderResult, UploaderOptions } from "uploader";
2+
import React, { useLayoutEffect } from "react";
3+
import { useElementRef } from "react-uploader/Utils";
44

55
interface Props {
66
height?: string;
7-
onComplete?: (files: UploaderResult[]) => void
8-
options?: UploaderOptions
9-
uploader: Uploader
7+
onComplete?: (files: UploaderResult[]) => void;
8+
options?: UploaderOptions;
9+
uploader: Uploader;
1010
width?: string;
1111
}
1212

13-
export const UploadDropzone = ({uploader, options, onComplete, width, height}: Props): JSX.Element => {
13+
export const UploadDropzone = ({ uploader, options, onComplete, width, height }: Props): JSX.Element => {
1414
const [element, elementRef] = useElementRef();
1515

1616
useLayoutEffect(() => {
1717
if (element !== undefined) {
18-
uploader.open({
19-
...options,
20-
container: element,
21-
layout: "inline"
22-
}).then(files => {
23-
if (onComplete !== undefined) {
24-
onComplete(files)
25-
}
26-
}, error => console.error("Uploader error.", error))
18+
uploader
19+
.open({
20+
...options,
21+
container: element,
22+
layout: "inline"
23+
})
24+
.then(
25+
files => {
26+
if (onComplete !== undefined) {
27+
onComplete(files);
28+
}
29+
},
30+
error => console.error("Uploader error.", error)
31+
);
2732
}
28-
}, [element])
33+
}, [element]);
2934

30-
return <div ref={elementRef} style={{position: "relative", width: "100%", maxWidth: width ?? "600px", height: "375px" ?? height}} />
31-
}
35+
return (
36+
<div
37+
ref={elementRef}
38+
style={{ position: "relative", width: "100%", maxWidth: width ?? "600px", height: "375px" ?? height }}
39+
/>
40+
);
41+
};

src/Utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useCallback, useState} from "react";
1+
import { useCallback, useState } from "react";
22

33
export function useElementRef(): [HTMLElement | undefined, (e: HTMLElement | null) => void] {
44
const [element, setElement] = useState<HTMLElement | undefined>(undefined);

tests/UploadButton.test.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
import { UploadButton } from 'react-uploader/UploadButton';
1+
import { UploadButton } from "react-uploader/UploadButton";
22
import React from "react";
3-
import {Uploader} from "uploader";
4-
import {configure, mount} from 'enzyme';
5-
import Adapter from 'enzyme-adapter-react-16';
3+
import { Uploader } from "uploader";
4+
import { configure, mount } from "enzyme";
5+
import Adapter from "enzyme-adapter-react-16";
66

7-
(global as any).ResizeObserver = require('resize-observer-polyfill')
8-
const uploader = new Uploader({apiKey: "free"})
7+
(global as any).ResizeObserver = require("resize-observer-polyfill");
8+
const uploader = new Uploader({ apiKey: "free" });
99
configure({ adapter: new Adapter() });
1010

1111
describe("UploadButton Component", () => {
12-
1312
test("Renders the given child", () => {
14-
const html = mount(<UploadButton uploader={uploader}>{({onClick}) => <button onClick={onClick}>Click Me</button>}</UploadButton>);
15-
expect(html.text()).toEqual('Click Me');
16-
})
13+
const html = mount(
14+
<UploadButton uploader={uploader}>{({ onClick }) => <button onClick={onClick}>Click Me</button>}</UploadButton>
15+
);
16+
expect(html.text()).toEqual("Click Me");
17+
});
1718

1819
test("Displays the Uploader modal when clicked", async () => {
1920
const html = mount(
2021
<div>
21-
<UploadButton uploader={uploader} options={{container: "#container"}}>
22-
{({onClick}) => <button onClick={onClick}>Click Me</button>}
22+
<UploadButton uploader={uploader} options={{ container: "#container" }}>
23+
{({ onClick }) => <button onClick={onClick}>Click Me</button>}
2324
</UploadButton>
2425
<div id="container" />
2526
</div>,
2627
{ attachTo: document.body }
2728
);
2829

29-
html.find("button").simulate('click');
30+
html.find("button").simulate("click");
3031

3132
await tick();
3233

33-
expect(html.html()).toContain('Upload a File');
34-
})
35-
})
34+
expect(html.html()).toContain("Upload a File");
35+
});
36+
});
3637

3738
async function tick(): Promise<void> {
3839
await new Promise(resolve => {
3940
setTimeout(resolve, 1000);
40-
})
41+
});
4142
}

tests/UploadDropzone.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import React from "react";
2-
import {Uploader} from "uploader";
3-
import {configure, mount} from 'enzyme';
4-
import Adapter from 'enzyme-adapter-react-16';
5-
import {UploadDropzone} from "react-uploader/UploadDropzone";
2+
import { Uploader } from "uploader";
3+
import { configure, mount } from "enzyme";
4+
import Adapter from "enzyme-adapter-react-16";
5+
import { UploadDropzone } from "react-uploader/UploadDropzone";
66

7-
(global as any).ResizeObserver = require('resize-observer-polyfill')
8-
const uploader = new Uploader({apiKey: "free"})
7+
(global as any).ResizeObserver = require("resize-observer-polyfill");
8+
const uploader = new Uploader({ apiKey: "free" });
99
configure({ adapter: new Adapter() });
1010

1111
describe("UploadDropzone Component", () => {
1212
test("Renders the Uploader component inline", async () => {
1313
const html = mount(<UploadDropzone uploader={uploader} />, { attachTo: document.body });
1414
await tick();
15-
expect(html.html()).toContain('Upload a File');
16-
})
17-
})
15+
expect(html.html()).toContain("Upload a File");
16+
});
17+
});
1818

1919
async function tick(): Promise<void> {
2020
await new Promise(resolve => {
2121
setTimeout(resolve, 1000);
22-
})
22+
});
2323
}

0 commit comments

Comments
 (0)