🆕 Add new UI scripts and update gitignore to ignore cache directory
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
App,
|
||||
Text,
|
||||
Button,
|
||||
TextField,
|
||||
VStack,
|
||||
HStack,
|
||||
State,
|
||||
ForEach,
|
||||
Spacer,
|
||||
Divider,
|
||||
} from "perry/ui"
|
||||
|
||||
const todos = State<string[]>([])
|
||||
const count = State(0)
|
||||
const input = State("")
|
||||
|
||||
App({
|
||||
title: "Todo App",
|
||||
width: 480,
|
||||
height: 600,
|
||||
body: VStack(16, [
|
||||
Text("My Todos"),
|
||||
|
||||
HStack(8, [
|
||||
TextField("What needs to be done?", (value: string) => input.set(value)),
|
||||
Button("Add", () => {
|
||||
const text = input.value
|
||||
if (text.length > 0) {
|
||||
todos.set([...todos.value, text])
|
||||
count.set(count.value + 1)
|
||||
input.set("")
|
||||
}
|
||||
}),
|
||||
]),
|
||||
|
||||
Divider(),
|
||||
|
||||
ForEach(count, (i: number) =>
|
||||
HStack(8, [
|
||||
Text(todos.value[i]),
|
||||
Spacer(),
|
||||
Button("Delete", () => {
|
||||
todos.set(todos.value.filter((_, idx) => idx !== i))
|
||||
count.set(count.value - 1)
|
||||
}),
|
||||
]),
|
||||
),
|
||||
|
||||
Spacer(),
|
||||
Text(`${count.value} items`),
|
||||
]),
|
||||
})
|
||||
Reference in New Issue
Block a user