Sha256: 37e2cd9249a02370ea86530c1fd1375ecc846e5e7d9a09c77e2f7c14ce8128b0

Contents?: true

Size: 1.2 KB

Versions: 142

Compression:

Stored size: 1.2 KB

Contents

/* @flow */

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

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

142 entries across 142 versions & 1 rubygems

Version Path
playbook_ui-8.1.2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.1.0.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.0.3 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.2.0.pre.alpha2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.1.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.0.2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.2.0.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.1.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.0.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.0.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.0.0.pre.alpha5 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.0.0.pre.alpha4 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-8.0.0.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-7.16.0.pre.alpha5 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-7.16.0.pre.alpha4 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-7.16.0.pre.alpha3 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-7.16.0.pre.alpha2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-7.16.0.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-7.14.0.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-7.16.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx