memorium/islands/Counter.tsx

32 lines
890 B
TypeScript
Raw Permalink Normal View History

2023-07-26 13:47:01 +02:00
import type { Signal } from "@preact/signals";
2023-07-30 19:40:39 +02:00
import { Button } from "@components/Button.tsx";
2023-08-02 13:25:19 +02:00
import { IconCircleMinus, IconCirclePlus } from "@components/icons.tsx";
2023-07-26 13:47:01 +02:00
interface CounterProps {
count: Signal<number>;
}
export default function Counter(props: CounterProps) {
2023-08-02 13:25:19 +02:00
props.count.value = Math.max(1, props.count.value);
2023-07-26 13:47:01 +02:00
return (
2023-08-02 13:25:19 +02:00
<div class="flex items-center px-1 py-2 rounded-xl">
<Button
class=""
onClick={() => props.count.value -= 1}
>
<IconCircleMinus />
</Button>
<input
class="text-3xl bg-transparent inline text-center -mx-4"
type="number"
2023-08-02 13:25:19 +02:00
size={props.count.toString().length}
value={props.count}
onInput={(ev) => props.count.value = ev.target?.value}
/>
2023-08-02 13:25:19 +02:00
<Button onClick={() => props.count.value += 1}>
<IconCirclePlus />
</Button>
2023-07-26 13:47:01 +02:00
</div>
);
}