Sha256: 3604be6014075a262a0cd3f9e974354597a78e136e61b6fa167ce4405e41b419

Contents?: true

Size: 1.7 KB

Versions: 529

Compression:

Stored size: 1.7 KB

Contents

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

import { buildCss, buildHtmlProps } from '../utilities/props'
import { globalProps } from '../utilities/globalProps'

import Body from '../pb_body/_body'
import Icon from '../pb_icon/_icon'

const statusMap: {neutral: 'neutral', decrease: 'negative' ,increase: 'positive'} = {
  increase: 'positive',
  decrease: 'negative',
  neutral: 'neutral',
}

const iconMap = {
  increase: 'arrow-up',
  decrease: 'arrow-down',
}

type StatChangeProps = {
  change?: 'increase' | 'decrease' | 'neutral',
  className?: string,
  icon?: string,
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
  id?: string,
  value?: string | number,
}

const StatChange = (props: StatChangeProps): React.ReactElement => {
  const { 
    change = 'neutral', 
    className, 
    htmlOptions = {},
    icon, 
    id, 
    value 
  } = props

  const status = statusMap[change as keyof typeof statusMap]
  let returnedIcon = iconMap[change as keyof typeof iconMap]
  if (icon) {
    returnedIcon = icon
  }

  const htmlProps = buildHtmlProps(htmlOptions)

  return (
    <>
      {value &&
        <div
            className={classnames(
              buildCss('pb_stat_change_kit', status),
              globalProps(props),
              className
              )}
            id={id}
            {...htmlProps}
        >
          <Body status={status}>
            {returnedIcon &&
              <>
                <Icon
                    fixed_width
                    icon={returnedIcon}
                />
                {' '}
              </>
            }
            {`${value}%`}
          </Body>
        </div>
      }
    </>
  )
}

export default StatChange

Version data entries

529 entries across 529 versions & 1 rubygems

Version Path
playbook_ui-14.10.0.pre.rc.5 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.10.0.pre.rc.4 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.alpha.PLAY16264818 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.alpha.PBNTR702stickyleftcolrails4806 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.10.0.pre.rc.3 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.10.0.pre.rc.2 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.alpha.play1742globalheightfixes4766 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.10.0.pre.rc.1 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.alpha.PBNTR686advancedtablepaginationpoc4747 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.alpha.pbntr700newresettodefaultprop4736 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.10.0.pre.rc.0 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.18 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.17 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.16 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.15 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.14 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.13 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.12 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
playbook_ui-14.9.0.pre.rc.11 app/pb_kits/playbook/pb_stat_change/_stat_change.tsx