-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1382 from WenHaoHub/task1
task1: WenHaoHub
- Loading branch information
Showing
22 changed files
with
567 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Task1 | ||
todilist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!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>Todo</title> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "task1", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"clsx": "^2.1.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"@typescript-eslint/eslint-plugin": "^7.2.0", | ||
"@typescript-eslint/parser": "^7.2.0", | ||
"@vitejs/plugin-react-swc": "^3.5.0", | ||
"autoprefixer": "^10.4.19", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.6", | ||
"postcss": "^8.4.38", | ||
"tailwindcss": "^3.4.3", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} | ||
|
||
.todo { | ||
display: flex; | ||
height: 65px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect, useState } from 'react' | ||
import './App.css' | ||
import Header from './componets/Header' | ||
import AddToDo from './componets/AddToDo' | ||
import ToDoList from './componets/ToDoList' | ||
|
||
export interface Todo { | ||
id: string | ||
text: string | ||
completed: boolean | ||
} | ||
|
||
const STORAGE_KEY = 'todo' | ||
|
||
function App() { | ||
const [data, setData] = useState<Todo[]>(JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')) | ||
|
||
useEffect(() => { | ||
localStorage.setItem(STORAGE_KEY, JSON.stringify(data)) | ||
}, [data]) | ||
|
||
return ( | ||
<div className="w-[600px]"> | ||
<Header /> | ||
<AddToDo addItem={setData} /> | ||
<ToDoList | ||
data={data} | ||
updateData={setData} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default App |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.toggle-all { | ||
width: 1px; | ||
height: 1px; | ||
border: none; | ||
opacity: 0; | ||
} | ||
|
||
.toggle-all + label { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 45px; | ||
height: 65px; | ||
font-size: 0; | ||
} | ||
|
||
.toggle-all + label:before { | ||
content: '❯'; | ||
display: inline-block; | ||
font-size: 22px; | ||
color: #949494; | ||
padding: 10px 27px 10px 27px; | ||
-webkit-transform: rotate(90deg); | ||
transform: rotate(90deg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { useCallback, useState } from 'react' | ||
import { Todo } from '../App' | ||
import './AddToDo.css' | ||
|
||
function AddToDo({ addItem }: { addItem: React.Dispatch<React.SetStateAction<Todo[]>> }) { | ||
const [text, setText] = useState('') | ||
const [isSelect, setSelect] = useState(false); | ||
|
||
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
setText(e.target.value) | ||
}, []) | ||
|
||
const handleAdd = | ||
(e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key !== 'Enter') return | ||
if (text.trim() === '') return //原生方法 | ||
//写函数 表示前一次的state, | ||
addItem((prev) => { | ||
console.log('>>>prev', prev); | ||
return [...prev, { id: Date.now().toString(), text, completed: false }] | ||
}) | ||
setText('') | ||
} | ||
|
||
|
||
|
||
const selectAll = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
addItem((prev) => { | ||
const isAllCompleted = prev.every((todo) => todo.completed) | ||
if (e.target.checked === false && isAllCompleted) { | ||
setSelect(e.target.checked) | ||
return prev.map((todo) => ({ ...todo, completed: !isAllCompleted })) | ||
} else if (e.target.checked === false && !isAllCompleted) { | ||
return prev.map((todo) => ({ ...todo, completed: !isAllCompleted })) | ||
} else if (e.target.checked === true && isAllCompleted) { | ||
setSelect(e.target.checked) | ||
return prev.map((todo) => ({ ...todo, completed: true })) | ||
|
||
} else { | ||
setSelect(e.target.checked) | ||
return prev.map((todo) => ({ ...todo, completed: !isAllCompleted })) | ||
} | ||
}) | ||
} | ||
|
||
return ( | ||
<div className="todo rounded border-2 flex items-center"> | ||
<label className="ml-4 mr-2"> | ||
<input | ||
type="checkbox" | ||
checked={isSelect} | ||
onChange={selectAll} | ||
/> | ||
{/* Dark mode */} | ||
</label> | ||
|
||
<input | ||
className="px-4 grow" | ||
placeholder="添加代办事项" | ||
type="text" | ||
value={text} | ||
onChange={handleChange} | ||
onKeyUp={handleAdd} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default AddToDo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function Header() { | ||
return ( | ||
<header className="m-6"> | ||
<h1 >TodoList</h1> | ||
</header> | ||
) | ||
} | ||
|
||
export default Header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { clsx } from 'clsx' | ||
import { Todo } from '../App' | ||
|
||
type ToDoItemProps = { | ||
todo: Todo | ||
onToggle: (id: string) => void | ||
removeItem: (id: string) => void | ||
} | ||
|
||
function ToDoItem({ todo, onToggle, removeItem }: ToDoItemProps) { | ||
console.log('>>>ToDoItem',); | ||
return ( | ||
<div className="todo text-2xl items-center border-b-2 todo-item"> | ||
<input | ||
className="w-[45px] h-[20px]" | ||
type="checkbox" | ||
checked={todo.completed} | ||
onChange={() => onToggle(todo.id)} | ||
/> | ||
<span className={clsx('grow text-left px-4', todo.completed && 'completed')}>{todo.text}</span> | ||
<button | ||
className="destroy mr-5" | ||
onClick={() => removeItem(todo.id)} | ||
></button> | ||
</div> | ||
) | ||
} | ||
|
||
export default ToDoItem |
Oops, something went wrong.