@taiga-ui/kit
Version:
Taiga UI Angular main components kit
97 lines (91 loc) • 5.7 kB
JavaScript
import { TuiLabel } from '@taiga-ui/core/components/label';
import { TuiTextfieldComponent, TuiTextfieldOptionsDirective } from '@taiga-ui/core/components/textfield';
import * as i2 from '@taiga-ui/core/portals/dropdown';
import { TuiDropdownAuto, TuiDropdownContent } from '@taiga-ui/core/portals/dropdown';
import { TuiCalendarRange } from '@taiga-ui/kit/components/calendar-range';
import * as i0 from '@angular/core';
import { InjectionToken, inject, input, computed, Directive } 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 { TUI_LAST_DAY, TuiDay, TUI_FIRST_DAY, RANGE_SEPARATOR_CHAR, DATE_RANGE_FILLER_LENGTH, TuiDayRange } from '@taiga-ui/cdk/date-time';
import { tuiProvideOptions, tuiProvide } from '@taiga-ui/cdk/utils/di';
import { tuiSetSignal } from '@taiga-ui/cdk/utils/miscellaneous';
import * as i1 from '@taiga-ui/core/components/input';
import { TuiWithInput } from '@taiga-ui/core/components/input';
import { TUI_INPUT_DATE_OPTIONS, TUI_INPUT_DATE_DEFAULT_OPTIONS, TuiInputDateBase, tuiWithDateFiller } 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),
valueTransformer: TUI_IDENTITY_VALUE_TRANSFORMER,
}),
});
const tuiInputDateRangeOptionsProvider = (options) => tuiProvideOptions(TUI_INPUT_DATE_RANGE_OPTIONS, options, TUI_INPUT_DATE_DEFAULT_OPTIONS);
class TuiInputDateRangeDirective extends TuiInputDateBase {
constructor() {
super(...arguments);
this.max = input(this.options.max, {
transform: (max) => max instanceof TuiDay ? max : TUI_LAST_DAY,
});
this.min = input(this.options.min, {
transform: (min) => min instanceof TuiDay ? min : TUI_FIRST_DAY,
});
this.filler = tuiWithDateFiller((filler) => `${filler}${RANGE_SEPARATOR_CHAR}${filler}`);
this.mask = tuiMaskito(computed(() => maskitoDateRangeOptionsGenerator({
dateSeparator: this.format().separator,
mode: this.format().mode,
min: this.min().toLocalNativeDate(),
max: this.max().toLocalNativeDate(),
minLength: this.minLength() || {},
maxLength: this.maxLength() || {},
})));
this.minLength = input(null);
this.maxLength = input(null);
}
processCalendar(calendar) {
super.processCalendar(calendar);
tuiSetSignal(calendar.minLength, this.minLength());
tuiSetSignal(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: "19.2.21", ngImport: i0, type: TuiInputDateRangeDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.21", type: TuiInputDateRangeDirective, isStandalone: true, selector: "input[tuiInputDateRange]", inputs: { max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, minLength: { classPropertyName: "minLength", publicName: "minLength", isSignal: true, isRequired: false, transformFunction: null }, maxLength: { classPropertyName: "maxLength", publicName: "maxLength", isSignal: true, isRequired: false, transformFunction: null } }, 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, TUI_INPUT_DATE_RANGE_OPTIONS),
], usesInheritance: true, hostDirectives: [{ directive: i1.TuiWithInput }, { directive: i2.TuiDropdownAuto }, { directive: i3.MaskitoDirective }], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: TuiInputDateRangeDirective, decorators: [{
type: Directive,
args: [{
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, TUI_INPUT_DATE_RANGE_OPTIONS),
],
hostDirectives: [TuiWithInput, TuiDropdownAuto, MaskitoDirective],
}]
}] });
const TuiInputDateRange = [
TuiInputDateRangeDirective,
TuiCalendarRange,
TuiLabel,
TuiTextfieldComponent,
TuiTextfieldOptionsDirective,
TuiDropdownContent,
];
/**
* 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