igniteui-react-grids
Version:
Ignite UI React grid components.
120 lines (119 loc) • 4.12 kB
JavaScript
import * as React from 'react';
import { IgrGridToolbarBaseAction } from "./igr-grid-toolbar-base-action";
import { GridToolbarAdvancedFiltering } from "./GridToolbarAdvancedFiltering";
import { isValidProp, interfaceToInternal } from "igniteui-react-core";
import { OverlaySettings } from "./OverlaySettings";
/**
* Provides a pre-configured button to open the advanced filtering dialog of the grid.
* @igxModule IgxGridToolbarModule
* @igxParent IgxGridToolbarComponent
* @example
* ```html
* Custom text
* ```
*/
export class IgrGridToolbarAdvancedFiltering extends IgrGridToolbarBaseAction {
createImplementation() {
var _a, _b;
let impl = new GridToolbarAdvancedFiltering();
let nat;
if (typeof document !== 'undefined') {
nat = document.createElement("igc-grid-toolbar-advanced-filtering");
}
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;
}
componentWillUnmount() {
if (this.portaledContentChildren.length > 0) {
for (const item of this.portaledContentChildren) {
const nativeElem = item.ele;
if (item.ele.parentElement !== this.nativeElement) {
// put it back where it should be for react's portals to find.
this.nativeElement.appendChild(nativeElem);
}
}
}
}
onImplementationCreated() {
super.onImplementationCreated();
this._portalManager.getPortal(this._renderer.getWrapper(this._implementation.nativeElement), "ChildContent", (p) => {
for (let i = 0; i < p.portalContainer.getChildCount(); i++) {
this.portaledContentChildren.push(p.portalContainer.getChildAt(i));
}
}, true);
}
constructor(props) {
super(props);
this.portaledContentChildren = [];
this._getMainRef = this._getMainRef.bind(this);
}
componentDidMount() {
this.mounted = true;
super.componentDidMount();
}
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;
}
get overlaySettings() {
return this.i.b.nativeElement;
}
set overlaySettings(v) {
this.i.b = interfaceToInternal(v, () => new OverlaySettings());
}
get name() {
return this.i.a;
}
set name(v) {
this.i.a = v;
}
findByName(name) {
var baseResult = super.findByName(name);
if (baseResult) {
return baseResult;
}
if (this.overlaySettings && this.overlaySettings.name && this.overlaySettings.name == name) {
return this.overlaySettings;
}
return null;
}
setNativeElement(element) {
this.i.setNativeElement(element);
}
}