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'
|
import {CaretUpOutlined, CaretDownOutlined} from '@ant-design/icons'
|
||||||
|
|
||||||
export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{
|
export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{
|
||||||
const [oldVal, setOldVal] = useState(NaN)
|
const [oldVal, setOldVal] = useState(NaN)
|
||||||
const [val, setVal] = useState('---')
|
const [val, setVal] = useState('---')
|
||||||
const arrowRef = useRef(null);
|
const [arrowState, setArrowState] = useState(0)
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
if(value)
|
if(value){
|
||||||
if(Number.isFinite(+value)){
|
if(Number.isFinite(+value)){
|
||||||
setVal((+value).toPrecision(4)??'---')
|
|
||||||
if (isArrowVisible)
|
if (isArrowVisible)
|
||||||
{
|
{
|
||||||
|
let newArrowState = 0
|
||||||
if (value > oldVal)
|
if (value > oldVal)
|
||||||
arrowRef.current = (<CaretUpOutlined style={{color:"red"}} />)
|
newArrowState = 1
|
||||||
else if (value < oldVal)
|
if (value < oldVal)
|
||||||
arrowRef.current = (<CaretDownOutlined style={{color:"red"}} />)
|
newArrowState = -1
|
||||||
|
setArrowState(newArrowState)
|
||||||
setOldVal(value)
|
setOldVal(value)
|
||||||
}
|
}
|
||||||
} else
|
setVal((+value).toPrecision(4)??'---')
|
||||||
setVal(value)
|
}
|
||||||
|
else
|
||||||
|
setVal(value)
|
||||||
|
}
|
||||||
|
|
||||||
},[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)=>{
|
export const Display = (props)=>{
|
||||||
|
Loading…
Reference in New Issue
Block a user