Sha256: 459f9995cc2d9a30ff178190989690112613126cf5f9858430b099490d709bfd

Contents?: true

Size: 1.2 KB

Versions: 39

Compression:

Stored size: 1.2 KB

Contents

/* @flow */

import React from 'react'
import classnames from 'classnames'
import { globalProps } from '../utilities/globalProps'

type DistributionBarProps = {
  className?: string,
  colors: array,
  data?: string,
  id?: string,
  size?: "lg" | "sm",
  widths?: array<number>,
}

const normalizeCharacters = (widths) => {
  return widths.map((width) => {
    return parseInt(width.toString().replace(/[^0-9.]/gi, ''))
  })
}

const barValues = (normalizedValues, colors) => {
  const arrSum = (value) => value.reduce((a, b) => a + b, 0)
  const widthSum = arrSum(normalizedValues)
  return normalizedValues.map((value, i) => {
    return (
      <div
          className={classnames('pb_distribution_width', colors[i] ? `color_${colors[i]}` : '')}
          key={i}
          style={{ width: `${(value * 100) / widthSum}%` }}
      />
    )
  })
}

const DistributionBar = (props: DistributionBarProps) => {
  const {
    size = 'lg',
    widths = [1],
    colors = [],
  } = props
  const normalizedValues = normalizeCharacters(widths)

  return (
    <div className={classnames(`pb_distribution_bar_${size}`, globalProps(props))}>
      {barValues(normalizedValues, colors)}
    </div>
  )
}

export default DistributionBar

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
playbook_ui-11.2.7 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.2.6 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.2.5 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.2.3 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.2.2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.2.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.2.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.1.2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.1.2.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.1.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.1.1.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.1.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.0.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.0.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.0.0.pre.alpha.2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-11.0.0.pre.alpha.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-10.26.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-10.27.0.pre.lazysizes1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-10.27.0.pre.datepicker1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-10.26.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx