@up-group-ui/react-controls
Version:
Up shared react controls
68 lines • 3.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var React = (0, tslib_1.__importStar)(require("react"));
var UpCheckBox_1 = (0, tslib_1.__importDefault)(require("../../Inputs/Checkbox/UpCheckBox"));
var UpDataGridCellHeader_1 = (0, tslib_1.__importDefault)(require("./UpDataGridCellHeader"));
var UpDataGrid_1 = require("./UpDataGrid");
var UpDataGridRowHeader = (function (_super) {
(0, tslib_1.__extends)(UpDataGridRowHeader, _super);
function UpDataGridRowHeader(props, context) {
var _this = _super.call(this, props, context) || this;
_this.onSelectionChange = function (event, isSelected) {
if (_this.props.onSelectionChange)
_this.props.onSelectionChange(isSelected);
};
_this.onSortChange = function (c, dir) {
var columns = [];
var sortedColumn = c;
sortedColumn.sortDir = dir;
_this.state.columns.map(function (value, index) {
value.isSorted = c.field == value.field;
if (value.isSorted)
value.sortDir = dir;
else
value.sortDir = null;
columns.push(value);
});
_this.setState({ columns: columns }, function () {
if (_this.props.onSortChange)
_this.props.onSortChange(sortedColumn, dir);
});
};
_this.state = {
isSelected: false,
columns: _this.props.columns,
};
return _this;
}
UpDataGridRowHeader.prototype.componentWillReceiveProps = function (nextProps) {
this.setState({
isSelected: false,
columns: nextProps.columns,
});
};
UpDataGridRowHeader.prototype.render = function () {
var _this = this;
var selection = ((0, jsx_runtime_1.jsx)(UpCheckBox_1.default, { options: [
(0, tslib_1.__assign)({ checked: this.props.isAllDataChecked, name: '', value: '', onOptionChange: this.onSelectionChange }, (!this.props.isSelectionAllEnabled && {
disabled: true,
})),
] }, void 0));
return ((0, jsx_runtime_1.jsx)("thead", (0, tslib_1.__assign)({ className: "up-data-grid-header" }, { children: (0, jsx_runtime_1.jsxs)("tr", { children: [this.props.isSelectionEnabled && ((0, jsx_runtime_1.jsx)(UpDataGridCellHeader_1.default, { className: "up-data-grid-header-cell-selection", column: {
label: selection,
isSortable: false,
}, textAlignCells: this.props.textAlignCells, width: '' }, "header-selection")), this.props.columns.map(function (value, index) {
return ((0, jsx_runtime_1.jsx)(UpDataGridCellHeader_1.default, { onSortChange: _this.onSortChange.bind(_this), column: value, textAlignCells: _this.props.textAlignCells }, "header-" + index));
}), (0, UpDataGrid_1.isActionEnabled)(this.props) && ((0, jsx_runtime_1.jsx)(UpDataGridCellHeader_1.default, { width: this.props.actions.length * 46 + "px", column: { label: '', isSortable: false }, textAlignCells: this.props.textAlignCells }, "header-actions"))] }, void 0) }), void 0));
};
UpDataGridRowHeader.defaultProps = {
isSelectionEnabled: true,
columns: [],
actions: null,
};
return UpDataGridRowHeader;
}(React.Component));
exports.default = UpDataGridRowHeader;
//# sourceMappingURL=UpDataGridRowHeader.js.map