UNPKG

@taiga-ui/kit

Version:
129 lines (124 loc) 5.85 kB
import { __decorate, __param } from 'tslib'; import { Optional, Self, Inject, ChangeDetectorRef, Input, ViewChild, Component, forwardRef, ChangeDetectionStrategy, NgModule } from '@angular/core'; import { NgControl } from '@angular/forms'; import { AbstractTuiNullableControl, TUI_FIRST_DAY, TUI_LAST_DAY, ALWAYS_FALSE_HANDLER, tuiDefaultProp, TUI_FOCUSABLE_ITEM_ACCESSOR, TuiPreventDefaultModule } from '@taiga-ui/cdk'; import { sizeBigger, TuiTextfieldSizeDirective, TUI_TEXTFIELD_SIZE, TuiPrimitiveTextfieldComponent, TuiHostedDropdownModule, TuiPrimitiveTextfieldModule, TuiSvgModule, TuiMonthPipeModule } from '@taiga-ui/core'; import { LEFT_ALIGNED_DROPDOWN_CONTROLLER_PROVIDER } from '@taiga-ui/kit/providers'; import { CommonModule } from '@angular/common'; import { TuiCalendarMonthModule } from '@taiga-ui/kit/components/calendar-month'; var TuiInputMonthComponent_1; // @dynamic let TuiInputMonthComponent = TuiInputMonthComponent_1 = class TuiInputMonthComponent extends AbstractTuiNullableControl { constructor(control, changeDetectorRef, textfieldSize) { super(control, changeDetectorRef); this.textfieldSize = textfieldSize; this.min = TUI_FIRST_DAY; this.max = TUI_LAST_DAY; this.disabledItemHandler = ALWAYS_FALSE_HANDLER; this.open = false; } get nativeFocusableElement() { return this.textfield ? this.textfield.nativeFocusableElement : null; } get focused() { return !!this.textfield && this.textfield.focused; } get calendarIcon() { return sizeBigger(this.textfieldSize.size) ? 'tuiIconCalendarLarge' : 'tuiIconCalendar'; } get canOpen() { return !this.computedDisabled && !this.readOnly; } onValueChange(value) { if (value === '') { this.updateValue(null); } } onMonthClick(month) { this.updateValue(month); this.close(); } onHovered(hovered) { this.updateHovered(hovered); } onFocused(focused) { this.updateFocused(focused); } onOpenChange(open) { this.open = open; } toggle() { this.open = !this.open; } setDisabledState() { super.setDisabledState(); this.close(); } close() { this.open = false; } }; TuiInputMonthComponent.ctorParameters = () => [ { type: NgControl, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NgControl,] }] }, { type: ChangeDetectorRef, decorators: [{ type: Inject, args: [ChangeDetectorRef,] }] }, { type: TuiTextfieldSizeDirective, decorators: [{ type: Inject, args: [TUI_TEXTFIELD_SIZE,] }] } ]; __decorate([ Input(), tuiDefaultProp() ], TuiInputMonthComponent.prototype, "min", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiInputMonthComponent.prototype, "max", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiInputMonthComponent.prototype, "disabledItemHandler", void 0); __decorate([ ViewChild(TuiPrimitiveTextfieldComponent) ], TuiInputMonthComponent.prototype, "textfield", void 0); TuiInputMonthComponent = TuiInputMonthComponent_1 = __decorate([ Component({ selector: 'tui-input-month', template: "<tui-hosted-dropdown\n class=\"hosted\"\n [canOpen]=\"canOpen\"\n [content]=\"dropdown\"\n [open]=\"open && canOpen\"\n (openChange)=\"onOpenChange($event)\"\n>\n <tui-primitive-textfield\n class=\"textfield\"\n [editable]=\"false\"\n [disabled]=\"disabled\"\n [nativeId]=\"nativeId\"\n [readOnly]=\"readOnly\"\n [iconContent]=\"calendarIcon\"\n [pseudoFocused]=\"pseudoFocused\"\n [pseudoHovered]=\"pseudoHovered\"\n [invalid]=\"computedInvalid\"\n [value]=\"value === null ? '' : (value | tuiMonth | async) + ' ' + value.formattedYear\"\n (valueChange)=\"onValueChange($event)\"\n (hoveredChange)=\"onHovered($event)\"\n (focusedChange)=\"onFocused($event)\"\n >\n <ng-content></ng-content>\n </tui-primitive-textfield>\n\n <ng-template #dropdown>\n <tui-calendar-month\n tuiPreventDefault=\"mousedown\"\n [disabledItemHandler]=\"disabledItemHandler\"\n [min]=\"min\"\n [max]=\"max\"\n [value]=\"value\"\n (monthClick)=\"onMonthClick($event)\"\n ></tui-calendar-month>\n </ng-template>\n</tui-hosted-dropdown>\n", providers: [ { provide: TUI_FOCUSABLE_ITEM_ACCESSOR, useExisting: forwardRef(() => TuiInputMonthComponent_1), }, LEFT_ALIGNED_DROPDOWN_CONTROLLER_PROVIDER, ], changeDetection: ChangeDetectionStrategy.OnPush, styles: [":host{display:block;border-radius:var(--tui-radius-m)}.hosted{display:block;border-radius:inherit}.textfield{border-radius:inherit}.icon{position:relative;cursor:pointer}"] }), __param(0, Optional()), __param(0, Self()), __param(0, Inject(NgControl)), __param(1, Inject(ChangeDetectorRef)), __param(2, Inject(TUI_TEXTFIELD_SIZE)) ], TuiInputMonthComponent); let TuiInputMonthModule = class TuiInputMonthModule { }; TuiInputMonthModule = __decorate([ NgModule({ imports: [ CommonModule, TuiCalendarMonthModule, TuiHostedDropdownModule, TuiPrimitiveTextfieldModule, TuiSvgModule, TuiPreventDefaultModule, TuiMonthPipeModule, ], declarations: [TuiInputMonthComponent], exports: [TuiInputMonthComponent], }) ], TuiInputMonthModule); /** * Generated bundle index. Do not edit. */ export { TuiInputMonthComponent, TuiInputMonthModule }; //# sourceMappingURL=taiga-ui-kit-components-input-month.js.map