UNPKG

igniteui-react-inputs

Version:

Ignite UI React input components.

428 lines (425 loc) 12.7 kB
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 { XCalendar } from './XCalendar'; import { IgrSelectedValueChangedEventArgs } from "./igr-selected-value-changed-event-args"; import { ControlDisplayDensity_$type } from "igniteui-react-core"; import { BaseControlTheme_$type } from "igniteui-react-core"; import { DayOfWeek_$type } from "./DayOfWeek"; import { FirstWeek_$type } from "./FirstWeek"; export class IgrXCalendar extends React.Component { set height(value) { this._height = value; if (this._elRef) { this._elRef.style.height = value; this._calendar.notifySizeChanged(); } } get height() { return this._height; } set width(value) { this._width = value; if (this._elRef) { this._elRef.style.height = value; this._calendar.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._calendar.provideContainer(this._renderer); } } render() { let children = []; let div = React.createElement("div", { className: "ig-x-calendar igr-x-calendar", 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._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 calendar = this.i; this._calendar = calendar; calendar.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._calendar.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._calendar.notifySizeChanged(); this.initializeContent(); } initializeContent() { this.updateStyle(); this.i.notifySizeChanged(); } createImplementation() { return new XCalendar(); } get i() { return this._implementation; } /** * Gets or Sets the value for the calendar. */ 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.av; } set today(v) { this.i.av = v; } /** * Gets or Sets the property name that contains the MinDate. */ get minDate() { return this.i.au; } set minDate(v) { this.i.au = v; } /** * Gets or Sets the property name that contains the MaxDate. */ get maxDate() { return this.i.at; } set maxDate(v) { this.i.at = v; } /** * Gets or sets the display density to use for the calendar. */ get density() { return this.i.t; } set density(v) { this.i.t = ensureEnum(ControlDisplayDensity_$type, v); } /** * Gets or sets the base built in theme to use for the calendar. */ get baseTheme() { return this.i.r; } set baseTheme(v) { this.i.r = ensureEnum(BaseControlTheme_$type, v); } /** * Gets or Sets the selected date background color */ get backgroundColor() { return brushToString(this.i.dg); } set backgroundColor(v) { this.i.dg = stringToBrush(v); } /** * Gets or Sets the selected date background color */ get selectedDateBackgroundColor() { return brushToString(this.i.dm); } set selectedDateBackgroundColor(v) { this.i.dm = stringToBrush(v); } /** * Gets or Sets the selected date background color */ get selectedFocusDateBackgroundColor() { return brushToString(this.i.dp); } set selectedFocusDateBackgroundColor(v) { this.i.dp = stringToBrush(v); } /** * Gets or Sets the focus date background color */ get focusDateBackgroundColor() { return brushToString(this.i.dj); } set focusDateBackgroundColor(v) { this.i.dj = stringToBrush(v); } /** * Gets or Sets the focus date background color */ get hoverBackgroundColor() { return brushToString(this.i.dl); } set hoverBackgroundColor(v) { this.i.dl = stringToBrush(v); } /** * Gets or Sets the selected date text color */ get textColor() { return brushToString(this.i.dq); } set textColor(v) { this.i.dq = stringToBrush(v); } /** * Gets or Sets the selected date text color */ get selectedDateTextColor() { return brushToString(this.i.dn); } set selectedDateTextColor(v) { this.i.dn = stringToBrush(v); } /** * Gets or Sets the focus date text color */ get focusDateTextColor() { return brushToString(this.i.dk); } set focusDateTextColor(v) { this.i.dk = stringToBrush(v); } /** * Gets or Sets the current date text color */ get currentDateTextColor() { return brushToString(this.i.di); } set currentDateTextColor(v) { this.i.di = stringToBrush(v); } /** * Gets or Sets the current date text color */ get currentDateBorderColor() { return brushToString(this.i.dh); } set currentDateBorderColor(v) { this.i.dh = stringToBrush(v); } /** * Gets or sets the ShowTodayButton property to detirmine if the today button is shown */ get showTodayButton() { return this.i.ae; } set showTodayButton(v) { this.i.ae = ensureBool(v); } /** * Gets or sets the font to use for the combobox. */ get textStyle() { if (this.i.v == null) { return null; } return this.i.v.fontString; } set textStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.v = fi; } /** * Gets or sets the FirstDayOfWeek property to detirmine first day of the week */ get firstDayOfWeek() { return this.i.l; } set firstDayOfWeek(v) { this.i.l = ensureEnum(DayOfWeek_$type, v); } /** * Gets or sets the FirstWeekOfYear property to detirmine first week of the year */ get firstWeekOfYear() { return this.i.o; } set firstWeekOfYear(v) { this.i.o = ensureEnum(FirstWeek_$type, v); } /** * Gets or sets the ShowWeekNumbers property to detirmine if the week numbers are shown */ get showWeekNumbers() { return this.i.af; } set showWeekNumbers(v) { this.i.af = 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("XCalendar"); 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; } /** * Exports visual information about the current state of the grid. */ exportVisualModel() { let iv = this.i.bj(); return (iv); } /** * Returns a serialized copy of the exported visual model */ exportSerializedVisualModel() { let iv = this.i.bs(); 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 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); } }