Skip to content

Commit 7167a8f

Browse files
committed
🐛 Erro triste no evento de editar o rolê
1 parent 859ff8e commit 7167a8f

File tree

5 files changed

+75
-20
lines changed

5 files changed

+75
-20
lines changed

src/App.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ const App = () => (
1111
<MainTitle content="Todo" />
1212

1313
<MainTask id="task1" content="Criar o title" />
14-
1514
<MainTask id="task2" content="Criar o title" />
16-
1715
<MainTask id="task3" content="Criar o title" />
18-
1916
<MainTask id="task4" content="Criar o title" />
2017
</>
2118
);

src/components/MainTask/index.js

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
1-
import React from 'react';
2-
3-
import { Label, Checkbox } from './styles';
4-
5-
const MainTask = ({id, content}) => (
6-
<>
7-
<Checkbox id={id} />
8-
<Label for={id}>
9-
{content}
10-
</Label>
11-
</>
12-
);
1+
import React, { useState, useRef, useEffect } from 'react';
2+
3+
import iconEdit from '../../img/icon_edit.svg';
4+
import iconDelete from "../../img/icon_delete.svg";
5+
import { Label, Checkbox, Icon, Content } from './styles';
6+
7+
function MainTask ({id, content}) {
8+
const [isEditable, setIsEditable] = useState(false);
9+
const componentContent = useRef(null);
10+
11+
function editable() {
12+
setIsEditable(old => !old);
13+
}
14+
15+
function selectText(event) {
16+
console.log('ENTROU AQUI AGORA!')
17+
console.log(event.target);
18+
19+
event.target.select();
20+
}
21+
22+
23+
useEffect(() => {
24+
isEditable && componentContent.current.focus();
25+
});
26+
27+
return (
28+
<>
29+
<Checkbox id={id}/>
30+
<Label htmlFor={id}>
31+
<Content contentEditable={isEditable} suppressContentEditableWarning={true}>
32+
{content}
33+
</Content>
34+
35+
<input ref={componentContent} onFocus={selectText} type="text" value="EITA MDN" />
36+
37+
<Icon src={iconEdit} onClick={editable} />
38+
<Icon src={iconDelete} />
39+
</Label>
40+
</>
41+
)
42+
};
43+
44+
1345

1446
export default MainTask;

src/components/MainTask/styles.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@ const Checkbox = styled.input.attrs({ type: "checkbox"})`
44
display: none;
55
`;
66

7+
const Icon = styled.img`
8+
opacity: 0;
9+
margin-left: 10px;
10+
transition: opacity 200ms linear, transform 200ms linear;
11+
12+
&:hover {
13+
transform: scale(1.2);
14+
}
15+
`;
16+
17+
const Content = styled.span`
18+
&[contenteditable="true"] {
19+
border: 2px dotted var(--color-first);
20+
}
21+
`;
22+
723
const Label = styled.label`
824
display: flex;
925
align-items: center;
1026
font-size: 22px;
1127
font-weight: 300;
1228
padding: 30px 20px;
1329
margin-bottom: 30px;
30+
cursor: pointer;
1431
15-
background-image: linear-gradient(270.67deg, rgba(255, 255, 255, 0) 0.13%, rgba(160, 163, 164, 0.483621) 18.84%, rgba(123, 127, 128, 0.671695) 39.1%, rgba(81, 86, 88, 0.885417) 75.46%, #3A4042 99.88%);
32+
background-image: linear-gradient(270.67deg, rgba(255, 255, 255, 0.15) 0.13%, rgba(160, 163, 164, 0.483621) 11.56%, rgba(123, 127, 128, 0.671695) 26.63%, rgba(81, 86, 88, 0.885417) 75.46%, #3A4042 99.88%);
1633
1734
&:before {
1835
content: "";
@@ -22,14 +39,17 @@ const Label = styled.label`
2239
border-radius: 50%;
2340
border: 2px solid var(--color-first);
2441
margin-right: 15px;
25-
cursor: pointer;
42+
43+
transition: background-color 200ms linear;
2644
}
2745
2846
${Checkbox}:checked + &:before {
2947
background-color: var(--color-first);
3048
}
31-
`;
32-
3349
50+
&:hover > ${Icon} {
51+
opacity: 1;
52+
}
53+
`;
3454

35-
export { Label, Checkbox }
55+
export { Label, Checkbox, Icon, Content }

src/img/icon_delete.svg

Lines changed: 3 additions & 0 deletions
Loading

src/img/icon_edit.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)