davidepollicino commited on
Commit
63f10e8
·
verified ·
1 Parent(s): c0e99a6

Upload components/TodoList.tsx with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/TodoList.tsx +46 -0
components/TodoList.tsx ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ interface Todo {
2
+ id: number
3
+ text: string
4
+ completed: boolean
5
+ }
6
+
7
+ interface TodoListProps {
8
+ todos: Todo[]
9
+ toggleTodo: (id: number) => void
10
+ deleteTodo: (id: number) => void
11
+ }
12
+
13
+ export default function TodoList({ todos, toggleTodo, deleteTodo }: TodoListProps) {
14
+ if (todos.length === 0) {
15
+ return <p className="text-gray-500">No todos yet. Add one above!</p>
16
+ }
17
+
18
+ return (
19
+ <ul className="space-y-2">
20
+ {todos.map(todo => (
21
+ <li key={todo.id} className="flex items-center justify-between p-2 border-b border-gray-200">
22
+ <div className="flex items-center space-x-2">
23
+ <input
24
+ type="checkbox"
25
+ checked={todo.completed}
26
+ onChange={() => toggleTodo(todo.id)}
27
+ className="h-5 w-5 text-blue-500 rounded focus:ring-blue-400"
28
+ />
29
+ <span className={`${todo.completed ? 'line-through text-gray-400' : 'text-gray-800'}`}>
30
+ {todo.text}
31
+ </span>
32
+ </div>
33
+ <button
34
+ onClick={() => deleteTodo(todo.id)}
35
+ className="text-red-500 hover:text-red-700 transition-colors"
36
+ aria-label="Delete todo"
37
+ >
38
+ <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
39
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
40
+ </svg>
41
+ </button>
42
+ </li>
43
+ ))}
44
+ </ul>
45
+ )
46
+ }