Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions packages/main/src/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ class Calendar extends CalendarPart {
@property()
_headerYearButtonTextSecType?: string;

@property()
_headerYearRangeButtonText?: string;

@property()
_headerYearRangeButtonTextSecType?: string;

@property({ noAttribute: true })
_pickersMode: `${CalendarPickersMode}` = "DAY_MONTH_YEAR";

Expand Down Expand Up @@ -477,16 +483,16 @@ class Calendar extends CalendarPart {
const yearFormat = DateFormat.getDateInstance({ format: "y", calendarType: this.primaryCalendarType });
const localeData = getCachedLocaleDataInstance(getLocale());
this._headerMonthButtonText = localeData.getMonthsStandAlone("wide", this.primaryCalendarType)[this._calendarDate.getMonth()];
this._headerYearButtonText = String(yearFormat.format(this._localDate, true));

if (this._currentPicker === "year") {
const rangeStart = new CalendarDateComponent(this._calendarDate, this._primaryCalendarType);
const rangeEnd = new CalendarDateComponent(this._calendarDate, this._primaryCalendarType);

rangeStart.setYear(this._currentPickerDOM._firstYear!);
rangeEnd.setYear(this._currentPickerDOM._lastYear!);

this._headerYearButtonText = `${yearFormat.format(rangeStart.toLocalJSDate(), true)} - ${yearFormat.format(rangeEnd.toLocalJSDate(), true)}`;
} else {
this._headerYearButtonText = String(yearFormat.format(this._localDate, true));
this._headerYearRangeButtonText = `${yearFormat.format(rangeStart.toLocalJSDate())} - ${yearFormat.format(rangeEnd.toLocalJSDate())}`;
}

this._secondaryCalendarType && this._setSecondaryCalendarTypeButtonText();
Expand Down Expand Up @@ -553,6 +559,7 @@ class Calendar extends CalendarPart {

_setSecondaryCalendarTypeButtonText() {
const yearFormatSecType = DateFormat.getDateInstance({ format: "y", calendarType: this._secondaryCalendarType });
this._headerYearButtonTextSecType = String(yearFormatSecType.format(this._localDate, true));

if (this._currentPicker === "year") {
const rangeStart = new CalendarDateComponent(this._calendarDate, this._primaryCalendarType);
Expand All @@ -564,9 +571,8 @@ class Calendar extends CalendarPart {
.firstDate;
const rangeEndSecType = transformDateToSecondaryType(this.primaryCalendarType, this._secondaryCalendarType, rangeEnd.valueOf() / 1000, true)
.lastDate;
this._headerYearButtonTextSecType = `${yearFormatSecType.format(rangeStartSecType.toLocalJSDate(), true)} - ${yearFormatSecType.format(rangeEndSecType.toLocalJSDate(), true)}`;
} else {
this._headerYearButtonTextSecType = String(yearFormatSecType.format(this._localDate, true));

this._headerYearRangeButtonTextSecType = `${yearFormatSecType.format(rangeStartSecType.toLocalJSDate())} - ${yearFormatSecType.format(rangeEndSecType.toLocalJSDate())}`;
}
}

Expand Down Expand Up @@ -616,6 +622,10 @@ class Calendar extends CalendarPart {
return this._currentPicker !== "year";
}

get _isHeaderYearRangeButtonHidden() {
return this._currentPicker !== "year";
}

_fireEventAndUpdateSelectedDates(selectedDates: Array<number>) {
const datesValues = selectedDates.map(timestamp => {
const calendarDate = CalendarDateComponent.fromTimestamp(timestamp * 1000, this._primaryCalendarType);
Expand Down
12 changes: 12 additions & 0 deletions packages/main/src/CalendarHeaderTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ export default function CalendarTemplate(this: Calendar) {
<span class="ui5-calheader-btn-sectext">{this._headerYearButtonTextSecType}</span>
}
</div>

<div
data-ui5-cal-header-btn-year-range
class="ui5-calheader-arrowbtn ui5-calheader-middlebtn ui5-calheader-yearrange-btn-disabled"
hidden={this._isHeaderYearRangeButtonHidden}
tabindex={-1}
>
<span>{this._headerYearRangeButtonText}</span>
{this.hasSecondaryCalendarType &&
<span class="ui5-calheader-btn-sectext">{this._headerYearRangeButtonTextSecType}</span>
}
</div>
</div>

<div
Expand Down
10 changes: 10 additions & 0 deletions packages/main/src/themes/CalendarHeader.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,13 @@
.ui5-calheader-middlebtn:focus:active::after {
border-color: var(--sapContent_ContrastFocusColor);
}

/* Todo: Remove with introduction of YearRangePicker */
.ui5-calheader-middlebtn.ui5-calheader-yearrange-btn-disabled {
pointer-events: none;
}

/* Todo: Remove with introduction of YearRangePicker */
.ui5-calheader-middlebtn.ui5-calheader-yearrange-btn-disabled:active .ui5-calheader-btn-sectext {
color: var(--sapNeutralElementColor);
}
Loading