igniteui-react-inputs
Version:
Ignite UI React input components.
591 lines (588 loc) • 17.9 kB
JavaScript
import * as React from 'react';
import { 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 { XDatePicker } from './XDatePicker';
import { IgrSelectedValueChangedEventArgs } from "./igr-selected-value-changed-event-args";
import { IgrGotFocusEventArgs } from "./igr-got-focus-event-args";
import { IgrLostFocusEventArgs } from "./igr-lost-focus-event-args";
import { IgrInputChangeEventArgs } from "./igr-input-change-event-args";
import { IgrKeyEventArgs } from "igniteui-react-core";
import { ControlDisplayDensity_$type } from "igniteui-react-core";
import { BaseControlTheme_$type } from "igniteui-react-core";
import { DateFormats_$type } from "./DateFormats";
import { DayOfWeek_$type } from "./DayOfWeek";
import { FirstWeek_$type } from "./FirstWeek";
export class IgrXDatePicker extends React.Component {
set height(value) {
this._height = value;
if (this._elRef) {
this._elRef.style.height = value;
this._datePicker.notifySizeChanged();
}
}
get height() {
return this._height;
}
set width(value) {
this._width = value;
if (this._elRef) {
this._elRef.style.height = value;
this._datePicker.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._datePicker.provideContainer(this._renderer);
}
}
render() {
let children = [];
let inputContainer = React.createElement("div", {
key: "inputContainer"
});
children.push(inputContainer);
let popupContainer = React.createElement("div", {
key: "popupContainer"
});
children.push(popupContainer);
let div = React.createElement("div", {
className: "ig-x-date-picker igr-x-date-picker",
ref: this._getMainRef,
children: children
});
return div;
}
constructor(props) {
super(props);
this._implementation = null;
this.__p = null;
this._hasUserValues = new Set();
this._stylingContainer = null;
this._stylingParent = null;
this._inStyling = false;
this._selectedValueChanged = null;
this._selectedValueChanged_wrapped = null;
this._gotFocus = null;
this._gotFocus_wrapped = null;
this._lostFocus = null;
this._lostFocus_wrapped = null;
this._keyDown = null;
this._keyDown_wrapped = null;
this._changing = null;
this._changing_wrapped = null;
this._valueChange = null;
this._valueChange_wrapped = null;
if (this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this));
}
this._getMainRef = this._getMainRef.bind(this);
this._implementation = this.createImplementation();
var datePicker = this.i;
this._datePicker = datePicker;
datePicker.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._datePicker.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._datePicker.notifySizeChanged();
this.initializeContent();
}
initializeContent() {
this.updateStyle();
this.i.notifySizeChanged();
}
createImplementation() {
return new XDatePicker();
}
get i() {
return this._implementation;
}
/**
* Gets or Sets the property name that contains the values.
*/
get value() {
return this.i.value;
}
set value(v) {
this.i.value = v;
}
/**
* Gets or Sets the property name that contains the values.
*/
get today() {
return this.i.bb;
}
set today(v) {
this.i.bb = v;
}
/**
* Gets or Sets the property name that contains the label.
*/
get label() {
return this.i.b4;
}
set label(v) {
this.i.b4 = v;
}
/**
* Gets or sets the color to use for the text.
*/
get labelTextColor() {
return brushToString(this.i.dx);
}
set labelTextColor(v) {
this.i.dx = stringToBrush(v);
}
/**
* Gets or sets the font to use for the combobox.
*/
get labelTextStyle() {
if (this.i.ac == null) {
return null;
}
return this.i.ac.fontString;
}
set labelTextStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.ac = fi;
}
/**
* Gets or Sets the property name that contains the placeholder.
*/
get placeholder() {
return this.i.cc;
}
set placeholder(v) {
this.i.cc = v;
}
/**
* Gets or Sets the property name that contains the MinDate.
*/
get minDate() {
return this.i.ba;
}
set minDate(v) {
this.i.ba = v;
}
/**
* Gets or Sets the property name that contains the MaxDate.
*/
get maxDate() {
return this.i.a9;
}
set maxDate(v) {
this.i.a9 = v;
}
/**
* Gets or sets the display density to use for the date pcicker.
*/
get density() {
return this.i.y;
}
set density(v) {
this.i.y = ensureEnum(ControlDisplayDensity_$type, v);
}
/**
* Gets or sets the base built in theme to use for the date picker.
*/
get baseTheme() {
return this.i.w;
}
set baseTheme(v) {
this.i.w = ensureEnum(BaseControlTheme_$type, v);
}
/**
* Gets or sets the font to use for the combobox.
*/
get textStyle() {
if (this.i.ad == null) {
return null;
}
return this.i.ad.fontString;
}
set textStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.ad = fi;
}
/**
* Gets or Sets the text color
*/
get textColor() {
return brushToString(this.i.dy);
}
set textColor(v) {
this.i.dy = stringToBrush(v);
}
/**
* Gets or Sets the text color
*/
get iconColor() {
return brushToString(this.i.dw);
}
set iconColor(v) {
this.i.dw = stringToBrush(v);
}
/**
* Gets or sets the ShowClearButton property to detirmine if the clear button is shown
*/
get showClearButton() {
return this.i.a0;
}
set showClearButton(v) {
this.i.a0 = ensureBool(v);
}
/**
* Gets or sets the ShowTodayButton property to detirmine if the today button is shown
*/
get showTodayButton() {
return this.i.a1;
}
set showTodayButton(v) {
this.i.a1 = ensureBool(v);
}
/**
* Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed
*/
get allowTextInput() {
return this.i.au;
}
set allowTextInput(v) {
this.i.au = ensureBool(v);
}
/**
* Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed
*/
get openOnFocus() {
return this.i.ay;
}
set openOnFocus(v) {
this.i.ay = ensureBool(v);
}
/**
* Gets or sets the FirstDayOfWeek property to detirmine first day of the week
*/
get firstDayOfWeek() {
return this.i.j;
}
set firstDayOfWeek(v) {
this.i.j = ensureEnum(DayOfWeek_$type, v);
}
/**
* Gets or sets the FirstWeekOfYear property to detirmine first week of the year
*/
get firstWeekOfYear() {
return this.i.l;
}
set firstWeekOfYear(v) {
this.i.l = ensureEnum(FirstWeek_$type, v);
}
/**
* Gets or sets the ShowWeekNumbers property to detirmine if the week numbers are shown
*/
get showWeekNumbers() {
return this.i.a2;
}
set showWeekNumbers(v) {
this.i.a2 = ensureBool(v);
}
/**
* Gets or sets the date time format to use for this column. If FormatString is specificied this value is ignored.
*/
get dateFormat() {
return this.i.e;
}
set dateFormat(v) {
this.i.e = ensureEnum(DateFormats_$type, v);
}
/**
* Gets or sets the Format property to detirmine the format of the date in the input
*/
get formatString() {
return this.i.bz;
}
set formatString(v) {
this.i.bz = v;
}
get isDisabled() {
return this.i.av;
}
set isDisabled(v) {
this.i.av = ensureBool(v);
}
/**
* Indicates that the calendar dropdown will position itself relative to the window instead of the document.
*/
get isFixed() {
return this.i.aw;
}
set isFixed(v) {
this.i.aw = ensureBool(v);
}
/**
* Indicates that the dropdown should open as a child of the date picker.
*/
get openAsChild() {
return this.i.ax;
}
set openAsChild(v) {
this.i.ax = ensureBool(v);
}
/**
* Indicates that the dropdown will place itself into the browser top layer.
*/
get useTopLayer() {
return this.i.a3;
}
set useTopLayer(v) {
this.i.a3 = ensureBool(v);
}
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("XDatePicker");
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.dg();
}
/**
* Exports visual information about the current state of the grid.
*/
exportVisualModel() {
let iv = this.i.bg();
return (iv);
}
/**
* Returns a serialized copy of the exported visual model
*/
exportSerializedVisualModel() {
let iv = this.i.bw();
return (iv);
}
/**
* Called when date is selected.
*/
get selectedValueChanged() {
return this._selectedValueChanged;
}
set selectedValueChanged(ev) {
if (this._selectedValueChanged_wrapped !== null) {
this.i.selectedValueChanged = delegateRemove(this.i.selectedValueChanged, this._selectedValueChanged_wrapped);
this._selectedValueChanged_wrapped = null;
this._selectedValueChanged = null;
}
this._selectedValueChanged = ev;
this._selectedValueChanged_wrapped = (o, e) => {
let outerArgs = new IgrSelectedValueChangedEventArgs();
outerArgs._provideImplementation(e);
if (this.beforeSelectedValueChanged) {
this.beforeSelectedValueChanged(this, outerArgs);
}
if (this._selectedValueChanged) {
this._selectedValueChanged(this, outerArgs);
}
};
this.i.selectedValueChanged = delegateCombine(this.i.selectedValueChanged, this._selectedValueChanged_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 IgrGotFocusEventArgs();
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 IgrLostFocusEventArgs();
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);
;
}
get keyDown() {
return this._keyDown;
}
set keyDown(ev) {
if (this._keyDown_wrapped !== null) {
this.i.keyDown = delegateRemove(this.i.keyDown, this._keyDown_wrapped);
this._keyDown_wrapped = null;
this._keyDown = null;
}
this._keyDown = ev;
this._keyDown_wrapped = (o, e) => {
let outerArgs = new IgrKeyEventArgs();
outerArgs._provideImplementation(e);
if (this.beforeKeyDown) {
this.beforeKeyDown(this, outerArgs);
}
if (this._keyDown) {
this._keyDown(this, outerArgs);
}
};
this.i.keyDown = delegateCombine(this.i.keyDown, this._keyDown_wrapped);
;
}
get changing() {
return this._changing;
}
set changing(ev) {
if (this._changing_wrapped !== null) {
this.i.changing = delegateRemove(this.i.changing, this._changing_wrapped);
this._changing_wrapped = null;
this._changing = null;
}
this._changing = ev;
this._changing_wrapped = (o, e) => {
let outerArgs = new IgrInputChangeEventArgs();
outerArgs._provideImplementation(e);
if (this.beforeChanging) {
this.beforeChanging(this, outerArgs);
}
if (this._changing) {
this._changing(this, outerArgs);
}
};
this.i.changing = delegateCombine(this.i.changing, this._changing_wrapped);
;
}
get valueChange() {
return this._valueChange;
}
set valueChange(ev) {
if (this._valueChange_wrapped !== null) {
this.i.propertyChanged = delegateRemove(this.i.propertyChanged, this._valueChange_wrapped);
this._valueChange_wrapped = null;
this._valueChange = null;
}
this._valueChange = ev;
this._valueChange_wrapped = (o, e) => {
let ext = this.value;
if (this.beforeValueChange) {
this.beforeValueChange(this, ext);
}
if (this._valueChange) {
this._valueChange(this, ext);
}
};
this.i.propertyChanged = delegateCombine(this.i.propertyChanged, this._valueChange_wrapped);
}
}