Skip to content

Commit dc75ad1

Browse files
committed
[DEPENDENCIES]: bump jest, typescript and eslint
1 parent eeee42a commit dc75ad1

File tree

4 files changed

+139
-8
lines changed

4 files changed

+139
-8
lines changed

DEV-part2.MD

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Introduction
2+
3+
As we've seen in the last [post](https://dev.to/jinssj3/dropzone-ui-the-new-way-of-providing-drag-and-drop-file-uploads-in-react-app-5djd), [Dropzone UI](https://www.npmjs.com/package/@dropzone-ui/react) is a complete set of react components that allows developers to spend less time in coding a drag and drop component for file uploads on React apps.
4+
5+
In this post we'll check the File life cicly process and how powerful is one of the components that come inside this amazing library: `<FileItem/>`
6+
7+
# High-level file life cycle process
8+
9+
To work with [`dropzone-ui`](https://www.npmjs.com/package/@dropzone-ui/react) we can summarize the file life cycle in 5 main activities:
10+
11+
1. Create react app (however you can also start with next.js)
12+
13+
2. Install Dropzone-ui
14+
15+
3. Configure Components
16+
17+
4. Drop Files
18+
19+
5. Validate Files
20+
21+
6. Show validated files
22+
23+
7. Clean File List
24+
25+
8. Upload files
26+
27+
9. Get result of upload process
28+
29+
In this post we'll focus on activity number 3, since it´s more related with `FileItem` component. The validation activity will be covered in other post, but we can assume that we want to validate files to have as valid only image files. This is set in `accept`, a `Dropzone` component prop.
30+
31+
## Validated files
32+
33+
First, it is necesary to understand what kind of props are reqires in `FileItem` component:
34+
35+
## Beautiful by default
36+
37+
FileItem is beautiful by default since it was built following Material Design guidelines and all the icons comes from [Google's Material Icons](https://fonts.google.com/icons).
38+
39+
## Default file type preview
40+
41+
Another aspect that stands out, is that `FileItem` provides a default file preview when file type is not an image.
42+
43+
## Image file preview
44+
45+
Of course, it also provides image previews when the given file is an image.
46+
47+
The default image file type previews were made checking the file `mime type`.
48+
49+
![Image description](https://user-images.githubusercontent.com/43678736/139614260-602b512c-cf78-48fe-ae57-1057e7ec8135.gif)
50+
51+
Acording to [MDN](https://developer.mozilla.org/en-US/docs/Glossary/MIME_type), _MIME type_ (now properly called "media type", but also sometimes "content type") is a string sent along with a file indicating the type of the file (describing the content format, for example, a sound file might be labeled `audio/ogg`, or an image file `image/png`).
52+
53+
It serves the same purpose as filename extensions traditionally do on Windows. The name originates from the MIME standard originally used in E-Mail.
54+
55+
In a nutshell, the `mime type` an attrribute that describes the file content. In node.js the `File`object has an attribute called `type` that returns the mime type of a file. The full list considered for this task comes from the Common MIME types list from [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types):
56+
imagennn
57+
58+
## Multilanguage support
59+
60+
In this library, both `<Dropzone/>` and `<FileItem/>` provides a way to translate all the possible labels into other languages. Currently, the supported languages are: `Spanish`,`Portuguese`,`French`, `Chinese`, `Russian` and, of course, `English`.
61+
62+
## Installation
63+
64+
The installation processis quite easy, once you created a react app, you just need to install @dropzone-ui/react as an [npm dependency](https://www.npmjs.com/package/@dropzone-ui/react).
65+
66+
For uploading files, peer dependency [axios](https://www.npmjs.com/package/axios) must be also installed together with `dropzone-ui`.
67+
68+
```sh
69+
// with npm
70+
npm i @dropzone-ui/react axios
71+
```
72+
73+
```sh
74+
// with yarn
75+
yarn add @dropzone-ui/react axios
76+
```
77+
78+
# Usage and examples
79+
80+
In order to understand properly how to work with dropzone-ui `FileItem`, let's check the process in high level.
81+
82+
We will check how to use this component and how its behavior change due to its props in simple samples.
83+
84+
## 1) Basic example with no image preview
85+
86+
In this sample code (taken from [`codesandbox`](https://codesandbox.io/s/dropzone-ui-file-item-with-no-image-preview-14i2m)) we are telling the component that we don´t want it to provide the image preview in case of image files (e.g. png or jpeg images):
87+
88+
```jsx
89+
import { Dropzone, FileItem } from "@dropzone-ui/react";
90+
import { useState } from "react";
91+
export default function App() {
92+
const [files, setFiles] = useState([]);
93+
const updateFiles = ([...files,...incommingFiles]) => {
94+
setFiles(incommingFiles);
95+
};
96+
const onDelete = (id) => {
97+
setFiles(files.filter((x) => x.id !== id));
98+
};
99+
return (
100+
<Dropzone
101+
onChange={updateFiles}
102+
value={files}
103+
onClean
104+
>
105+
{files.map((file) => (
106+
<FileItem
107+
{...file}
108+
key={file.id}
109+
onDelete={onDelete}
110+
info
111+
/>
112+
))}
113+
</Dropzone>
114+
);
115+
}
116+
```
117+
118+
The result, after dropping some files id the following:
119+
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9x5i600zfb9ceonede4.png)
120+
121+
As you can see, the first 2 files are images and the default icon is showed. The image preview is not generated because we didn´t include the ``. This can be useful when there is no need to show the image and also when you think you can experiment performance issues due to internet connection or the web page is already heavy.
122+
123+
# Conclusion
124+
125+
In conclusion, this is an amazing library for drag and drop files with image previews. This time we've seen `FileItem` component in deep. Next posts will show more about this great package. You can find more info in the documentation https://www.npmjs.com/package/dropzone-ui.

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
:rocket: [Spanish](./README_ES.md)
22

3+
# Dropzone UI
4+
The best and most complete file upload library for [React](https://reactjs.org/) apps.
5+
36
<p align="center">
4-
<h1 align="center"><img src="https://user-images.githubusercontent.com/43678736/132112022-0ca409ae-cca2-43c8-be89-110376260a3f.png" alt="dropone-ui-logo" width="172" height="172" align="center">Dropzone-UI</h1>
7+
<h1 align="center"><img src="https://user-images.githubusercontent.com/43678736/132112022-0ca409ae-cca2-43c8-be89-110376260a3f.png" alt="dropone-ui-logo" width="172" height="172" align="center"> Dropzone UI</h1>
58
</p>
69

10+
711
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/dropzone-ui/react/blob/HEAD/LICENSE)
812
[![npm latest package](https://img.shields.io/npm/v/@dropzone-ui/react.svg?logo=npm&logoColor=fff&label=NPM+package&color=limegreen)](https://www.npmjs.com/package/@dropzone-ui/react)
913
[![Rate on Openbase](https://badges.openbase.com/js/rating/@dropzone-ui/react.svg)](https://openbase.com/js/@dropzone-ui/react?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
@@ -17,7 +21,7 @@
1721
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
1822
[![GitHub Repo stars](https://img.shields.io/github/stars/dropzone-ui/react?label=Star%20me%20please%20:D&style=social)](https://github.com/dropzone-ui/react)
1923

20-
The most complete and most powerful library for managing file uploads on [React](https://reactjs.org/) apps.
24+
2125

2226
## Sample result:
2327

@@ -39,7 +43,7 @@ Did you like the project? Please don't forget to give us a :star: star on :octoc
3943
- :performing_arts: [\<Examples and use cases\>](#Usage-and-examples)
4044

4145
- :computer: [\<Server side implementation/>](#uploading)
42-
46+
4347
- :earth_americas: [\<Localization\>](#localization)
4448

4549
## Installation
@@ -340,4 +344,4 @@ export interface CustomValidateFileResponse {
340344
This project is licensed under the terms of the
341345
[MIT license](/LICENSE).
342346

343-
Did you like the project? Please don't forget to give us a :star: star on :octocat: [github](https://github.com/dropzone-ui/dropzone-ui) :D
347+
Did you like the project? Please don't forget to give us a :star: star on :octocat: [github](https://github.com/dropzone-ui/dropzone-ui) :D

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dropzone-ui/react",
3-
"version": "5.8.4",
3+
"version": "6.0.1",
44
"description": "The most complete React library for managing file uploads. Multilanguage support. Server side support. Material design styles.",
55
"main": "./build/index.js",
66
"module": "./build/index.es.js",
@@ -22,6 +22,7 @@
2222
"react",
2323
"drag",
2424
"drop",
25+
"mui",
2526
"typescript",
2627
"front-end",
2728
"framework",
@@ -58,7 +59,7 @@
5859
"@storybook/testing-react": "^0.0.22",
5960
"@testing-library/jest-dom": "^5.15.0",
6061
"@testing-library/react": "^12.0.0",
61-
"@types/jest": "^27.0.0",
62+
"@types/jest": "^27.0.3",
6263
"@types/node": "^16.11.7",
6364
"@types/testing-library__jest-dom": "^5.9.3",
6465
"@types/testing-library__react": "^10.2.0",
@@ -71,7 +72,7 @@
7172
"eslint-config-prettier": "^8.1.0",
7273
"eslint-plugin-jest": "^25.2.4",
7374
"eslint-plugin-prettier": "^4.0.0",
74-
"eslint-plugin-react": "^7.27.0",
75+
"eslint-plugin-react": "^7.27.1",
7576
"fork-ts-checker-webpack-plugin": "^6.4.0",
7677
"identity-obj-proxy": "^3.0.0",
7778
"jest": "^26.4.2",
@@ -90,7 +91,7 @@
9091
"set-value": "^4.0.1",
9192
"ts-loader": "^9.2.5",
9293
"tslib": "^2.1.0",
93-
"typescript": "^4.4.4",
94+
"typescript": "^4.5.2",
9495
"rollup-plugin-json": "^4.0.0"
9596
},
9697
"scripts": {

src/components/icons/Upload/Upload.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const Upload: FC<UploadProps> = (props: UploadProps) => {
1818
fill={color ? color : "#000000"}
1919
className={className || ""}
2020
>
21+
2122
<g>
2223
<rect
2324
fill={colorFill || "none"}

0 commit comments

Comments
 (0)