-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2주차] 변지혜 미션 제출합니다. #3
base: master
Are you sure you want to change the base?
Changes from all commits
11fe570
9ff350c
0b872e6
78710e6
71000ea
01de348
bcc3405
fb864df
a04787a
ff6e9fc
3fe8eae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import TodoTemplate from "./TodoTemplate"; | ||
|
||
function App() { | ||
return ( | ||
<div> | ||
<h1>18기 프론트 화이팅~ 푸하항ㅋ</h1> | ||
</div> | ||
); | ||
return ( | ||
<> | ||
<TodoTemplate /> | ||
</> | ||
); | ||
} | ||
|
||
export default App; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
import GlobalStyle from "./styles/GlobalStyle"; | ||
|
||
import TodoTopbar from "./components/TodoTopbar"; | ||
import TodoListItem from "./components/TodoListItem"; | ||
|
||
function TodoTemplate() { | ||
//todo | ||
const initialTodoData = localStorage.getItem("list") | ||
? JSON.parse(localStorage.getItem("list")) | ||
: []; | ||
|
||
const [list, setList] = useState(initialTodoData); | ||
const [value, setValue] = useState(""); | ||
|
||
const deleteTodo = (id) => { | ||
let deletedTodo = list.filter((data) => data.id !== id); | ||
setList(deletedTodo); | ||
localStorage.setItem("list", JSON.stringify(deletedTodo)); | ||
}; | ||
|
||
const toggleTodo = (id) => { | ||
let toggledTodo = list.map((data) => | ||
data.id === id ? { ...data, completed: !data.completed } : data | ||
); | ||
setList(toggledTodo); | ||
localStorage.setItem("list", JSON.stringify(toggledTodo)); | ||
}; | ||
|
||
return ( | ||
<> | ||
<GlobalStyle /> | ||
<TodoTopbar | ||
list={list} | ||
value={value} | ||
setList={setList} | ||
setValue={setValue} | ||
/> | ||
<TodoContainer> | ||
<article> | ||
<h3 class="list-title">TODO</h3> | ||
<div class="todo-list"> | ||
{list.map((data) => | ||
data.completed ? ( | ||
<></> | ||
) : ( | ||
<TodoListItem | ||
key={data.id} | ||
todo={data} | ||
deleteTodo={deleteTodo} | ||
toggleTodo={toggleTodo} | ||
/> | ||
) | ||
)} | ||
</div> | ||
</article> | ||
<article> | ||
<h3 class="list-title">DONE</h3> | ||
<div class="done-list"> | ||
{list.map((data) => | ||
data.completed ? ( | ||
<TodoListItem | ||
key={data.id} | ||
todo={data} | ||
deleteTodo={deleteTodo} | ||
toggleTodo={toggleTodo} | ||
/> | ||
) : ( | ||
<></> | ||
) | ||
)} | ||
</div> | ||
</article> | ||
</TodoContainer> | ||
</> | ||
); | ||
} | ||
|
||
export default TodoTemplate; | ||
|
||
const TodoContainer = styled.section` | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
justify-content: center; | ||
|
||
min-height: 18.75em; | ||
max-width: 60%; | ||
|
||
border-radius: 2.125em; | ||
border: 0.1875em solid #7adb84; | ||
padding: 0.3125em 0.625em; | ||
margin: 0.625em auto; | ||
|
||
position: relative; | ||
|
||
.list-title { | ||
margin: 0.625em 0 0.625em 0.3125em; | ||
font-family: "Pretendard-Regular"; | ||
color: #00c013; | ||
} | ||
|
||
.todo-list, | ||
.done-list { | ||
list-style: none; | ||
margin: 0 0 0.625em; | ||
padding: 0 1.875em 0 0.625em; | ||
|
||
max-height: 18em; | ||
overflow-y: scroll; | ||
|
||
&::-webkit-scrollbar { | ||
width: 5px; | ||
} | ||
|
||
&::-webkit-scrollbar-thumb { | ||
background: #7adb84; | ||
border-radius: 1.875em; | ||
} | ||
Comment on lines
+116
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스크롤바까지 디테일 신경쓴게 아주 좋습니다!! |
||
|
||
&::-webkit-scrollbar-track { | ||
background-color: transparent; | ||
} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import del from "../images/delete.png"; | ||
import check from "../images/checkbox.png"; | ||
import done from "../images/donebox.png"; | ||
|
||
function TodoListItem({ todo, deleteTodo, toggleTodo }) { | ||
return ( | ||
<ListItem> | ||
<IsDoneBox | ||
onClick={() => toggleTodo(todo.id)} | ||
src={todo.completed ? done : check} | ||
></IsDoneBox> | ||
<TodoText onClick={() => toggleTodo(todo.id)}>{todo.title}</TodoText> | ||
<TodoDel src={del} onClick={() => deleteTodo(todo.id)} /> | ||
</ListItem> | ||
); | ||
} | ||
|
||
export default TodoListItem; | ||
|
||
const ListItem = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
|
||
padding: 0.1875em 0; | ||
transition: color 0.3s; | ||
color: #000; | ||
font-family: "SUITE-Regular"; | ||
font-size: 0.75em; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
color: #4caf50; | ||
} | ||
`; | ||
|
||
const TodoText = styled.span` | ||
width: 100%; | ||
max-width: 100%; | ||
white-space: normal; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
`; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 리뷰받았던 내용인데, word-break: break-all;를 추가해 영어길이가 길어졌을 때, 깨지는 것을 방지하는 것이 좋을 것 같아요! |
||
const IsDoneBox = styled.img` | ||
width: 1.25em; | ||
height: 1.25em; | ||
padding-right: 1em; | ||
border: none; | ||
border-radius: 0.3125em; | ||
background-color: transparent; | ||
cursor: pointer; | ||
`; | ||
|
||
const TodoDel = styled.img` | ||
width: 1.25em; | ||
height: 1.25em; | ||
padding: 0; | ||
border: none; | ||
border-radius: 0.3125em; | ||
background-color: transparent; | ||
cursor: pointer; | ||
|
||
opacity: 0; | ||
transition: opacity 0.3s; | ||
${ListItem}:hover & { | ||
opacity: 1; | ||
} | ||
`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 퍼센트와 rem을 잘 다루시는 것 같아요. 멋지고 부럽습니다 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 completed 기준으로 todolist, donelist 따로 array를 저장한 후에 map 함수를 사용하였는데, 삼항연산자를 이용해서 예외처리를 하는 방법도 좋은 방법인거 같습니다!