UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

806 lines (800 loc) 26.5 kB
import * as React from 'react'; import { fromSize, toSize, ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core"; import { FontInfo } from "igniteui-react-core"; import { ReactRenderer } from "igniteui-react-core"; import { delegateCombine, delegateRemove } from "igniteui-react-core"; import { SyncableObservableCollection$1 } from "igniteui-react-core"; import { CheckboxList } from './CheckboxList'; import { IgrDataGrid } from "./igr-data-grid"; import { IgrCheckedChangedEventArgs } from "./igr-checked-changed-event-args"; import { IgrSelectAllCheckboxChangedEventArgs } from "./igr-select-all-checkbox-changed-event-args"; import { PrimaryKeyValue } from "./PrimaryKeyValue"; import { IgrGridSelectedKeysCollection } from "./igr-grid-selected-keys-collection"; import { GridSelectedKeysCollection as GridSelectedKeysCollection_internal } from "./GridSelectedKeysCollection"; import { CheckboxListIndexType_$type } from "./CheckboxListIndexType"; import { InputGroupDisplayType_$type } from "igniteui-react-inputs"; import { BaseControlTheme_$type } from "igniteui-react-core"; import { ControlDisplayDensity_$type } from "igniteui-react-core"; import { ScrollbarStyle_$type } from "igniteui-react-core"; import { IgrCheckboxListIndexTypeChangedEventArgs } from './igr-checkbox-list-index-type-changed-event-args'; import { IgrCheckboxListKeysClearedEventArgs } from './igr-checkbox-list-keys-cleared-event-args'; export class IgrCheckboxList extends React.Component { set height(value) { this._height = value; if (this._elRef) { this._elRef.style.height = value; this._checkboxList.notifySizeChanged(); } } get height() { return this._height; } set width(value) { this._width = value; if (this._elRef) { this._elRef.style.height = value; this._checkboxList.notifySizeChanged(); } } get width() { return this._width; } set dataSource(value) { this._dataSource = value; if (this._checkboxList != null) { this._checkboxList.itemsSource = this._dataSource; } } get dataSource() { return this._dataSource; } _getMainRef(ref) { this._elRef = ref; this.verifyReferences(); } _getGridRef(ref) { this._gridRef = ref; this.verifyReferences(); } _getSelectAllSection(ref) { this._selectAllSectionRef = ref; this.verifyReferences(); } _getFilterHr(ref) { this._filterHrRef = ref; this.verifyReferences(); } verifyReferences() { if (this._elRef != null && this._gridRef != null && this._filterHrRef != null && this._selectAllSectionRef != null) { this._renderer = new ReactRenderer(this._elRef, document, false, null); var selectAllSectionWrapper = this._renderer.getWrapper(this._selectAllSectionRef); this._checkboxList.provideContainer(this._renderer, this._gridRef.i, selectAllSectionWrapper); var filterHr = this._renderer.getWrapper(this._filterHrRef); filterHr.setStyleProperty("margin", "3px 0px"); filterHr.setStyleProperty("border-top", "1px solid #dde2eb"); filterHr.setStyleProperty("border-left", "0px"); filterHr.setStyleProperty("border-right", "0px"); filterHr.setStyleProperty("border-bottom", "0px"); this._checkboxList.provideHrElement(filterHr); } } render() { let children = []; //let filterContainerChildren: any[] = []; let filterContainer = React.createElement("div", { key: "filterContainer" //children: filterContainerChildren }); children.push(filterContainer); let filterHr = React.createElement("hr", { ref: this._getFilterHr, key: "filterHr" //children: filterContainerChildren }); children.push(filterHr); /*let filter = React.createElement("input", { ref: this._getFilterRef, type: "text", key: "checkboxListFilterInput" }); filterContainerChildren.push(filter);*/ let selectAllSection = React.createElement("div", { ref: this._getSelectAllSection, key: "selectAllSection" }); children.push(selectAllSection); let grid = React.createElement(IgrDataGrid, { ref: this._getGridRef, key: "checkboxListGrid", headerHeight: 0 }); children.push(grid); let div = React.createElement("div", { className: "ig-checkbox-list igr-checkbox-list", ref: this._getMainRef, children: children }); return div; } constructor(props) { super(props); this._dataSource = null; this._wrapper = null; this._implementation = null; this._keys = null; this.__p = null; this._hasUserValues = new Set(); this._stylingContainer = null; this._stylingParent = null; this._inStyling = false; this._selectedKeyAdded = null; this._selectedKeyAdded_wrapped = null; this._selectedKeyRemoved = null; this._selectedKeyRemoved_wrapped = null; this._checkedChanged = null; this._checkedChanged_wrapped = null; this._indexTypeChanged = null; this._indexTypeChanged_wrapped = null; this._keysCleared = null; this._keysCleared_wrapped = null; this._selectAllCheckboxChanged = null; this._selectAllCheckboxChanged_wrapped = null; if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._getMainRef = this._getMainRef.bind(this); this._getGridRef = this._getGridRef.bind(this); this._getSelectAllSection = this._getSelectAllSection.bind(this); this._getFilterHr = this._getFilterHr.bind(this); this._implementation = this.createImplementation(); var checkboxList = this.i; this._checkboxList = checkboxList; checkboxList.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() { if (this._checkboxList) this._checkboxList.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._checkboxList.notifySizeChanged(); this.initializeContent(); } initializeContent() { this.updateStyle(); this.i.notifySizeChanged(); } createImplementation() { return new CheckboxList(); } get i() { return this._implementation; } /** * Gets the collection responsible for selection in the CheckboxList. Selection is determined by two factors: * whether everything is selected or deselected and the values present in this collection. If everything is * selected then any items in this collection will be deselected. If everything is deselected then any items in * this collection will be selected. The CheckboxList defaults all items as deselected. This state can change * when you use the SelectAll and DeselectAll methods. */ get keys() { if (this._keys === null) { let coll = new IgrGridSelectedKeysCollection(); let innerColl = this.i.keys; if (!innerColl) { innerColl = new GridSelectedKeysCollection_internal(); } this._keys = coll._fromInner(innerColl); } return this._keys; } set keys(v) { if (this._keys !== null) { this._keys._setSyncTarget(null); this._keys = null; } let coll = new IgrGridSelectedKeysCollection(); this._keys = coll._fromOuter(v); let syncColl = new SyncableObservableCollection$1(PrimaryKeyValue.$type); let innerColl = this.i.keys; if (!innerColl) { innerColl = new GridSelectedKeysCollection_internal(); } syncColl._inner = innerColl; syncColl.clear(); this._keys._setSyncTarget(syncColl); } /** * Gets or sets the primary key to use for the CheckboxList. */ get primaryKey() { return this.i.primaryKey; } set primaryKey(v) { if (v && !Array.isArray(v) && typeof (v) == "string") { const re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.primaryKey = v; } /** * Gets or Sets the property name that contains the values. */ get dataMemberPath() { return this.i.dataMemberPath; } set dataMemberPath(v) { this.i.dataMemberPath = v; } /** * Gets or Sets the property name that contains the values. */ get selectedMemberPath() { return this.i.selectedMemberPath; } set selectedMemberPath(v) { this.i.selectedMemberPath = v; } /** * Gets or Sets the property name that contains the values. */ get filterPlaceholderText() { return this.i.bm; } set filterPlaceholderText(v) { this.i.bm = v; } /** * Gets or Sets the property name that contains the values. */ get searchInputType() { return this.i.x; } set searchInputType(v) { this.i.x = ensureEnum(InputGroupDisplayType_$type, v); } /** * Gets or Sets the property name that contains the values. */ get rowHeight() { return this.i.a3; } set rowHeight(v) { this.i.a3 = +v; } get actualRowHeight() { return this.i.a1; } /** * Gets or Sets the property name that contains the values. */ get cellTextStyle() { if (this.i.ai == null) { return null; } return this.i.ai.fontString; } set cellTextStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.ai = fi; } /** * Gets or Sets the property name that contains the values. */ get indexType() { return this.i.indexType; } set indexType(v) { this.i.indexType = ensureEnum(CheckboxListIndexType_$type, v); } /** * Gets or Sets the property name that contains the values. */ get baseTheme() { return this.i.baseTheme; } set baseTheme(v) { this.i.baseTheme = ensureEnum(BaseControlTheme_$type, v); } /** * Gets or Sets the property name that contains the values. */ get density() { return this.i.density; } set density(v) { this.i.density = ensureEnum(ControlDisplayDensity_$type, v); } /** * Gets or sets the search icon color. */ get searchIconColor() { return brushToString(this.i.searchIconColor); } set searchIconColor(v) { this.i.searchIconColor = stringToBrush(v); } /** * Gets or sets the search background color. */ get searchBackgroundColor() { return brushToString(this.i.ea); } set searchBackgroundColor(v) { this.i.ea = stringToBrush(v); } /** * Gets or sets the search text color. */ get searchTextColor() { return brushToString(this.i.searchTextColor); } set searchTextColor(v) { this.i.searchTextColor = stringToBrush(v); } /** * Gets or sets the search border color. */ get searchBorderColor() { return brushToString(this.i.eb); } set searchBorderColor(v) { this.i.eb = stringToBrush(v); } /** * Gets or sets the text style. */ get searchTextStyle() { if (this.i.aj == null) { return null; } return this.i.aj.fontString; } set searchTextStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.aj = fi; } /** * Gets or sets the checkbox tick color. */ get checkboxTickColor() { return brushToString(this.i.d2); } set checkboxTickColor(v) { this.i.d2 = stringToBrush(v); } /** * Gets or sets the checkbox background color when checked. */ get checkboxCheckedBackgroundColor() { return brushToString(this.i.d0); } set checkboxCheckedBackgroundColor(v) { this.i.d0 = stringToBrush(v); } /** * Gets or sets the checkbox background color when unchecked. */ get checkboxUncheckedBackgroundColor() { return brushToString(this.i.d3); } set checkboxUncheckedBackgroundColor(v) { this.i.d3 = stringToBrush(v); } /** * Gets or sets the checkbox border color when checked. */ get checkboxCheckedBorderColor() { return brushToString(this.i.d1); } set checkboxCheckedBorderColor(v) { this.i.d1 = stringToBrush(v); } /** * Gets or sets the checkbox border color when unchecked. */ get checkboxUncheckedBorderColor() { return brushToString(this.i.d4); } set checkboxUncheckedBorderColor(v) { this.i.d4 = stringToBrush(v); } /** * Gets or sets the style of scrollbar. */ get scrollbarStyle() { return this.i.aa; } set scrollbarStyle(v) { this.i.aa = ensureEnum(ScrollbarStyle_$type, v); } /** * Gets or sets the scrollbar background color. */ get scrollbarBackground() { return brushToString(this.i.d9); } set scrollbarBackground(v) { this.i.d9 = stringToBrush(v); } /** * Gets / sets the caption of the "Select All" checkbox. */ get selectAllCaption() { return this.i.b4; } set selectAllCaption(v) { this.i.b4 = v; } /** * Gets or sets the color to use for the "Select All" label. */ get selectAllCaptionTextColor() { return brushToString(this.i.ee); } set selectAllCaptionTextColor(v) { this.i.ee = stringToBrush(v); } /** * Gets or sets the color to use for the actual header selectAllCaption text. */ get actualSelectAllCaptionTextColor() { return brushToString(this.i.dy); } set actualSelectAllCaptionTextColor(v) { this.i.dy = stringToBrush(v); } /** * Gets / sets whether the "Select all" checkbox is visible. */ get showSelectAll() { return this.i.showSelectAll; } set showSelectAll(v) { this.i.showSelectAll = ensureBool(v); } /** * Gets or sets the color to use for the background of the component. */ get backgroundColor() { return brushToString(this.i.backgroundColor); } set backgroundColor(v) { this.i.backgroundColor = stringToBrush(v); } /** * Gets or sets the color to use when hovering over a grid row. */ get rowHoverBackgroundColor() { return brushToString(this.i.rowHoverBackgroundColor); } set rowHoverBackgroundColor(v) { this.i.rowHoverBackgroundColor = stringToBrush(v); } /** * Gets or sets the color to use for the text of the component. */ get textColor() { return brushToString(this.i.eg); } set textColor(v) { this.i.eg = stringToBrush(v); } /** * Gets or sets whether the filter input is visible. */ get showFilter() { return this.i.au; } set showFilter(v) { this.i.au = ensureBool(v); } /** * Gets or sets whether row hover highlighting is enabled. */ get isRowHoverEnabled() { return this.i.ar; } set isRowHoverEnabled(v) { this.i.ar = ensureBool(v); } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.keys != null && this.keys.findByName && this.keys.findByName(name)) { return this.keys.findByName(name); } 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("CheckboxList"); 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._otherStyling) { this._otherStyling(container, component, parent); } this._inStyling = false; } /** * selects all the items in the checkbox list. */ selectAll() { this.i.dd(); } /** * Deselects all the items in the checkbox list. */ deselectAll() { this.i.ci(); } notifySetItem(index, oldItem, newItem) { this.i.cs(index, oldItem, newItem); } /** * Manually notifies the checkboxlist's grid that the data it has bound to has been cleared and needs to be re-examined. * This should not be called if the data that the grid is bound to is already observable. */ notifyClearItems() { this.i.cp(); } notifyInsertItem(index, newItem) { this.i.cq(index, newItem); } notifyRemoveItem(index, oldItem) { this.i.cr(index, oldItem); } addKeyValue(value) { this.i.cd(value); } removeKeyValue(value) { this.i.db(value); } getDesiredSize(availableSize) { let iv = this.i.getDesiredSize(toSize(availableSize)); return fromSize(iv); } /** * Returns true if no items are selected / checked; otherwise false. */ isNothingSelected() { let iv = this.i.ap(); return (iv); } /** * Returns true if all of the items are selected / checked; otherwise false. */ isEverythingSelected() { let iv = this.i.ao(); return (iv); } /** * Called when an item is added. */ get selectedKeyAdded() { return this._selectedKeyAdded; } set selectedKeyAdded(ev) { if (this._selectedKeyAdded_wrapped !== null) { this.i.selectedKeyAdded = delegateRemove(this.i.selectedKeyAdded, this._selectedKeyAdded_wrapped); this._selectedKeyAdded_wrapped = null; this._selectedKeyAdded = null; } this._selectedKeyAdded = ev; this._selectedKeyAdded_wrapped = (o, e) => { let outerArgs = new IgrCheckedChangedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeSelectedKeyAdded) { this.beforeSelectedKeyAdded(this, outerArgs); } if (this._selectedKeyAdded) { this._selectedKeyAdded(this, outerArgs); } }; this.i.selectedKeyAdded = delegateCombine(this.i.selectedKeyAdded, this._selectedKeyAdded_wrapped); ; } /** * Called when an item is removed. */ get selectedKeyRemoved() { return this._selectedKeyRemoved; } set selectedKeyRemoved(ev) { if (this._selectedKeyRemoved_wrapped !== null) { this.i.selectedKeyRemoved = delegateRemove(this.i.selectedKeyRemoved, this._selectedKeyRemoved_wrapped); this._selectedKeyRemoved_wrapped = null; this._selectedKeyRemoved = null; } this._selectedKeyRemoved = ev; this._selectedKeyRemoved_wrapped = (o, e) => { let outerArgs = new IgrCheckedChangedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeSelectedKeyRemoved) { this.beforeSelectedKeyRemoved(this, outerArgs); } if (this._selectedKeyRemoved) { this._selectedKeyRemoved(this, outerArgs); } }; this.i.selectedKeyRemoved = delegateCombine(this.i.selectedKeyRemoved, this._selectedKeyRemoved_wrapped); ; } /** * Called when a checkbox is checked or unchecked. */ get checkedChanged() { return this._checkedChanged; } set checkedChanged(ev) { if (this._checkedChanged_wrapped !== null) { this.i.checkedChanged = delegateRemove(this.i.checkedChanged, this._checkedChanged_wrapped); this._checkedChanged_wrapped = null; this._checkedChanged = null; } this._checkedChanged = ev; this._checkedChanged_wrapped = (o, e) => { let outerArgs = new IgrCheckedChangedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeCheckedChanged) { this.beforeCheckedChanged(this, outerArgs); } if (this._checkedChanged) { this._checkedChanged(this, outerArgs); } }; this.i.checkedChanged = delegateCombine(this.i.checkedChanged, this._checkedChanged_wrapped); ; } get indexTypeChanged() { return this._indexTypeChanged; } set indexTypeChanged(ev) { if (this._indexTypeChanged_wrapped !== null) { this.i.indexTypeChanged = delegateRemove(this.i.indexTypeChanged, this._indexTypeChanged_wrapped); this._indexTypeChanged_wrapped = null; this._indexTypeChanged = null; } this._indexTypeChanged = ev; this._indexTypeChanged_wrapped = (o, e) => { let outerArgs = new IgrCheckboxListIndexTypeChangedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeIndexTypeChanged) { this.beforeIndexTypeChanged(this, outerArgs); } if (this._indexTypeChanged) { this._indexTypeChanged(this, outerArgs); } }; this.i.indexTypeChanged = delegateCombine(this.i.indexTypeChanged, this._indexTypeChanged_wrapped); ; } get keysCleared() { return this._keysCleared; } set keysCleared(ev) { if (this._keysCleared_wrapped !== null) { this.i.keysCleared = delegateRemove(this.i.keysCleared, this._keysCleared_wrapped); this._keysCleared_wrapped = null; this._keysCleared = null; } this._keysCleared = ev; this._keysCleared_wrapped = (o, e) => { let outerArgs = new IgrCheckboxListKeysClearedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeKeysCleared) { this.beforeKeysCleared(this, outerArgs); } if (this._keysCleared) { this._keysCleared(this, outerArgs); } }; this.i.keysCleared = delegateCombine(this.i.keysCleared, this._keysCleared_wrapped); ; } /** * Called when the SelectAll checkbox is checked or unchecked. */ get selectAllCheckboxChanged() { return this._selectAllCheckboxChanged; } set selectAllCheckboxChanged(ev) { if (this._selectAllCheckboxChanged_wrapped !== null) { this.i.selectAllCheckboxChanged = delegateRemove(this.i.selectAllCheckboxChanged, this._selectAllCheckboxChanged_wrapped); this._selectAllCheckboxChanged_wrapped = null; this._selectAllCheckboxChanged = null; } this._selectAllCheckboxChanged = ev; this._selectAllCheckboxChanged_wrapped = (o, e) => { let outerArgs = new IgrSelectAllCheckboxChangedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeSelectAllCheckboxChanged) { this.beforeSelectAllCheckboxChanged(this, outerArgs); } if (this._selectAllCheckboxChanged) { this._selectAllCheckboxChanged(this, outerArgs); } }; this.i.selectAllCheckboxChanged = delegateCombine(this.i.selectAllCheckboxChanged, this._selectAllCheckboxChanged_wrapped); ; } }