d2-ui
Version:
133 lines (102 loc) • 5.57 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
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; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _simpleAssign = require('simple-assign');
var _simpleAssign2 = _interopRequireDefault(_simpleAssign);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _TableRowColumn = require('./TableRowColumn');
var _TableRowColumn2 = _interopRequireDefault(_TableRowColumn);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function getStyles(props, context) {
var tableFooter = context.muiTheme.tableFooter;
return {
cell: {
borderTop: '1px solid ' + tableFooter.borderColor,
verticalAlign: 'bottom',
padding: 20,
textAlign: 'left',
whiteSpace: 'nowrap'
}
};
}
var TableFooter = function (_Component) {
_inherits(TableFooter, _Component);
function TableFooter() {
_classCallCheck(this, TableFooter);
return _possibleConstructorReturn(this, Object.getPrototypeOf(TableFooter).apply(this, arguments));
}
_createClass(TableFooter, [{
key: 'render',
value: function render() {
var _props = this.props;
var adjustForCheckbox = _props.adjustForCheckbox;
var children = _props.children;
var className = _props.className;
var style = _props.style;
var other = _objectWithoutProperties(_props, ['adjustForCheckbox', 'children', 'className', 'style']);
var prepareStyles = this.context.muiTheme.prepareStyles;
var styles = getStyles(this.props, this.context);
var footerRows = _react2.default.Children.map(children, function (child, rowNumber) {
var newChildProps = {
displayBorder: false,
key: 'f-' + rowNumber,
rowNumber: rowNumber,
style: (0, _simpleAssign2.default)({}, styles.cell, child.props.style)
};
var newDescendants = void 0;
if (adjustForCheckbox) {
newDescendants = [_react2.default.createElement(_TableRowColumn2.default, { key: 'fpcb' + rowNumber, style: { width: 24 } })].concat(_toConsumableArray(_react2.default.Children.toArray(child.props.children)));
}
return _react2.default.cloneElement(child, newChildProps, newDescendants);
});
return _react2.default.createElement(
'tfoot',
_extends({ className: className, style: prepareStyles((0, _simpleAssign2.default)({}, style)) }, other),
footerRows
);
}
}]);
return TableFooter;
}(_react.Component);
TableFooter.muiName = 'TableFooter';
TableFooter.propTypes = {
/**
* @ignore
* 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: _react.PropTypes.bool,
/**
* Children passed to table footer.
*/
children: _react.PropTypes.node,
/**
* The css class name of the root element.
*/
className: _react.PropTypes.string,
/**
* Override the inline-styles of the root element.
*/
style: _react.PropTypes.object
};
TableFooter.defaultProps = {
adjustForCheckbox: true,
style: {}
};
TableFooter.contextTypes = {
muiTheme: _react.PropTypes.object.isRequired
};
exports.default = TableFooter;
;