|
| 1 | +# todo context api notes |
| 2 | + |
| 3 | +## Todo Form UI |
| 4 | + |
| 5 | +```javascript |
| 6 | +function TodoForm() { |
| 7 | + |
| 8 | + |
| 9 | + return ( |
| 10 | + <form className="flex"> |
| 11 | + <input |
| 12 | + type="text" |
| 13 | + placeholder="Write Todo..." |
| 14 | + className="w-full border border-black/10 rounded-l-lg px-3 outline-none duration-150 bg-white/20 py-1.5" |
| 15 | + /> |
| 16 | + <button type="submit" className="rounded-r-lg px-3 py-1 bg-green-600 text-white shrink-0"> |
| 17 | + Add |
| 18 | + </button> |
| 19 | + </form> |
| 20 | + ); |
| 21 | +} |
| 22 | + |
| 23 | +export default TodoForm; |
| 24 | + |
| 25 | + |
| 26 | +``` |
| 27 | + |
| 28 | +## Todo Item UI |
| 29 | + |
| 30 | +```javascript |
| 31 | +function TodoItem({ todo }) { |
| 32 | + |
| 33 | + |
| 34 | + return ( |
| 35 | + <div |
| 36 | + className={`flex border border-black/10 rounded-lg px-3 py-1.5 gap-x-3 shadow-sm shadow-white/50 duration-300 text-black ${ |
| 37 | + todo.completed ? "bg-[#c6e9a7]" : "bg-[#ccbed7]" |
| 38 | + }`} |
| 39 | + > |
| 40 | + <input |
| 41 | + type="checkbox" |
| 42 | + className="cursor-pointer" |
| 43 | + checked={todo.completed} |
| 44 | + onChange={toggleCompleted} |
| 45 | + /> |
| 46 | + <input |
| 47 | + type="text" |
| 48 | + className={`border outline-none w-full bg-transparent rounded-lg ${ |
| 49 | + isTodoEditable ? "border-black/10 px-2" : "border-transparent" |
| 50 | + } ${todo.completed ? "line-through" : ""}`} |
| 51 | + value={todoMsg} |
| 52 | + onChange={(e) => setTodoMsg(e.target.value)} |
| 53 | + readOnly={!isTodoEditable} |
| 54 | + /> |
| 55 | + {/* Edit, Save Button */} |
| 56 | + <button |
| 57 | + className="inline-flex w-8 h-8 rounded-lg text-sm border border-black/10 justify-center items-center bg-gray-50 hover:bg-gray-100 shrink-0 disabled:opacity-50" |
| 58 | + onClick={() => { |
| 59 | + if (todo.completed) return; |
| 60 | + |
| 61 | + if (isTodoEditable) { |
| 62 | + editTodo(); |
| 63 | + } else setIsTodoEditable((prev) => !prev); |
| 64 | + }} |
| 65 | + disabled={todo.completed} |
| 66 | + > |
| 67 | + {isTodoEditable ? "📁" : "✏️"} |
| 68 | + </button> |
| 69 | + {/* Delete Todo Button */} |
| 70 | + <button |
| 71 | + className="inline-flex w-8 h-8 rounded-lg text-sm border border-black/10 justify-center items-center bg-gray-50 hover:bg-gray-100 shrink-0" |
| 72 | + onClick={() => deleteTodo(todo.id)} |
| 73 | + > |
| 74 | + ❌ |
| 75 | + </button> |
| 76 | + </div> |
| 77 | + ); |
| 78 | +} |
| 79 | + |
| 80 | +export default TodoItem; |
| 81 | + |
| 82 | +``` |
| 83 | + |
| 84 | +## App js UI |
| 85 | + |
| 86 | +```javascript |
| 87 | +<div className="bg-[#172842] min-h-screen py-8"> |
| 88 | + <div className="w-full max-w-2xl mx-auto shadow-md rounded-lg px-4 py-3 text-white"> |
| 89 | + <h1 className="text-2xl font-bold text-center mb-8 mt-2">Manage Your Todos</h1> |
| 90 | + <div className="mb-4"> |
| 91 | + {/* Todo form goes here */} |
| 92 | + </div> |
| 93 | + <div className="flex flex-wrap gap-y-3"> |
| 94 | + {/*Loop and Add TodoItem here */} |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | +``` |
| 99 | + |
| 100 | + |
0 commit comments