Sha256: 0ecb5059a32e954b03817948175e938b66b0a666e49443907548eac141b5cef8

Contents?: true

Size: 1.08 KB

Versions: 44

Compression:

Stored size: 1.08 KB

Contents

/* @flow */

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

type DistributionBarProps = {
  className?: String,
  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) => {
  const arrSum = (value) => value.reduce((a, b) => a + b, 0)
  const widthSum = arrSum(normalizedValues)
  return normalizedValues.map((value, i) => {
    return (
      <div
          className="pb_distribution_width"
          key={i}
          style={{ width: `${(value * 100) / widthSum}%` }}
      />
    )
  })
}

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

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

export default DistributionBar

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
playbook_ui-6.0.1.pre.alpha5 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-6.0.1.pre.alpha4 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-6.0.1.pre.alpha3 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-6.0.1.pre.alpha2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.2.0.pre.alpha15 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.2.0.pre.alpha14 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.2.0.pre.alpha13 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-6.0.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.2.0.pre.alpha12 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-6.0.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.2.0.pre.alpha11 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.5.1.pre.alpha4 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.5.1.pre.alpha3 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.5.1.pre.alpha2 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.5.1.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.2.0.pre.alpha10 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.5.1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.5.0 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.5.0.pre.alpha1 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx
playbook_ui-5.2.0.pre.alpha9 app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx