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-9.15.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.15.0.pre.decouple.website1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.14.1.alpha.radio.alignment app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.14.1.alpha.highcharts9 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.14.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.13.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.12.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.12.0.pre.text.addon app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.11.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.10.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.10.0.pre.date.time.stacked.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.10.0.pre.alpha2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.10.0.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.9.0.alpha.inline1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.9.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.8.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.7.0.pre.alphawidth1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.7.0.pre.alpha.a11y.btn app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.7.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-9.6.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx