meck-rc-table
Version:
table ui component for react
49 lines (40 loc) • 1.15 kB
JavaScript
import _extends from 'babel-runtime/helpers/extends';
import React from 'react';
import { connect } from 'mini-store';
function TableHeaderRow(_ref) {
var row = _ref.row,
height = _ref.height,
components = _ref.components;
var style = { height: height };
var HeaderRow = 'tr';
var HeaderCell = 'th';
if (components.header) {
HeaderRow = components.header.row || HeaderRow;
HeaderCell = components.header.cell || HeaderCell;
}
return React.createElement(
HeaderRow,
{ style: style },
row.map(function (cell, i) {
return React.createElement(HeaderCell, _extends({}, cell, { key: i }));
})
);
}
function getRowHeight(state, props) {
var fixedColumnsHeadRowsHeight = state.fixedColumnsHeadRowsHeight;
var columns = props.columns,
rows = props.rows;
var headerHeight = fixedColumnsHeadRowsHeight[0];
if (headerHeight && columns) {
if (headerHeight === 'auto') {
return 'auto';
}
return headerHeight / rows.length;
}
return null;
}
export default connect(function (state, props) {
return {
height: getRowHeight(state, props)
};
})(TableHeaderRow);