@up-group/react-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
59 lines • 2.77 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var SvgIcon_1 = require("../../Display/SvgIcon");
var classnames = require("classnames");
var UpDataGridCellHeader = (function (_super) {
__extends(UpDataGridCellHeader, _super);
function UpDataGridCellHeader(props, context) {
var _this = _super.call(this, props, context) || this;
_this.onCellClick = function () {
if (_this.props.column.isSortable === true) {
_this.setState({ isSorted: true, sortDirection: _this.state.sortDirection == "ASC" ? "DESC" : "ASC" }, function () {
_this.props.onSortChange(_this.props.column, _this.state.sortDirection);
});
}
};
_this.state = {
isSorted: false,
sortDirection: null
};
return _this;
}
UpDataGridCellHeader.prototype.componentWillReceiveProps = function (newProps) {
if (newProps.column.isSorted !== this.state.isSorted) {
this.setState({ isSorted: newProps.column.isSorted, sortDirection: (newProps.column.isSorted) ? (this.state.sortDirection == null) ? "DESC" : "ASC" : null });
}
};
UpDataGridCellHeader.prototype.render = function () {
var sortIcon = null;
if (this.state.sortDirection == "DESC") {
sortIcon = "sort-desc";
}
else if (this.state.sortDirection == "ASC") {
sortIcon = "sort-asc";
}
var width = "auto";
if (this.props.width) {
width = this.props.width;
}
return (React.createElement("th", { style: { width: width }, className: classnames("up-data-grid-header-cell", (this.props.column.isSortable) ? 'up-data-grid-sortable' : ''), onClick: this.onCellClick },
this.props.column.label,
this.state.isSorted && sortIcon != null &&
React.createElement(SvgIcon_1.default, { width: 10, iconName: sortIcon })));
};
UpDataGridCellHeader.defaultProps = {};
return UpDataGridCellHeader;
}(React.Component));
exports.default = UpDataGridCellHeader;
//# sourceMappingURL=UpDataGridCellHeader.js.map
;