Skip to content
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

[1주차] 고윤정 미션 제출합니다. #6

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
29 changes: 28 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,34 @@
</head>

<body>
<div class="container"></div>
<div class="container">
<span class="title">To Do List</span>
<!-- <form action=""> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 코드나 console.log 등은 나중에 지워 주세요!

<input
type="text"
id="todoInput"
placeholder="할 일을 입력하세요"
onkeydown="EnterKeyDown()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엘리먼트에 인라인으로 이벤트를 바인딩하는 것은 유지보수성을 악화시켜서 지양하는 것이 좋습니다! script.js 파일 내에서 addEventListener()를 사용해 보세요!

/>
<button id="addBtn">+</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript에서는 주로 lowerCamelCase를 사용하지만, CSS에서 id나 class명을 지정할 때에는 일반적으로 kebab-case를 사용합니다! 또한 축약형을 사용하는 것보다는 길더라도 정확한 이름을 사용하는 게 더 좋을 수도 있습니다 👀

Suggested change
<button id="addBtn">+</button>
<button id="add-button">+</button>
스크린샷 2024-08-28 오후 4 34 16

(참고) TOAST UI - HTML/CSS/Sass

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바스크립트에선 카멜케이스를 주로 사용한다고 들었는데 왜 가끔은 케밥케이스를 사용하지? 라는 의문을 가졌었는데 덕분에 궁금증이 해결됐습니다! 그리고 축약형이 무조건 좋은 줄 알았는데 아니었네요😮 피드백 감사합니다!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컨벤션은 습관으로 들이도록 노력해야겠어요! 덕분에 복습 합니다 ㅎㅎ

<!-- </form> -->
<div class="division-line"></div>
Copy link
Member

@corinthionia corinthionia Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿굿!


<div class="todo-box">
<span class="list-title">📝 TO DO ()</span>
<div class="todo-d">
<ul id="todoList"></ul>
</div>
</div>
<div class="division-line"></div>

<div class="done-box">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 <section> 등의 Semantic tag를 사용해 보는 것도 좋을 것 같아요~!

<span class="list-title">✔️ DONE ()</span>
<div class="done-d">
<ul id="doneList"></ul>
</div>
</div>
</div>
</body>
<script src="script.js"></script>
</html>
67 changes: 66 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
// 다들 화이팅!! ٩( *˙0˙*)۶
// 다들 화이팅!! ٩( *˙0˙*)۶
const todoInput = document.querySelector('#todoInput'); //입력창
const addBtn = document.querySelector('#addBtn'); //+ 버튼
const todoList = document.querySelector('#todoList'); //TO DO
const doneList = document.querySelector('#doneList'); //DONE
const todoTitle = document.querySelector('.todo-box .list-title'); // TO DO 제목
const doneTitle = document.querySelector('.done-box .list-title'); // DONE 제목
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCasekebab-case를 섞어서 사용하셨는데 혹시 어떤 기준으로 나누신 건가요? id랑 class 차이일까요?!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떠한 기준을 가지고 나눈건 아니고 원래 기본적으로 camelCase를 사용하는데 전에 자바스크립트 강의를 들었을 때 container의 id나 class명을 kebab-case로 썼던 기억이 있어서 저도 모르게 container나 box는 kebab-case로 사용한 것 같습니다..!🫨


function EnterKeyDown() {
//엔터키로 추가
if (window.event.keyCode === 13 && todoInput.value !== '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode를 통해 해당 라인을 보면 아래와 같은 경고문이 뜹니다! window 객체를 통해 키 입력을 감지하는 것보다는, EnterKeyDown 함수가 이벤트 리스너로 사용되니 이벤트 객체를 전달받아 addEventListener를 통해 이벤트를 등록하는 방식이 더 좋을 것 같아요~ 참고할 만한 자료

스크린샷 2024-08-28 오후 4 38 13

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 <input> 태그를 <form> 태그로 감싸 사용한다면 별도의 keyDown 이벤트를 구현하지 않아도 엔터키 입력으로 할 일 추가가 가능해집니다!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 동일한 방법으로 키 입력을 감지하는 방법을 알아보다가 <input>태그를 <form>태그로 감싸 사용하면 엔터키 입력으로 추가가 가능해진다는 사실을 알고 바로<form>태그 사용했습니다. 제 기준에는 <form>태그가 편하더라구요 😁

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window.event.keyCode도 키보드 이벤트가 발생했을 때 어떤 키가 눌렸는지 확인하기 위해 사용되는 속성이라는걸 처음 알았네요! 위에 주현님 코드리뷰도 보면서 어떤 메소드가 더 좋은건지 덕분에 배워갑니다!

addToDo();
}
}

addBtn.addEventListener('click', () => {
//+ 버튼으로 추가
if (todoInput.value !== '') addToDo();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 공백 입력 방지 구현해 주셨네요 👍🏻

});

