-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
43 lines (38 loc) · 1.19 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Reorder } from 'motion/react'
import { useState } from 'react'
import { Experiment } from '../../components/experiment'
import { Form } from './components/todo-form'
import { TodoItem } from './components/todo-item'
export type Todo = {
id: string
value: string
}
export function TodolistExperiment() {
const [todos, setTodos] = useState<Array<Todo>>([])
const handleSubmit = (value: string) => {
setTodos([...todos, { id: crypto.randomUUID(), value }])
}
const handleDelete = (id: string) => {
setTodos(todos.filter((todo) => todo.id !== id))
}
return (
<Experiment>
<Experiment.Heading>Todolist</Experiment.Heading>
<Experiment.Body>
<div className="flex min-h-full w-full flex-col items-center gap-4 p-4 lg:px-12 lg:py-8">
<Form onSubmit={handleSubmit} />
<Reorder.Group
axis="y"
values={todos}
onReorder={setTodos}
className="flex w-full flex-col gap-2"
>
{todos.map((todo) => (
<TodoItem key={todo.id} todo={todo} onDelete={handleDelete} />
))}
</Reorder.Group>
</div>
</Experiment.Body>
</Experiment>
)
}