2021-05-24 15:19:38 +05:00
|
|
|
import { useState } from 'react';
|
|
|
|
import {CaretUpOutlined, CaretDownOutlined} from '@ant-design/icons'
|
|
|
|
|
|
|
|
export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{
|
|
|
|
const [oldVal, setOldVal] = useState(NaN)
|
2021-04-16 15:50:01 +05:00
|
|
|
|
2021-05-24 15:19:38 +05:00
|
|
|
let val = '---'
|
|
|
|
let arrow = null
|
2021-04-16 15:50:01 +05:00
|
|
|
if(value)
|
2021-05-24 15:19:38 +05:00
|
|
|
if(Number.isFinite(+value)){
|
2021-04-16 15:50:01 +05:00
|
|
|
val = (+value).toPrecision(4)??'---'
|
2021-05-24 15:19:38 +05:00
|
|
|
if (isArrowVisible)
|
|
|
|
{
|
|
|
|
arrow = value > oldVal
|
|
|
|
? <CaretUpOutlined style={{color:"red"}} onClick={!isArrowVisible} />
|
|
|
|
: <CaretDownOutlined style={{color:"red"}} onClick={!isArrowVisible} />
|
|
|
|
setOldVal(value)
|
|
|
|
}
|
|
|
|
} else
|
2021-04-16 15:50:01 +05:00
|
|
|
val = value
|
|
|
|
|
2021-05-24 15:19:38 +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>
|
|
|
|
|
|
|
|
}
|