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

5주차 과제 제출... #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions TodoList/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
50 changes: 50 additions & 0 deletions TodoList/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions TodoList/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions TodoList/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions TodoList/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "todolist",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10"
}
}
1 change: 1 addition & 0 deletions TodoList/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions TodoList/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.App {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
13 changes: 13 additions & 0 deletions TodoList/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import './App.css';
import TodoList from './TodoList';

const App: React.FC = () => {
return (
<div className="App">
<TodoList />
</div>
);
};

export default App;
103 changes: 103 additions & 0 deletions TodoList/src/TodoList.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
.container {
width: 400px;
height: 600px;
margin: auto;
border-radius: 4px;
box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.15);
padding: 20px;
background-color: white;
color: rgba(102, 140, 255);
font-family: Arial, sans-serif;
}
h1 {
font-size: 25px;
text-align: center;
color: rgba(102, 140, 255);
border-bottom: 1px solid #f4f0f0;
padding-bottom: 10px;
margin-bottom: 20px;
}
.todo-input {
display: flex;
width: 100%;
}
.todo-input input {
width: 100%;
height: 50%;
padding: 15px;
font-size: 14px;
border: none;
outline: none;
border-radius: 5px;
margin-top: 10px;
box-sizing: border-box;
}
ul {
list-style: none;
padding: 0;
margin-top: 10px;
max-height: 400px;
overflow-y: auto;
}
li {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
font-size: 14px;
}
li.done {
text-decoration: line-through;
color: rgba(102, 140, 255);
}
li.done span {
text-decoration: line-through;
color: inherit;
}
.circle-checkbox {
display: flex;
align-items: center;
}
.circle-checkbox input {
display: none;
}
.circle-checkbox .checkmark {
height: 14px;
width: 14px;
background-color: white;
border: 2px solid rgba(102, 140, 255);
border-radius: 50%;
cursor: pointer;
}
.circle-checkbox input:checked + .checkmark {
background-color: rgba(102, 140, 255);
border: 2px solid rgba(102, 140, 255);
}
.delete-btn {
background: none;
border: none;
color: rgba(102, 140, 255);
font-size: 14px;
cursor: pointer;
text-decoration: none;
}
footer {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
padding-top: 20px;
border-top: 1px solid #eee;
}
.footer-add-btn {
background-color: white;
color: rgba(102, 140, 255);
padding: 6px 12px;
border: none;
border-radius: 5px;
border-top: #ccc;
cursor: pointer;
font-size: 12px;
}

79 changes: 79 additions & 0 deletions TodoList/src/TodoList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { useState } from 'react';
import './TodoList.css';

type Todo = {
id: number;
todoText: string;
isDone: boolean;
};

const TodoList: React.FC = () => {
const [todos, setTodos] = useState<Todo[]>([]);
const [input, setInput] = useState<string>("");
Comment on lines +10 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

React.FC가 무엇인가요? 이렇게 작성하신 이유도 알려주세요


const addTodo = (): void => {
if (input.trim() === "") {
alert("등록할 일정을 입력해주세요!");
return;
}
const newTodo: Todo = {
id: Date.now(),
todoText: input,
isDone: false,
};
setTodos([...todos, newTodo]);
setInput("");
};

const toggleTodo = (id: number): void => {
setTodos(
todos.map((todo) =>
todo.id === id ? { ...todo, isDone: !todo.isDone } : todo
)
);
};

const deleteTodo = (id: number): void => {
setTodos(todos.filter((todo) => todo.id !== id));
};
Comment on lines +14 to +38
Copy link
Contributor

Choose a reason for hiding this comment

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

함수의 반환값이 없다는 것을 명시적으로 작성해주셨네요!
명시적으로 작성해주신 이유가 있으실까요?


const remainingTodos: number = todos.filter((todo) => !todo.isDone).length;

return (
<div className="container">
<h1>TodoList</h1>
<div className="todo-input">
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="오늘 할 일을 추가해보세요!"
/>
</div>
<ul>
{todos.map((todo) => (
<li key={todo.id} className={todo.isDone ? "done" : ""}>
<label className="circle-checkbox">
<input
type="checkbox"
checked={todo.isDone}
onChange={() => toggleTodo(todo.id)}
/>
<span className="checkmark"></span>
</label>
<span>{todo.todoText}</span>
<button onClick={() => deleteTodo(todo.id)} className="delete-btn">
삭제
</button>
</li>
))}
</ul>
<footer>
<span>오늘 할 일 {remainingTodos}</span>
<button onClick={addTodo} className="footer-add-btn">추가하기</button>
</footer>
</div>
);
};

export default TodoList;
1 change: 1 addition & 0 deletions TodoList/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions TodoList/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
html, body {
width: 100%;
height: 100%;
font-family: Arial, sans-serif;
}
#root {
height: 100%;
}
10 changes: 10 additions & 0 deletions TodoList/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
1 change: 1 addition & 0 deletions TodoList/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading