Skip to content

Commit 95ee985

Browse files
authored
Create TodoApp component for managing tasks
TodoApp is a simple and efficient task-management tool designed to help users stay organized and productive. With its clean, modern interface and responsive design, TodoApp makes it easy to add tasks, mark them as complete, and delete them when no longer needed. Built with smooth animations and intuitive controls, TodoApp delivers a user-friendly experience perfect for managing daily routines, work responsibilities, personal goals, or long-term projects. Key Features Add new tasks with a single click Mark tasks as complete with a simple tap Delete tasks instantly Smooth transition animations powered by Framer Motion Modern design using shadcn UI components Fully responsive layout for all screen sizes Whether you're tracking small reminders or planning your whole day, TodoApp keeps your workflow organized and stress-free.
1 parent 82b562b commit 95ee985

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

denam host

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React, { useState, useEffect } from "react";
2+
3+
export default function TodoApp() {
4+
const [todos, setTodos] = useState(() =>
5+
JSON.parse(localStorage.getItem("todos") || "[]")
6+
);
7+
const [input, setInput] = useState("");
8+
9+
// Save todos to localStorage whenever they change
10+
useEffect(() => {
11+
localStorage.setItem("todos", JSON.stringify(todos));
12+
}, [todos]);
13+
14+
const addTodo = (e) => {
15+
e.preventDefault();
16+
if (!input.trim()) return;
17+
setTodos([...todos, { id: Date.now(), text: input, done: false }]);
18+
setInput("");
19+
};
20+
21+
const toggleTodo = (id) => {
22+
setTodos(todos =>
23+
todos.map(todo =>
24+
todo.id === id ? { ...todo, done: !todo.done } : todo
25+
)
26+
);
27+
};
28+
29+
const deleteTodo = (id) => {
30+
setTodos(todos => todos.filter(todo => todo.id !== id));
31+
};
32+
33+
return (
34+
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
35+
<div className="bg-white rounded-xl shadow-lg p-8 w-full max-w-md">
36+
<h1 className="text-2xl font-bold mb-6 text-center">To-Do List</h1>
37+
<form className="flex mb-4 gap-2" onSubmit={addTodo}>
38+
<input
39+
className="flex-1 border rounded-lg px-3 py-2 outline-none border-gray-300 focus:border-emerald-500"
40+
value={input}
41+
onChange={e => setInput(e.target.value)}
42+
placeholder="What needs to be done?"
43+
autoFocus
44+
/>
45+
<button className="bg-emerald-600 text-white px-4 py-2 rounded-lg hover:bg-emerald-700" type="submit">
46+
Add
47+
</button>
48+
</form>
49+
<ul>
50+
{todos.length === 0 ? (
51+
<li className="text-center text-gray-400">No tasks yet.</li>
52+
) : (
53+
todos.map(todo => (
54+
<li
55+
key={todo.id}
56+
className="flex items-center justify-between py-2 border-b border-gray-100 last:border-b-0"
57+
>
58+
<label className="flex items-center gap-2 flex-1 cursor-pointer">
59+
<input
60+
type="checkbox"
61+
checked={todo.done}
62+
onChange={() => toggleTodo(todo.id)}
63+
className="w-4 h-4 accent-emerald-600"
64+
/>
65+
<span className={todo.done ? "line-through text-gray-400" : ""}>
66+
{todo.text}
67+
</span>
68+
</label>
69+
<button
70+
className="ml-2 text-gray-400 hover:text-red-500 text-lg px-2"
71+
onClick={() => deleteTodo(todo.id)}
72+
aria-label="Delete"
73+
>
74+
×
75+
</button>
76+
</li>
77+
))
78+
)}
79+
</ul>
80+
</div>
81+
</div>
82+
);
83+
}

0 commit comments

Comments
 (0)