@arche-mc2/arche-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
91 lines • 4.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var SvgIcon_1 = require("../../Display/SvgIcon");
var theming_1 = require("../../../Common/theming");
var UpTooltip_1 = require("../../Display/Tooltip/UpTooltip");
var UpLigne_1 = require("../../Display/Ligne/UpLigne");
var classnames = require("classnames");
var Box_1 = require("../Box");
var typestyle_1 = require("typestyle");
var headerCellStyles = typestyle_1.style({
$nest: {
"& .up-data-grid-header-cell-icons .up-icon-wrapper": {
height: "8px"
},
"& .up-data-grid-header-cell-icons": {
marginLeft: "8px"
},
"& .tooltip-icon": {
marginLeft: '8px',
marginTop: '4px'
}
}
});
var UpDataGridCellHeader = (function (_super) {
tslib_1.__extends(UpDataGridCellHeader, _super);
function UpDataGridCellHeader(props, context) {
var _this = _super.call(this, props, context) || this;
_this.onCellClick = function (sortDirection) {
if (!sortDirection) {
sortDirection = _this.state.sortDirection === "ASC" ? "DESC" : "ASC";
}
if (_this.props.column.isSortable === true &&
_this.state.sortDirection != sortDirection) {
_this.setState({ isSorted: true, sortDirection: sortDirection }, function () {
_this.props.onSortChange(_this.props.column, _this.state.sortDirection);
});
}
};
_this.state = {
isSorted: props.column ? props.column.isSorted : false,
sortDirection: props.column ? props.column.sortDir : null
};
return _this;
}
UpDataGridCellHeader.prototype.componentWillReceiveProps = function (newProps) {
if (newProps.column.isSorted != null &&
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 _this = this;
var sortDescIcon = "arrow-down";
var sortAscIcon = "arrow-up";
var arrowColor = theming_1.default.colorMap.primary;
var Tooltip = this.props.column.tooltip && (React.createElement(UpTooltip_1.default, { title: this.props.column.tooltip.title, content: this.props.column.tooltip.content, delayHide: 100, delayShow: 100 },
React.createElement(UpLigne_1.default, null,
React.createElement(SvgIcon_1.default, { width: 20, height: 20, iconName: this.props.column.tooltip.icon || 'info', className: "tooltip-icon" }))));
var width = "auto";
if (this.props.width != null) {
width = this.props.width;
}
return (React.createElement("th", { style: width ? { width: width } : {}, className: classnames(headerCellStyles, 'up-data-grid-header-cell', this.props.column.isSortable ? 'up-data-grid-sortable' : '', this.props.className) },
React.createElement(Box_1.default, { flexDirection: 'row', justifyContent: this.props.textAlignCells === 'center' ? 'center'
: this.props.textAlignCells === 'left' ? 'flex-start'
: this.props.textAlignCells === 'right' ? 'flex-end' : 'normal', alignItems: 'center' },
React.createElement("span", { onClick: function () { return _this.onCellClick(); }, className: 'up-data-grid-header-cell-label' }, this.props.column.label),
this.props.column.isSortable && (React.createElement(Box_1.default, { className: 'up-data-grid-header-cell-icons', flexDirection: 'column', style: { width: 'auto' } },
React.createElement(SvgIcon_1.default, { width: 12, height: 12, iconName: sortAscIcon, color: this.state.isSorted &&
this.state.sortDirection == 'ASC'
? arrowColor
: '#D7D7D7', onClick: function () { return _this.onCellClick('ASC'); } }),
React.createElement(SvgIcon_1.default, { width: 12, height: 12, iconName: sortDescIcon, color: this.state.isSorted &&
this.state.sortDirection == 'DESC'
? arrowColor
: '#D7D7D7', onClick: function () { return _this.onCellClick('DESC'); } }))),
Tooltip)));
};
return UpDataGridCellHeader;
}(React.Component));
exports.default = UpDataGridCellHeader;
//# sourceMappingURL=UpDataGridCellHeader.js.map