2021-05-28 14:30:55 +05:00
|
|
|
import { useState, useEffect } from 'react';
|
2021-05-24 15:19:38 +05:00
|
|
|
import {CaretUpOutlined, CaretDownOutlined} from '@ant-design/icons'
|
|
|
|
|
|
|
|
export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{
|
|
|
|
const [oldVal, setOldVal] = useState(NaN)
|
2021-05-24 17:57:13 +05:00
|
|
|
const [val, setVal] = useState('---')
|
2021-05-28 14:30:55 +05:00
|
|
|
const [arrowState, setArrowState] = useState(0)
|
2021-05-24 17:57:13 +05:00
|
|
|
|
|
|
|
useEffect(()=>{
|
2021-05-28 14:30:55 +05:00
|
|
|
if(value){
|
2021-05-24 17:57:13 +05:00
|
|
|
if(Number.isFinite(+value)){
|
|
|
|
if (isArrowVisible)
|
|
|
|
{
|
2021-05-28 14:30:55 +05:00
|
|
|
let newArrowState = 0
|
2021-05-24 17:57:13 +05:00
|
|
|
if (value > oldVal)
|
2021-05-28 14:30:55 +05:00
|
|
|
newArrowState = 1
|
|
|
|
if (value < oldVal)
|
|
|
|
newArrowState = -1
|
|
|
|
setArrowState(newArrowState)
|
2021-05-24 17:57:13 +05:00
|
|
|
setOldVal(value)
|
|
|
|
}
|
2021-05-28 14:30:55 +05:00
|
|
|
setVal((+value).toPrecision(4)??'---')
|
|
|
|
}
|
|
|
|
else
|
|
|
|
setVal(value)
|
|
|
|
}
|
|
|
|
|
2021-05-28 14:37:54 +05:00
|
|
|
},[value, isArrowVisible, oldVal])
|
2021-04-16 15:50:01 +05:00
|
|
|
|
2021-05-28 14:30:55 +05:00
|
|
|
let arrow = null
|
|
|
|
switch (arrowState){
|
|
|
|
case 1:
|
|
|
|
arrow = <CaretUpOutlined style={{color:"red"}}/>
|
2021-05-28 14:37:54 +05:00
|
|
|
break
|
2021-05-28 14:30:55 +05:00
|
|
|
case -1:
|
|
|
|
arrow = <CaretDownOutlined style={{color:"red"}}/>
|
2021-05-28 14:37:54 +05:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
break
|
2021-05-28 14:30:55 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
return(<span className='display_value'>{prefix} {val} {suffix}{arrow}</span>)
|
2021-04-16 15:50:01 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const Display = (props)=>{
|
|
|
|
const {label} = props
|
|
|
|
|
|
|
|
return <div className={props.className}>
|
|
|
|
<div className='display_label'>{label}</div>
|
|
|
|
<div style={{display:"flex", flexGrow:1}}>
|
|
|
|
<ValueDisplay {...props}/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
}
|