UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

294 lines (293 loc) 9.31 kB
import * as React from 'react'; import { ensureEnum, brushToString, stringToBrush, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core"; import { FontInfo } from "igniteui-react-core"; import { ReactRenderer } from "igniteui-react-core"; import { ColumnChooser } from './ColumnChooser'; import { IgrCheckboxList } from "./igr-checkbox-list"; import { IgrDataGrid } from "./igr-data-grid"; import { BaseControlTheme_$type } from "igniteui-react-core"; import { ControlDisplayDensity_$type } from "igniteui-react-core"; export class IgrColumnChooser extends React.Component { set height(value) { this._height = value; if (this._elRef) { this._elRef.style.height = value; this._columnChooser.notifySizeChanged(); } } get height() { return this._height; } set width(value) { this._width = value; if (this._elRef) { this._elRef.style.height = value; this._columnChooser.notifySizeChanged(); } } get width() { return this._width; } _getMainRef(ref) { this._elRef = ref; if (this._elRef != null && this._checkboxListRef != null) { this._renderer = new ReactRenderer(this._elRef, document, false, null); this._columnChooser.provideContainer(this._renderer, this._checkboxListRef.i); } } _getCheckboxListRef(ref) { this._checkboxListRef = ref; if (this._elRef != null && this._checkboxListRef != null) { this._renderer = new ReactRenderer(this._elRef, document, false, null); this._columnChooser.provideContainer(this._renderer, this._checkboxListRef.i); } } render() { let children = []; let title = React.createElement("span", { key: "titleSpan" }); children.push(title); let checkboxList = React.createElement(IgrCheckboxList, { ref: this._getCheckboxListRef, key: "checkboxList" }); children.push(checkboxList); let div = React.createElement("div", { className: "ig-column-chooser igr-column-chooser", ref: this._getMainRef, children: children }); return div; } constructor(props) { super(props); this._wrapper = null; this._implementation = null; this.__p = null; this._hasUserValues = new Set(); this._stylingContainer = null; this._stylingParent = null; this._inStyling = false; if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._getMainRef = this._getMainRef.bind(this); this._getCheckboxListRef = this._getCheckboxListRef.bind(this); /*this._getShowAllRef = this._getShowAllRef.bind(this); this._getHideAllRef = this._getHideAllRef.bind(this);*/ this._implementation = this.createImplementation(); var columnChooser = this.i; this._columnChooser = columnChooser; columnChooser.notifySizeChanged(); if (props) { this.initializeProperties(); } } shouldComponentUpdate(nextProps, nextState) { const mod = getModifiedProps(this.props, nextProps); for (const p of Object.keys(mod)) { if (isValidProp(this, p)) { this[p] = mod[p]; } } return true; } initializeProperties() { for (const p of Object.keys(this.props)) { if (isValidProp(this, p)) { this[p] = this.props[p]; } } } // supports angular themes or custom properties set in CSS updateStyle() { this._styling(this._elRef, this); } destroy() { this._columnChooser.destroy(); if (this._renderer) { this._renderer.destroy(); } } componentWillUnmount() { } componentDidMount() { this._elRef.style.width = this._width ? this._width : ""; this._elRef.style.height = this._height ? this._height : ""; this._columnChooser.notifySizeChanged(); this.initializeContent(); } initializeContent() { this.updateStyle(); this.i.notifySizeChanged(); } createImplementation() { return new ColumnChooser(); } get i() { return this._implementation; } /** * Gets or Sets the property name that contains the values. */ get targetGrid() { const r = this.i.c; if (r == null) { return null; } if (!r.externalObject) { let e = new IgrDataGrid({}); if (r.$type) { e._implementation = r; } else { if (e.i.setNativeElement) { e.i.setNativeElement(r); } } r.externalObject = e; } return r.externalObject; } set targetGrid(v) { if (v != null && this._stylingContainer && v._styling) v._styling(this._stylingContainer, this, this); v == null ? this.i.c = null : this.i.c = v.i; } /** * Gets or Sets the property name that contains the values. */ get title() { return this.i.v; } set title(v) { this.i.v = v; } /** * Gets or Sets the property name that contains the values. */ get titleStyle() { if (this.i.j == null) { return null; } return this.i.j.fontString; } set titleStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.j = fi; } /** * Gets or Sets the property name that contains the values. */ get titleColor() { return brushToString(this.i.ar); } set titleColor(v) { this.i.ar = stringToBrush(v); } /** * Gets or Sets the property name that contains the values. */ get filterPlaceholderText() { return this.i.s; } set filterPlaceholderText(v) { this.i.s = v; } /** * Gets or Sets the property name that contains the values. */ get baseTheme() { return this.i.f; } set baseTheme(v) { this.i.f = ensureEnum(BaseControlTheme_$type, v); } /** * Gets or Sets the property name that contains the values. */ get density() { return this.i.h; } set density(v) { this.i.h = ensureEnum(ControlDisplayDensity_$type, v); } /** * Gets or Sets the property name that contains the values. */ get backgroundColor() { return brushToString(this.i.aq); } set backgroundColor(v) { this.i.aq = stringToBrush(v); } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.targetGrid && this.targetGrid.name && this.targetGrid.name == name) { return this.targetGrid; } return null; } get hasUserValues() { return this._hasUserValues; } __m(propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } } _styling(container, component, parent) { if (this._inStyling) { return; } this._inStyling = true; this._stylingContainer = container; this._stylingParent = component; let genericPrefix = ""; let typeName = this.i.$type.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } genericPrefix = toSpinal("ColumnChooser"); let additionalPrefixes = []; let prefix = toSpinal(typeName); additionalPrefixes.push(prefix + "-"); let 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); } let basePrefix = toSpinal(typeName); additionalPrefixes.push(basePrefix + "-"); b = b.baseType; } if (parent) { let parentTypeName = parent.i.$type.name; if (parentTypeName.indexOf("Xam") === 0) { parentTypeName = parentTypeName.substring(3); } let parentPrefix = toSpinal(parentTypeName); additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-"); additionalPrefixes.push(parentPrefix + "-" + prefix + "-"); } initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes); if (this.targetGrid && this.targetGrid._styling) { this.targetGrid._styling(container, component, this); } if (this._otherStyling) { this._otherStyling(container, component, parent); } this._inStyling = false; } }