@ -15,11 +15,18 @@ function Maybe({condition, children}) {
}
export default class TopStats extends React . Component {
renderPercentageComparison ( name , comparison ) {
renderPercentageComparison ( name , comparison , forceDarkBg = false ) {
const formattedComparison = numberFormatter ( Math . abs ( comparison ) )
const defaultClassName = "text-xs text-gray-100"
const noChangeClassName = "text-xs text-gray-300"
const defaultClassName = classNames ( {
"text-xs dark:text-gray-100" : ! forceDarkBg ,
"text-xs text-gray-100" : forceDarkBg
} )
const noChangeClassName = classNames ( {
"text-xs text-gray-700 dark:text-gray-300" : ! forceDarkBg ,
"text-xs text-gray-300" : forceDarkBg
} )
if ( comparison > 0 ) {
const color = name === 'Bounce rate' ? 'text-red-400' : 'text-green-500'
@ -65,7 +72,7 @@ export default class TopStats extends React.Component {
< div >
{ query . comparison && < div className = "whitespace-nowrap" >
{ this . topStatNumberLong ( stat . name , stat . value ) } vs . { this . topStatNumberLong ( stat . name , stat . comparison _value ) } { statName }
< span className = "ml-2" > { this . renderPercentageComparison ( stat . name , stat . change )} < / s p a n >
< span className = "ml-2" > { this . renderPercentageComparison ( stat . name , stat . change , true )} < / s p a n >
< / d i v > }
{ ! query . comparison && < div className = "whitespace-nowrap" >
@ -134,6 +141,9 @@ export default class TopStats extends React.Component {
< div >
< span className = "flex items-center justify-between whitespace-nowrap" >
< p className = "font-bold text-xl dark:text-gray-100" id = { METRIC _MAPPING [ stat . name ] } > { this . topStatNumberShort ( stat . name , stat . value ) } < / p >
< Maybe condition = { ! query . comparison } >
{ this . renderPercentageComparison ( stat . name , stat . change ) }
< / M a y b e >
< / s p a n >
< Maybe condition = { query . comparison } >
< p className = "text-xs dark:text-gray-100" > { formatDateRange ( site , topStatData . from , topStatData . to ) } < / p >