UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

271 lines (270 loc) 11.1 kB
import { __assign, __extends } from "tslib"; import * as React from 'react'; import { IgrColumnCollection } from "./igr-column-collection"; import { IgrColumn } from "./igr-column"; import { ColumnGroup } from "./ColumnGroup"; import { ContentChildrenManager } from "igniteui-react-core"; import { CollectionAdapter, isValidProp, ensureBool } from "igniteui-react-core"; import { Column } from "./Column"; import { NotifyCollectionChangedAction } from "igniteui-react-core"; import { IgrColumnTemplateContext } from "./igr-column-template-context"; import { ReactTemplateAdapter } from "igniteui-react-core"; import { html } from "lit-html"; /** * **Ignite UI for Angular Column Group** * @igxParent IgxGridComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxColumnGroupComponent, IgxRowIslandComponent */ var IgrColumnGroup = /** @class */ /*@__PURE__*/ (function (_super) { __extends(IgrColumnGroup, _super); function IgrColumnGroup(props) { var _this = _super.call(this, props) || this; _this._children = null; _this._getMainRef = _this._getMainRef.bind(_this); return _this; } IgrColumnGroup.prototype.createImplementation = function () { var _a, _b; var impl = new ColumnGroup(); var nat; if (typeof document !== 'undefined') { nat = document.createElement("igc-column-group"); } else { nat = { style: {} }; } if ((_a = this.props) === null || _a === void 0 ? void 0 : _a.className) { nat.className = this.props.className; } if ((_b = this.props) === null || _b === void 0 ? void 0 : _b.id) { nat.id = this.props.id; } impl.setNativeElement(nat); return impl; }; Object.defineProperty(IgrColumnGroup.prototype, "i", { /** * @hidden */ get: function () { return this._implementation; }, enumerable: false, configurable: true }); IgrColumnGroup.prototype._initializeAdapters = function () { var _this = this; if (!this._contentChildrenManager) { var resolveNested_1 = (function (props, propName, nestedPropName) { var _a; var prop = props[propName]; if (Array.isArray(prop)) { return prop.map(function (x) { var _a; return (_a = x[nestedPropName]) !== null && _a !== void 0 ? _a : resolveNested_1(x.props, propName, nestedPropName); }).join("_"); } else if (prop) { return (_a = prop.props[nestedPropName]) !== null && _a !== void 0 ? _a : resolveNested_1(prop.props, propName, nestedPropName); } else { return props[nestedPropName]; } }); this._contentChildrenManager = new ContentChildrenManager(function (ch) { var key = ch.key || ch.props.name; if (!key) { var type = (ch.type); var instance = new type; var name_1 = instance.i.$type.name; switch (name_1) { case "Column": return ch.props.field; case "ColumnGroup": return resolveNested_1(ch.props, "children", "field"); case "ColumnLayout": return resolveNested_1(ch.props, "children", "field"); default: return undefined; } } return key; }, function (ch) { var key = ch.key || ch.props.name; if (!key) { var type = (ch.type); var instance = new type; var name_2 = instance.i.$type.name; switch (name_2) { case "Column": return ch.props.field; case "ColumnGroup": return resolveNested_1(ch.props, "children", "field"); case "ColumnLayout": return resolveNested_1(ch.props, "children", "field"); default: return undefined; } } return key; }, function () { if (_this._updateContentChildren) { _this._updateContentChildren(); } else if (_this._updateAdapters) { _this._updateAdapters(); } }); } this._childrenAdapter = new CollectionAdapter(this.contentChildren, this.i.bo, this.actualChildren, function (c) { return c.i; }, function (i) { if (_this._initializeElement) { _this._initializeElement(i); } }, function (i) { if (_this._destroyElement) { _this._destroyElement(i); } }); if (_super.prototype["_initializeAdapters"]) { _super.prototype["_initializeAdapters"].call(this); } }; IgrColumnGroup.prototype._updateAdapters = function () { if (_super.prototype["_updateAdapters"]) { _super.prototype["_updateAdapters"].call(this); } var contentChildrenActual = this._contentChildrenManager.contentChildrenActual; this.contentChildren.length = 0; for (var i = 0; i < contentChildrenActual.length; i++) { if ((Column.$type).isAssignableFrom(contentChildrenActual[i].i.$type)) { this.contentChildren.push(contentChildrenActual[i]); } } if (this._childrenAdapter != null) { this._childrenAdapter.notifyContentChanged(); } }; IgrColumnGroup.prototype.render = function () { var _this = this; var nativePropsName = Object.keys(this.props).filter(function (prop) { return !isValidProp(_this, prop) && prop !== "originalRef" && prop !== "className"; }); var nativeProps = {}; nativePropsName.forEach(function (propName) { nativeProps[propName] = _this.props[propName]; }); var visibleChildren = []; React.Children.forEach(this.props.children, function (ch) { if (ch) { visibleChildren.push(ch); } }); var children = this._contentChildrenManager.getChildren(visibleChildren); this._portalManager.onRender(children); var style = {}; style.display = 'contents'; if (this.props.style) { style = this.props.style; } var div = React.createElement("div", __assign(__assign({}, nativeProps), { ref: this._getMainRef, style: style, children: children })); return div; }; IgrColumnGroup.prototype._getMainRef = function (ref) { this._elRef = ref; }; Object.defineProperty(IgrColumnGroup.prototype, "actualChildren", { get: function () { if (!this._actualChildren) { this._actualChildren = []; } return this._actualChildren; }, enumerable: false, configurable: true }); Object.defineProperty(IgrColumnGroup.prototype, "contentChildren", { get: function () { if (!this._contentChildren) { this._contentChildren = []; } return this._contentChildren; }, enumerable: false, configurable: true }); Object.defineProperty(IgrColumnGroup.prototype, "children", { /** * @deprecated Use the `childColumns` property instead. */ get: function () { var _this = this; if (this._children === null) { var coll = new IgrColumnCollection(); var inner = coll._innerColl; this._children = coll; inner.addListener(function (sender, e) { switch (e.action) { case NotifyCollectionChangedAction.Add: _this._childrenAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0)); break; case NotifyCollectionChangedAction.Remove: _this._childrenAdapter.removeManualItemAt(e.oldStartingIndex); break; case NotifyCollectionChangedAction.Replace: _this._childrenAdapter.removeManualItemAt(e.oldStartingIndex); _this._childrenAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0)); break; case NotifyCollectionChangedAction.Reset: _this._childrenAdapter.clearManualItems(); break; } }); ; } return this._children; }, enumerable: false, configurable: true }); Object.defineProperty(IgrColumnGroup.prototype, "collapsible", { get: function () { return this.i.bp; }, set: function (v) { this.i.bp = ensureBool(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrColumnGroup.prototype, "expanded", { get: function () { return this.i.bq; }, set: function (v) { this.i.bq = ensureBool(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrColumnGroup.prototype, "collapsibleIndicatorTemplate", { /** * Allows you to define a custom template for expand/collapse indicator * @memberof IgxColumnGroupComponent */ get: function () { return this._collapsibleIndicatorTemplate; }, set: function (v) { this._collapsibleIndicatorTemplate = v; if (!this._collapsibleIndicatorTemplateAdapter) { this._collapsibleIndicatorTemplateAdapter = new ReactTemplateAdapter(this._renderer, this._portalManager, "bs", { html: html }, function () { return new IgrColumnTemplateContext(); }); } this._collapsibleIndicatorTemplateAdapter.setValue(this.i, this._collapsibleIndicatorTemplate); }, enumerable: false, configurable: true }); IgrColumnGroup.prototype.findByName = function (name) { var baseResult = _super.prototype.findByName.call(this, name); if (baseResult) { return baseResult; } if (this.children != null && this.children.findByName && this.children.findByName(name)) { return this.children.findByName(name); } return null; }; return IgrColumnGroup; }(IgrColumn)); export { IgrColumnGroup };