File size: 1,651 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import { localize } from 'i18n-calypso';
import { find } from 'lodash';
import PropTypes from 'prop-types';
import { Component } from 'react';
import ChartLegendItem from './legend-item';
const noop = () => {};
class ChartLegend extends Component {
static propTypes = {
activeCharts: PropTypes.array,
activeTab: PropTypes.object.isRequired,
availableCharts: PropTypes.array,
clickHandler: PropTypes.func,
tabs: PropTypes.array,
};
static defaultProps = {
activeCharts: [],
availableCharts: [],
clickHandler: noop,
tabs: [],
};
onFilterChange = ( chartItem ) => {
this.props.clickHandler( chartItem );
};
render() {
const legendColors = [ 'chart__legend-color is-dark-blue' ];
const activeTab = this.props.activeTab;
const legendItems = this.props.availableCharts.map( function ( legendItem, index ) {
const colorClass = legendColors[ index ];
const checked = -1 !== this.props.activeCharts.indexOf( legendItem );
const tab = find( this.props.tabs, { attr: legendItem } );
return (
<ChartLegendItem
key={ index }
className={ colorClass }
label={ tab.label }
attr={ tab.attr }
changeHandler={ this.onFilterChange }
checked={ checked }
/>
);
}, this );
return (
<div className="chart__legend">
<ul className="chart__legend-options">
<li className="chart__legend-option" key="default-tab">
<span className="chart__legend-label">
<span className="chart__legend-color is-wordpress-blue" />
{ activeTab.label }
</span>
</li>
{ legendItems }
</ul>
</div>
);
}
}
export default localize( ChartLegend );
|