UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

124 lines (123 loc) 4.37 kB
import * as React from 'react'; import { delegateCombine, delegateRemove } from "igniteui-react-core"; import { IgrGridStateInfoEventArgs } from "./igr-grid-state-info-event-args"; import { IgrGridStateBaseDirective } from "./igr-grid-state-base-directive"; import { GridState } from "./GridState"; import { isValidProp, interfaceToInternal } from "igniteui-react-core"; import { GridStateInfo } from "./GridStateInfo"; /** * State component allows saving and restoring the state of the grid features. * @igxParent IgxGridComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxPivotGridComponent, * */ export class IgrGridState extends IgrGridStateBaseDirective { createImplementation() { var _a, _b; let impl = new GridState(); let nat; if (typeof document !== 'undefined') { nat = document.createElement("igc-grid-state"); } 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; } /** * @hidden */ get i() { return this._implementation; } constructor(props) { super(props); this._stateParsed = null; this._stateParsed_wrapped = null; this._getMainRef = this._getMainRef.bind(this); } render() { const nativePropsName = Object.keys(this.props).filter(prop => !isValidProp(this, prop) && prop !== "originalRef" && prop !== "className"); const nativeProps = {}; nativePropsName.forEach(propName => { nativeProps[propName] = this.props[propName]; }); let propChildren = this.props.children; let children = []; React.Children.forEach(propChildren, (ch) => { children.push(React.cloneElement(ch)); }); this._portalManager.onRender(children); let style = {}; style.display = 'contents'; if (this.props.style) { style = this.props.style; } let div = React.createElement("div", Object.assign(Object.assign({}, nativeProps), { ref: this._getMainRef, style: style, children: children })); return div; } _getMainRef(ref) { this._elRef = ref; } applyState(state, features) { this.i.k((state == null ? null : interfaceToInternal(state, () => new GridStateInfo())), features); } applyStateFromString(state, features) { this.i.l(state, features); } getState(features) { let iv = this.i.h(features); let ret = null; if (iv && iv.externalObject) { ret = iv.externalObject; } else { if (iv) { ret = iv.nativeElement; delete ret.externalObject; } } return ret; } getStateAsString(features) { let iv = this.i.j(features); return (iv); } /** * Event emitted when set state is called with a string. * Returns the parsed state object so that it can be further modified before applying to the grid. */ get stateParsed() { return this._stateParsed; } set stateParsed(ev) { if (this._stateParsed_wrapped !== null) { this.i.stateParsed = delegateRemove(this.i.stateParsed, this._stateParsed_wrapped); this._stateParsed_wrapped = null; this._stateParsed = null; } this._stateParsed = ev; this._stateParsed_wrapped = (o, e) => { let outerArgs = new IgrGridStateInfoEventArgs(); outerArgs._provideImplementation(e); if (this.beforeStateParsed) { this.beforeStateParsed(this, outerArgs); } if (this._stateParsed) { this._stateParsed(this, outerArgs); } }; this.i.stateParsed = delegateCombine(this.i.stateParsed, this._stateParsed_wrapped); if (this.i.stateParsedChanged) { this.i.stateParsedChanged(); } ; } }