@taiga-ui/kit
Version:
Taiga UI Angular main components kit
96 lines (90 loc) • 5.42 kB
JavaScript
import { TuiCalendarRange } from '@taiga-ui/kit/components/calendar-range';
import * as i0 from '@angular/core';
import { InjectionToken, inject, computed, signal, Directive, Input } from '@angular/core';
import * as i3 from '@maskito/angular';
import { MaskitoDirective } from '@maskito/angular';
import { maskitoDateRangeOptionsGenerator } from '@maskito/kit';
import { TUI_IDENTITY_VALUE_TRANSFORMER, tuiAsControl, tuiValueTransformerFrom } from '@taiga-ui/cdk/classes';
import { RANGE_SEPARATOR_CHAR, DATE_RANGE_FILLER_LENGTH, TuiDayRange } from '@taiga-ui/cdk/date-time';
import { tuiProvideOptions, tuiDirectiveBinding, tuiProvide } from '@taiga-ui/cdk/utils/miscellaneous';
import * as i1 from '@taiga-ui/core/components/textfield';
import { TuiTextfieldComponent, TuiWithTextfield } from '@taiga-ui/core/components/textfield';
import * as i2 from '@taiga-ui/core/directives/dropdown';
import { TuiDropdownAuto } from '@taiga-ui/core/directives/dropdown';
import { TUI_ITEMS_HANDLERS } from '@taiga-ui/core/directives/items-handlers';
import { TUI_INPUT_DATE_OPTIONS_NEW, TUI_INPUT_DATE_DEFAULT_OPTIONS_NEW, TuiInputDateBase, TUI_DATE_ADAPTER } from '@taiga-ui/kit/components/input-date';
import { tuiMaskito } from '@taiga-ui/kit/utils';
const TUI_INPUT_DATE_RANGE_OPTIONS = new InjectionToken(ngDevMode ? 'TUI_INPUT_DATE_RANGE_OPTIONS' : '', {
factory: () => ({
...inject(TUI_INPUT_DATE_OPTIONS_NEW),
valueTransformer: TUI_IDENTITY_VALUE_TRANSFORMER,
}),
});
const tuiInputDateRangeOptionsProvider = (options) => tuiProvideOptions(TUI_INPUT_DATE_RANGE_OPTIONS, options, TUI_INPUT_DATE_DEFAULT_OPTIONS_NEW);
class TuiInputDateRangeDirective extends TuiInputDateBase {
constructor() {
super(...arguments);
this.identity = inject(TUI_ITEMS_HANDLERS).identityMatcher.set((a, b) => a.daySame(b));
this.rangeFiller = tuiDirectiveBinding(TuiTextfieldComponent, 'fillerSetter', computed((filler = this.filler()) => `${filler}${RANGE_SEPARATOR_CHAR}${filler}`), {});
this.mask = tuiMaskito(computed(() => maskitoDateRangeOptionsGenerator({
dateSeparator: this.format().separator,
mode: TUI_DATE_ADAPTER[this.format().mode],
min: this.min().toLocalNativeDate(),
max: this.max().toLocalNativeDate(),
minLength: this.minLength() || {},
maxLength: this.maxLength() || {},
})));
this.minLength = signal(null);
this.maxLength = signal(null);
}
set minLengthSetter(minLength) {
this.minLength.set(minLength);
}
set maxLengthSetter(maxLength) {
this.maxLength.set(maxLength);
}
processCalendar(calendar) {
super.processCalendar(calendar);
calendar.minLength = this.minLength();
calendar.maxLength = this.maxLength();
}
onValueChange(value) {
this.control?.control?.updateValueAndValidity({ emitEvent: false });
this.onChange(value.length === DATE_RANGE_FILLER_LENGTH
? TuiDayRange.normalizeParse(value, this.format().mode)
: null);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiInputDateRangeDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: TuiInputDateRangeDirective, isStandalone: true, selector: "input[tuiInputDateRange]", inputs: { minLengthSetter: ["minLength", "minLengthSetter"], maxLengthSetter: ["maxLength", "maxLengthSetter"] }, providers: [
// TODO: Add SelectOption after data-list in calendar-range is refactored
tuiAsControl(TuiInputDateRangeDirective),
tuiValueTransformerFrom(TUI_INPUT_DATE_RANGE_OPTIONS),
tuiProvide(TUI_INPUT_DATE_OPTIONS_NEW, TUI_INPUT_DATE_RANGE_OPTIONS),
], usesInheritance: true, hostDirectives: [{ directive: i1.TuiWithTextfield }, { directive: i2.TuiDropdownAuto }, { directive: i3.MaskitoDirective }], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiInputDateRangeDirective, decorators: [{
type: Directive,
args: [{
standalone: true,
selector: 'input[tuiInputDateRange]',
providers: [
// TODO: Add SelectOption after data-list in calendar-range is refactored
tuiAsControl(TuiInputDateRangeDirective),
tuiValueTransformerFrom(TUI_INPUT_DATE_RANGE_OPTIONS),
tuiProvide(TUI_INPUT_DATE_OPTIONS_NEW, TUI_INPUT_DATE_RANGE_OPTIONS),
],
hostDirectives: [TuiWithTextfield, TuiDropdownAuto, MaskitoDirective],
}]
}], propDecorators: { minLengthSetter: [{
type: Input,
args: ['minLength']
}], maxLengthSetter: [{
type: Input,
args: ['maxLength']
}] } });
const TuiInputDateRange = [TuiInputDateRangeDirective, TuiCalendarRange];
/**
* Generated bundle index. Do not edit.
*/
export { TUI_INPUT_DATE_RANGE_OPTIONS, TuiInputDateRange, TuiInputDateRangeDirective, tuiInputDateRangeOptionsProvider };
//# sourceMappingURL=taiga-ui-kit-components-input-date-range.mjs.map