Files
ERitors-Scribe-Desktop/components/form/NumberInput.tsx
natreex 64ed90d993 Remove unused components and models for improved maintainability
- Deleted redundant components (`AddActionButton`, `AlertBox`, `AlertStack`, `BackButton`, `CancelButton`, and `CollapsableArea`) and related files.
- Removed unused models (`Book`, `BookSerie`, `BookTables`, `Character`, and `Chapter`) to reduce codebase clutter.
- Updated project structure and references to reflect these removals.
2026-03-22 22:37:31 -04:00

52 lines
1.3 KiB
TypeScript

import React, {ChangeEvent, Dispatch} from "react";
interface NumberInputProps {
value: number | null;
setValue?: Dispatch<React.SetStateAction<number>>;
onValueChange?: (value: number | null) => void;
placeholder?: string;
readOnly?: boolean;
disabled?: boolean;
}
export default function NumberInput(
{
value,
setValue,
onValueChange,
placeholder,
readOnly = false,
disabled = false
}: NumberInputProps
) {
function handleChange(e: ChangeEvent<HTMLInputElement>): void {
const inputValue: string = e.target.value;
if (inputValue === '') {
if (onValueChange) {
onValueChange(null);
}
return;
}
const newValue: number = parseInt(inputValue, 10);
if (!isNaN(newValue)) {
if (onValueChange) {
onValueChange(newValue);
} else if (setValue) {
setValue(newValue);
}
}
}
return (
<input
type="number"
value={value ?? ''}
onChange={handleChange}
className="input-base"
placeholder={placeholder}
readOnly={readOnly}
disabled={disabled}
/>
)
}