Skip to content

Commit be6b001

Browse files
authored
refactor!: update date-picker overlay content to use CSS grid (#9360)
1 parent a8c85a6 commit be6b001

10 files changed

+100
-119
lines changed

packages/date-picker/src/vaadin-date-picker-month-scroller.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ stylesTemplate.innerHTML = `
1212
<style>
1313
:host {
1414
--vaadin-infinite-scroller-item-height: 270px;
15-
position: absolute;
16-
top: 0;
17-
left: 0;
18-
right: 0;
19-
bottom: 0;
20-
height: 100%;
15+
grid-area: months;
16+
height: auto;
2117
}
2218
</style>
2319
`;

packages/date-picker/src/vaadin-date-picker-overlay-content-mixin.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ export const DatePickerOverlayContentMixin = (superClass) =>
7575
value: '(min-width: 375px)',
7676
},
7777

78-
_translateX: {
79-
observer: '_translateXChanged',
80-
},
81-
8278
_yearScrollerWidth: {
8379
value: 50,
8480
},
@@ -710,11 +706,7 @@ export const DatePickerOverlayContentMixin = (superClass) =>
710706

711707
/** @private */
712708
_toggleYearScroller() {
713-
if (this._isYearScrollerVisible()) {
714-
this._closeYearScroller();
715-
} else {
716-
this._openYearScroller();
717-
}
709+
this.toggleAttribute('years-visible');
718710
}
719711

720712
/** @private */
@@ -729,19 +721,6 @@ export const DatePickerOverlayContentMixin = (superClass) =>
729721
this._translateX = this._yearScrollerWidth;
730722
}
731723

