Skip to content

fix(ui5-calendar): show year range in YearPicker header #11450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
28 changes: 20 additions & 8 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,15 @@ 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(), true)} - ${yearFormat.format(rangeEnd.toLocalJSDate(), true)}`;
}

this._secondaryCalendarType && this._setSecondaryCalendarTypeButtonText();
Expand Down Expand Up @@ -553,6 +558,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 +570,7 @@ 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(), true)} - ${yearFormatSecType.format(rangeEndSecType.toLocalJSDate(), true)}`;
}
}

Expand Down Expand Up @@ -597,11 +601,19 @@ class Calendar extends CalendarPart {
}

/**
* The year button is hidden when the year picker is shown
* The year range button is shown only in the year picker
* @private
*/
get _isHeaderYearRangeButtonHidden(): boolean {
return this._currentPicker !== "year";
}

/**
* The year button is shown only in the day & month pickers
* @private
*/
get _isHeaderYearButtonHidden(): boolean {
return this._currentPicker === "year";
return !(this._currentPicker === "day" || this._currentPicker === "month");
}

get _isDayPickerHidden() {
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
2 changes: 1 addition & 1 deletion packages/main/src/YearPickerTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function YearPickerTemplate(this: YearPicker) {
</span>
{
year.yearInSecType &&
<span class="ui5-yp-year-sec-type">
<span class="ui5-yp-item-sec-type">
{year.yearInSecType}
</span>
}
Expand Down
20 changes: 19 additions & 1 deletion packages/main/src/themes/CalendarHeader.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@
user-select: none;
}

/* Todo: Remove with introduction of YearRangePicker */
.ui5-calheader-middlebtn.ui5-calheader-yearrange-btn-disabled:hover,
.ui5-calheader-middlebtn.ui5-calheader-yearrange-btn-disabled:active,
.ui5-calheader-middlebtn.ui5-calheader-yearrange-btn-disabled:focus,
.ui5-calheader-middlebtn.ui5-calheader-yearrange-btn-disabled:focus:active,
.ui5-calheader-middlebtn.ui5-calheader-yearrange-btn-disabled {
cursor: default;
outline: none;
background-color: var(--sapButton_Lite_Background);
color: var(--sapButton_Lite_TextColor);
border: transparent;
box-shadow: none;
}

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

.ui5-calheader-arrowbtn.ui5-calheader-arrowbtn-disabled:hover,
.ui5-calheader-arrowbtn.ui5-calheader-arrowbtn-disabled:active,
.ui5-calheader-arrowbtn.ui5-calheader-arrowbtn-disabled:focus,
Expand Down Expand Up @@ -73,7 +92,6 @@

.ui5-calheader-arrowbtn:not(:active) .ui5-calheader-btn-sectext {
color: var(--sapNeutralElementColor);
font-size: var(--sapFontSmallSize);
}

.ui5-calheader-arrowicon {
Expand Down
Loading