UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

569 lines (565 loc) 19.7 kB
import { __assign, __extends, __values } from "tslib"; import * as React from 'react'; import { delegateCombine, delegateRemove } from "igniteui-react-core"; import { IgrNumberEventArgs } from "igniteui-react"; import { IgrPageCancellableEventArgs } from "./igr-page-cancellable-event-args"; import { IgrPageEventArgs } from "./igr-page-event-args"; import { Paginator } from "./Paginator"; import { TypeRegistrar } from "igniteui-react-core"; import { ReactRenderer, PortalManager } from "igniteui-react-core"; import { NamePatcher, getModifiedProps, isValidProp, interfaceToInternal, toSpinal, initializePropertiesFromCss } from "igniteui-react-core"; import { OverlaySettings } from "./OverlaySettings"; import { PaginatorResourceStrings } from "./PaginatorResourceStrings"; /** * Paginator component description * @igxParent IgxGridComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxPivotGridComponent, * */ var IgrPaginator = /** @class */ /*@__PURE__*/ (function (_super) { __extends(IgrPaginator, _super); function IgrPaginator(props) { var _this = _super.call(this, props) || this; _this.mounted = false; _this.__p = null; _this._hasUserValues = new Set(); _this._stylingContainer = null; _this._stylingParent = null; _this._inStyling = false; _this._perPageChange = null; _this._perPageChange_wrapped = null; _this._pageChange = null; _this._pageChange_wrapped = null; _this._paging = null; _this._paging_wrapped = null; _this._pagingDone = null; _this._pagingDone_wrapped = null; if (_this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this)); } _this._getMainRef = _this._getMainRef.bind(_this); _this._implementation = _this.createImplementation(); _this._portalManager = new PortalManager("templates", function () { if (_this.mounted) { _this.setState({}); } }); if (typeof window !== 'undefined' && typeof document !== 'undefined') { _this._renderer = new ReactRenderer(_this._implementation.nativeElement, document, false, null, _this._portalManager); } _this._implementation.externalObject = _this; _this.onImplementationCreated(); if (_this._initializeAdapters) { _this._initializeAdapters(); } return _this; } IgrPaginator.prototype.createImplementation = function () { var _a, _b; var impl = new Paginator(); var nat; if (typeof document !== 'undefined') { nat = document.createElement("igc-paginator"); } 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(IgrPaginator.prototype, "nativeElement", { get: function () { return this._implementation.nativeElement; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "i", { /** * @hidden */ get: function () { return this._implementation; } /** * @hidden */, enumerable: false, configurable: true }); IgrPaginator._createFromInternal = function (internal) { if (!internal) { return null; } if (!internal.$type) { return null; } var name = internal.$type.name; var externalName = "Igr" + name; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); }; IgrPaginator.prototype.onImplementationCreated = function () { }; IgrPaginator.prototype.componentDidMount = function () { var e_1, _a; this.mounted = true; 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_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; } } }; IgrPaginator.prototype.shouldComponentUpdate = function (nextProps, nextState) { var e_2, _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_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; } } return true; }; IgrPaginator.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 propChildren = this.props.children; var children = []; React.Children.forEach(propChildren, function (ch) { children.push(React.cloneElement(ch)); }); 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, className: this.props.className, style: style, children: children })); return div; }; IgrPaginator.prototype._getMainRef = function (ref) { this._elRef = ref; }; Object.defineProperty(IgrPaginator.prototype, "totalPages", { /** * Total pages calculated from totalRecords and perPage */ get: function () { return this.i.n; }, set: function (v) { this.i.n = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "page", { /** * Gets/Sets the current page of the paginator. * The default is 0. * ```typescript * let page = this.paginator.page; * ``` * @memberof IgxPaginatorComponent */ get: function () { return this.i.l; }, set: function (v) { this.i.l = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "perPage", { /** * Gets/Sets the number of visible items per page in the paginator. * The default is 15. * ```typescript * let itemsPerPage = this.paginator.perPage; * ``` * @memberof IgxPaginatorComponent */ get: function () { return this.i.m; }, set: function (v) { this.i.m = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "totalRecords", { /** * Sets the total records. * ```typescript * let totalRecords = this.paginator.totalRecords; * ``` * @memberof IgxPaginatorComponent */ get: function () { return this.i.o; }, set: function (v) { this.i.o = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "selectOptions", { /** * Sets custom options in the select of the paginator * ```typescript * let options = this.paginator.selectOptions; * ``` * @memberof IgxPaginatorComponent */ get: function () { return this.i.a; }, set: function (v) { if (v && !Array.isArray(v) && typeof (v) == "string") { var re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.a = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "overlaySettings", { get: function () { return this.i.d.nativeElement; }, set: function (v) { this.i.d = interfaceToInternal(v, function () { return new OverlaySettings(); }); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "resourceStrings", { /** * An accessor that sets the resource strings. * By default it uses EN resources. */ get: function () { return this.i.g.nativeElement; }, set: function (v) { this.i.g = interfaceToInternal(v, function () { return new PaginatorResourceStrings(); }); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "isLastPage", { /** * Returns if the current page is the last page. * ```typescript * const lastPage = this.paginator.isLastPage; * ``` */ get: function () { return this.i.k; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "isFirstPage", { /** * Returns if the current page is the first page. * ```typescript * const lastPage = this.paginator.isFirstPage; * ``` */ get: function () { return this.i.j; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "name", { get: function () { return this.i.r; }, set: function (v) { this.i.r = v; }, enumerable: false, configurable: true }); IgrPaginator.prototype.findByName = function (name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.overlaySettings && this.overlaySettings.name && this.overlaySettings.name == name) { return this.overlaySettings; } if (this.resourceStrings && this.resourceStrings.name && this.resourceStrings.name == name) { return this.resourceStrings; } return null; }; Object.defineProperty(IgrPaginator.prototype, "hasUserValues", { get: function () { return this._hasUserValues; }, enumerable: false, configurable: true }); IgrPaginator.prototype.__m = function (propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } }; IgrPaginator.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("Paginator"); 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._otherStyling) { this._otherStyling(container, component, parent); } this._inStyling = false; }; IgrPaginator.prototype.setNativeElement = function (element) { this.i.setNativeElement(element); }; /** * Goes to the next page of the `IgxPaginatorComponent`, if the paginator is not already at the last page. * ```typescript * this.paginator.nextPage(); * ``` * @memberof IgxPaginatorComponent */ IgrPaginator.prototype.nextPage = function () { this.i.s(); }; /** * Goes to the previous page of the `IgxPaginatorComponent`, if the paginator is not already at the first page. * ```typescript * this.paginator.previousPage(); * ``` * @memberof IgxPaginatorComponent */ IgrPaginator.prototype.previousPage = function () { this.i.y(); }; /** * Goes to the desired page index. * ```typescript * this.paginator.paginate(1); * ``` * val * @memberof IgxPaginatorComponent * @param * val */ IgrPaginator.prototype.paginate = function (val) { this.i.u(val); }; Object.defineProperty(IgrPaginator.prototype, "perPageChange", { get: function () { return this._perPageChange; }, set: function (ev) { var _this = this; if (this._perPageChange_wrapped !== null) { this.i.perPageChange = delegateRemove(this.i.perPageChange, this._perPageChange_wrapped); this._perPageChange_wrapped = null; this._perPageChange = null; } this._perPageChange = ev; this._perPageChange_wrapped = function (o, e) { var outerArgs = new IgrNumberEventArgs(); outerArgs._provideImplementation(e); if (_this.beforePerPageChange) { _this.beforePerPageChange(_this, outerArgs); } if (_this._perPageChange) { _this._perPageChange(_this, outerArgs); } }; this.i.perPageChange = delegateCombine(this.i.perPageChange, this._perPageChange_wrapped); if (this.i.perPageChangeChanged) { this.i.perPageChangeChanged(); } ; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "pageChange", { get: function () { return this._pageChange; }, set: function (ev) { var _this = this; if (this._pageChange_wrapped !== null) { this.i.pageChange = delegateRemove(this.i.pageChange, this._pageChange_wrapped); this._pageChange_wrapped = null; this._pageChange = null; } this._pageChange = ev; this._pageChange_wrapped = function (o, e) { var outerArgs = new IgrNumberEventArgs(); outerArgs._provideImplementation(e); if (_this.beforePageChange) { _this.beforePageChange(_this, outerArgs); } if (_this._pageChange) { _this._pageChange(_this, outerArgs); } }; this.i.pageChange = delegateCombine(this.i.pageChange, this._pageChange_wrapped); if (this.i.pageChangeChanged) { this.i.pageChangeChanged(); } ; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "paging", { get: function () { return this._paging; }, set: function (ev) { var _this = this; if (this._paging_wrapped !== null) { this.i.paging = delegateRemove(this.i.paging, this._paging_wrapped); this._paging_wrapped = null; this._paging = null; } this._paging = ev; this._paging_wrapped = function (o, e) { var outerArgs = new IgrPageCancellableEventArgs(); outerArgs._provideImplementation(e); if (_this.beforePaging) { _this.beforePaging(_this, outerArgs); } if (_this._paging) { _this._paging(_this, outerArgs); } }; this.i.paging = delegateCombine(this.i.paging, this._paging_wrapped); if (this.i.pagingChanged) { this.i.pagingChanged(); } ; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPaginator.prototype, "pagingDone", { get: function () { return this._pagingDone; }, set: function (ev) { var _this = this; if (this._pagingDone_wrapped !== null) { this.i.pagingDone = delegateRemove(this.i.pagingDone, this._pagingDone_wrapped); this._pagingDone_wrapped = null; this._pagingDone = null; } this._pagingDone = ev; this._pagingDone_wrapped = function (o, e) { var outerArgs = new IgrPageEventArgs(); outerArgs._provideImplementation(e); if (_this.beforePagingDone) { _this.beforePagingDone(_this, outerArgs); } if (_this._pagingDone) { _this._pagingDone(_this, outerArgs); } }; this.i.pagingDone = delegateCombine(this.i.pagingDone, this._pagingDone_wrapped); if (this.i.pagingDoneChanged) { this.i.pagingDoneChanged(); } ; }, enumerable: false, configurable: true }); return IgrPaginator; }(React.Component)); export { IgrPaginator };