Skip to content

Commit 8e6f085

Browse files
authored
Add files via upload
completed without errormodal
1 parent 979358d commit 8e6f085

File tree

4 files changed

+99
-33
lines changed

4 files changed

+99
-33
lines changed

todo-list/src/UI/Card.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Card = (props) => {
2+
return (
3+
<>
4+
<div className={`${props.className}`}>{props.children}</div>
5+
</>
6+
);
7+
};
8+
9+
export default Card;

todo-list/src/UI/Todo.jsx

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,70 @@
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+
};
2011

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>
2446

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>
2953
</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+
</>
3168
);
3269
};
3370

todo-list/src/components/TodoForm.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ const TodoForm = (props) => {
1616
};
1717
const addTodoHandler = () => {
1818
props.setTodos((prevState) => {
19-
return [...prevState, { todo: todo.todo, state: todo.state }];
19+
return [
20+
...prevState,
21+
{
22+
todo: todo.todo,
23+
state: todo.state,
24+
id: Math.floor(Math.random() * 1000),
25+
},
26+
];
2027
});
2128
setTodos({ todo: "", state: false });
2229
};
@@ -34,6 +41,7 @@ const TodoForm = (props) => {
3441
todokey="todo"
3542
className="shadow appearance-none border w-full py-2 px-3 mr-4 text-grey-darker"
3643
placeholder="Add Todo"
44+
value={todo.todo}
3745
/>
3846
<button
3947
onClick={addTodoHandler}

todo-list/src/components/Todos.jsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import { useState } from "react";
22
import Todo from "../UI/Todo";
33
import TodoForm from "./TodoForm";
4-
4+
import Card from "../UI/Card";
55
const Todos = () => {
66
const [todos, setTodos] = useState([]);
7-
console.log(todos);
8-
97
return (
10-
<div className="h-screen flex">
8+
<div className="h-screen">
119
<TodoForm setTodos={setTodos} />
12-
<Todo />
10+
11+
{todos.length > 0 && (
12+
<Card className="bg-white rounded shadow p-6 w-full lg:w-3/4 lg:max-w-lg m-auto">
13+
<div className="h-100 w-full flex items-center justify-center bg-teal-lightest font-sans flex-col">
14+
{todos.map((todo) => (
15+
<Todo
16+
key={todo.id}
17+
todo={todo}
18+
todos={todos}
19+
setTodos={setTodos}
20+
/>
21+
))}
22+
</div>
23+
</Card>
24+
)}
1325
</div>
1426
);
1527
};

0 commit comments

Comments
 (0)