igniteui-react-inputs
Version:
Ignite UI React input components.
460 lines (459 loc) • 14.5 kB
JavaScript
import * as React from 'react';
import { ColorEditor } from "./ColorEditor";
import { ensureEnum, brushToString, stringToBrush, ensureBool, 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";
import { IgrColorEditorLostFocusEventArgs } from "./igr-color-editor-lost-focus-event-args";
import { IgrColorEditorGotFocusEventArgs } from "./igr-color-editor-got-focus-event-args";
export class IgrColorEditor 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 igr-color-editor",
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;
this._gotFocus = null;
this._gotFocus_wrapped = null;
this._lostFocus = null;
this._lostFocus_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("colorEditorContent", 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 colorEditor = this.i;
this._colorEditor = colorEditor;
colorEditor.provideContainer(ren);
if (props) {
this.initializeProperties();
}
}
//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._colorEditor.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 ColorEditor();
}
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 color value of the editor.
*/
get value() {
return brushToString(this.i.value);
}
set value(v) {
this.i.value = stringToBrush(v);
}
/**
* Gets or Sets the property name that contains the label.
*/
get label() {
return this.i.az;
}
set label(v) {
this.i.az = v;
}
/**
* Gets or sets the color to use for the text.
*/
get labelTextColor() {
return brushToString(this.i.cn);
}
set labelTextColor(v) {
this.i.cn = stringToBrush(v);
}
/**
* Gets or sets the font to use for the input.
*/
get labelTextStyle() {
if (this.i.o == null) {
return null;
}
return this.i.o.fontString;
}
set labelTextStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.o = fi;
}
/**
* Gets or sets the display density to use for the date pcicker.
*/
get density() {
return this.i.k;
}
set density(v) {
this.i.k = ensureEnum(ControlDisplayDensity_$type, v);
}
/**
* Gets or sets the base built in theme to use for the date picker.
*/
get baseTheme() {
return this.i.i;
}
set baseTheme(v) {
this.i.i = ensureEnum(BaseControlTheme_$type, v);
}
/**
* Gets or sets the font to use for the combobox.
*/
get textStyle() {
if (this.i.p == null) {
return null;
}
return this.i.p.fontString;
}
set textStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.p = fi;
}
/**
* Gets or Sets the text color
*/
get textColor() {
return brushToString(this.i.co);
}
set textColor(v) {
this.i.co = stringToBrush(v);
}
/**
* Gets or Sets the text color
*/
get iconColor() {
return brushToString(this.i.cm);
}
set iconColor(v) {
this.i.cm = stringToBrush(v);
}
/**
* Gets or sets the ShowClearButton property to detirmine if the clear button is shown
*/
get showClearButton() {
return this.i.am;
}
set showClearButton(v) {
this.i.am = ensureBool(v);
}
/**
* Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed
*/
get allowTextInput() {
return this.i.ag;
}
set allowTextInput(v) {
this.i.ag = ensureBool(v);
}
/**
* Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed
*/
get openOnFocus() {
return this.i.ak;
}
set openOnFocus(v) {
this.i.ak = ensureBool(v);
}
get isDisabled() {
return this.i.ah;
}
set isDisabled(v) {
this.i.ah = ensureBool(v);
}
/**
* Indicates that the editor dropdown will position itself relative to the window instead of the document.
*/
get isFixed() {
return this.i.ai;
}
set isFixed(v) {
this.i.ai = ensureBool(v);
}
/**
* Indicates that the dropdown should open as a child of the color editor.
*/
get openAsChild() {
return this.i.aj;
}
set openAsChild(v) {
this.i.aj = ensureBool(v);
}
/**
* Indicates that the dropdown will place itself into the browser top layer.
*/
get useTopLayer() {
return this.i.an;
}
set useTopLayer(v) {
this.i.an = ensureBool(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("ColorEditor");
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;
}
select() {
this.i.b8();
}
/**
* Called when color 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 color 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);
;
}
get gotFocus() {
return this._gotFocus;
}
set gotFocus(ev) {
if (this._gotFocus_wrapped !== null) {
this.i.gotFocus = delegateRemove(this.i.gotFocus, this._gotFocus_wrapped);
this._gotFocus_wrapped = null;
this._gotFocus = null;
}
this._gotFocus = ev;
this._gotFocus_wrapped = (o, e) => {
let outerArgs = new IgrColorEditorGotFocusEventArgs();
outerArgs._provideImplementation(e);
if (this.beforeGotFocus) {
this.beforeGotFocus(this, outerArgs);
}
if (this._gotFocus) {
this._gotFocus(this, outerArgs);
}
};
this.i.gotFocus = delegateCombine(this.i.gotFocus, this._gotFocus_wrapped);
;
}
get lostFocus() {
return this._lostFocus;
}
set lostFocus(ev) {
if (this._lostFocus_wrapped !== null) {
this.i.lostFocus = delegateRemove(this.i.lostFocus, this._lostFocus_wrapped);
this._lostFocus_wrapped = null;
this._lostFocus = null;
}
this._lostFocus = ev;
this._lostFocus_wrapped = (o, e) => {
let outerArgs = new IgrColorEditorLostFocusEventArgs();
outerArgs._provideImplementation(e);
if (this.beforeLostFocus) {
this.beforeLostFocus(this, outerArgs);
}
if (this._lostFocus) {
this._lostFocus(this, outerArgs);
}
};
this.i.lostFocus = delegateCombine(this.i.lostFocus, this._lostFocus_wrapped);
;
}
}