Skip to content

Commit 99fb430

Browse files
committed
Using framer-motion to improves UX
1 parent 426d005 commit 99fb430

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

src/components/FileList/index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, useState } from 'react';
22

33
import { CircularProgressbar } from 'react-circular-progressbar';
44

5-
import { Container, FileInfo, Preview, List } from './styles';
5+
import { Container, FileInfo, Preview, List, ListItem } from './styles';
66

77
import { ThemeContext } from 'styled-components';
88

@@ -12,22 +12,35 @@ import { UploadContext } from '../../providers/UploadProvider';
1212
function FileList() {
1313
const themeContext = useContext(ThemeContext);
1414
const { uploadedFiles, handleDelete } = useContext(UploadContext);
15+
const [deleteFileAnimation, setDeleteFileAnimation] = useState('');
1516

1617
return (
17-
<Container>
18+
<Container initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }}>
1819
<h4>Imagens carregadas</h4>
1920
<List>
2021
{uploadedFiles.map((file) => (
21-
<li key={file.id}>
22+
<ListItem
23+
key={file.id}
24+
initial={{ opacity: 0, x: -100 }}
25+
animate={
26+
deleteFileAnimation === file.id
27+
? { opacity: 0, scale: 0 }
28+
: { opacity: 1, x: 0 }
29+
}
30+
>
2231
<FileInfo>
2332
<Preview src={file.preview} alt="preview" />
24-
2533
<div>
2634
<strong>{file.name}</strong>
2735
<span>
2836
{file.readableSize}
2937
{!!file.url && (
30-
<button onClick={(e) => handleDelete(file.id)}>
38+
<button
39+
onClick={(e) => {
40+
setDeleteFileAnimation(file.id);
41+
handleDelete(file.id);
42+
}}
43+
>
3144
Excluir
3245
</button>
3346
)}
@@ -60,7 +73,7 @@ function FileList() {
6073
)}
6174
{file.uploaded && <MdCheckCircle size={34} color="#4caf50" />}
6275
{file.error && <MdError size={34} color="#f44336" />}
63-
</li>
76+
</ListItem>
6477
))}
6578
</List>
6679
</Container>

src/components/FileList/styles.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
import styled, { keyframes } from 'styled-components';
1+
import { motion } from 'framer-motion';
2+
import styled from 'styled-components';
23

3-
const showAnimation = keyframes`
4-
0% {
5-
opacity:0;
6-
transform: scaleY(0) translateY(-100%);
7-
}
8-
100% {
9-
opacity:1;
10-
transform: scaleY(1) translateY(0%);
11-
}
12-
`;
13-
14-
export const Container = styled.section`
4+
export const Container = styled(motion.section)`
155
display: flex;
166
flex-direction: column;
177
min-height: 50px;
@@ -24,7 +14,7 @@ export const Container = styled.section`
2414
}
2515
`;
2616

27-
export const List = styled.ul`
17+
export const List = styled(motion.ul)`
2818
display: flex;
2919
flex-direction: column;
3020
@@ -35,17 +25,15 @@ export const List = styled.ul`
3525
3626
max-height: 200px;
3727
overflow-x: auto;
28+
`;
3829

39-
& li {
40-
display: flex;
41-
justify-content: space-between;
42-
align-items: center;
43-
animation: ${showAnimation} linear 0.3s;
44-
animation-iteration-count: 1;
30+
export const ListItem = styled(motion.li)`
31+
display: flex;
32+
justify-content: space-between;
33+
align-items: center;
4534
46-
& + li {
47-
margin-top: 10px;
48-
}
35+
& + li {
36+
margin-top: 10px;
4937
}
5038
`;
5139

src/components/Upload/styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const DropContainer = styled.div.attrs({ className: 'dropzone' })`
3434
flex-direction: column;
3535
justify-content: center;
3636
align-items: center;
37-
height: 100%;
37+
height: 150px;
3838
width: 100%;
3939
padding: 15px 30px;
4040

0 commit comments

Comments
 (0)