UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

321 lines (318 loc) 9.68 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 { ColumnGrouping } from './ColumnGrouping'; import { IgrDataGrid } from "./igr-data-grid"; import { BaseControlTheme_$type } from "igniteui-react-core"; import { ControlDisplayDensity_$type } from "igniteui-react-core"; export class IgrColumnGrouping extends React.Component { set height(value) { this._height = value; if (this._elRef) { this._elRef.style.height = value; this._columnGrouping.notifySizeChanged(); } } get height() { return this._height; } set width(value) { this._width = value; if (this._elRef) { this._elRef.style.height = value; this._columnGrouping.notifySizeChanged(); } } get width() { return this._width; } _getMainRef(ref) { this._elRef = ref; if (this._elRef != null) { this._renderer = new ReactRenderer(this._elRef, document, false, null); this._columnGrouping.provideContainer(this._renderer); } } render() { let children = []; let groupAreaContainer = React.createElement("div", { key: "groupAreaContainer" }); children.push(groupAreaContainer); let div = React.createElement("div", { className: "ig-column-grouping igr-column-grouping", 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._implementation = this.createImplementation(); var columnGrouping = this.i; this._columnGrouping = columnGrouping; columnGrouping.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._columnGrouping.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._columnGrouping.notifySizeChanged(); this.initializeContent(); } initializeContent() { this.updateStyle(); this.i.notifySizeChanged(); } createImplementation() { return new ColumnGrouping(); } get i() { return this._implementation; } /** * Gets or Sets the property name that contains the values. */ get targetGrid() { const r = this.i.targetGrid; 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.targetGrid = null : this.i.targetGrid = v.i; } /** * Gets or Sets the property name that contains the values. */ get baseTheme() { return this.i.g; } set baseTheme(v) { this.i.g = ensureEnum(BaseControlTheme_$type, v); } /** * Gets or Sets the property name that contains the values. */ get density() { return this.i.i; } set density(v) { this.i.i = ensureEnum(ControlDisplayDensity_$type, v); } /** * Gets or Sets the property name that contains the values. */ get title() { return this.i.al; } set title(v) { this.i.al = v; } /** * Gets or Sets the property name that contains the values. */ get titleColor() { return brushToString(this.i.bm); } set titleColor(v) { this.i.bm = stringToBrush(v); } /** * Gets or Sets the property name that contains the values. */ get textStyle() { if (this.i.k == null) { return null; } return this.i.k.fontString; } set textStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.k = fi; } /** * Gets or Sets the property name that contains the values. */ get textColor() { return brushToString(this.i.bl); } set textColor(v) { this.i.bl = stringToBrush(v); } /** * Gets or Sets the property name that contains the values. */ get iconColor() { return brushToString(this.i.bi); } set iconColor(v) { this.i.bi = stringToBrush(v); } /** * Gets or sets the background color of the column items in the group area. */ get itemBackgroundColor() { return brushToString(this.i.bj); } set itemBackgroundColor(v) { this.i.bj = stringToBrush(v); } /** * Gets or sets the background color of the column items when hovered by the mouse. */ get itemHoverBackgroundColor() { return brushToString(this.i.bk); } set itemHoverBackgroundColor(v) { this.i.bk = stringToBrush(v); } /** * Gets or sets the background of the group by area. */ get backgroundColor() { return brushToString(this.i.bh); } set backgroundColor(v) { this.i.bh = 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("ColumnGrouping"); 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; } /** * Exports visual information about the current state of the grid. */ exportVisualModel() { let iv = this.i.exportVisualModel(); return (iv); } /** * Returns a serialized copy of the exported visual model */ exportSerializedVisualModel() { let iv = this.i.exportSerializedVisualModel(); return (iv); } }