d2-ui
Version:
156 lines (126 loc) • 4.75 kB
JavaScript
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _tableRowColumn = require('./table-row-column');
var _tableRowColumn2 = _interopRequireDefault(_tableRowColumn);
var _stylePropable = require('../mixins/style-propable');
var _stylePropable2 = _interopRequireDefault(_stylePropable);
var _getMuiTheme = require('../styles/getMuiTheme');
var _getMuiTheme2 = _interopRequireDefault(_getMuiTheme);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var TableFooter = _react2.default.createClass({
displayName: 'TableFooter',
propTypes: {
/**
* Controls whether or not header rows should be adjusted
* for a checkbox column. If the select all checkbox is true,
* this property will not influence the number of columns.
* This is mainly useful for "super header" rows so that
* the checkbox column does not create an offset that needs
* to be accounted for manually.
*/
adjustForCheckbox: _react2.default.PropTypes.bool,
/**
* Children passed to table footer.
*/
children: _react2.default.PropTypes.node,
/**
* The css class name of the root element.
*/
className: _react2.default.PropTypes.string,
/**
* Override the inline-styles of the root element.
*/
style: _react2.default.PropTypes.object
},
contextTypes: {
muiTheme: _react2.default.PropTypes.object
},
//for passing default theme context to children
childContextTypes: {
muiTheme: _react2.default.PropTypes.object
},
mixins: [_stylePropable2.default],
getDefaultProps: function getDefaultProps() {
return {
adjustForCheckbox: true,
style: {}
};
},
getInitialState: function getInitialState() {
return {
muiTheme: this.context.muiTheme || (0, _getMuiTheme2.default)()
};
},
getChildContext: function getChildContext() {
return {
muiTheme: this.state.muiTheme
};
},
//to update theme inside state whenever a new theme is passed down
//from the parent / owner using context
componentWillReceiveProps: function componentWillReceiveProps(nextProps, nextContext) {
var newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({ muiTheme: newMuiTheme });
},
getTheme: function getTheme() {
return this.state.muiTheme.tableFooter;
},
getStyles: function getStyles() {
var styles = {
cell: {
borderTop: '1px solid ' + this.getTheme().borderColor,
verticalAlign: 'bottom',
padding: 20,
textAlign: 'left',
whiteSpace: 'nowrap'
}
};
return styles;
},
_createRows: function _createRows() {
var _this = this;
var rowNumber = 0;
return _react2.default.Children.map(this.props.children, function (child) {
return _this._createRow(child, rowNumber++);
});
},
_createRow: function _createRow(child, rowNumber) {
var styles = this.getStyles();
var props = {
displayBorder: false,
key: 'f-' + rowNumber,
rowNumber: rowNumber,
style: this.mergeStyles(styles.cell, child.props.style)
};
var children = [this._getCheckboxPlaceholder(props)];
_react2.default.Children.forEach(child.props.children, function (child) {
children.push(child);
});
return _react2.default.cloneElement(child, props, children);
},
_getCheckboxPlaceholder: function _getCheckboxPlaceholder(props) {
if (!this.props.adjustForCheckbox) return null;
var key = 'fpcb' + props.rowNumber;
return _react2.default.createElement(_tableRowColumn2.default, { key: key, style: { width: 24 } });
},
render: function render() {
var _props = this.props;
var className = _props.className;
var style = _props.style;
var other = _objectWithoutProperties(_props, ['className', 'style']);
var footerRows = this._createRows();
return _react2.default.createElement(
'tfoot',
_extends({ className: className, style: this.prepareStyles(style) }, other),
footerRows
);
}
});
exports.default = TableFooter;
module.exports = exports['default'];
;