import React, { useEffect, useState } from "react"; import * as CONSTANTS from "../../../types/world/worldConstants"; interface InputToggleProps { label: string; // Represents the toggle state (on/off) min?: number; max?: number; onClick?: () => void; // Function to handle toggle clicks onChange?: (value: number) => void; // Function to handle toggle clicks disabled?: boolean; value?: number; onPointerUp?: (value: number) => void; } const InputRange: React.FC = ({ label, onClick, onChange, min, max, disabled, value, onPointerUp, }) => { const [rangeValue, setRangeValue] = useState(value ? value : 5); function handleChange(e: React.ChangeEvent) { const newValue = parseInt(e.target.value); // Parse the value to an integer setRangeValue(newValue); // Update the local state if (onChange) { onChange(newValue); // Call the onChange function if it exists } } useEffect(() => { value && setRangeValue(value); }, [value]); function handlePointerUp(e: React.PointerEvent) { const newValue = parseInt(e.currentTarget.value, 10); // Parse value correctly if (onPointerUp) { onPointerUp(newValue); // Call the callback function if it exists } } function handlekey(e: React.KeyboardEvent) { const newValue = parseInt(e.currentTarget.value, 10); // Parse value correctly if (onPointerUp) { onPointerUp(newValue); // Call the callback function if it exists } } return (
{ if (e.key === "ArrowUp" || e.key === "ArrowDown") { console.log("e.key: ", e.key); handlekey(e); } }} />
); }; export default InputRange;