@energinet/watt 1.5.6 → 1.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,11 +57,15 @@ class WattYearField {
57
57
  min = input();
58
58
  /** The maximum selectable date. */
59
59
  max = input();
60
+ /** Enable buttons to step through years. */
61
+ canStepThroughYears = input(false);
60
62
  /** Emits when the selected year has changed. */
61
63
  yearChange = outputFromObservable(this.valueChanges);
62
64
  /** Emits when the field loses focus. */
63
65
  // eslint-disable-next-line @angular-eslint/no-output-native
64
66
  blur = output();
67
+ isPrevYearButtonDisabled = computed(() => this.isPrevYearBeforeOrEqualToMinDate());
68
+ isNextYearButtonDisabled = computed(() => this.isNextYearAfterOrEqualToMaxDate());
65
69
  handleFocus = (picker) => {
66
70
  this.isOpen.set(true);
67
71
  picker.showPopover();
@@ -87,8 +91,54 @@ class WattYearField {
87
91
  setDisabledState = (x) => (x ? this.control.disable() : this.control.enable());
88
92
  registerOnTouched = (fn) => this.blur.subscribe(fn);
89
93
  registerOnChange = (fn) => this.valueChanges.subscribe(fn);
94
+ /**
95
+ * @ignore
96
+ */
97
+ prevYear(field) {
98
+ this.changeYear(field, -1);
99
+ }
100
+ /**
101
+ * @ignore
102
+ */
103
+ nextYear(field) {
104
+ this.changeYear(field, 1);
105
+ }
106
+ /**
107
+ * @ignore
108
+ */
109
+ changeYear(field, value) {
110
+ const currentDate = dayjs(field.value, YEAR_FORMAT, true);
111
+ if (!currentDate.isValid())
112
+ return;
113
+ const newDate = currentDate.add(value, 'year');
114
+ this.handleSelectedChange(field, newDate.toDate());
115
+ }
116
+ /**
117
+ * @ignore
118
+ */
119
+ isPrevYearBeforeOrEqualToMinDate() {
120
+ const min = this.min();
121
+ if (!min)
122
+ return false;
123
+ const selectedDate = dayjs(this.selected());
124
+ const isBefore = selectedDate.isBefore(min, 'year');
125
+ const isSame = selectedDate.isSame(min, 'year');
126
+ return isSame || isBefore;
127
+ }
128
+ /**
129
+ * @ignore
130
+ */
131
+ isNextYearAfterOrEqualToMaxDate() {
132
+ const max = this.max();
133
+ if (!max)
134
+ return false;
135
+ const selectedDate = dayjs(this.selected());
136
+ const isAfter = selectedDate.isAfter(max, 'year');
137
+ const isSame = selectedDate.isSame(max, 'year');
138
+ return isSame || isAfter;
139
+ }
90
140
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: WattYearField, deps: [], target: i0.ɵɵFactoryTarget.Component });
91
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.1", type: WattYearField, isStandalone: true, selector: "watt-year-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { yearChange: "yearChange", blur: "blur" }, providers: [
141
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.1", type: WattYearField, isStandalone: true, selector: "watt-year-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, canStepThroughYears: { classPropertyName: "canStepThroughYears", publicName: "canStepThroughYears", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { yearChange: "yearChange", blur: "blur" }, providers: [
92
142
  {
93
143
  provide: NG_VALUE_ACCESSOR,
94
144
  useExisting: forwardRef(() => WattYearField),
@@ -126,7 +176,24 @@ class WattYearField {
126
176
  <ng-content select="watt-field-error" ngProjectAs="watt-field-error" />
127
177
  <ng-content select="watt-field-hint" ngProjectAs="watt-field-hint" />
128
178
  </watt-field>
129
- `, isInline: true, styles: ["watt-year-field{display:block;width:100%}.watt-year-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: MatCalendar, selector: "mat-calendar", inputs: ["headerComponent", "startAt", "startView", "selected", "minDate", "maxDate", "dateFilter", "dateClass", "comparisonStart", "comparisonEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedChange", "yearSelected", "monthSelected", "viewChanged", "_userSelection", "_userDragDrop"], exportAs: ["matCalendar"] }, { kind: "component", type: WattButtonComponent, selector: "watt-button", inputs: ["icon", "variant", "type", "formId", "disabled", "loading"] }, { kind: "component", type: WattFieldComponent, selector: "watt-field", inputs: ["control", "label", "id", "chipMode", "tooltip", "placeholder", "anchorName"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
179
+
180
+ @if (canStepThroughYears()) {
181
+ <span class="watt-year-field__step-through" [class.watt-year-field__has-label]="!!label()">
182
+ <watt-button
183
+ variant="icon"
184
+ icon="left"
185
+ (click)="prevYear(field)"
186
+ [disabled]="control.disabled || isPrevYearButtonDisabled()"
187
+ />
188
+ <watt-button
189
+ variant="icon"
190
+ icon="right"
191
+ (click)="nextYear(field)"
192
+ [disabled]="control.disabled || isNextYearButtonDisabled()"
193
+ />
194
+ </span>
195
+ }
196
+ `, isInline: true, styles: ["watt-year-field{display:block;width:100%}watt-year-field:has(.watt-year-field__step-through){display:flex;flex-align:flex-start}watt-year-field:has(.watt-year-field__step-through) .watt-year-field__step-through{display:flex}watt-year-field:has(.watt-year-field__has-label) .watt-year-field__step-through{margin-top:28px}.watt-year-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: MatCalendar, selector: "mat-calendar", inputs: ["headerComponent", "startAt", "startView", "selected", "minDate", "maxDate", "dateFilter", "dateClass", "comparisonStart", "comparisonEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedChange", "yearSelected", "monthSelected", "viewChanged", "_userSelection", "_userDragDrop"], exportAs: ["matCalendar"] }, { kind: "component", type: WattButtonComponent, selector: "watt-button", inputs: ["icon", "variant", "type", "formId", "disabled", "loading"] }, { kind: "component", type: WattFieldComponent, selector: "watt-field", inputs: ["control", "label", "id", "chipMode", "tooltip", "placeholder", "anchorName"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
130
197
  }
131
198
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: WattYearField, decorators: [{
132
199
  type: Component,
@@ -168,7 +235,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImpor
168
235
  <ng-content select="watt-field-error" ngProjectAs="watt-field-error" />
169
236
  <ng-content select="watt-field-hint" ngProjectAs="watt-field-hint" />
170
237
  </watt-field>
171
- `, styles: ["watt-year-field{display:block;width:100%}.watt-year-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"] }]
238
+
239
+ @if (canStepThroughYears()) {
240
+ <span class="watt-year-field__step-through" [class.watt-year-field__has-label]="!!label()">
241
+ <watt-button
242
+ variant="icon"
243
+ icon="left"
244
+ (click)="prevYear(field)"
245
+ [disabled]="control.disabled || isPrevYearButtonDisabled()"
246
+ />
247
+ <watt-button
248
+ variant="icon"
249
+ icon="right"
250
+ (click)="nextYear(field)"
251
+ [disabled]="control.disabled || isNextYearButtonDisabled()"
252
+ />
253
+ </span>
254
+ }
255
+ `, styles: ["watt-year-field{display:block;width:100%}watt-year-field:has(.watt-year-field__step-through){display:flex;flex-align:flex-start}watt-year-field:has(.watt-year-field__step-through) .watt-year-field__step-through{display:flex}watt-year-field:has(.watt-year-field__has-label) .watt-year-field__step-through{margin-top:28px}.watt-year-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"] }]
172
256
  }] });
173
257
 
174
258
  //#region License
@@ -1 +1 @@
1
- {"version":3,"file":"energinet-watt-year-field.mjs","sources":["../../../libs/watt/package/year-field/watt-year-field.component.ts","../../../libs/watt/package/year-field/index.ts","../../../libs/watt/package/year-field/energinet-watt-year-field.ts"],"sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport {\n input,\n output,\n signal,\n computed,\n Component,\n forwardRef,\n ViewEncapsulation,\n ChangeDetectionStrategy,\n} from '@angular/core';\n\nimport {\n FormControl,\n NG_VALUE_ACCESSOR,\n ReactiveFormsModule,\n ControlValueAccessor,\n} from '@angular/forms';\n\nimport { share } from 'rxjs';\nimport { MatCalendar } from '@angular/material/datepicker';\nimport { outputFromObservable, takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';\n\nimport { dayjs } from '@energinet/watt/core/date';\nimport { WattFieldComponent } from '@energinet/watt/field';\nimport { WattButtonComponent } from '@energinet/watt/button';\n\nexport const YEAR_FORMAT = 'YYYY';\n\n/* eslint-disable @angular-eslint/component-class-suffix */\n@Component({\n selector: 'watt-year-field',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => WattYearField),\n multi: true,\n },\n ],\n imports: [ReactiveFormsModule, MatCalendar, WattButtonComponent, WattFieldComponent],\n styles: [\n `\n watt-year-field {\n display: block;\n width: 100%;\n }\n\n .watt-year-field-picker {\n position: fixed;\n position-area: bottom span-right;\n position-try-fallbacks: flip-block;\n width: 296px;\n height: 354px;\n inset: unset;\n margin: unset;\n border: 0;\n }\n `,\n ],\n template: `\n <watt-field [label]=\"label()\" [control]=\"control\" [anchorName]=\"anchorName\">\n <input\n #field\n readonly\n [formControl]=\"control\"\n (focus)=\"handleFocus(picker)\"\n (blur)=\"handleBlur(picker, $event)\"\n />\n <watt-button icon=\"date\" variant=\"icon\" (click)=\"field.focus()\" />\n <div\n #picker\n class=\"watt-elevation watt-year-field-picker\"\n popover=\"manual\"\n tabindex=\"0\"\n [style.position-anchor]=\"anchorName\"\n >\n @if (isOpen()) {\n <mat-calendar\n startView=\"multi-year\"\n [startAt]=\"selected()\"\n [selected]=\"selected()\"\n [minDate]=\"min()\"\n [maxDate]=\"max()\"\n (yearSelected)=\"handleSelectedChange(field, $event)\"\n />\n }\n </div>\n <ng-content />\n <ng-content select=\"watt-field-error\" ngProjectAs=\"watt-field-error\" />\n <ng-content select=\"watt-field-hint\" ngProjectAs=\"watt-field-hint\" />\n </watt-field>\n `,\n})\nexport class WattYearField implements ControlValueAccessor {\n // Popovers exists on an entirely different layer, meaning that for anchor positioning they\n // look at the entire tree for the anchor name. This gives each field a unique anchor name.\n private static instance = 0;\n private instance = WattYearField.instance++;\n protected anchorName = `--watt-year-field-popover-anchor-${this.instance}`;\n\n // The format of the inner FormControl is different from that of the outer FormControl\n protected control = new FormControl('', { nonNullable: true });\n\n // `registerOnChange` may subscribe to this component after it has been destroyed, thus\n // triggering an NG0911 from the `takeUntilDestroyed` operator. By sharing the observable,\n // the observable will already be closed and `subscribe` becomes a proper noop.\n private valueChanges = this.control.valueChanges.pipe(takeUntilDestroyed(), share());\n private year = toSignal(this.valueChanges);\n protected selected = computed(() => {\n const date = dayjs(this.year(), YEAR_FORMAT, true);\n if (date.isValid()) return date.toDate();\n return undefined;\n });\n\n // This is used to reset the MatCalendar component by destroying and then recreating it\n // whenever the picker is opened. There is no methods to do it programatically.\n protected isOpen = signal(false);\n\n /** Set the label text for `watt-field`. */\n label = input('');\n\n /** The minimum selectable date. */\n min = input<Date>();\n\n /** The maximum selectable date. */\n max = input<Date>();\n\n /** Emits when the selected year has changed. */\n yearChange = outputFromObservable(this.valueChanges);\n\n /** Emits when the field loses focus. */\n // eslint-disable-next-line @angular-eslint/no-output-native\n blur = output<FocusEvent>();\n\n protected handleFocus = (picker: HTMLElement) => {\n this.isOpen.set(true);\n picker.showPopover();\n };\n\n protected handleBlur = (picker: HTMLElement, event: FocusEvent) => {\n if (event.relatedTarget instanceof HTMLElement && picker.contains(event.relatedTarget)) {\n const target = event.target as HTMLInputElement; // safe type assertion\n setTimeout(() => target.focus()); // keep focus on input element while using the picker\n } else {\n picker.hidePopover();\n this.isOpen.set(false);\n this.blur.emit(event);\n }\n };\n\n protected handleSelectedChange = (field: HTMLInputElement, date: Date) => {\n field.value = dayjs(date).format(YEAR_FORMAT);\n field.dispatchEvent(new Event('input', { bubbles: true }));\n setTimeout(() => field.blur());\n };\n\n // Implementation for ControlValueAccessor\n writeValue = (value: string | null) => this.control.setValue(value ?? '');\n setDisabledState = (x: boolean) => (x ? this.control.disable() : this.control.enable());\n registerOnTouched = (fn: () => void) => this.blur.subscribe(fn);\n registerOnChange = (fn: (value: string | null) => void) => this.valueChanges.subscribe(fn);\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nexport { WattYearField, YEAR_FORMAT } from './watt-year-field.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;;;;;;;;;;;;;;;AAeG;AACH;AA2BO,MAAM,WAAW,GAAG;AAE3B;MAkEa,aAAa,CAAA;;;AAGhB,IAAA,OAAO,QAAQ,GAAG,CAAC;AACnB,IAAA,QAAQ,GAAG,aAAa,CAAC,QAAQ,EAAE;AACjC,IAAA,UAAU,GAAG,CAAoC,iCAAA,EAAA,IAAI,CAAC,QAAQ,EAAE;;AAGhE,IAAA,OAAO,GAAG,IAAI,WAAW,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;;;;AAKtD,IAAA,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,CAAC;AAC5E,IAAA,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;AAChC,IAAA,QAAQ,GAAG,QAAQ,CAAC,MAAK;AACjC,QAAA,MAAM,IAAI,GA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A,uBAAA,CAAA,EAAA,OAAA,EAAA,CAAA,gBAAA,EAAA,cAAA,EAAA,eAAA,EAAA,aAAA,EAAA,gBAAA,EAAA,eAAA,CAAA,EAAA,QAAA,EAAA,CAAA,aAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,mBAAmB,8HAAE,kBAAkB,EAAA,QAAA,EAAA,YAAA,EAAA,MAAA,EAAA,CAAA,SAAA,EAAA,OAAA,EAAA,IAAA,EAAA,UAAA,EAAA,SAAA,EAAA,aAAA,EAAA,YAAA,CAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,aAAA,EAAA,EAAA,CAAA,iBAAA,CAAA,IAAA,EAAA,CAAA;;2FAsDxE,aAAa,EAAA,UAAA,EAAA,CAAA;kBAjEzB,SAAS;+BACE,iBAAiB,EAAA,aAAA,EACZ,iBAAiB,CAAC,IAAI,mBACpB,uBAAuB,CAAC,MAAM,EACpC,SAAA,EAAA;AACT,wBAAA;AACE,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,WAAW,EAAE,UAAU,CAAC,mBAAmB,CAAC;AAC5C,4BAAA,KAAK,EAAE,IAAI;AACZ,yBAAA;qBACF,EACQ,OAAA,EAAA,CAAC,mBAAmB,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,EAoB1E,QAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCT,EAAA,CAAA,EAAA,MAAA,EAAA,CAAA,iNAAA,CAAA,EAAA;;;AC9GH;AACA;;;;;;;;;;;;;;;AAeG;AACH;;ACjBA;;AAEG;;;;"}
1
+ {"version":3,"file":"energinet-watt-year-field.mjs","sources":["../../../libs/watt/package/year-field/watt-year-field.component.ts","../../../libs/watt/package/year-field/index.ts","../../../libs/watt/package/year-field/energinet-watt-year-field.ts"],"sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport {\n input,\n output,\n signal,\n computed,\n Component,\n forwardRef,\n ViewEncapsulation,\n ChangeDetectionStrategy,\n} from '@angular/core';\n\nimport {\n FormControl,\n NG_VALUE_ACCESSOR,\n ReactiveFormsModule,\n ControlValueAccessor,\n} from '@angular/forms';\n\nimport { share } from 'rxjs';\nimport { MatCalendar } from '@angular/material/datepicker';\nimport { outputFromObservable, takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';\n\nimport { dayjs } from '@energinet/watt/core/date';\nimport { WattFieldComponent } from '@energinet/watt/field';\nimport { WattButtonComponent } from '@energinet/watt/button';\n\nexport const YEAR_FORMAT = 'YYYY';\n\n/* eslint-disable @angular-eslint/component-class-suffix */\n@Component({\n selector: 'watt-year-field',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => WattYearField),\n multi: true,\n },\n ],\n imports: [ReactiveFormsModule, MatCalendar, WattButtonComponent, WattFieldComponent],\n styles: [\n `\n watt-year-field {\n display: block;\n width: 100%;\n\n &:has(.watt-year-field__step-through) {\n display: flex;\n flex-align: flex-start;\n\n .watt-year-field__step-through {\n display: flex;\n }\n }\n\n &:has(.watt-year-field__has-label) {\n .watt-year-field__step-through {\n margin-top: 28px;\n }\n }\n }\n\n .watt-year-field-picker {\n position: fixed;\n position-area: bottom span-right;\n position-try-fallbacks: flip-block;\n width: 296px;\n height: 354px;\n inset: unset;\n margin: unset;\n border: 0;\n }\n `,\n ],\n template: `\n <watt-field [label]=\"label()\" [control]=\"control\" [anchorName]=\"anchorName\">\n <input\n #field\n readonly\n [formControl]=\"control\"\n (focus)=\"handleFocus(picker)\"\n (blur)=\"handleBlur(picker, $event)\"\n />\n <watt-button icon=\"date\" variant=\"icon\" (click)=\"field.focus()\" />\n <div\n #picker\n class=\"watt-elevation watt-year-field-picker\"\n popover=\"manual\"\n tabindex=\"0\"\n [style.position-anchor]=\"anchorName\"\n >\n @if (isOpen()) {\n <mat-calendar\n startView=\"multi-year\"\n [startAt]=\"selected()\"\n [selected]=\"selected()\"\n [minDate]=\"min()\"\n [maxDate]=\"max()\"\n (yearSelected)=\"handleSelectedChange(field, $event)\"\n />\n }\n </div>\n <ng-content />\n <ng-content select=\"watt-field-error\" ngProjectAs=\"watt-field-error\" />\n <ng-content select=\"watt-field-hint\" ngProjectAs=\"watt-field-hint\" />\n </watt-field>\n\n @if (canStepThroughYears()) {\n <span class=\"watt-year-field__step-through\" [class.watt-year-field__has-label]=\"!!label()\">\n <watt-button\n variant=\"icon\"\n icon=\"left\"\n (click)=\"prevYear(field)\"\n [disabled]=\"control.disabled || isPrevYearButtonDisabled()\"\n />\n <watt-button\n variant=\"icon\"\n icon=\"right\"\n (click)=\"nextYear(field)\"\n [disabled]=\"control.disabled || isNextYearButtonDisabled()\"\n />\n </span>\n }\n `,\n})\nexport class WattYearField implements ControlValueAccessor {\n // Popovers exists on an entirely different layer, meaning that for anchor positioning they\n // look at the entire tree for the anchor name. This gives each field a unique anchor name.\n private static instance = 0;\n private instance = WattYearField.instance++;\n protected anchorName = `--watt-year-field-popover-anchor-${this.instance}`;\n\n // The format of the inner FormControl is different from that of the outer FormControl\n protected control = new FormControl('', { nonNullable: true });\n\n // `registerOnChange` may subscribe to this component after it has been destroyed, thus\n // triggering an NG0911 from the `takeUntilDestroyed` operator. By sharing the observable,\n // the observable will already be closed and `subscribe` becomes a proper noop.\n private valueChanges = this.control.valueChanges.pipe(takeUntilDestroyed(), share());\n private year = toSignal(this.valueChanges);\n protected selected = computed(() => {\n const date = dayjs(this.year(), YEAR_FORMAT, true);\n if (date.isValid()) return date.toDate();\n return undefined;\n });\n\n // This is used to reset the MatCalendar component by destroying and then recreating it\n // whenever the picker is opened. There is no methods to do it programatically.\n protected isOpen = signal(false);\n\n /** Set the label text for `watt-field`. */\n label = input('');\n\n /** The minimum selectable date. */\n min = input<Date>();\n\n /** The maximum selectable date. */\n max = input<Date>();\n\n /** Enable buttons to step through years. */\n canStepThroughYears = input(false);\n\n /** Emits when the selected year has changed. */\n yearChange = outputFromObservable(this.valueChanges);\n\n /** Emits when the field loses focus. */\n // eslint-disable-next-line @angular-eslint/no-output-native\n blur = output<FocusEvent>();\n\n isPrevYearButtonDisabled = computed(() => this.isPrevYearBeforeOrEqualToMinDate());\n isNextYearButtonDisabled = computed(() => this.isNextYearAfterOrEqualToMaxDate());\n\n protected handleFocus = (picker: HTMLElement) => {\n this.isOpen.set(true);\n picker.showPopover();\n };\n\n protected handleBlur = (picker: HTMLElement, event: FocusEvent) => {\n if (event.relatedTarget instanceof HTMLElement && picker.contains(event.relatedTarget)) {\n const target = event.target as HTMLInputElement; // safe type assertion\n setTimeout(() => target.focus()); // keep focus on input element while using the picker\n } else {\n picker.hidePopover();\n this.isOpen.set(false);\n this.blur.emit(event);\n }\n };\n\n protected handleSelectedChange = (field: HTMLInputElement, date: Date) => {\n field.value = dayjs(date).format(YEAR_FORMAT);\n field.dispatchEvent(new Event('input', { bubbles: true }));\n setTimeout(() => field.blur());\n };\n\n // Implementation for ControlValueAccessor\n writeValue = (value: string | null) => this.control.setValue(value ?? '');\n setDisabledState = (x: boolean) => (x ? this.control.disable() : this.control.enable());\n registerOnTouched = (fn: () => void) => this.blur.subscribe(fn);\n registerOnChange = (fn: (value: string | null) => void) => this.valueChanges.subscribe(fn);\n\n /**\n * @ignore\n */\n protected prevYear(field: HTMLInputElement): void {\n this.changeYear(field, -1);\n }\n /**\n * @ignore\n */\n protected nextYear(field: HTMLInputElement): void {\n this.changeYear(field, 1);\n }\n\n /**\n * @ignore\n */\n private changeYear(field: HTMLInputElement, value: number): void {\n const currentDate = dayjs(field.value, YEAR_FORMAT, true);\n\n if (!currentDate.isValid()) return;\n\n const newDate = currentDate.add(value, 'year');\n this.handleSelectedChange(field, newDate.toDate());\n }\n\n /**\n * @ignore\n */\n isPrevYearBeforeOrEqualToMinDate(): boolean {\n const min = this.min();\n\n if (!min) return false;\n\n const selectedDate = dayjs(this.selected());\n\n const isBefore = selectedDate.isBefore(min, 'year');\n const isSame = selectedDate.isSame(min, 'year');\n\n return isSame || isBefore;\n }\n\n /**\n * @ignore\n */\n isNextYearAfterOrEqualToMaxDate(): boolean {\n const max = this.max();\n\n if (!max) return false;\n\n const selectedDate = dayjs(this.selected());\n\n const isAfter = selectedDate.isAfter(max, 'year');\n const isSame = selectedDate.isSame(max, 'year');\n\n return isSame || isAfter;\n }\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nexport { WattYearField, YEAR_FORMAT } from './watt-year-field.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;;;;;;;;;;;;;;;AAeG;AACH;AA2BO,MAAM,WAAW,GAAG;AAE3B;MAkGa,aAAa,CAAA;;;AAGhB,IAAA,OAAO,QAAQ,GAAG,CAAC;AACnB,IAAA,QAAQ,GAAG,aAAa,CAAC,QAAQ,EAAE;AACjC,IAAA,UAAU,GAAG,CAAoC,iCAAA,EAAA,IAAI,CAAC,QAAQ,EA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AAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,aAAA,EAAA,EAAA,CAAA,iBAAA,CAAA,IAAA,EAAA,CAAA;;2FAsFxE,aAAa,EAAA,UAAA,EAAA,CAAA;kBAjGzB,SAAS;+BACE,iBAAiB,EAAA,aAAA,EACZ,iBAAiB,CAAC,IAAI,mBACpB,uBAAuB,CAAC,MAAM,EACpC,SAAA,EAAA;AACT,wBAAA;AACE,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,WAAW,EAAE,UAAU,CAAC,mBAAmB,CAAC;AAC5C,4BAAA,KAAK,EAAE,IAAI;AACZ,yBAAA;qBACF,EACQ,OAAA,EAAA,CAAC,mBAAmB,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,EAmC1E,QAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDT,EAAA,CAAA,EAAA,MAAA,EAAA,CAAA,weAAA,CAAA,EAAA;;;AC9IH;AACA;;;;;;;;;;;;;;;AAeG;AACH;;ACjBA;;AAEG;;;;"}
@@ -3,11 +3,11 @@ import { computed, signal, input, output, forwardRef, ChangeDetectionStrategy, V
3
3
  import * as i1 from '@angular/forms';
4
4
  import { FormControl, ReactiveFormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
5
5
  import { takeUntilDestroyed, toSignal, outputFromObservable } from '@angular/core/rxjs-interop';
6
- import { MatCalendar } from '@angular/material/datepicker';
7
6
  import { map, share } from 'rxjs';
7
+ import { MatCalendar } from '@angular/material/datepicker';
8
+ import { dayjs } from '@energinet/watt/core/date';
8
9
  import { WattFieldComponent } from '@energinet/watt/field';
9
10
  import { WattButtonComponent } from '@energinet/watt/button';
10
- import { dayjs } from '@energinet/watt/core/date';
11
11
 
12
12
  //#region License
13
13
  /**
@@ -93,11 +93,15 @@ class WattYearMonthField {
93
93
  min = input();
94
94
  /** The maximum selectable date. */
95
95
  max = input();
96
+ /** Enable buttons to step through months. */
97
+ canStepThroughMonths = input(false);
96
98
  /** Emits when the selected month has changed. */
97
99
  monthChange = outputFromObservable(this.valueChanges);
98
100
  /** Emits when the field loses focus. */
99
101
  // eslint-disable-next-line @angular-eslint/no-output-native
100
102
  blur = output();
103
+ isPrevMonthButtonDisabled = computed(() => this.isPrevMonthBeforeOrEqualToMinDate());
104
+ isNextMonthButtonDisabled = computed(() => this.isNextMonthAfterOrEqualToMaxDate());
101
105
  handleFocus = (picker) => {
102
106
  this.isOpen.set(true);
103
107
  picker.showPopover();
@@ -123,8 +127,54 @@ class WattYearMonthField {
123
127
  setDisabledState = (x) => (x ? this.control.disable() : this.control.enable());
124
128
  registerOnTouched = (fn) => this.blur.subscribe(fn);
125
129
  registerOnChange = (fn) => this.valueChanges.subscribe(fn);
130
+ /**
131
+ * @ignore
132
+ */
133
+ prevMonth(field) {
134
+ this.changeMonth(field, -1);
135
+ }
136
+ /**
137
+ * @ignore
138
+ */
139
+ nextMonth(field) {
140
+ this.changeMonth(field, 1);
141
+ }
142
+ /**
143
+ * @ignore
144
+ */
145
+ changeMonth(field, value) {
146
+ const currentDate = YearMonth.fromView(field.value).toDate();
147
+ if (!currentDate)
148
+ return;
149
+ const newDate = dayjs(currentDate).add(value, 'month');
150
+ this.handleSelectedChange(field, newDate.toDate());
151
+ }
152
+ /**
153
+ * @ignore
154
+ */
155
+ isPrevMonthBeforeOrEqualToMinDate() {
156
+ const min = this.min();
157
+ if (!min)
158
+ return false;
159
+ const selectedDate = dayjs(this.selected());
160
+ const isBefore = selectedDate.isBefore(min, 'month');
161
+ const isSame = selectedDate.isSame(min, 'month');
162
+ return isSame || isBefore;
163
+ }
164
+ /**
165
+ * @ignore
166
+ */
167
+ isNextMonthAfterOrEqualToMaxDate() {
168
+ const max = this.max();
169
+ if (!max)
170
+ return false;
171
+ const selectedDate = dayjs(this.selected());
172
+ const isAfter = selectedDate.isAfter(max, 'month');
173
+ const isSame = selectedDate.isSame(max, 'month');
174
+ return isSame || isAfter;
175
+ }
126
176
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: WattYearMonthField, deps: [], target: i0.ɵɵFactoryTarget.Component });
127
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.1", type: WattYearMonthField, isStandalone: true, selector: "watt-yearmonth-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { monthChange: "monthChange", blur: "blur" }, providers: [
177
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.1", type: WattYearMonthField, isStandalone: true, selector: "watt-yearmonth-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, canStepThroughMonths: { classPropertyName: "canStepThroughMonths", publicName: "canStepThroughMonths", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { monthChange: "monthChange", blur: "blur" }, providers: [
128
178
  {
129
179
  provide: NG_VALUE_ACCESSOR,
130
180
  useExisting: forwardRef(() => WattYearMonthField),
@@ -162,7 +212,27 @@ class WattYearMonthField {
162
212
  <ng-content select="watt-field-error" ngProjectAs="watt-field-error" />
163
213
  <ng-content select="watt-field-hint" ngProjectAs="watt-field-hint" />
164
214
  </watt-field>
165
- `, isInline: true, styles: ["watt-yearmonth-field{display:block;width:100%}watt-yearmonth-field input{text-transform:capitalize}.watt-yearmonth-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: MatCalendar, selector: "mat-calendar", inputs: ["headerComponent", "startAt", "startView", "selected", "minDate", "maxDate", "dateFilter", "dateClass", "comparisonStart", "comparisonEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedChange", "yearSelected", "monthSelected", "viewChanged", "_userSelection", "_userDragDrop"], exportAs: ["matCalendar"] }, { kind: "component", type: WattButtonComponent, selector: "watt-button", inputs: ["icon", "variant", "type", "formId", "disabled", "loading"] }, { kind: "component", type: WattFieldComponent, selector: "watt-field", inputs: ["control", "label", "id", "chipMode", "tooltip", "placeholder", "anchorName"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
215
+
216
+ @if (canStepThroughMonths()) {
217
+ <span
218
+ class="watt-yearmonth-field__step-through"
219
+ [class.watt-yearmonth-field__has-label]="!!label()"
220
+ >
221
+ <watt-button
222
+ variant="icon"
223
+ icon="left"
224
+ (click)="prevMonth(field)"
225
+ [disabled]="control.disabled || isPrevMonthButtonDisabled()"
226
+ />
227
+ <watt-button
228
+ variant="icon"
229
+ icon="right"
230
+ (click)="nextMonth(field)"
231
+ [disabled]="control.disabled || isNextMonthButtonDisabled()"
232
+ />
233
+ </span>
234
+ }
235
+ `, isInline: true, styles: ["watt-yearmonth-field{display:block;width:100%}watt-yearmonth-field input{text-transform:capitalize}watt-yearmonth-field:has(.watt-yearmonth-field__step-through){display:flex;flex-align:flex-start}watt-yearmonth-field:has(.watt-yearmonth-field__step-through) .watt-yearmonth-field__step-through{display:flex}watt-yearmonth-field:has(.watt-yearmonth-field__has-label) .watt-yearmonth-field__step-through{margin-top:28px}.watt-yearmonth-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: MatCalendar, selector: "mat-calendar", inputs: ["headerComponent", "startAt", "startView", "selected", "minDate", "maxDate", "dateFilter", "dateClass", "comparisonStart", "comparisonEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedChange", "yearSelected", "monthSelected", "viewChanged", "_userSelection", "_userDragDrop"], exportAs: ["matCalendar"] }, { kind: "component", type: WattButtonComponent, selector: "watt-button", inputs: ["icon", "variant", "type", "formId", "disabled", "loading"] }, { kind: "component", type: WattFieldComponent, selector: "watt-field", inputs: ["control", "label", "id", "chipMode", "tooltip", "placeholder", "anchorName"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
166
236
  }
167
237
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: WattYearMonthField, decorators: [{
168
238
  type: Component,
@@ -204,7 +274,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImpor
204
274
  <ng-content select="watt-field-error" ngProjectAs="watt-field-error" />
205
275
  <ng-content select="watt-field-hint" ngProjectAs="watt-field-hint" />
206
276
  </watt-field>
207
- `, styles: ["watt-yearmonth-field{display:block;width:100%}watt-yearmonth-field input{text-transform:capitalize}.watt-yearmonth-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"] }]
277
+
278
+ @if (canStepThroughMonths()) {
279
+ <span
280
+ class="watt-yearmonth-field__step-through"
281
+ [class.watt-yearmonth-field__has-label]="!!label()"
282
+ >
283
+ <watt-button
284
+ variant="icon"
285
+ icon="left"
286
+ (click)="prevMonth(field)"
287
+ [disabled]="control.disabled || isPrevMonthButtonDisabled()"
288
+ />
289
+ <watt-button
290
+ variant="icon"
291
+ icon="right"
292
+ (click)="nextMonth(field)"
293
+ [disabled]="control.disabled || isNextMonthButtonDisabled()"
294
+ />
295
+ </span>
296
+ }
297
+ `, styles: ["watt-yearmonth-field{display:block;width:100%}watt-yearmonth-field input{text-transform:capitalize}watt-yearmonth-field:has(.watt-yearmonth-field__step-through){display:flex;flex-align:flex-start}watt-yearmonth-field:has(.watt-yearmonth-field__step-through) .watt-yearmonth-field__step-through{display:flex}watt-yearmonth-field:has(.watt-yearmonth-field__has-label) .watt-yearmonth-field__step-through{margin-top:28px}.watt-yearmonth-field-picker{position:fixed;position-area:bottom span-right;position-try-fallbacks:flip-block;width:296px;height:354px;inset:unset;margin:unset;border:0}\n"] }]
208
298
  }] });
209
299
 
210
300
  //#region License
@@ -1 +1 @@
1
- {"version":3,"file":"energinet-watt-yearmonth-field.mjs","sources":["../../../libs/watt/package/yearmonth-field/year-month.ts","../../../libs/watt/package/yearmonth-field/watt-yearmonth-field.component.ts","../../../libs/watt/package/yearmonth-field/index.ts","../../../libs/watt/package/yearmonth-field/energinet-watt-yearmonth-field.ts"],"sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport { dayjs } from '@energinet/watt/core/date';\n\n/** Represents a year and month. */\nexport class YearMonth {\n static readonly VIEW_FORMAT = 'MMMM YYYY';\n static readonly MODEL_FORMAT = 'YYYY-MM';\n\n private constructor(private date: dayjs.Dayjs | null) {}\n\n /** Creates a `YearMonth` instance from a `Date` object. */\n static fromDate = (value: Date) => new YearMonth(dayjs(value));\n\n /** Creates a `YearMonth` instance from a `string` in the view format. */\n static fromView = (value: string) =>\n new YearMonth(value ? dayjs(value, YearMonth.VIEW_FORMAT, true) : null);\n\n /** Creates a `YearMonth` instance from a `string` in the model format. */\n static fromModel = (value: string | null | undefined) =>\n new YearMonth(value ? dayjs(value, YearMonth.MODEL_FORMAT, true) : null);\n\n /** Converts the `YearMonth` instance to a `Date` object. */\n toDate = () => this.date?.toDate() ?? null;\n\n /** Converts the `YearMonth` instance to a `string` in the view format. */\n toView = () => this.date?.format(YearMonth.VIEW_FORMAT) ?? '';\n\n /** Converts the `YearMonth` instance to a `string` in the model format. */\n toModel = () => this.date?.format(YearMonth.MODEL_FORMAT) ?? null;\n}\n\nexport const YEARMONTH_FORMAT = YearMonth.MODEL_FORMAT;\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport {\n ChangeDetectionStrategy,\n Component,\n computed,\n forwardRef,\n input,\n output,\n signal,\n ViewEncapsulation,\n} from '@angular/core';\nimport {\n ControlValueAccessor,\n FormControl,\n NG_VALUE_ACCESSOR,\n ReactiveFormsModule,\n} from '@angular/forms';\nimport { outputFromObservable, takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';\nimport { MatCalendar } from '@angular/material/datepicker';\nimport { map, share } from 'rxjs';\nimport { WattFieldComponent } from '@energinet/watt/field';\nimport { WattButtonComponent } from '@energinet/watt/button';\nimport { YearMonth } from './year-month';\n\n/* eslint-disable @angular-eslint/component-class-suffix */\n@Component({\n selector: 'watt-yearmonth-field',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => WattYearMonthField),\n multi: true,\n },\n ],\n imports: [ReactiveFormsModule, MatCalendar, WattButtonComponent, WattFieldComponent],\n styles: [\n `\n watt-yearmonth-field {\n display: block;\n width: 100%;\n & input {\n text-transform: capitalize;\n }\n }\n\n .watt-yearmonth-field-picker {\n position: fixed;\n position-area: bottom span-right;\n position-try-fallbacks: flip-block;\n width: 296px;\n height: 354px;\n inset: unset;\n margin: unset;\n border: 0;\n }\n `,\n ],\n template: `\n <watt-field [label]=\"label()\" [control]=\"control\" [anchorName]=\"anchorName\">\n <input\n #field\n readonly\n [formControl]=\"control\"\n (focus)=\"handleFocus(picker)\"\n (blur)=\"handleBlur(picker, $event)\"\n />\n <watt-button icon=\"date\" variant=\"icon\" (click)=\"field.focus()\" />\n <div\n #picker\n class=\"watt-elevation watt-yearmonth-field-picker\"\n popover=\"manual\"\n tabindex=\"0\"\n [style.position-anchor]=\"anchorName\"\n >\n @if (isOpen()) {\n <mat-calendar\n startView=\"multi-year\"\n [startAt]=\"selected()\"\n [selected]=\"selected()\"\n [minDate]=\"min()\"\n [maxDate]=\"max()\"\n (monthSelected)=\"handleSelectedChange(field, $event)\"\n />\n }\n </div>\n <ng-content />\n <ng-content select=\"watt-field-error\" ngProjectAs=\"watt-field-error\" />\n <ng-content select=\"watt-field-hint\" ngProjectAs=\"watt-field-hint\" />\n </watt-field>\n `,\n})\nexport class WattYearMonthField implements ControlValueAccessor {\n // Popovers exists on an entirely different layer, meaning that for anchor positioning they\n // look at the entire tree for the anchor name. This gives each field a unique anchor name.\n private static instance = 0;\n private instance = WattYearMonthField.instance++;\n protected anchorName = `--watt-yearmonth-field-popover-anchor-${this.instance}`;\n\n // The format of the inner FormControl is different from that of the outer FormControl\n protected control = new FormControl('', { nonNullable: true });\n\n // `registerOnChange` may subscribe to this component after it has been destroyed, thus\n // triggering an NG0911 from the `takeUntilDestroyed` operator. By sharing the observable,\n // the observable will already be closed and `subscribe` becomes a proper noop.\n private yearMonthChanges = this.control.valueChanges.pipe(map(YearMonth.fromView));\n private valueChanges = this.yearMonthChanges.pipe(\n map((yearMonth) => yearMonth.toModel()),\n takeUntilDestroyed(),\n share()\n );\n\n private yearMonth = toSignal(this.yearMonthChanges);\n protected selected = computed(() => this.yearMonth()?.toDate());\n\n // This is used to reset the MatCalendar component by destroying and then recreating it\n // whenever the picker is opened. There is no methods to do it programatically.\n protected isOpen = signal(false);\n\n /** Set the label text for `watt-field`. */\n label = input('');\n\n /** The minimum selectable date. */\n min = input<Date>();\n\n /** The maximum selectable date. */\n max = input<Date>();\n\n /** Emits when the selected month has changed. */\n monthChange = outputFromObservable(this.valueChanges);\n\n /** Emits when the field loses focus. */\n // eslint-disable-next-line @angular-eslint/no-output-native\n blur = output<FocusEvent>();\n\n protected handleFocus = (picker: HTMLElement) => {\n this.isOpen.set(true);\n picker.showPopover();\n };\n\n protected handleBlur = (picker: HTMLElement, event: FocusEvent) => {\n if (event.relatedTarget instanceof HTMLElement && picker.contains(event.relatedTarget)) {\n const target = event.target as HTMLInputElement; // safe type assertion\n setTimeout(() => target.focus()); // keep focus on input element while using the picker\n } else {\n picker.hidePopover();\n this.isOpen.set(false);\n this.blur.emit(event);\n }\n };\n\n protected handleSelectedChange = (field: HTMLInputElement, date: Date) => {\n field.value = YearMonth.fromDate(date).toView();\n field.dispatchEvent(new Event('input', { bubbles: true }));\n setTimeout(() => field.blur());\n };\n\n // Implementation for ControlValueAccessor\n writeValue = (value: string | null) => this.control.setValue(YearMonth.fromModel(value).toView());\n setDisabledState = (x: boolean) => (x ? this.control.disable() : this.control.enable());\n registerOnTouched = (fn: () => void) => this.blur.subscribe(fn);\n registerOnChange = (fn: (value: string | null) => void) => this.valueChanges.subscribe(fn);\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nexport { WattYearMonthField } from './watt-yearmonth-field.component';\nexport { YEARMONTH_FORMAT } from './year-month';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;;;;;;;;;;;;;;;AAeG;AACH;AAGA;MACa,SAAS,CAAA;AAIQ,IAAA,IAAA;AAH5B,IAAA,OAAgB,WAAW,GAAG,WAAW;AACzC,IAAA,OAAgB,YAAY,GAAG,SAAS;AAExC,IAAA,WAAA,CAA4B,IAAwB,EAAA;QAAxB,IAAI,CAAA,IAAA,GAAJ,IAAI;;;AAGhC,IAAA,OAAO,QAAQ,GAAG,CAAC,KAAW,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;AAG9D,IAAA,OAAO,QAAQ,GAAG,CAAC,KAAa,KAC9B,IAAI,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;;AAGzE,IAAA,OAAO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CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,mBAAmB,8HAAE,kBAAkB,EAAA,QAAA,EAAA,YAAA,EAAA,MAAA,EAAA,CAAA,SAAA,EAAA,OAAA,EAAA,IAAA,EAAA,UAAA,EAAA,SAAA,EAAA,aAAA,EAAA,YAAA,CAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,aAAA,EAAA,EAAA,CAAA,iBAAA,CAAA,IAAA,EAAA,CAAA;;2FAyDxE,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBApE9B,SAAS;+BACE,sBAAsB,EAAA,aAAA,EACjB,iBAAiB,CAAC,IAAI,mBACpB,uBAAuB,CAAC,MAAM,EACpC,SAAA,EAAA;AACT,wBAAA;AACE,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,WAAW,EAAE,UAAU,CAAC,wBAAwB,CAAC;AACjD,4BAAA,KAAK,EAAE,IAAI;AACZ,yBAAA;qBACF,EACQ,OAAA,EAAA,CAAC,mBAAmB,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,EAuB1E,QAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCT,EAAA,CAAA,EAAA,MAAA,EAAA,CAAA,gRAAA,CAAA,EAAA;;;AC5GH;AACA;;;;;;;;;;;;;;;AAeG;AACH;;ACjBA;;AAEG;;;;"}
1
+ {"version":3,"file":"energinet-watt-yearmonth-field.mjs","sources":["../../../libs/watt/package/yearmonth-field/year-month.ts","../../../libs/watt/package/yearmonth-field/watt-yearmonth-field.component.ts","../../../libs/watt/package/yearmonth-field/index.ts","../../../libs/watt/package/yearmonth-field/energinet-watt-yearmonth-field.ts"],"sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport { dayjs } from '@energinet/watt/core/date';\n\n/** Represents a year and month. */\nexport class YearMonth {\n static readonly VIEW_FORMAT = 'MMMM YYYY';\n static readonly MODEL_FORMAT = 'YYYY-MM';\n\n private constructor(private date: dayjs.Dayjs | null) {}\n\n /** Creates a `YearMonth` instance from a `Date` object. */\n static fromDate = (value: Date) => new YearMonth(dayjs(value));\n\n /** Creates a `YearMonth` instance from a `string` in the view format. */\n static fromView = (value: string) =>\n new YearMonth(value ? dayjs(value, YearMonth.VIEW_FORMAT, true) : null);\n\n /** Creates a `YearMonth` instance from a `string` in the model format. */\n static fromModel = (value: string | null | undefined) =>\n new YearMonth(value ? dayjs(value, YearMonth.MODEL_FORMAT, true) : null);\n\n /** Converts the `YearMonth` instance to a `Date` object. */\n toDate = () => this.date?.toDate() ?? null;\n\n /** Converts the `YearMonth` instance to a `string` in the view format. */\n toView = () => this.date?.format(YearMonth.VIEW_FORMAT) ?? '';\n\n /** Converts the `YearMonth` instance to a `string` in the model format. */\n toModel = () => this.date?.format(YearMonth.MODEL_FORMAT) ?? null;\n}\n\nexport const YEARMONTH_FORMAT = YearMonth.MODEL_FORMAT;\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport {\n ChangeDetectionStrategy,\n Component,\n computed,\n forwardRef,\n input,\n output,\n signal,\n ViewEncapsulation,\n} from '@angular/core';\nimport {\n ControlValueAccessor,\n FormControl,\n NG_VALUE_ACCESSOR,\n ReactiveFormsModule,\n} from '@angular/forms';\nimport { outputFromObservable, takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';\nimport { map, share } from 'rxjs';\nimport { MatCalendar } from '@angular/material/datepicker';\n\nimport { dayjs } from '@energinet/watt/core/date';\nimport { WattFieldComponent } from '@energinet/watt/field';\nimport { WattButtonComponent } from '@energinet/watt/button';\n\nimport { YearMonth } from './year-month';\n\n/* eslint-disable @angular-eslint/component-class-suffix */\n@Component({\n selector: 'watt-yearmonth-field',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => WattYearMonthField),\n multi: true,\n },\n ],\n imports: [ReactiveFormsModule, MatCalendar, WattButtonComponent, WattFieldComponent],\n styles: [\n `\n watt-yearmonth-field {\n display: block;\n width: 100%;\n\n & input {\n text-transform: capitalize;\n }\n\n &:has(.watt-yearmonth-field__step-through) {\n display: flex;\n flex-align: flex-start;\n\n .watt-yearmonth-field__step-through {\n display: flex;\n }\n }\n\n &:has(.watt-yearmonth-field__has-label) {\n .watt-yearmonth-field__step-through {\n margin-top: 28px;\n }\n }\n }\n\n .watt-yearmonth-field-picker {\n position: fixed;\n position-area: bottom span-right;\n position-try-fallbacks: flip-block;\n width: 296px;\n height: 354px;\n inset: unset;\n margin: unset;\n border: 0;\n }\n `,\n ],\n template: `\n <watt-field [label]=\"label()\" [control]=\"control\" [anchorName]=\"anchorName\">\n <input\n #field\n readonly\n [formControl]=\"control\"\n (focus)=\"handleFocus(picker)\"\n (blur)=\"handleBlur(picker, $event)\"\n />\n <watt-button icon=\"date\" variant=\"icon\" (click)=\"field.focus()\" />\n <div\n #picker\n class=\"watt-elevation watt-yearmonth-field-picker\"\n popover=\"manual\"\n tabindex=\"0\"\n [style.position-anchor]=\"anchorName\"\n >\n @if (isOpen()) {\n <mat-calendar\n startView=\"multi-year\"\n [startAt]=\"selected()\"\n [selected]=\"selected()\"\n [minDate]=\"min()\"\n [maxDate]=\"max()\"\n (monthSelected)=\"handleSelectedChange(field, $event)\"\n />\n }\n </div>\n <ng-content />\n <ng-content select=\"watt-field-error\" ngProjectAs=\"watt-field-error\" />\n <ng-content select=\"watt-field-hint\" ngProjectAs=\"watt-field-hint\" />\n </watt-field>\n\n @if (canStepThroughMonths()) {\n <span\n class=\"watt-yearmonth-field__step-through\"\n [class.watt-yearmonth-field__has-label]=\"!!label()\"\n >\n <watt-button\n variant=\"icon\"\n icon=\"left\"\n (click)=\"prevMonth(field)\"\n [disabled]=\"control.disabled || isPrevMonthButtonDisabled()\"\n />\n <watt-button\n variant=\"icon\"\n icon=\"right\"\n (click)=\"nextMonth(field)\"\n [disabled]=\"control.disabled || isNextMonthButtonDisabled()\"\n />\n </span>\n }\n `,\n})\nexport class WattYearMonthField implements ControlValueAccessor {\n // Popovers exists on an entirely different layer, meaning that for anchor positioning they\n // look at the entire tree for the anchor name. This gives each field a unique anchor name.\n private static instance = 0;\n private instance = WattYearMonthField.instance++;\n protected anchorName = `--watt-yearmonth-field-popover-anchor-${this.instance}`;\n\n // The format of the inner FormControl is different from that of the outer FormControl\n protected control = new FormControl('', { nonNullable: true });\n\n // `registerOnChange` may subscribe to this component after it has been destroyed, thus\n // triggering an NG0911 from the `takeUntilDestroyed` operator. By sharing the observable,\n // the observable will already be closed and `subscribe` becomes a proper noop.\n private yearMonthChanges = this.control.valueChanges.pipe(map(YearMonth.fromView));\n private valueChanges = this.yearMonthChanges.pipe(\n map((yearMonth) => yearMonth.toModel()),\n takeUntilDestroyed(),\n share()\n );\n\n private yearMonth = toSignal(this.yearMonthChanges);\n protected selected = computed(() => this.yearMonth()?.toDate());\n\n // This is used to reset the MatCalendar component by destroying and then recreating it\n // whenever the picker is opened. There is no methods to do it programatically.\n protected isOpen = signal(false);\n\n /** Set the label text for `watt-field`. */\n label = input('');\n\n /** The minimum selectable date. */\n min = input<Date>();\n\n /** The maximum selectable date. */\n max = input<Date>();\n\n /** Enable buttons to step through months. */\n canStepThroughMonths = input(false);\n\n /** Emits when the selected month has changed. */\n monthChange = outputFromObservable(this.valueChanges);\n\n /** Emits when the field loses focus. */\n // eslint-disable-next-line @angular-eslint/no-output-native\n blur = output<FocusEvent>();\n\n isPrevMonthButtonDisabled = computed(() => this.isPrevMonthBeforeOrEqualToMinDate());\n isNextMonthButtonDisabled = computed(() => this.isNextMonthAfterOrEqualToMaxDate());\n\n protected handleFocus = (picker: HTMLElement) => {\n this.isOpen.set(true);\n picker.showPopover();\n };\n\n protected handleBlur = (picker: HTMLElement, event: FocusEvent) => {\n if (event.relatedTarget instanceof HTMLElement && picker.contains(event.relatedTarget)) {\n const target = event.target as HTMLInputElement; // safe type assertion\n setTimeout(() => target.focus()); // keep focus on input element while using the picker\n } else {\n picker.hidePopover();\n this.isOpen.set(false);\n this.blur.emit(event);\n }\n };\n\n protected handleSelectedChange = (field: HTMLInputElement, date: Date) => {\n field.value = YearMonth.fromDate(date).toView();\n field.dispatchEvent(new Event('input', { bubbles: true }));\n setTimeout(() => field.blur());\n };\n\n // Implementation for ControlValueAccessor\n writeValue = (value: string | null) => this.control.setValue(YearMonth.fromModel(value).toView());\n setDisabledState = (x: boolean) => (x ? this.control.disable() : this.control.enable());\n registerOnTouched = (fn: () => void) => this.blur.subscribe(fn);\n registerOnChange = (fn: (value: string | null) => void) => this.valueChanges.subscribe(fn);\n\n /**\n * @ignore\n */\n protected prevMonth(field: HTMLInputElement): void {\n this.changeMonth(field, -1);\n }\n /**\n * @ignore\n */\n protected nextMonth(field: HTMLInputElement): void {\n this.changeMonth(field, 1);\n }\n\n /**\n * @ignore\n */\n private changeMonth(field: HTMLInputElement, value: number): void {\n const currentDate = YearMonth.fromView(field.value).toDate();\n\n if (!currentDate) return;\n\n const newDate = dayjs(currentDate).add(value, 'month');\n this.handleSelectedChange(field, newDate.toDate());\n }\n\n /**\n * @ignore\n */\n isPrevMonthBeforeOrEqualToMinDate(): boolean {\n const min = this.min();\n\n if (!min) return false;\n\n const selectedDate = dayjs(this.selected());\n\n const isBefore = selectedDate.isBefore(min, 'month');\n const isSame = selectedDate.isSame(min, 'month');\n\n return isSame || isBefore;\n }\n\n /**\n * @ignore\n */\n isNextMonthAfterOrEqualToMaxDate(): boolean {\n const max = this.max();\n\n if (!max) return false;\n\n const selectedDate = dayjs(this.selected());\n\n const isAfter = selectedDate.isAfter(max, 'month');\n const isSame = selectedDate.isSame(max, 'month');\n\n return isSame || isAfter;\n }\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nexport { WattYearMonthField } from './watt-yearmonth-field.component';\nexport { YEARMONTH_FORMAT } from './year-month';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;;;;;;;;;;;;;;;AAeG;AACH;AAGA;MACa,SAAS,CAAA;AAIQ,IAAA,IAAA;AAH5B,IAAA,OAAgB,WAAW,GAAG,WAAW;AACzC,IAAA,OAAgB,YAAY,GAAG,SAAS;AAExC,IAAA,WAAA,CAA4B,IAAwB,EAAA;QAAxB,IAAI,CAAA,IAAA,GAAJ,IAAI;;;AAGhC,IAAA,OAAO,QAAQ,GAAG,CAAC,KAAW,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;AAG9D,IAAA,OAAO,QAAQ,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AE,UAAU,CAAC,wBAAwB,CAAC;AACjD,4BAAA,KAAK,EAAE,IAAI;AACZ,yBAAA;qBACF,EACQ,OAAA,EAAA,CAAC,mBAAmB,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,EAuC1E,QAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDT,EAAA,CAAA,EAAA,MAAA,EAAA,CAAA,+kBAAA,CAAA,EAAA;;;ACnJH;AACA;;;;;;;;;;;;;;;AAeG;AACH;;ACjBA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@energinet/watt",
4
- "version": "1.5.6",
4
+ "version": "1.5.8",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  ".": {
@@ -16,10 +16,14 @@ export declare class WattYearField implements ControlValueAccessor {
16
16
  min: import("@angular/core").InputSignal<Date | undefined>;
17
17
  /** The maximum selectable date. */
18
18
  max: import("@angular/core").InputSignal<Date | undefined>;
19
+ /** Enable buttons to step through years. */
20
+ canStepThroughYears: import("@angular/core").InputSignal<boolean>;
19
21
  /** Emits when the selected year has changed. */
20
22
  yearChange: import("@angular/core").OutputRef<string>;
21
23
  /** Emits when the field loses focus. */
22
24
  blur: import("@angular/core").OutputEmitterRef<FocusEvent>;
25
+ isPrevYearButtonDisabled: import("@angular/core").Signal<boolean>;
26
+ isNextYearButtonDisabled: import("@angular/core").Signal<boolean>;
23
27
  protected handleFocus: (picker: HTMLElement) => void;
24
28
  protected handleBlur: (picker: HTMLElement, event: FocusEvent) => void;
25
29
  protected handleSelectedChange: (field: HTMLInputElement, date: Date) => void;
@@ -27,6 +31,26 @@ export declare class WattYearField implements ControlValueAccessor {
27
31
  setDisabledState: (x: boolean) => void;
28
32
  registerOnTouched: (fn: () => void) => import("@angular/core").OutputRefSubscription;
29
33
  registerOnChange: (fn: (value: string | null) => void) => import("rxjs").Subscription;
34
+ /**
35
+ * @ignore
36
+ */
37
+ protected prevYear(field: HTMLInputElement): void;
38
+ /**
39
+ * @ignore
40
+ */
41
+ protected nextYear(field: HTMLInputElement): void;
42
+ /**
43
+ * @ignore
44
+ */
45
+ private changeYear;
46
+ /**
47
+ * @ignore
48
+ */
49
+ isPrevYearBeforeOrEqualToMinDate(): boolean;
50
+ /**
51
+ * @ignore
52
+ */
53
+ isNextYearAfterOrEqualToMaxDate(): boolean;
30
54
  static ɵfac: i0.ɵɵFactoryDeclaration<WattYearField, never>;
31
- static ɵcmp: i0.ɵɵComponentDeclaration<WattYearField, "watt-year-field", never, { "label": { "alias": "label"; "required": false; "isSignal": true; }; "min": { "alias": "min"; "required": false; "isSignal": true; }; "max": { "alias": "max"; "required": false; "isSignal": true; }; }, { "yearChange": "yearChange"; "blur": "blur"; }, never, ["*", "watt-field-error", "watt-field-hint"], true, never>;
55
+ static ɵcmp: i0.ɵɵComponentDeclaration<WattYearField, "watt-year-field", never, { "label": { "alias": "label"; "required": false; "isSignal": true; }; "min": { "alias": "min"; "required": false; "isSignal": true; }; "max": { "alias": "max"; "required": false; "isSignal": true; }; "canStepThroughYears": { "alias": "canStepThroughYears"; "required": false; "isSignal": true; }; }, { "yearChange": "yearChange"; "blur": "blur"; }, never, ["*", "watt-field-error", "watt-field-hint"], true, never>;
32
56
  }
@@ -16,10 +16,14 @@ export declare class WattYearMonthField implements ControlValueAccessor {
16
16
  min: import("@angular/core").InputSignal<Date | undefined>;
17
17
  /** The maximum selectable date. */
18
18
  max: import("@angular/core").InputSignal<Date | undefined>;
19
+ /** Enable buttons to step through months. */
20
+ canStepThroughMonths: import("@angular/core").InputSignal<boolean>;
19
21
  /** Emits when the selected month has changed. */
20
22
  monthChange: import("@angular/core").OutputRef<string | null>;
21
23
  /** Emits when the field loses focus. */
22
24
  blur: import("@angular/core").OutputEmitterRef<FocusEvent>;
25
+ isPrevMonthButtonDisabled: import("@angular/core").Signal<boolean>;
26
+ isNextMonthButtonDisabled: import("@angular/core").Signal<boolean>;
23
27
  protected handleFocus: (picker: HTMLElement) => void;
24
28
  protected handleBlur: (picker: HTMLElement, event: FocusEvent) => void;
25
29
  protected handleSelectedChange: (field: HTMLInputElement, date: Date) => void;
@@ -27,6 +31,26 @@ export declare class WattYearMonthField implements ControlValueAccessor {
27
31
  setDisabledState: (x: boolean) => void;
28
32
  registerOnTouched: (fn: () => void) => import("@angular/core").OutputRefSubscription;
29
33
  registerOnChange: (fn: (value: string | null) => void) => import("rxjs").Subscription;
34
+ /**
35
+ * @ignore
36
+ */
37
+ protected prevMonth(field: HTMLInputElement): void;
38
+ /**
39
+ * @ignore
40
+ */
41
+ protected nextMonth(field: HTMLInputElement): void;
42
+ /**
43
+ * @ignore
44
+ */
45
+ private changeMonth;
46
+ /**
47
+ * @ignore
48
+ */
49
+ isPrevMonthBeforeOrEqualToMinDate(): boolean;
50
+ /**
51
+ * @ignore
52
+ */
53
+ isNextMonthAfterOrEqualToMaxDate(): boolean;
30
54
  static ɵfac: i0.ɵɵFactoryDeclaration<WattYearMonthField, never>;
31
- static ɵcmp: i0.ɵɵComponentDeclaration<WattYearMonthField, "watt-yearmonth-field", never, { "label": { "alias": "label"; "required": false; "isSignal": true; }; "min": { "alias": "min"; "required": false; "isSignal": true; }; "max": { "alias": "max"; "required": false; "isSignal": true; }; }, { "monthChange": "monthChange"; "blur": "blur"; }, never, ["*", "watt-field-error", "watt-field-hint"], true, never>;
55
+ static ɵcmp: i0.ɵɵComponentDeclaration<WattYearMonthField, "watt-yearmonth-field", never, { "label": { "alias": "label"; "required": false; "isSignal": true; }; "min": { "alias": "min"; "required": false; "isSignal": true; }; "max": { "alias": "max"; "required": false; "isSignal": true; }; "canStepThroughMonths": { "alias": "canStepThroughMonths"; "required": false; "isSignal": true; }; }, { "monthChange": "monthChange"; "blur": "blur"; }, never, ["*", "watt-field-error", "watt-field-hint"], true, never>;
32
56
  }