| 
1 |  | -const Todo = () => {  | 
2 |  | - return (  | 
3 |  | - <div className="h-100 w-full flex items-center justify-center bg-teal-lightest font-sans">  | 
4 |  | - <div className="bg-white rounded shadow p-6 m-4 w-full lg:w-3/4 lg:max-w-lg">  | 
5 |  | - <div className="flex mb-4 items-center">  | 
6 |  | - <p className="w-full text-grey-darkest">  | 
7 |  | - Add another component to Tailwind Components  | 
8 |  | - </p>  | 
9 |  | - <button className="flex-no-shrink p-2 ml-4 mr-2 border-2 rounded hover:text-white text-green border-green hover:bg-green-600">  | 
10 |  | - Done  | 
11 |  | - </button>  | 
12 |  | - <button className="flex-no-shrink p-2 ml-2 border-2 rounded text-red border-red hover:text-white hover:bg-red-600">  | 
13 |  | - Remove  | 
14 |  | - </button>  | 
15 |  | - </div>  | 
16 |  | - <div className="flex mb-4 items-center">  | 
17 |  | - <p className="w-full line-through text-green">  | 
18 |  | - Submit Todo App Component to Tailwind Components  | 
19 |  | - </p>  | 
 | 1 | +import { useState } from "react";  | 
 | 2 | + | 
 | 3 | +const Todo = (props) => {  | 
 | 4 | + const todo = props.todo;  | 
 | 5 | + const [todoState, setTodoState] = useState(todo.state);  | 
 | 6 | + | 
 | 7 | + const deleteTodoHandler = (todoId) => {  | 
 | 8 | + console.log(todoId);  | 
 | 9 | + props.setTodos(() => props.todos.filter((todo) => todo.id !== todoId));  | 
 | 10 | + };  | 
20 | 11 | 
 
  | 
21 |  | - <button className="flex-no-shrink p-2 ml-4 mr-2 border-2 rounded text-grey border-grey hover:text-white hover:bg-gray-400">  | 
22 |  | - Not Done  | 
23 |  | - </button>  | 
 | 12 | + return (  | 
 | 13 | + <>  | 
 | 14 | + <div className="flex mb-4 items-center">  | 
 | 15 | + <p  | 
 | 16 | + className={`w-full text-grey-darkest min-w-[280px] max-w-[280px] ${  | 
 | 17 | + todoState ? "line-through" : ""  | 
 | 18 | + }`}  | 
 | 19 | + >  | 
 | 20 | + {todo.todo}  | 
 | 21 | + </p>  | 
 | 22 | + <button  | 
 | 23 | + onClick={() => {  | 
 | 24 | + setTodoState((prevState) => {  | 
 | 25 | + return !prevState;  | 
 | 26 | + });  | 
 | 27 | + }}  | 
 | 28 | + className={`flex-no-shrink p-2 ml-4 mr-2 border-2 rounded hover:text-white text-green border-green hover:bg-green-600 ${  | 
 | 29 | + todoState ? "hidden" : "block"  | 
 | 30 | + }`}  | 
 | 31 | + >  | 
 | 32 | + Done  | 
 | 33 | + </button>  | 
 | 34 | + <button  | 
 | 35 | + onClick={() => {  | 
 | 36 | + setTodoState((prevState) => {  | 
 | 37 | + return !prevState;  | 
 | 38 | + });  | 
 | 39 | + }}  | 
 | 40 | + className={`flex-no-shrink p-2 ml-4 mr-2 border-2 rounded hover:text-white text-green border-green hover:bg-gray-400  | 
 | 41 | + ${todoState ? "block" : "hidden"}  | 
 | 42 | + `}  | 
 | 43 | + >  | 
 | 44 | + Not Done  | 
 | 45 | + </button>  | 
24 | 46 | 
 
  | 
25 |  | - <button className="flex-no-shrink p-2 ml-2 border-2 rounded text-red border-red hover:text-white hover:bg-red-600">  | 
26 |  | - Remove  | 
27 |  | - </button>  | 
28 |  | - </div>  | 
 | 47 | + <button  | 
 | 48 | + onClick={() => deleteTodoHandler(todo.id)}  | 
 | 49 | + className="flex-no-shrink p-2 ml-2 border-2 rounded text-red border-red hover:text-white hover:bg-red-600"  | 
 | 50 | + >  | 
 | 51 | + Remove  | 
 | 52 | + </button>  | 
29 | 53 |  </div>  | 
30 |  | - </div>  | 
 | 54 | + {/* <div className="flex mb-4 items-center">  | 
 | 55 | + <p className="w-full line-through text-green">  | 
 | 56 | + Submit Todo App Component to Tailwind Components  | 
 | 57 | + </p>  | 
 | 58 | +
  | 
 | 59 | + <button className="flex-no-shrink p-2 ml-4 mr-2 border-2 rounded text-grey border-grey hover:text-white hover:bg-gray-400">  | 
 | 60 | + Not Done  | 
 | 61 | + </button>  | 
 | 62 | +
  | 
 | 63 | + <button className="flex-no-shrink p-2 ml-2 border-2 rounded text-red border-red hover:text-white hover:bg-red-600">  | 
 | 64 | + Remove  | 
 | 65 | + </button>  | 
 | 66 | + </div> */}  | 
 | 67 | + </>  | 
31 | 68 |  );  | 
32 | 69 | };  | 
33 | 70 | 
 
  | 
 | 
0 commit comments