import React from 'react' ; export type PercentageChangeProps = { base : number ; peak : number ; className ? : string ; } ; export const PercentageChange = ( { base , peak , className = '' } ) => { const round = ( num ) => Math . round ( ( num + Number . EPSILON ) * 100 ) / 100 ; const render = ( value , color = 'inherit' ) => < span style = { { color } } className = { className } > { value } < /span>; if ( base === peak ) return render ( `0.0%` ) ; if ( base !== 0 && base < peak ) return render ( `↑ ${ round ( ( ( peak - base ) / base ) * 100 ) }%` , 'var(--palette-success-dark)' ) ; if ( base !== 0 && base > peak ) return render ( `↓ ${ round ( ( ( base - peak ) / base ) * 100 ) }%` , 'var(--palette-error-dark)' ) ; return render ( ' – ' ) ; } ;