Sha256: 7f79f65c3571bdfaf081c7d71cd79fda996a6294fe352e1fbab3a9c9c84a0e28
Contents?: true
Size: 1.46 KB
Versions: 644
Compression:
Stored size: 1.46 KB
Contents
import React from 'react' import classnames from 'classnames' import { globalProps } from '../utilities/globalProps' import { buildHtmlProps } from '../utilities/props' type DistributionBarProps = { className?: string, colors: [], data?: string, htmlOptions?: {[key: string]: string | number | boolean | (() => void)}, id?: string, size?: "lg" | "sm", widths?: number[], } const normalizeCharacters = (widths: number[]) => { return widths.map((width) => { return parseInt(width.toString().replace(/[^0-9.]/gi, '')) }) } const barValues = (normalizedValues: number[], colors: []) => { const arrSum = (value: number[]) => 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): React.ReactElement => { const { htmlOptions = {}, size = 'lg', widths = [1], colors = [], } = props const normalizedValues = normalizeCharacters(widths) const htmlProps = buildHtmlProps(htmlOptions) return ( <div className={classnames(`pb_distribution_bar_${size}`, globalProps(props))} {...htmlProps} > {barValues(normalizedValues, colors)} </div> ) } export default DistributionBar
Version data entries
644 entries across 644 versions & 1 rubygems