Sha256: 9bff7392066214d35b44d52c97026dddae711e2cd73d370cdbcf27a0af786087

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

/* @flow */

import React from 'react'
import classnames from 'classnames'

import {
  Body,
  Icon,
} from '../'

type StatChangeProps = {
  change?: 'increase' | 'decrease' | 'neutral',
  className?: String,
  id?: String,
  value?: String | Number
}

const statChangeCSS = ({}: StatChangeProps, status) => {

  const statusStyle = status !== '' ? `_${status}` : ''

  return 'pb_stat_change_kit' + statusStyle
}

const StatChange = (props: StatChangeProps) => {
  const {
    change='neutral',
    className,
    id,
    value,
  } = props

  const status = (function(change) {
    switch(change) {
      case 'increase':
        return 'positive';
      case 'decrease':
        return 'negative';
      default:
        return 'neutral';
    }
  })(change)

  const icon = (function(change) {
    switch(change) {
      case 'increase':
        return 'arrow-up';
      case 'decrease':
        return 'arrow-down';
      default:
        return null;
    }
  })(change)

  const displayIcon = function(icon) {
    if (icon) {
      return (
        <span>
          <Icon icon={icon} fixed_width={true} />
          &nbsp;
        </span>
      )
    }
  }

  const displayValue = function(status, value) {
    if (value) {
      return (
        <Body status={status}>
          {displayIcon(icon)}
          {value}
        </Body>
      )
    }
  }

  return (
    <div id={id} className={classnames(statChangeCSS(props, status), className)}>
      {displayValue(status, value)}
    </div>
  )
}

export default StatChange

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
playbook_ui-2.9.6 app/pb_kits/playbook/pb_stat_change/_stat_change.jsx
playbook_ui-2.9.5 app/pb_kits/playbook/pb_stat_change/_stat_change.jsx
playbook_ui-2.9.4 app/pb_kits/playbook/pb_stat_change/_stat_change.jsx
playbook_ui-2.9.3 app/pb_kits/playbook/pb_stat_change/_stat_change.jsx
playbook_ui-2.9.2 app/pb_kits/playbook/pb_stat_change/_stat_change.jsx