igniteui-react-inputs
Version:
Ignite UI React input components.
378 lines (377 loc) • 12.3 kB
JavaScript
import * as React from 'react';
import { ColorEditorPanel } from "./ColorEditorPanel";
import { ensureEnum, brushToString, stringToBrush, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core";
import { FontInfo } from "igniteui-react-core";
import { ReactRenderer, PortalManager } from "igniteui-react-core";
import { delegateCombine, delegateRemove } from "igniteui-react-core";
import { TypeRegistrar } from "igniteui-react-core";
import { ControlDisplayDensity_$type } from "igniteui-react-core";
import { BaseControlTheme_$type } from "igniteui-react-core";
import { IgrColorEditorPanelSelectedValueChangedEventArgs } from "./igr-color-editor-panel-selected-value-changed-event-args";
export class IgrColorEditorPanel extends React.Component {
_getMainRef(ref) {
this._elRef = ref;
}
render() {
let propChildren = this.props.children;
let children = [];
React.Children.forEach(propChildren, (ch) => {
children.push(React.cloneElement(ch));
});
this._portalManager.onRender(children);
let div = React.createElement("div", {
className: "ig-color-editor-panel igr-color-editor-panel",
ref: this._getMainRef,
children: children
});
return div;
}
requestRender() {
if (this._initialized) {
this.setState({});
}
}
constructor(props) {
super(props);
this._wrapper = null;
this.mounted = false;
this.__p = null;
this._hasUserValues = new Set();
this._stylingContainer = null;
this._stylingParent = null;
this._inStyling = false;
this._valueChanged = null;
this._valueChanged_wrapped = null;
this._valueChanging = null;
this._valueChanging_wrapped = null;
if (this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this));
}
this._implementation = this.createImplementation();
this._implementation.externalObject = this;
this._getMainRef = this._getMainRef.bind(this);
var container;
if (document) {
container = document.createElement("div");
}
var root;
root = container;
if (container != null) {
root = container;
}
this.requestRender = this.requestRender.bind(this);
this._portalManager = new PortalManager("colorEditorPanelContent", this.requestRender);
var ren = new ReactRenderer(root, document, true, {}, this._portalManager);
this._wrapper = ren;
this._container = this._wrapper.rootWrapper;
this._container.setStyleProperty("display", "block");
var colorEditorPanel = this.i;
this._colorEditorPanel = colorEditorPanel;
colorEditorPanel.provideContainer(ren);
if (props) {
this.initializeProperties();
}
}
//private _onDisplayChanged() {
// this._container.setStyleProperty("display", this.display);
//}
//private _onFlexDirectionChanged() {
// this._container.setStyleProperty("flex-direction", this.flexDirection);
//}
//private _onFlexGrowChanged() {
// this._container.setStyleProperty("flex-grow", this.flexGrow);
//}
//private _onAlignItemsChanged() {
// this._container.setStyleProperty("align-items", this.alignItems);
//}
//private _getLabelPortal(element: DomWrapper, portalCallback: (portal: DomPortal) => void): void {
// this._portalManager.getPortal(element, "TemplateContent", portalCallback);
//}
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._colorEditorPanel.destroy();
this._wrapper.destroy();
}
componentWillUnmount() {
}
componentDidMount() {
this._elRef.appendChild(this._container.getNativeElement());
this.initializeContent();
}
initializeContent() {
this._styling(this._container.getNativeElement(), this);
this.updateStyle();
}
createImplementation() {
return new ColorEditorPanel();
}
get nativeElement() {
return this._implementation.nativeElement;
}
/**
* @hidden
*/
get i() {
return this._implementation;
} /**
* @hidden
*/
static _createFromInternal(internal) {
if (!internal) {
return null;
}
if (!internal.$type) {
return null;
}
let name = internal.$type.name;
let externalName = "Igr" + name;
if (!TypeRegistrar.isRegistered(externalName)) {
return null;
}
return TypeRegistrar.create(externalName);
}
/**
* Gets or Sets the value for the color editor panel.
*/
get value() {
return brushToString(this.i.value);
}
set value(v) {
this.i.value = stringToBrush(v);
}
/**
* Gets or sets the display density to use for the ColorEditorPanel.
*/
get density() {
return this.i.h;
}
set density(v) {
this.i.h = ensureEnum(ControlDisplayDensity_$type, v);
}
/**
* Gets or sets the base built in theme to use for the ColorEditorPanel.
*/
get baseTheme() {
return this.i.f;
}
set baseTheme(v) {
this.i.f = ensureEnum(BaseControlTheme_$type, v);
}
/**
* Gets or Sets the selected color background color
*/
get backgroundColor() {
return brushToString(this.i.by);
}
set backgroundColor(v) {
this.i.by = stringToBrush(v);
}
/**
* Gets or Sets the selected color boreder color
*/
get selectedColorBorderColor() {
return brushToString(this.i.b1);
}
set selectedColorBorderColor(v) {
this.i.b1 = stringToBrush(v);
}
/**
* Gets or Sets the selected color border color
*/
get selectedFocusDateBackgroundColor() {
return brushToString(this.i.b2);
}
set selectedFocusDateBackgroundColor(v) {
this.i.b2 = stringToBrush(v);
}
/**
* Gets or Sets the focus color border color
*/
get focusColorBorderColor() {
return brushToString(this.i.bz);
}
set focusColorBorderColor(v) {
this.i.bz = stringToBrush(v);
}
/**
* Gets or Sets the focus date background color
*/
get hoverBackgroundColor() {
return brushToString(this.i.b0);
}
set hoverBackgroundColor(v) {
this.i.b0 = stringToBrush(v);
}
/**
* Gets or Sets the selected date text color
*/
get textColor() {
return brushToString(this.i.b3);
}
set textColor(v) {
this.i.b3 = stringToBrush(v);
}
/**
* Gets or sets the font to use for the combobox.
*/
get textStyle() {
if (this.i.j == null) {
return null;
}
return this.i.j.fontString;
}
set textStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.j = fi;
}
/**
* Gets or sets the scaling value used to affect the pixel density of the control.
* A higher scaling ratio will produce crisper visuals at the expense of memory. Lower values will cause the control
* to appear blurry.
*/
get pixelScalingRatio() {
return this.i.ae;
}
set pixelScalingRatio(v) {
this.i.ae = +v;
}
get actualPixelScalingRatio() {
return this.i.ab;
}
set actualPixelScalingRatio(v) {
this.i.ab = +v;
}
findByName(name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(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("ColorEditorPanel");
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;
}
/**
* Called when date is selected.
*/
get valueChanged() {
return this._valueChanged;
}
set valueChanged(ev) {
if (this._valueChanged_wrapped !== null) {
this.i.valueChanged = delegateRemove(this.i.valueChanged, this._valueChanged_wrapped);
this._valueChanged_wrapped = null;
this._valueChanged = null;
}
this._valueChanged = ev;
this._valueChanged_wrapped = (o, e) => {
let outerArgs = new IgrColorEditorPanelSelectedValueChangedEventArgs();
outerArgs._provideImplementation(e);
if (this.beforeValueChanged) {
this.beforeValueChanged(this, outerArgs);
}
if (this._valueChanged) {
this._valueChanged(this, outerArgs);
}
};
this.i.valueChanged = delegateCombine(this.i.valueChanged, this._valueChanged_wrapped);
;
}
/**
* Called when date is selected.
*/
get valueChanging() {
return this._valueChanging;
}
set valueChanging(ev) {
if (this._valueChanging_wrapped !== null) {
this.i.valueChanging = delegateRemove(this.i.valueChanging, this._valueChanging_wrapped);
this._valueChanging_wrapped = null;
this._valueChanging = null;
}
this._valueChanging = ev;
this._valueChanging_wrapped = (o, e) => {
let outerArgs = new IgrColorEditorPanelSelectedValueChangedEventArgs();
outerArgs._provideImplementation(e);
if (this.beforeValueChanging) {
this.beforeValueChanging(this, outerArgs);
}
if (this._valueChanging) {
this._valueChanging(this, outerArgs);
}
};
this.i.valueChanging = delegateCombine(this.i.valueChanging, this._valueChanging_wrapped);
;
}
}