732-
/** @private */
733-
_isYearScrollerVisible() {
734-
return this._translateX < this._yearScrollerWidth / 2;
735-
}
736-
737-
/** @private */
738-
_translateXChanged(x) {
739-
if (!this._desktopMode) {
740-
this._monthScroller.style.transform = `translateX(${x - this._yearScrollerWidth}px)`;
741-
this._yearScroller.style.transform = `translateX(${x}px)`;
742-
}
743-
}
744-
745724
/** @private */
746725
_yearAfterXMonths(months) {
747726
return dateAfterXMonths(months).getFullYear();

packages/date-picker/src/vaadin-date-picker-overlay-content-styles.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,37 @@ import { css } from 'lit';
77

88
export const overlayContentStyles = css`
99
:host {
10-
display: flex;
11-
flex-direction: column;
10+
display: grid;
11+
grid-template-areas:
12+
'header header'
13+
'months years'
14+
'toolbar years';
15+
grid-template-columns: minmax(0, 1fr) 0;
1216
height: 100%;
13-
width: 100%;
1417
outline: none;
1518
}
1619
20+
:host([desktop]) {
21+
grid-template-columns: minmax(0, 1fr) auto;
22+
}
23+
24+
:host([fullscreen][years-visible]) {
25+
grid-template-columns: minmax(0, 1fr) auto;
26+
}
27+
28+
:host([fullscreen]) :is([part='toggle-button'], [part='clear-button'], [part='label']) {
29+
display: none;
30+
}
31+
1732
[part='overlay-header'] {
18-
display: flex;
19-
flex-shrink: 0;
20-
flex-wrap: nowrap;
33+
display: none;
34+
grid-area: header;
2135
align-items: center;
36+
justify-content: center;
2237
}
2338
24-
:host(:not([fullscreen])) [part='overlay-header'] {
25-
display: none;
39+
:host([fullscreen]) [part='overlay-header'] {
40+
display: flex;
2641
}
2742
2843
[part='label'] {
@@ -38,20 +53,16 @@ export const overlayContentStyles = css`
3853
}
3954
4055
#scrollers {
41-
display: flex;
42-
height: 100%;
43-
width: 100%;
44-
position: relative;
45-
overflow: hidden;
56+
display: contents;
4657
}
4758
48-
:host([desktop]) ::slotted([slot='months']) {
49-
right: 50px;
50-
transform: none !important;
59+
::slotted([slot='years']) {
60+
visibility: hidden;
5161
}
5262
53-
:host([desktop]) ::slotted([slot='years']) {
54-
transform: none !important;
63+
:host([desktop]) ::slotted([slot='years']),
64+
:host([years-visible]) ::slotted([slot='years']) {
65+
visibility: visible;
5566
}
5667
5768
:host(.animate) ::slotted([slot='months']),
@@ -61,8 +72,13 @@ export const overlayContentStyles = css`
6172
6273
[part='toolbar'] {
6374
display: flex;
75+
grid-area: toolbar;
6476
justify-content: space-between;
6577
z-index: 2;
6678
flex-shrink: 0;
6779
}
80+
81+
:host([fullscreen]) [part='toolbar'] {
82+
grid-area: header;
83+
}
6884
`;

packages/date-picker/src/vaadin-date-picker-year-scroller.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ stylesTemplate.innerHTML = `
1313
--vaadin-infinite-scroller-item-height: 80px;
1414
width: 50px;
1515
display: block;
16-
height: 100%;
17-
position: absolute;
18-
right: 0;
19-
transform: translateX(100%);
16+
position: relative;
17+
grid-area: years;
18+
height: auto;
2019
-webkit-tap-highlight-color: transparent;
2120
-webkit-user-select: none;
2221
user-select: none;

packages/date-picker/src/vaadin-infinite-scroller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ template.innerHTML = `
2121
height: 100%;
2222
overflow: auto;
2323
outline: none;
24-
margin-right: -40px;
2524
-webkit-overflow-scrolling: touch;
2625
overflow-x: hidden;
26+
scrollbar-width: none;
2727
}
2828
2929
#scroller.notouchscroll {
@@ -38,7 +38,6 @@ template.innerHTML = `
3838
position: absolute;
3939
width: var(--vaadin-infinite-scroller-buffer-width, 100%);
4040
box-sizing: border-box;
41-
padding-right: 40px;
4241
top: var(--vaadin-infinite-scroller-buffer-offset, 0);
4342
}
4443
</style>

packages/date-picker/test/overlay-content.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('overlay', () => {
2424
beforeEach(async () => {
2525
overlay = fixtureSync(`
2626
<vaadin-date-picker-overlay-content
27-
style="position: absolute; top: 0"
27+
style="position: absolute; top: 0; min-width: 300px"
2828
scroll-duration="0"
2929
></vaadin-date-picker-overlay-content>
3030
`);
-1.2 KB
Loading
-1.28 KB
Loading

packages/date-picker/theme/lumo/vaadin-date-picker-overlay-content-styles.js

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ registerStyles(
2020
cursor: default;
2121
}
2222
23+
:host([dir='rtl']) {
24+
background-position: top left;
25+
}
26+
2327
::slotted([slot='months']) {
2428
/* Month calendar height:
2529
header height + margin-bottom
@@ -39,36 +43,25 @@ registerStyles(
3943
-webkit-mask-image: linear-gradient(transparent, #000 10%, #000 85%, transparent);
4044
mask-image: linear-gradient(transparent, #000 10%, #000 85%, transparent);
4145
position: relative;
42-
margin-right: 57px;
4346
}
4447
4548
::slotted([slot='years']) {
4649
/* TODO get rid of fixed magic number */
47-
--vaadin-infinite-scroller-buffer-width: 97px;
50+
--vaadin-infinite-scroller-buffer-width: 57px;
4851
width: 57px;
49-
height: auto;
50-
top: 0;
51-
bottom: 0;
5252
font-size: var(--lumo-font-size-s);
5353
box-shadow: inset 2px 0 4px 0 var(--lumo-shade-5pct);
5454
-webkit-mask-image: linear-gradient(transparent, #000 35%, #000 65%, transparent);
5555
mask-image: linear-gradient(transparent, #000 35%, #000 65%, transparent);
5656
cursor: var(--lumo-clickable-cursor);
5757
}
5858
59-
::slotted([slot='years']:hover) {
60-
--_lumo-date-picker-year-opacity: 1;
61-
}
62-
63-
/* TODO unsupported selector */
64-
#scrollers {
65-
position: static;
66-
display: block;
59+
:host([dir='rtl']) ::slotted([slot='years']) {
60+
box-shadow: inset -2px 0 4px 0 var(--lumo-shade-5pct);
6761
}
6862
69-
/* TODO fix this in vaadin-date-picker that it adapts to the width of the year scroller */
70-
:host([desktop]) ::slotted([slot='months']) {
71-
right: auto;
63+
::slotted([slot='years']:hover) {
64+
--_lumo-date-picker-year-opacity: 1;
7265
}
7366
7467
/* Year scroller position indicator */
@@ -84,10 +77,14 @@ registerStyles(
8477
z-index: 1;
8578
}
8679
80+
:host([dir='rtl']) ::slotted([slot='years'])::before {
81+
right: 0;
82+
transform: translate(75%, -50%) rotate(45deg);
83+
}
84+
8785
[part='toolbar'] {
8886
padding: var(--lumo-space-s);
8987
border-bottom-left-radius: var(--lumo-border-radius-l);
90-
margin-right: 57px;
9188
}
9289
9390
[part='toolbar'] ::slotted(vaadin-button) {
@@ -97,26 +94,15 @@ registerStyles(
9794
/* Narrow viewport mode (fullscreen) */
9895
9996
:host([fullscreen]) [part='toolbar'] {
100-
order: -1;
10197
background-color: var(--lumo-base-color);
10298
}
10399
104100
:host([fullscreen]) [part='overlay-header'] {
105-
order: -2;
106101
height: var(--lumo-size-m);
107102
padding: var(--lumo-space-s);
108-
position: absolute;
109-
left: 0;
110-
right: 0;
111103
justify-content: center;
112104
}
113105
114-
:host([fullscreen]) [part='toggle-button'],
115-
:host([fullscreen]) [part='clear-button'],
116-
[part='overlay-header'] [part='label'] {
117-
display: none;
118-
}
119-
120106
/* Very narrow screen (year scroller initially hidden) */
121107
122108
[part='years-toggle-button'] {
@@ -150,14 +136,10 @@ registerStyles(
150136
151137
/* TODO make date-picker adapt to the width of the years part */
152138
::slotted([slot='years']) {
153-
--vaadin-infinite-scroller-buffer-width: 90px;
139+
--vaadin-infinite-scroller-buffer-width: 50px;
154140
width: 50px;
155141
background-color: var(--lumo-shade-5pct);
156142
}
157-
158-
:host([years-visible]) ::slotted([slot='months']) {
159-
padding-left: 50px;
160-
}
161143
}
162144
`,
163145
{ moduleId: 'lumo-date-picker-overlay-content' },

0 commit comments

Comments
 (0)