@csegames/camelot-unchained
Version:
Camelot Unchained Client Library
44 lines (43 loc) • 2.1 kB
JavaScript
;
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var _ = require("lodash");
var aphrodite_1 = require("aphrodite");
var defaultGridStatsStyle = {
statContainer: {
display: 'flex'
},
statListSection: {
flex: 1
},
listItemContainer: {}
};
exports.GridStats = function (props) {
var ss = aphrodite_1.StyleSheet.create(defaultGridStatsStyle);
var custom = aphrodite_1.StyleSheet.create(props.styles || {});
var statArray = props.statArray;
var numberOfItemsInGrid = Math.ceil(statArray.length / props.howManyGrids);
var emptyListItems = props.shouldRenderEmptyListItems ? _.fill(Array(numberOfItemsInGrid * props.howManyGrids - statArray.length), '') : [];
var beginningArrayIndex = 0;
var arrayOfGrids = _.fill(Array(props.howManyGrids), '').map(function (ignore, index) {
var isLastGrid = index + 1 === props.howManyGrids;
var grids = [];
if (isLastGrid) {
grids = statArray.slice(beginningArrayIndex, numberOfItemsInGrid * (index + 1)).concat(emptyListItems);
} else {
grids = statArray.slice(beginningArrayIndex, numberOfItemsInGrid * (index + 1));
}
beginningArrayIndex = numberOfItemsInGrid * (index + 1);
return grids;
});
return React.createElement("div", { className: aphrodite_1.css(ss.statContainer, custom.statContainer) }, arrayOfGrids.map(function (grid, index) {
return React.createElement("div", { key: index, className: aphrodite_1.css(ss.statListSection, custom.statListSection) }, props.renderHeaderItem && props.renderHeaderItem(), grid.map(function (item, i) {
return React.createElement("div", { key: i, className: aphrodite_1.css(ss.listItemContainer, custom.listItemContainer) }, props.renderListItem(item, i));
}));
}));
};