igniteui-react-grids
Version: 
Ignite UI React grid components.
195 lines (193 loc) • 6.55 kB
JavaScript
import * as React from 'react';
import { delegateCombine, delegateRemove } from "igniteui-react-core";
import { IgrExporterEventArgs } from "./igr-exporter-event-args";
import { IgrVoidEventArgs } from "igniteui-react";
import { IgrBaseToolbarDirective } from "./igr-base-toolbar-directive";
import { GridToolbarExporter } from "./GridToolbarExporter";
import { isValidProp, ensureBool } from "igniteui-react-core";
/**
 * Provides a pre-configured exporter component for the grid.
 * @remarks
 * This component still needs the actual exporter service(s) provided in the DI chain
 * in order to export something.
 * @igxModule IgxGridToolbarModule
 * @igxParent IgxGridToolbarComponent
*/
export class IgrGridToolbarExporter extends IgrBaseToolbarDirective {
    createImplementation() {
        var _a, _b;
        let impl = new GridToolbarExporter();
        let nat;
        if (typeof document !== 'undefined') {
            nat = document.createElement("igc-grid-toolbar-exporter");
        }
        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._exportStarted = null;
        this._exportStarted_wrapped = null;
        this._exportEnded = null;
        this._exportEnded_wrapped = null;
        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;
    }
    /**
     * Show entry for CSV export.
    */
    get exportCSV() {
        return this.i.w;
    }
    set exportCSV(v) {
        this.i.w = ensureBool(v);
    }
    /**
     * Show entry for Excel export.
    */
    get exportExcel() {
        return this.i.x;
    }
    set exportExcel(v) {
        this.i.x = ensureBool(v);
    }
    /**
     * The name for the exported file.
    */
    get filename() {
        return this.i.y;
    }
    set filename(v) {
        this.i.y = v;
    }
    /**
     * Export the grid's data
     * type File type to export
    
    * @param type  * File type to export
    */
    exportGrid(type) {
        this.i.aa((type == null ? null : type));
    }
    /**
     * Emitted when starting an export operation. Re-emitted additionally
     * by the grid itself.
    */
    get exportStarted() {
        return this._exportStarted;
    }
    set exportStarted(ev) {
        if (this._exportStarted_wrapped !== null) {
            this.i.exportStarted = delegateRemove(this.i.exportStarted, this._exportStarted_wrapped);
            this._exportStarted_wrapped = null;
            this._exportStarted = null;
        }
        this._exportStarted = ev;
        this._exportStarted_wrapped = (o, e) => {
            let outerArgs = new IgrExporterEventArgs();
            outerArgs._provideImplementation(e);
            if (this.beforeExportStarted) {
                this.beforeExportStarted(this, outerArgs);
            }
            if (this._exportStarted) {
                this._exportStarted(this, outerArgs);
            }
        };
        this.i.exportStarted = delegateCombine(this.i.exportStarted, this._exportStarted_wrapped);
        if (this.i.exportStartedChanged) {
            this.i.exportStartedChanged();
        }
        ;
    }
    /**
     * Emitted on successful ending of an export operation.
    */
    get exportEnded() {
        return this._exportEnded;
    }
    set exportEnded(ev) {
        if (this._exportEnded_wrapped !== null) {
            this.i.exportEnded = delegateRemove(this.i.exportEnded, this._exportEnded_wrapped);
            this._exportEnded_wrapped = null;
            this._exportEnded = null;
        }
        this._exportEnded = ev;
        this._exportEnded_wrapped = (o, e) => {
            let outerArgs = new IgrVoidEventArgs();
            outerArgs._provideImplementation(e);
            if (this.beforeExportEnded) {
                this.beforeExportEnded(this, outerArgs);
            }
            if (this._exportEnded) {
                this._exportEnded(this, outerArgs);
            }
        };
        this.i.exportEnded = delegateCombine(this.i.exportEnded, this._exportEnded_wrapped);
        if (this.i.exportEndedChanged) {
            this.i.exportEndedChanged();
        }
        ;
    }
}