forked from ddrilling/asb_cloud_front
Убрал рефы.
Починил поведение при неизменяющемся значении
This commit is contained in:
parent
3757112dc1
commit
eb92d5a0d7
21393
package-lock.json
generated
21393
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,28 +1,42 @@
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import {CaretUpOutlined, CaretDownOutlined} from '@ant-design/icons'
|
||||
|
||||
export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{
|
||||
const [oldVal, setOldVal] = useState(NaN)
|
||||
const [val, setVal] = useState('---')
|
||||
const arrowRef = useRef(null);
|
||||
const [arrowState, setArrowState] = useState(0)
|
||||
|
||||
useEffect(()=>{
|
||||
if(value)
|
||||
if(value){
|
||||
if(Number.isFinite(+value)){
|
||||
setVal((+value).toPrecision(4)??'---')
|
||||
if (isArrowVisible)
|
||||
{
|
||||
let newArrowState = 0
|
||||
if (value > oldVal)
|
||||
arrowRef.current = (<CaretUpOutlined style={{color:"red"}} />)
|
||||
else if (value < oldVal)
|
||||
arrowRef.current = (<CaretDownOutlined style={{color:"red"}} />)
|
||||
newArrowState = 1
|
||||
if (value < oldVal)
|
||||
newArrowState = -1
|
||||
setArrowState(newArrowState)
|
||||
setOldVal(value)
|
||||
}
|
||||
} else
|
||||
setVal(value)
|
||||
setVal((+value).toPrecision(4)??'---')
|
||||
}
|
||||
else
|
||||
setVal(value)
|
||||
}
|
||||
|
||||
},[value])
|
||||
|
||||
return(<span className='display_value'>{prefix} {val} {suffix}{arrowRef.current}</span>)
|
||||
let arrow = null
|
||||
switch (arrowState){
|
||||
case 1:
|
||||
arrow = <CaretUpOutlined style={{color:"red"}}/>
|
||||
break;
|
||||
case -1:
|
||||
arrow = <CaretDownOutlined style={{color:"red"}}/>
|
||||
}
|
||||
|
||||
return(<span className='display_value'>{prefix} {val} {suffix}{arrow}</span>)
|
||||
}
|
||||
|
||||
export const Display = (props)=>{
|
||||
|
Loading…
Reference in New Issue
Block a user