Skip to content

Commit

Permalink
style: fix stylings and focus selected year in year grid
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed May 23, 2021
1 parent 305168b commit e6a9dba
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
25 changes: 13 additions & 12 deletions src/date-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ export class DatePicker extends DatePickerMixin(DatePickerMinMaxMixin(LitElement

if (changedProperties.has('startView')) {
const oldStartView = changedProperties.get('startView') as CalendarView;
const newStartView = this.startView;

if (!calendarViews.includes(this.startView)) {
if (!calendarViews.includes(newStartView)) {
this.startView = this.startView = oldStartView;
}
}
Expand Down Expand Up @@ -171,11 +172,12 @@ export class DatePicker extends DatePickerMixin(DatePickerMinMaxMixin(LitElement
protected updated(changedProperties: DatePickerChangedProperties): void {
super.updated(changedProperties);

if (this.startView === 'calendar') {
// TODO: Do stuff for calendar
} else if (this.startView === 'yearGrid') {
// TODO: Do stuff for year grid
}
// FIXME: focus element based on start view
// if (this.startView === 'calendar') {
// // TODO: Do stuff for calendar
// } else if (this.startView === 'yearGrid') {
// // TODO: Do stuff for year grid
// }
}

protected render(): TemplateResult {
Expand Down Expand Up @@ -223,12 +225,11 @@ export class DatePicker extends DatePickerMixin(DatePickerMinMaxMixin(LitElement
<div class=selected-month>${selectedMonth}</div>
<div class=selected-year>${selectedYear}</div>
<div class=month-dropdown>
<mwc-icon-button
label=${this.yearDropdownLabel}
@click=${this.#updateStartView}
>${iconArrowDropdown}</mwc-icon-button>
</div>
<mwc-icon-button
class=month-dropdown
label=${this.yearDropdownLabel}
@click=${this.#updateStartView}
>${iconArrowDropdown}</mwc-icon-button>
</div>
${
Expand Down
11 changes: 9 additions & 2 deletions src/month-calendar/stylings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ export const monthCalendarStyling = css`
.calendar-day-value,
.weekday-value {
position: relative;
font-size: 14px;
font-size: 13px;
}
th,
td {
padding: 0;
}
.weekday {
max-height: 28px;
height: 28px;
}
.weekday-value {
padding: 0 0 9px;
max-height: 16px;
height: 16px;
color: #8c8c8c;
line-height: 1;
}
.calendar-day::after,
Expand Down
10 changes: 8 additions & 2 deletions src/stylings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const datePickerStyling = css`
--date-picker-width: var(--date-picker-base-width);
--date-picker-height: var(--date-picker-base-height);
display: flex;
flex-direction: column;
min-width: var(--date-picker-width);
max-width: var(--date-picker-width);
min-height: var(--date-picker-height);
Expand Down Expand Up @@ -42,13 +44,17 @@ export const datePickerStyling = css`
.month-and-year-selector {
display: flex;
align-items: center;
font-size: 13px;
}
.selected-year,
.month-dropdown {
.selected-year {
margin: 0 0 0 4px;
}
.month-dropdown {
margin: 0 0 0 -8px;
}
.month-pagination {
display: flex;
margin: 0 -4px 0 0;
Expand Down
4 changes: 4 additions & 0 deletions src/year-grid-button/stylings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { css } from '@lit/reactive-element';
export const yearGridButtonStyling = css`
:host {
--mdc-button-horizontal-padding: 0;
--mdc-theme-primary: var(--year-grid-button-color, #000);
--mdc-theme-on-primary: var(--year-grid-button-text-color);
align-items: center;
justify-content: center;
Expand All @@ -18,6 +20,8 @@ export const yearGridButtonStyling = css`
width: 52px;
height: 28px;
padding: 0;
background-color: inherit;
color: inherit;
font: inherit;
font-size: 14px;
border-radius: 52px;
Expand Down
12 changes: 12 additions & 0 deletions src/year-grid/year-grid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../year-grid-button/app-year-grid-button.js';

import { property } from '@lit/reactive-element/decorators/property.js';
import { queryAsync } from '@lit/reactive-element/decorators/query-async.js';
import type { TemplateResult } from 'lit';
import { nothing } from 'lit';
import { html, LitElement } from 'lit';
Expand All @@ -20,6 +21,9 @@ export class YearGrid extends LitElement implements YearGridProperties {
@property({ attribute: false })
public data: YearGridData;

@queryAsync('app-year-grid-button[data-year][unelevated]')
public selectedYearGridButton!: Promise<HTMLButtonElement | null>;

public static styles = [
resetShadowRoot,
yearGridStyling,
Expand All @@ -42,6 +46,14 @@ export class YearGrid extends LitElement implements YearGridProperties {
return this.data.formatters != null;
}

protected async updated(): Promise<void> {
const selectedYearGridButton = await this.selectedYearGridButton;

if (selectedYearGridButton) {
selectedYearGridButton.scrollIntoView();
}
}

protected render(): TemplateResult | typeof nothing {
const {
date,
Expand Down

0 comments on commit e6a9dba

Please sign in to comment.