function addToDo() {
let todoContents = todoInput.value;

const li = document.createElement('li');
const span = document.createElement('span');
const btn = document.createElement('button');

li.appendChild(span); //appendChild() : 선택한 요소 안에 자식요소를 추가
li.appendChild(btn);

span.textContent = todoContents; //textContent : 노드 내의 모든 텍스트 추출
btn.textContent = '✖️';

todoList.appendChild(li);

todoInput.value = ' ';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 되면 할 일 추가 후 인풋 필드에 공백이 남아 있게 되니 아래처럼 수정해야 할 것 같습니다!

Suggested change
todoInput.value = ' ';
todoInput.value = '';


updateCount();

//완료
li.addEventListener('click', () => {
li.classList.toggle('complete');
if (li.classList.contains('complete')) {
doneList.appendChild(li);
} else {
todoList.appendChild(li);
}
Comment on lines +35 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

완전 깔끔하네요 👍🏻👍🏻

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggle메서드를 이용해서 요소를 숨기거나 보이게 하는 방법도 매우 좋은 것 같네요! 적용해봐야겠어요 ~

// console.log(li.classList.contains('complete'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제출할 때 console.log는 지워 주세용

updateCount();
});

//삭제
btn.addEventListener('click', (e) => {
e.stopPropagation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 삭제 버튼을 눌렀을 때 토글되는 문제 때문에 추가하신 거죠?!
이렇게 작성해도 괜찮긴 하지만 '텍스트를 누르면 토글', '삭제버튼 누르면 삭제'의 기능을 보다 정확히 구현하려면 41번째 줄에 li에 토글(click) 이벤트를 다는 대신 span에 달면 e.stopPropagation(); 이 부분을 안 써도 될 것 같아요!

 //완료
  span.addEventListener('click', () => { ... })

참고 자료 - 이벤트 버블링

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉 저도 이벤트 전파 때문에 e.stopPropagation사용했는데 태그를 세분화해서 클릭이벤트를 적용하면 전파가 일어나지않겠군요 👍🏻👍🏻

li.remove();
updateCount();
});
}

function updateCount() {
const todoCnt = todoList.children.length;
const doneCnt = doneList.children.length;

todoTitle.textContent = `📝 TO DO (${todoCnt})`;
doneTitle.textContent = `✔️ DONE (${doneCnt})`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

템플릿 리터럴 깔끔하네요 굿굿!! 👏🏻👏🏻

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateCount 함수 코드가 단순하면서도 필요한 기능을 효과적 작성하신 것 같아요! 저도 간결하고 좋은 코드 작성하고싶어요!

}
132 changes: 131 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
@@ -1 +1,131 @@
/* 자유롭게 디자인 해 주세요! */
/* 자유롭게 디자인 해 주세요! */
@font-face {
font-family: 'LINESeedKR-Th';
src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/[email protected]/LINESeedKR-Th.woff2')
format('woff2');
Comment on lines +3 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 폰트 적용해야하는데 어떤식으로 적용할지 잘 몰랐던 것 같아요! 다음에 저도 이런식으로 적용해야겠어요!

font-weight: 100;
font-style: normal;
}

@font-face {
font-family: 'LINESeedKR-Rg';
src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/[email protected]/LINESeedKR-Rg.woff2')
format('woff2');
font-weight: 400;
font-style: normal;
}

@font-face {
font-family: 'LINESeedKR-Bd';
src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/[email protected]/LINESeedKR-Bd.woff2')
format('woff2');
font-weight: 700;
font-style: normal;
}
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-image: linear-gradient(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그라데이션 오묘하니 예쁘네요 ✨🩵

to right,
rgb(176, 196, 222),
rgb(230, 239, 250)
);
}

.container {
margin-top: 120px;
width: 360px;
height: 500px;
border-radius: 20px;
padding: 24px;
padding-top: 30px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
padding: 24px;
padding-top: 30px;
padding: 30px 24px 24px 24px;

이렇게 줄여 쓸 수도 있습니다! 순서대로 상 우 하 좌 (시계방향!)

box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
background-color: white;
}

span.title {
font-family: 'LINESeedKR-Bd';
font-size: 24px;
color: rgb(59, 59, 59);
}

span.list-title {
font-family: 'LINESeedKR-Bd';
color: rgb(59, 59, 59);
}

.division-line {
border-top: 1px solid rgb(222, 222, 222);
}

.todo-box {
margin-top: 15px;
}

.done-box {
margin-top: 15px;
}

.todo-d {
height: 140px;
font-family: 'LINESeedKR-Rg';
}

.done-d {
height: 140px;
}

input {
width: 310px;
height: 40px;
border-radius: 30px;
border-style: solid;
border-width: 1.2px;
border-color: rgb(222, 222, 222);
font-size: 12px;
padding-left: 12px;
margin-top: 15px;
margin-bottom: 15px;
}

input:focus {
outline: none;
border-color: lightsteelblue;
transition: 0.2s;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 css 속성은 저도 몰랐던 부분이네요! 윤정님 코드 보면서 하나 더 알아갑니다!

}

button {
border: none;
width: 25px;
height: 40px;
font-size: 20px;
background-color: white;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

버튼을 사용할 때에는 cursor: pointer로 커서를 변경하는 디테일도 챙기면 좋을 것 같습니다! 😉
참고자료 - 커서 속성


button:hover {
color: lightsteelblue;
transition: 0.2s;
}
Comment on lines +109 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 lightsteelblue 이 색상 예쁘네요


ul li {
cursor: pointer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻👍🏻

}

#todoList button {
width: 34px;
height: 20px;
font-size: 14px;
}

#doneList button {
width: 34px;
height: 20px;
font-size: 14px;
}

#doneList li.complete {
text-decoration: line-through;
Copy link

@jissssu jissssu Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

텍스트에 장식 효과를 적용하는 속성을 적용해봐야겠어요!!

color: rgb(222, 222, 222);
}