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

Open
wants to merge 3 commits 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 김산호/assignment/.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 김산호/assignment/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 김산호/assignment/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 김산호/assignment/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>
30 changes: 30 additions & 0 deletions 김산호/assignment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "assignment",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"less": "^4.2.0",
"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 김산호/assignment/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.
9 changes: 9 additions & 0 deletions 김산호/assignment/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import TodoContainer from './TodoContainer'

function App() {
return (
<TodoContainer />
)
}

export default App
26 changes: 26 additions & 0 deletions 김산호/assignment/src/Bottom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.bottom {
margin-top: auto;
display: flex;
border-top: 1px solid #bbb;
}
.todayTasksDiv {
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
font-size: 12px;
font-weight: bold;
color: rgba(102, 140, 255);
flex: 1;
}
.addTodoDiv {
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
font-size: 12px;
font-weight: bold;
color: rgba(102, 140, 255);
flex: 1;
cursor: pointer;
}
19 changes: 19 additions & 0 deletions 김산호/assignment/src/Bottom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import './Bottom.css';

type Props = {
todoList: Todo[],
onClick: () => void;
}

function Bottom({todoList, onClick}: Props) {
const todayTasks = todoList.filter((todo) => !todo.isDone);

return (
<div className="bottom">
<div className="todayTasksDiv">오늘 할 일 {todayTasks.length}</div>
<div className="addTodoDiv" onClick={onClick}>추가하기</div>
</div>
)
}

export default Bottom
10 changes: 10 additions & 0 deletions 김산호/assignment/src/Header.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.header {
font-size: 25px;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
border-bottom: 1px solid #bbb;
color: rgba(102, 140, 255);
}
9 changes: 9 additions & 0 deletions 김산호/assignment/src/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import './Header.css';

function Header() {
return (
<div className="header">TodoList</div>
)
}

export default Header
23 changes: 23 additions & 0 deletions 김산호/assignment/src/TodoContainer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
html, body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
* {
box-sizing: border-box;
}
.TodoContainer {
border: 1px solid #bbb;
width: 400px;
height: 600px;
margin: auto;
box-shadow: 0px 0px 10px #DDD;
display: flex;
flex-direction: column;
}
.TodoContainer button {
margin-left: 5px;
padding: 3px 10px;
}
51 changes: 51 additions & 0 deletions 김산호/assignment/src/TodoContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, {useState} from "react";
import TodoList from "./TodoList";
import './TodoContainer.css';
import Header from "./Header";
import TodoInput from "./TodoInput";
import Bottom from "./Bottom";

function TodoContainer() {
const [todoList, setTodoList] = useState<Todo[]>([]);
const [todoText, setTodoText] = useState<string>('');

const onClick = () => {
addTodo(todoText);
setTodoText('');
};

const addTodo: AddTodoFunc = (todoText: string) => {
if (todoText.trim() === '') {
alert('등록할 일정을 입력해주세요!');
} else {
const lastIndex = todoList.length - 1;
const lastId = lastIndex == -1 ? 0 : todoList[lastIndex].id;
const todo = {id: lastId + 1, todoText: todoText, isDone: false};
setTodoList([...todoList, todo]);
}
}

const toggleTodo: ToggleTodoFunc = (id: number) => {
const newTodoList = todoList.map(
todo => todo.id !== id ? todo : {...todo, isDone: !todo.isDone}
);
setTodoList(newTodoList);
}

const deleteTodo: DeleteTodoFunc = (id: number) => {
setTodoList( todoList.filter(todo => todo.id !== id));
}

return (
<div className="TodoContainer">
<Header/>
<TodoInput todoText={todoText} setTodoText={setTodoText} />
<TodoList todoList={todoList} toggleTodo={toggleTodo} deleteTodo={deleteTodo}/>
<Bottom todoList={todoList} onClick={onClick} />
</div>
)


}

export default TodoContainer;
6 changes: 6 additions & 0 deletions 김산호/assignment/src/TodoInput.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.todoInput {
border: none;
outline: none;
padding: 6px;
width: 220px;
}
15 changes: 15 additions & 0 deletions 김산호/assignment/src/TodoInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import './TodoInput.css'

type Props = {
todoText: string,
setTodoText: (title: string) => void
}

function TodoInput({todoText, setTodoText}: Props) {
return (
<input className="todoInput" type="text" placeholder="오늘 할 일을 추가해보세요!"
value={todoText} onChange={e => setTodoText(e.target.value)} />
)
}

export default TodoInput
58 changes: 58 additions & 0 deletions 김산호/assignment/src/TodoList.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.todoListWrapper {
padding: 5px;
}
.todo {
display: flex;
height: 18px;
margin-bottom: 10px;
font-size: 14px;
font-weight: bold;
color: rgba(102, 140, 255);
align-items: center;
}
.checkboxContainer {
display: flex;
align-items: center;
cursor: pointer;
position: relative;
margin-right: 5px;
}
.chk{
position: absolute;
left: -999em;
}
.circle{
display: inline-block;
width: 20px; height: 20px;
border: 1px solid #bbb;
box-sizing: border-box;
border-radius: 10px;
position: relative; top: 4px;
cursor: pointer;
margin-bottom: 5px;
}
.circle:after{
content: '\2714';
font-size: 24px; color: #333;
position: absolute; top: -14px; left: 0;
opacity: 0;
transition: 0.2s;
}
.chk:checked + .circle{
background-color: rgba(102, 140, 255);
border: 2px solid #333;
}
.chk:checked + .circle:after {
opacity: 0;
}
.done {
text-decoration: line-through;
text-decoration-color: black;
align-items: center;
}
.delete {
margin-left: auto;
margin-right: 20px;
font-weight: bold;
cursor: pointer;
}
Loading