You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
511 B
TypeScript
25 lines
511 B
TypeScript
import { JSX, h } from "preact";
|
|
import { useRef } from "preact/hooks";
|
|
import { Callback } from "../../../utils.ts";
|
|
|
|
export const NumberInput = (
|
|
p: Omit<JSX.HTMLAttributes<HTMLInputElement>, "onInput"> & {
|
|
value: number;
|
|
min?: number;
|
|
max?: number;
|
|
onInput: Callback<[number]>;
|
|
},
|
|
) => {
|
|
const ref = useRef<HTMLInputElement>(null);
|
|
|
|
return h("input", {
|
|
...p,
|
|
type: "number",
|
|
ref,
|
|
min: p.min,
|
|
max: p.max,
|
|
value: p.value,
|
|
onInput: () => p.onInput(Number(ref.current!.value)),
|
|
});
|
|
};
|