Skip to content

Commit 6de0ea2

Browse files
arthur-polidoriobrunopbrito-totvs
authored andcommitted
feat(datepicker): adiciona modos de seleção monthYear e year
Adiciona suporte a novos modos no po-datepicker: - Seleção de mês e ano (monthYear) - Seleção apenas de ano (year) Fixes: DTHFUI-12615
1 parent faab158 commit 6de0ea2

16 files changed

Lines changed: 2981 additions & 82 deletions

projects/ui/src/lib/components/po-calendar/po-calendar-base.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ export class PoCalendarBaseComponent {
243243
return this.mode === PoCalendarMode.Range;
244244
}
245245

246+
get isMonthYear() {
247+
return this.mode === PoCalendarMode.MonthYear;
248+
}
249+
250+
get isYear() {
251+
return this.mode === PoCalendarMode.Year;
252+
}
253+
254+
// Propriedade interna utilizada pelo po-datepicker.
255+
// Define o limite de anos exibidos nas variações `month-year` e `year`,
256+
// considerando a data atual como referência.
257+
//
258+
// O valor informado determina o intervalo de anos anterior e posterior
259+
// à data corrente que será disponibilizado para seleção.
260+
@Input('p-year-range-limit') yearRangeLimit?: number = 150;
261+
246262
// Propriedade que permite integrar o po-combo no componente de calendar. Implementa o template de header com `PoCombo`.
247263
@Input('p-header-template') headerTemplate?: TemplateRef<any>;
248264

projects/ui/src/lib/components/po-calendar/po-calendar-mode.enum.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
*/
88
export enum PoCalendarMode {
99
/** Modo de seleção de intervalo (data inicial e final). */
10-
Range = 'range'
10+
Range = 'range',
11+
12+
// Modo de seleção de mês e ano.
13+
MonthYear = 'month-year',
14+
15+
// Modo de seleção de ano.
16+
Year = 'year'
1117
}

projects/ui/src/lib/components/po-calendar/po-calendar.component.html

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
@if (isRange) {
1+
@if (isMonthYear) {
2+
<div class="po-calendar po-calendar-month-year">
3+
<ng-container *ngTemplateOutlet="calendarMonth"></ng-container>
4+
<ng-container *ngTemplateOutlet="calendarYear"></ng-container>
5+
</div>
6+
} @else if (isYear) {
7+
<div class="po-calendar po-calendar-year">
8+
<ng-container *ngTemplateOutlet="calendarYear"></ng-container>
9+
</div>
10+
} @else if (isRange) {
211
<div
312
class="po-calendar"
413
[class.po-calendar-with-presets]="effectivePresets().length > 0"
@@ -66,3 +75,48 @@
6675
>
6776
</po-calendar-wrapper>
6877
</ng-template>
78+
79+
<ng-template #calendarMonth>
80+
<ul class="po-calendar-months">
81+
@for (month of displayMonths; track month; let i = $index) {
82+
<li class="po-calendar-month-item">
83+
<po-button
84+
#monthOption
85+
[class.po-button-selected]="i === selectedIndexMonth"
86+
role="option"
87+
p-kind="tertiary"
88+
p-label="{{ month }}"
89+
[attr.aria-selected]="i === selectedIndexMonth"
90+
[p-tabindex]="i === focusedIndex ? 0 : -1"
91+
[p-size]="size"
92+
[p-disabled]="isMonthDisabled(i)"
93+
(p-click)="selectMonth(i, $event, true)"
94+
(keydown)="onKeydownMonth($event, i)"
95+
></po-button>
96+
</li>
97+
}
98+
</ul>
99+
</ng-template>
100+
101+
<ng-template #calendarYear>
102+
<ul class="po-calendar-years">
103+
@for (year of displayYears; track year; let i = $index) {
104+
<li class="po-calendar-year-item">
105+
<po-button
106+
#yearOption
107+
[class.po-button-selected]="i === selectedIndexYear"
108+
role="option"
109+
p-kind="tertiary"
110+
p-label="{{ year }}"
111+
[attr.aria-selected]="i === selectedIndexYear"
112+
[p-tabindex]="i === focusedIndex ? 0 : -1"
113+
[p-size]="size"
114+
[p-disabled]="isYearDisabled(year)"
115+
(p-click)="selectYear(i, $event, true, year)"
116+
(keydown)="onKeydownYear($event, i)"
117+
>
118+
</po-button>
119+
</li>
120+
}
121+
</ul>
122+
</ng-template>

0 commit comments

Comments
 (0)