Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | 1x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 51x 38x 38x 38x 51x 51x 2x 51x 51x 2x 38x 38x 38x 38x 38x 38x 11x 11x 63x 63x 4x 59x 59x 7x 6x 4x 2x | /** * Copyright (c) Siemens 2016 - 2025 * SPDX-License-Identifier: MIT */ import { A11yModule, ConfigurableFocusTrap, ConfigurableFocusTrapFactory, FocusMonitor } from '@angular/cdk/a11y'; import { booleanAttribute, ChangeDetectionStrategy, Component, computed, ElementRef, inject, input, model, OnChanges, OnDestroy, OnInit, output, signal, SimpleChanges, viewChild, DOCUMENT } from '@angular/core'; import { Cell } from './components/si-calendar-body.component'; import { isValid, nextMonth, previousMonth } from './date-time-helper'; import { SiDatepickerComponent } from './si-datepicker.component'; import { DatepickerConfig, DateRange } from './si-datepicker.model'; @Component({ selector: 'si-datepicker-overlay', imports: [SiDatepickerComponent, A11yModule], template: ` <si-datepicker #datepicker tabindex="-1" [initialFocus]="initialFocus()" [config]="firstDatepickerConfig()" [class.first-datepicker]="isTwoMonthDateRange() && !isMobile()" [class.first-datepicker-mobile]="isTwoMonthDateRange() && isMobile()" [date]="date()" [dateRange]="dateRange()" [dateRangeRole]="isTwoMonthDateRange() ? 'START' : undefined" [time12h]="time12h()" [timepickerLabel]="firstDatepickerConfig().startTimeLabel" [maxMonth]="maxMonth()" [rangeType]="rangeType()" [(activeHover)]="activeHover" (dateChange)="date.set($event)" (dateRangeChange)="dateRange.set($event)" (disabledTimeChange)="disableTime = $event; disabledTimeChange.emit($event)" (focusedDateChange)="firstDatepickerFocusDateChange($event)" (rangeTypeChange)="rangeType.set($event)" /> @if (isTwoMonthDateRange()) { <si-datepicker #datepickerTwo class="mh-100 overflow-auto" tabindex="-1" dateRangeRole="END" [class.second-datepicker]="!isMobile()" [class.second-datepicker-mobile]="isMobile()" [hideTimeToggle]="true" [initialFocus]="initialFocus()" [config]="secondDatepickerConfig()" [date]="date()" [hideCalendar]="isMobile()" [minMonth]="minMonth()" [dateRange]="dateRange()" [disabledTime]="disableTime" [time12h]="time12h()" [timepickerLabel]="secondDatepickerConfig().endTimeLabel" [rangeType]="rangeType()" [(activeHover)]="activeHover" (dateRangeChange)="dateRange.set($event)" (focusedDateChange)="secondDatepickerFocusDateChange($event)" (rangeTypeChange)="rangeType.set($event)" /> } `, styleUrl: './si-datepicker-overlay.component.scss', changeDetection: ChangeDetectionStrategy.Default, host: { class: 'mt-md-1 d-flex elevation-2 rounded-2 overflow-auto align-items-stretch', '[class.flex-wrap]': 'isMobile()', '[class.mobile-datepicker-overlay]': 'isMobile()', '[class.fade]': 'isMobile()', '[class.show]': 'completeAnimation()' } }) export class SiDatepickerOverlayComponent implements OnChanges, OnInit, OnDestroy { protected readonly minMonth = signal<Date | undefined>(undefined); protected readonly maxMonth = signal<Date | undefined>(undefined); protected readonly datepicker = viewChild.required(SiDatepickerComponent); /** * {@inheritDoc SiDatepickerComponent#initialFocus} * @defaultValue false */ readonly initialFocus = input(false, { transform: booleanAttribute }); /** * {@inheritDoc SiDatepickerComponent#config} * @defaultValue * ``` * {} * ``` */ readonly config = input<DatepickerConfig>({}); /** * {@inheritDoc SiDatepickerComponent#date} */ readonly date = model<Date>(); /** * {@inheritDoc SiDatepickerComponent#dateRange} */ readonly dateRange = model<DateRange>(); /** * {@inheritDoc SiDatepickerComponent#rangeType} */ readonly rangeType = model<'START' | 'END'>(); /** * {@inheritDoc SiDatepickerComponent#time12h} * @defaultValue false */ readonly time12h = input(false, { transform: booleanAttribute }); /** * Emits an event to notify about disabling the time from the datepicker. * When time is disable, we construct a pure date object in UTC 00:00:00 time. */ readonly disabledTimeChange = output<boolean>(); private readonly document = inject(DOCUMENT); private readonly elementRef = inject(ElementRef); private readonly focusMonitor = inject(FocusMonitor); private readonly focusTrapFactory = inject(ConfigurableFocusTrapFactory); private focusTrap!: ConfigurableFocusTrap; private previousActiveElement?: Element | HTMLElement; protected disableTime = false; protected activeHover?: Cell; protected readonly isTwoMonthDateRange = computed( () => !!this.config().enableDateRange && (!!this.config().enableTwoMonthDateRange || !!this.config().showTime) ); protected readonly firstDatepickerConfig = signal<DatepickerConfig>({}); protected readonly secondDatepickerConfig = signal<DatepickerConfig>({}); /** * Indicate that the overlay is opened in small screen. * A modal dialog animation display when true and a wrapped two month calendar layout is displayed. * * @defaultValue false */ readonly isMobile = input(false); protected readonly completeAnimation = signal(false); ngOnChanges(changes: SimpleChanges): void { if (changes.config) { const config = this.config(); this.firstDatepickerConfig.set( !this.isTwoMonthDateRange ? config : { ...config, hideLabels: true } ); this.secondDatepickerConfig.set({ ...config, hideLabels: true }); } const dateRange = this.dateRange(); if ( changes.config?.currentValue?.onlyMonthSelection && this.isTwoMonthDateRange() && dateRange?.start ) { this.minMonth.set(new Date(dateRange?.start.getFullYear(), 0, 1)); } this.rangeType.set('START'); if ( isValid(changes.dateRange?.currentValue?.start) && !isValid(changes.dateRange?.currentValue?.end) ) { this.rangeType.set('END'); } } ngOnInit(): void { this.focusTrap = this.focusTrapFactory.create(this.elementRef.nativeElement); this.previousActiveElement = this.document.activeElement ?? undefined; Iif (this.isMobile()) { setTimeout(() => this.completeAnimation.set(true), 150); } } ngOnDestroy(): void { this.focusMonitor.stopMonitoring(this.elementRef); this.focusTrap.destroy(); if (this.initialFocus() && this.previousActiveElement && 'focus' in this.previousActiveElement) this.previousActiveElement.focus(); } /** * Focus active cell in the current datepicker view. */ focusActiveCell(): void { this.datepicker().focusActiveCell(); } protected firstDatepickerFocusDateChange(newFocusedDate?: Date): void { Iif (!newFocusedDate) { return; } if (this.config()?.onlyMonthSelection) { this.minMonth.set(new Date(newFocusedDate.getFullYear() + 1, 0, 1)); } else if (newFocusedDate !== this.maxMonth()) { this.minMonth.set(nextMonth(newFocusedDate)); } } protected secondDatepickerFocusDateChange(newFocusedDate?: Date): void { if (newFocusedDate && newFocusedDate !== this.minMonth()) { if (this.config()?.onlyMonthSelection) { this.maxMonth.set(new Date(newFocusedDate.getFullYear() - 1, 11, 31)); } else { this.maxMonth.set(previousMonth(newFocusedDate)); } } } } |