Skip to content

Commit

Permalink
refactor: update logic rendering navigation buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed May 28, 2021
1 parent f94bc4c commit 4cda306
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/date-picker/date-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { calendarViews,MAX_DATE } from '../constants.js';
import { adjustOutOfRangeValue } from '../helpers/adjust-out-of-range-value.js';
import { dateValidator } from '../helpers/date-validator.js';
import { dispatchCustomEvent } from '../helpers/dispatch-custom-event.js';
import { isInTargetMonth } from '../helpers/is-in-current-month.js';
import { splitString } from '../helpers/split-string.js';
import { toDateString } from '../helpers/to-date-string.js';
import { toFormatters } from '../helpers/to-formatters.js';
Expand Down Expand Up @@ -212,16 +213,8 @@ export class DatePicker extends DatePickerMixin(DatePickerMinMaxMixin(LitElement
nothing :
html`
<div class=month-pagination>
<mwc-icon-button
data-navigation=previous
label=${this.previousMonthLabel}
@click=${this.#navigateMonth}
>${iconChevronLeft}</mwc-icon-button>
<mwc-icon-button
data-navigation=next
label=${this.nextMonthLabel}
@click=${this.#navigateMonth}
>${iconChevronRight}</mwc-icon-button>
${this.#renderNavigationButton('previous', !isInTargetMonth(min, currentDate))}
${this.#renderNavigationButton('next', !isInTargetMonth(max, currentDate))}
</div>
`
}
Expand Down Expand Up @@ -310,6 +303,21 @@ export class DatePicker extends DatePickerMixin(DatePickerMinMaxMixin(LitElement
`;
};

#renderNavigationButton = (
navigationType: 'previous' | 'next',
shouldRender = false
): TemplateResult => {
const isPreviousNavigationType = navigationType === 'previous';

return shouldRender ? html`
<mwc-icon-button
data-navigation=${navigationType}
label=${isPreviousNavigationType ? this.previousMonthLabel : this.nextMonthLabel}
@click=${this.#navigateMonth}
>${isPreviousNavigationType ? iconChevronLeft : iconChevronRight}</mwc-icon-button>
` : html`<div data-navigation=${navigationType}></div>`;
};

#navigateMonth = (ev: MouseEvent): void => {
const currentDate = this._currentDate;
const isPreviousNavigation = (
Expand Down
8 changes: 8 additions & 0 deletions src/date-picker/stylings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export const datePickerStyling = css`
display: flex;
margin: 0 -4px 0 0;
}
.month-pagination > [data-navigation="previous"],
.month-pagination > [data-navigation="next"] {
max-width: 48px;
max-height: 48px;
min-width: 48px;
min-height: 48px;
}
/** #endregion header */
.year-grid {
Expand Down

0 comments on commit 4cda306

Please sign in to comment.