UNPKG

igniteui-webcomponents-inputs

Version:

Ignite UI Web Components inputs components.

680 lines (677 loc) 24.9 kB
import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, toSpinal, enumToString, getAllPropertyNames, fromSpinal } from "igniteui-webcomponents-core"; import { FontInfo } from "igniteui-webcomponents-core"; import { WebComponentRenderer } from "igniteui-webcomponents-core"; import { delegateCombine, delegateRemove } from "igniteui-webcomponents-core"; import { TypeRegistrar } from "igniteui-webcomponents-core"; import { RegisterElementHelper } from "igniteui-webcomponents-core"; import { XDatePicker } from './XDatePicker'; import { IgcSelectedValueChangedEventArgs } from "./igc-selected-value-changed-event-args"; import { IgcGotFocusEventArgs } from "./igc-got-focus-event-args"; import { IgcLostFocusEventArgs } from "./igc-lost-focus-event-args"; import { IgcInputChangeEventArgs } from "./igc-input-change-event-args"; import { IgcKeyEventArgs } from "igniteui-webcomponents-core"; import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core"; import { BaseControlTheme_$type } from "igniteui-webcomponents-core"; import { DateFormats_$type } from "./DateFormats"; import { DayOfWeek_$type } from "./DayOfWeek"; import { FirstWeek_$type } from "./FirstWeek"; import { IgcHTMLElement } from "igniteui-webcomponents-core"; export let IgcXDatePickerComponent = /*@__PURE__*/ (() => { class IgcXDatePickerComponent extends IgcHTMLElement { set height(value) { this._height = value; this.style.height = value; this.i.notifySizeChanged(); } get height() { return this._height; } set width(value) { this._width = value; this.style.width = value; this.i.notifySizeChanged(); } get width() { return this._width; } constructor() { super(); this._disconnected = false; this._settingAttributes = false; this._attached = false; this._queuedSetAttributes = []; this._updatingFromAttribute = false; 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._renderer = new WebComponentRenderer(this, document, true, null); this._implementation = this.createImplementation(); this._implementation.externalObject = this; this._container = this._renderer.createElement("div"); this._renderer.updateRoot(this._container); //this._renderer.rootWrapper.append(this._container); //this._container.setStyleProperty("width", "100%"); //this._container.setStyleProperty("height", "100%"); var datePicker = this.i; this._datePicker = datePicker; this._renderer.addSizeWatcher(() => { this._datePicker.notifySizeChanged(); }); } // supports angular themes or custom properties set in CSS updateStyle() { this._styling(this, this); } destroy() { this._datePicker.destroy(); } createImplementation() { return new XDatePicker(); } disconnectedCallback() { this._disconnected = true; this._datePicker.provideContainer(null); } connectedCallback() { if (this._disconnected) { this._disconnected = false; return; } this.classList.add("ig-x-date-picker"); this.classList.add("igc-x-date-picker"); var rootWrapper = this._renderer.rootWrapper; var rootElement = rootWrapper.getNativeElement(); this.appendChild(rootElement); this._attached = true; this.style.display = "block"; this.style.height = this._height; this.style.width = this._width; let inputContainer = this._renderer.createElement("div"); this._container.append(inputContainer); let popupContainer = this._renderer.createElement("div"); this._container.append(popupContainer); this._datePicker.provideContainer(this._renderer); this._datePicker.notifySizeChanged(); this._flushQueuedAttributes(); // supports themes or custom properties set in CSS this._styling(this, this); this.afterContentInit(); } afterContentInit() { this.i.notifySizeChanged(); } attributeSynced(name, value) { // an attribute was set by the component renderer. if (name === 'name') { this.i.setName(value); } } /** * @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 = "Igc" + name + "Component"; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); } _enqueueSetAttribute(attrName, attrValue) { this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue }); } _flushQueuedAttributes() { this._settingAttributes = true; for (let i = 0; i < this._queuedSetAttributes.length; i++) { this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue); } this._settingAttributes = false; this._queuedSetAttributes.length = 0; } _a(attrName, attrValue) { if (this._updatingFromAttribute) { return; } if (attrValue) { attrValue = attrValue.toString(); } this._settingAttributes = true; attrName = toSpinal(attrName); if (this._attached) { this.setAttribute(attrName, attrValue); } else { this._enqueueSetAttribute(attrName, attrValue); } this._settingAttributes = false; } static get observedAttributes() { if (IgcXDatePickerComponent._observedAttributesIgcXDatePickerComponent == null) { let names = getAllPropertyNames(IgcXDatePickerComponent); for (let i = 0; i < names.length; i++) { names[i] = toSpinal(names[i]); } IgcXDatePickerComponent._observedAttributesIgcXDatePickerComponent = names; } return IgcXDatePickerComponent._observedAttributesIgcXDatePickerComponent; } attributeChangedCallback(name, oldValue, newValue) { if (this._settingAttributes) { return; } let setName = fromSpinal(name); this._updatingFromAttribute = true; this[setName] = newValue; this._updatingFromAttribute = false; } static register() { if (!IgcXDatePickerComponent._isElementRegistered) { IgcXDatePickerComponent._isElementRegistered = true; RegisterElementHelper.registerElement(IgcXDatePickerComponent.htmlTagName, IgcXDatePickerComponent); } } /** * 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); this._a("labelTextColor", brushToString(this.i.dx)); } /** * 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; this._a("labelTextStyle", this.i.ac != null ? this.i.ac.fontString : ""); } /** * 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); this._a("density", enumToString(ControlDisplayDensity_$type, this.i.y)); } /** * 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); this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.w)); } /** * 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; this._a("textStyle", this.i.ad != null ? this.i.ad.fontString : ""); } /** * Gets or Sets the text color */ get textColor() { return brushToString(this.i.dy); } set textColor(v) { this.i.dy = stringToBrush(v); this._a("textColor", brushToString(this.i.dy)); } /** * Gets or Sets the text color */ get iconColor() { return brushToString(this.i.dw); } set iconColor(v) { this.i.dw = stringToBrush(v); this._a("iconColor", brushToString(this.i.dw)); } /** * 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); this._a("showClearButton", this.i.a0); } /** * 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); this._a("showTodayButton", this.i.a1); } /** * 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); this._a("allowTextInput", this.i.au); } /** * 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); this._a("openOnFocus", this.i.ay); } /** * 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); this._a("firstDayOfWeek", enumToString(DayOfWeek_$type, this.i.j)); } /** * 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); this._a("firstWeekOfYear", enumToString(FirstWeek_$type, this.i.l)); } /** * 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); this._a("showWeekNumbers", this.i.a2); } /** * 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); this._a("dateFormat", enumToString(DateFormats_$type, this.i.e)); } /** * 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); this._a("isDisabled", this.i.av); } /** * 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); this._a("isFixed", this.i.aw); } /** * 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); this._a("openAsChild", this.i.ax); } /** * 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); this._a("useTopLayer", this.i.a3); } 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("XDatePickerComponent"); 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 IgcSelectedValueChangedEventArgs(); 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 IgcGotFocusEventArgs(); 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 IgcLostFocusEventArgs(); 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 IgcKeyEventArgs(); 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 IgcInputChangeEventArgs(); 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 (e.propertyName == '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); } } IgcXDatePickerComponent._observedAttributesIgcXDatePickerComponent = null; IgcXDatePickerComponent.htmlTagName = "igc-x-date-picker"; IgcXDatePickerComponent._isElementRegistered = false; return IgcXDatePickerComponent; })();