Implement SliderTableField

This commit is contained in:
Justin Edmund 2023-03-17 20:07:22 -07:00
parent 3b3e2d50b3
commit 914f8929ed

View file

@ -21,11 +21,11 @@ interface Props {
} }
const SliderTableField = (props: Props) => { const SliderTableField = (props: Props) => {
const [value, setValue] = useState(props.value) const [value, setValue] = useState(0)
useEffect(() => { useEffect(() => {
if (props.value !== undefined && props.value !== value) if (props.value !== undefined && props.value !== value)
setValue(props.value) if (props.value) setValue(props.value)
}, [props.value]) }, [props.value])
useEffect(() => { useEffect(() => {
@ -40,10 +40,14 @@ const SliderTableField = (props: Props) => {
setValue(value[0]) setValue(value[0])
} }
function handleInputChange(event: React.ChangeEvent<HTMLInputElement>) { function onInputChange(event: React.ChangeEvent<HTMLInputElement>) {
setValue(parseInt(event.currentTarget?.value)) setValue(parseInt(event.currentTarget?.value))
} }
function onValueChange(value: number[]) {
setValue(value[0])
}
return ( return (
<TableField <TableField
name={props.name} name={props.name}
@ -58,8 +62,8 @@ const SliderTableField = (props: Props) => {
min={props.min} min={props.min}
max={props.max} max={props.max}
step={props.step} step={props.step}
value={[value ? value : 0]} value={[value]}
onValueChange={handleValueChange} onValueChange={onValueChange}
onValueCommit={handleValueCommit} onValueCommit={handleValueCommit}
/> />
<Input <Input
@ -69,7 +73,7 @@ const SliderTableField = (props: Props) => {
min={props.min} min={props.min}
max={props.max} max={props.max}
step={props.step} step={props.step}
onChange={handleInputChange} onChange={onInputChange}
/> />
</TableField> </TableField>
) )