Added value reporting and fixed a cycle error
This commit is contained in:
parent
87390bc07c
commit
fe3ef4129c
3 changed files with 22 additions and 5 deletions
|
|
@ -13,15 +13,21 @@ interface Props {
|
||||||
imageAlt?: string
|
imageAlt?: string
|
||||||
imageClass?: string
|
imageClass?: string
|
||||||
imageSrc?: string[]
|
imageSrc?: string[]
|
||||||
|
onValueChange: (value: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const InputTableField = (props: Props) => {
|
const InputTableField = (props: Props) => {
|
||||||
const [value, setValue] = useState(0)
|
const [value, setValue] = useState(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.value) setValue(props.value)
|
if (props.value !== undefined && props.value !== value)
|
||||||
|
setValue(props.value)
|
||||||
}, [props.value])
|
}, [props.value])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
props.onValueChange(value)
|
||||||
|
}, [value])
|
||||||
|
|
||||||
function onInputChange(event: React.ChangeEvent<HTMLInputElement>) {
|
function onInputChange(event: React.ChangeEvent<HTMLInputElement>) {
|
||||||
setValue(parseInt(event.currentTarget?.value))
|
setValue(parseInt(event.currentTarget?.value))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ interface Props {
|
||||||
name: string
|
name: string
|
||||||
label: string
|
label: string
|
||||||
description?: string
|
description?: string
|
||||||
value?: number
|
value: number
|
||||||
className?: string
|
className?: string
|
||||||
imageAlt?: string
|
imageAlt?: string
|
||||||
imageClass?: string
|
imageClass?: string
|
||||||
|
|
@ -17,15 +17,21 @@ interface Props {
|
||||||
min: number
|
min: number
|
||||||
max: number
|
max: number
|
||||||
step: number
|
step: number
|
||||||
|
onValueChange: (value: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const SliderTableField = (props: Props) => {
|
const SliderTableField = (props: Props) => {
|
||||||
const [value, setValue] = useState(0)
|
const [value, setValue] = useState(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.value) setValue(props.value)
|
if (props.value !== undefined && props.value !== value)
|
||||||
|
setValue(props.value)
|
||||||
}, [props.value])
|
}, [props.value])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
props.onValueChange(value)
|
||||||
|
}, [value])
|
||||||
|
|
||||||
function onInputChange(event: React.ChangeEvent<HTMLInputElement>) {
|
function onInputChange(event: React.ChangeEvent<HTMLInputElement>) {
|
||||||
setValue(parseInt(event.currentTarget?.value))
|
setValue(parseInt(event.currentTarget?.value))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,25 @@ interface Props {
|
||||||
name: string
|
name: string
|
||||||
label: string
|
label: string
|
||||||
description?: string
|
description?: string
|
||||||
value?: boolean
|
value: boolean
|
||||||
className?: string
|
className?: string
|
||||||
imageAlt?: string
|
imageAlt?: string
|
||||||
imageClass?: string
|
imageClass?: string
|
||||||
imageSrc?: string[]
|
imageSrc?: string[]
|
||||||
|
onValueChange: (value: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const SwitchTableField = (props: Props) => {
|
const SwitchTableField = (props: Props) => {
|
||||||
const [value, setValue] = useState(false)
|
const [value, setValue] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.value) setValue(props.value)
|
if (value !== props.value) setValue(props.value)
|
||||||
}, [props.value])
|
}, [props.value])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
props.onValueChange(value)
|
||||||
|
}, [value])
|
||||||
|
|
||||||
function onValueChange(value: boolean) {
|
function onValueChange(value: boolean) {
|
||||||
setValue(value)
|
setValue(value)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue