igniteui-react-grids
Version:
Ignite UI React grid components.
598 lines (593 loc) • 20.3 kB
JavaScript
import { __extends, __values } from "tslib";
import * as React from 'react';
import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core";
import { FontInfo } from "igniteui-react-core";
import { ReactRenderer } from "igniteui-react-core";
import { DataGridToolbar } from './DataGridToolbar';
import { IgrDataGrid } from "./igr-data-grid";
import { IgrColumnChooser } from "./igr-column-chooser";
import { IgrColumnPinning } from "./igr-column-pinning";
import { ControlDisplayDensity_$type } from "igniteui-react-core";
import { BaseControlTheme_$type } from "igniteui-react-core";
import { Thickness } from "igniteui-react-core";
var IgrDataGridToolbar = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrDataGridToolbar, _super);
function IgrDataGridToolbar(props) {
var _this = _super.call(this, props) || this;
_this._implementation = null;
_this.__p = null;
_this._hasUserValues = new Set();
_this._stylingContainer = null;
_this._stylingParent = null;
_this._inStyling = false;
if (_this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
}
_this._getMainRef = _this._getMainRef.bind(_this);
_this._getColumnChooserRef = _this._getColumnChooserRef.bind(_this);
_this._getColumnPinningRef = _this._getColumnPinningRef.bind(_this);
_this._implementation = _this.createImplementation();
var toolbar = _this.i;
_this._toolbar = toolbar;
toolbar.notifySizeChanged();
if (props) {
_this.initializeProperties();
}
return _this;
}
Object.defineProperty(IgrDataGridToolbar.prototype, "height", {
get: function () {
return this._height;
},
set: function (value) {
this._height = value;
if (this._elRef) {
this._elRef.style.height = value;
this._toolbar.notifySizeChanged();
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "width", {
get: function () {
return this._width;
},
set: function (value) {
this._width = value;
if (this._elRef) {
this._elRef.style.height = value;
this._toolbar.notifySizeChanged();
}
},
enumerable: false,
configurable: true
});
IgrDataGridToolbar.prototype._getMainRef = function (ref) {
this._elRef = ref;
if (this._elRef != null && this._columnChooserRef != null && this._columnPinningRef != null) {
this._renderer = new ReactRenderer(this._elRef, document, false, null);
this._toolbar.provideContainer(this._renderer, this._columnChooserRef.i, this._columnPinningRef.i);
}
};
IgrDataGridToolbar.prototype._getColumnChooserRef = function (ref) {
this._columnChooserRef = ref;
if (this._elRef != null && this._columnChooserRef != null && this._columnPinningRef != null) {
this._renderer = new ReactRenderer(this._elRef, document, false, null);
this._toolbar.provideContainer(this._renderer, this._columnChooserRef.i, this._columnPinningRef.i);
}
};
IgrDataGridToolbar.prototype._getColumnPinningRef = function (ref) {
this._columnPinningRef = ref;
if (this._elRef != null && this._columnChooserRef != null && this._columnPinningRef != null) {
this._renderer = new ReactRenderer(this._elRef, document, false, null);
this._toolbar.provideContainer(this._renderer, this._columnChooserRef.i, this._columnPinningRef.i);
}
};
IgrDataGridToolbar.prototype.render = function () {
var children = [];
var title = React.createElement("span", {
key: "titleSpan"
});
children.push(title);
var buttons = [];
var hideBtnContainer = React.createElement("div", {
key: "hideBtnContainer"
});
buttons.push(hideBtnContainer);
var pinBtnContainer = React.createElement("div", {
key: "pinBtnContainer"
});
buttons.push(pinBtnContainer);
/*let exportInput = React.createElement("input", {
key: "exportInput",
type: "Button"
});
buttons.push(exportInput);*/
var buttonsContainer = React.createElement("div", {
key: "buttonsContainer",
children: buttons
});
children.push(buttonsContainer);
var chooserDialogChildren = [];
var chooserDialog = React.createElement("div", {
key: "chooserDialog",
children: chooserDialogChildren
});
children.push(chooserDialog);
var columnChooser = React.createElement(IgrColumnChooser, {
ref: this._getColumnChooserRef,
key: "columnChooser"
});
chooserDialogChildren.push(columnChooser);
var pinningChildren = [];
var pinningDialog = React.createElement("div", {
key: "pinningDialog",
children: pinningChildren,
});
children.push(pinningDialog);
var columnPinning = React.createElement(IgrColumnPinning, {
ref: this._getColumnPinningRef,
key: "columnPinning"
});
pinningChildren.push(columnPinning);
/*let exportChildren: any[] = [];
let exportDialog = React.createElement("div", {
key: "exportDialog",
children: exportChildren,
style: {
background: "white",
display: "none",
position: "absolute",
zIndex: 12000,
borderWidth: "1px",
borderStyle: "solid"
}
});
children.push(exportDialog);
let exportExcel = React.createElement("input", {
key: "exportExcel",
type: "Button"
});
exportChildren.push(exportExcel);
let exportCsv = React.createElement("input", {
key: "exportCsv",
type: "Button"
});
exportChildren.push(exportCsv);*/
var div = React.createElement("div", {
className: "ig-data-grid-toolbar igr-data-grid-toolbar",
ref: this._getMainRef,
children: children
});
return div;
};
IgrDataGridToolbar.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var e_1, _a;
var mod = getModifiedProps(this.props, nextProps);
try {
for (var _b = __values(Object.keys(mod)), _c = _b.next(); !_c.done; _c = _b.next()) {
var p = _c.value;
if (isValidProp(this, p)) {
this[p] = mod[p];
}
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
return true;
};
IgrDataGridToolbar.prototype.initializeProperties = function () {
var e_2, _a;
try {
for (var _b = __values(Object.keys(this.props)), _c = _b.next(); !_c.done; _c = _b.next()) {
var p = _c.value;
if (isValidProp(this, p)) {
this[p] = this.props[p];
}
}
}
catch (e_2_1) {
e_2 = { error: e_2_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_2)
throw e_2.error;
}
}
};
// supports angular themes or custom properties set in CSS
IgrDataGridToolbar.prototype.updateStyle = function () {
this._styling(this._elRef, this);
};
IgrDataGridToolbar.prototype.destroy = function () {
this._toolbar.destroy();
if (this._renderer) {
this._renderer.destroy();
}
};
IgrDataGridToolbar.prototype.componentWillUnmount = function () {
};
IgrDataGridToolbar.prototype.componentDidMount = function () {
this._elRef.style.width = this._width ? this._width : "";
this._elRef.style.height = this._height ? this._height : "";
this._toolbar.notifySizeChanged();
this.initializeContent();
};
IgrDataGridToolbar.prototype.initializeContent = function () {
this.updateStyle();
this.i.notifySizeChanged();
};
IgrDataGridToolbar.prototype.createImplementation = function () {
return new DataGridToolbar();
};
Object.defineProperty(IgrDataGridToolbar.prototype, "i", {
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "targetGrid", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
var r = this.i.e;
if (r == null) {
return null;
}
if (!r.externalObject) {
var e = new IgrDataGrid({});
if (r.$type) {
e._implementation = r;
}
else {
if (e.i.setNativeElement) {
e.i.setNativeElement(r);
}
}
r.externalObject = e;
}
return r.externalObject;
},
set: function (v) {
if (v != null && this._stylingContainer && v._styling)
v._styling(this._stylingContainer, this, this);
v == null ? this.i.e = null : this.i.e = v.i;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "toolbarTitle", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.ar;
},
set: function (v) {
this.i.ar = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "toolbarTitleStyle", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
if (this.i.n == null) {
return null;
}
return this.i.n.fontString;
},
set: function (v) {
var fi = new FontInfo();
fi.fontString = v;
this.i.n = fi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "toolbarTitleColor", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return brushToString(this.i.bg);
},
set: function (v) {
this.i.bg = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "backgroundColor", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return brushToString(this.i.be);
},
set: function (v) {
this.i.be = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "dialogBackgroundColor", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return brushToString(this.i.bf);
},
set: function (v) {
this.i.bf = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "columnChooser", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.q;
},
set: function (v) {
this.i.q = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "columnChooserText", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.ad;
},
set: function (v) {
this.i.ad = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "columnChooserTitle", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.af;
},
set: function (v) {
this.i.af = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "columnPinning", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.r;
},
set: function (v) {
this.i.r = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "columnPinningText", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.ai;
},
set: function (v) {
this.i.ai = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "columnPinningTitle", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.ak;
},
set: function (v) {
this.i.ak = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "borderWidthBottom", {
get: function () {
return this.i.bi ? this.i.bi.bottom : NaN;
},
set: function (v) {
this.ensureBorderWidth();
this.i.bi.bottom = +v;
this.i.bi = this.i.bi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "borderWidthLeft", {
get: function () {
return this.i.bi ? this.i.bi.left : NaN;
},
set: function (v) {
this.ensureBorderWidth();
this.i.bi.left = +v;
this.i.bi = this.i.bi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "borderWidthRight", {
get: function () {
return this.i.bi ? this.i.bi.right : NaN;
},
set: function (v) {
this.ensureBorderWidth();
this.i.bi.right = +v;
this.i.bi = this.i.bi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "borderWidthTop", {
get: function () {
return this.i.bi ? this.i.bi.top : NaN;
},
set: function (v) {
this.ensureBorderWidth();
this.i.bi.top = +v;
this.i.bi = this.i.bi;
},
enumerable: false,
configurable: true
});
IgrDataGridToolbar.prototype.ensureBorderWidth = function () {
if (this.i.bi) {
return;
}
this.i.bi = new Thickness(2);
};
Object.defineProperty(IgrDataGridToolbar.prototype, "density", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.l;
},
set: function (v) {
this.i.l = ensureEnum(ControlDisplayDensity_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataGridToolbar.prototype, "baseTheme", {
/**
* Gets or Sets the property name that contains the values.
*/
get: function () {
return this.i.j;
},
set: function (v) {
this.i.j = ensureEnum(BaseControlTheme_$type, v);
},
enumerable: false,
configurable: true
});
IgrDataGridToolbar.prototype.findByName = function (name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
if (this.targetGrid && this.targetGrid.name && this.targetGrid.name == name) {
return this.targetGrid;
}
return null;
};
Object.defineProperty(IgrDataGridToolbar.prototype, "hasUserValues", {
get: function () {
return this._hasUserValues;
},
enumerable: false,
configurable: true
});
IgrDataGridToolbar.prototype.__m = function (propertyName) {
if (!this._inStyling) {
this._hasUserValues.add(propertyName);
}
};
IgrDataGridToolbar.prototype._styling = function (container, component, parent) {
if (this._inStyling) {
return;
}
this._inStyling = true;
this._stylingContainer = container;
this._stylingParent = component;
var genericPrefix = "";
var typeName = this.i.$type.name;
if (typeName.indexOf("Xam") === 0) {
typeName = typeName.substring(3);
}
genericPrefix = toSpinal("DataGridToolbar");
var additionalPrefixes = [];
var prefix = toSpinal(typeName);
additionalPrefixes.push(prefix + "-");
var b = this.i.$type.baseType;
while (b && b.name != "Object" &&
b.name != "Base" &&
b.name != "Control" &&
b.Name != "DependencyObject" &&
b.Name != "FrameworkElement") {
typeName = b.name;
if (typeName.indexOf("Xam") === 0) {
typeName = typeName.substring(3);
}
var basePrefix = toSpinal(typeName);
additionalPrefixes.push(basePrefix + "-");
b = b.baseType;
}
if (parent) {
var parentTypeName = parent.i.$type.name;
if (parentTypeName.indexOf("Xam") === 0) {
parentTypeName = parentTypeName.substring(3);
}
var parentPrefix = toSpinal(parentTypeName);
additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-");
additionalPrefixes.push(parentPrefix + "-" + prefix + "-");
}
initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes);
if (this.targetGrid && this.targetGrid._styling) {
this.targetGrid._styling(container, component, this);
}
if (this._otherStyling) {
this._otherStyling(container, component, parent);
}
this._inStyling = false;
};
/**
* Exports visual information about the current state of the toolbar.
*/
IgrDataGridToolbar.prototype.exportVisualModel = function () {
var iv = this.i.exportVisualModel();
return (iv);
};
/**
* Returns a serialized copy of the exported visual model
*/
IgrDataGridToolbar.prototype.exportSerializedVisualModel = function () {
var iv = this.i.exportSerializedVisualModel();
return (iv);
};
return IgrDataGridToolbar;
}(React.Component));
export { IgrDataGridToolbar };