import * as React from "react"; import { AbstractItemList, ItemListProps } from "./ItemListComponents" import { FastClick, ReactComponentType, PureRender } from "../../../" import { ItemProps } from './ListProps' const defaults = require('lodash/defaults') export interface ItemHistogramComponentProps extends ItemProps { showCheckbox: boolean } @PureRender export class ItemHistogramComponent extends React.Component { getCountRatio(){ const { rawCount, listDocCount } = this.props if ((rawCount == undefined) || (listDocCount == undefined) || (listDocCount == 0)) { return 0 } else { return rawCount / listDocCount } } render(){ const { bemBlocks, onClick, active, disabled, style, itemKey, label, count, showCount, showCheckbox, listDocCount } = this.props const block = bemBlocks.option const className = block() .state({ active, disabled, histogram: true }) .mix(bemBlocks.container("item")) const barWidth = (this.getCountRatio()*100) + '%' return (
{showCheckbox ? : undefined}
{label}
{(showCount && (count != undefined)) ?
{count}
: undefined}
) } } export class ItemHistogramList extends AbstractItemList { static defaultProps = defaults({ //mod: "sk-item-histogram", itemComponent: ItemHistogramComponent, showCount: true, }, AbstractItemList.defaultProps) }