Skip to content

Commit f31f93f

Browse files
committed
fix perfomance of buttons and improve month and year layout
1 parent 06729ad commit f31f93f

File tree

4 files changed

+131
-279
lines changed

4 files changed

+131
-279
lines changed

docs/src/pages/components/DatePicker.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<script>
5454
export default {
5555
data: () => ({
56-
date: new Date()
56+
date: new Date('2018-05-20')
5757
})
5858
};
5959
</script>

src/components/mdDatePicker/mdDatePicker.scss

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,46 +301,58 @@ $month-small-width: 280px;
301301
}
302302
}
303303

304-
.md-datepicker-years {
304+
.md-datepicker-years,
305+
.md-datepicker-months {
305306
max-height: 260px;
306307
padding: 0 8px 7px;
307308
display: flex;
308309
flex-wrap: wrap;
309310
overflow: auto;
311+
position: relative;
312+
z-index: 1;
313+
border-bottom: 1px solid rgba(#000, .12);
310314

311315
@include layout-xsmall {
312-
flex-flow: column;
316+
flex-flow: column nowrap;
317+
align-items: center;
313318
}
319+
}
314320

321+
.md-datepicker-years {
315322
.md-datepicker-year {
316323
min-width: 60px;
317324
margin: 8px 4px;
318325
padding: 0;
319326
flex: 1;
320327

328+
@include layout-xsmall {
329+
max-width: 128px;
330+
padding: 0 16px;
331+
}
332+
321333
&.md-primary {
322334
font-weight: 900;
323335

324336
@include layout-xsmall {
325-
font-size: 22px;
337+
font-size: 20px;
326338
}
327339
}
328340
}
329341
}
330342

331343
.md-datepicker-months {
332-
padding: 0 8px 7px;
333-
display: flex;
334-
flex-wrap: wrap;
335-
overflow: auto;
336-
337-
@include layout-xsmall {
338-
flex-flow: column;
339-
}
340-
341344
.md-datepicker-month {
342345
margin: 8px 4px;
343346
padding: 0;
344347
flex: 1 1 calc(33.333% - 8px);
348+
font-weight: 500;
349+
350+
@include layout-xsmall {
351+
flex: 1;
352+
}
353+
354+
&.md-primary {
355+
font-weight: 900;
356+
}
345357
}
346358
}

src/components/mdDatePicker/mdDatePicker.vue

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
'md-today': isToday(day),
5656
'md-selected': isSelectedDay(day)
5757
}"
58-
@click.native="setDate(day)"
59-
v-once>
58+
@click.native="setDate(day)">
6059
{{ day }}
6160
</md-button>
6261
</div>
@@ -70,10 +69,7 @@
7069
v-for="year in visibleYears()"
7170
:key="year"
7271
:class="[
73-
{
74-
'md-primary': isThisYear(year),
75-
'md-primary md-raised': isSelectedYear(year),
76-
},
72+
{ 'md-primary': isSelectedYear(year) },
7773
'data-' + year
7874
]"
7975
@click.native="setYear(year)">
@@ -86,10 +82,7 @@
8682
class="md-dense md-datepicker-month"
8783
v-for="(month, index) in locale.months"
8884
:key="month"
89-
:class="{
90-
'md-primary': isThisMonth(index),
91-
'md-primary md-raised': isSelectedMonth(index),
92-
}"
85+
:class="{ 'md-primary': isSelectedMonth(index) }"
9386
@click.native="setMonth(index)">
9487
{{ month }}
9588
</md-button>
@@ -124,7 +117,6 @@
124117
import isToday from 'date-fns/is_today';
125118
import isSameDay from 'date-fns/is_same_day';
126119
import isThisMonth from 'date-fns/is_this_month';
127-
import isThisYear from 'date-fns/is_this_year';
128120
import isBefore from 'date-fns/is_before';
129121
import isValidDate from 'date-fns/is_valid';
130122
@@ -160,8 +152,8 @@
160152
return years;
161153
},
162154
modelDate: this.value,
163-
currentDate: parseDate(this.value),
164-
selectedDate: parseDate(this.value),
155+
currentDate: isValidDate(this.value) ? parseDate(this.value) : Date.now(),
156+
selectedDate: isValidDate(this.value) ? parseDate(this.value) : Date.now(),
165157
createdMonths: [
166158
addMonths(this.value, -1),
167159
this.value,
@@ -202,17 +194,14 @@
202194
getDaysInMonth(month) {
203195
return getDaysInMonth(month);
204196
},
205-
isThisYear(year) {
206-
return isThisYear(setYear(new Date(), year));
207-
},
208197
isThisMonth(month) {
209198
return isThisMonth(setYear(new Date(), month));
210199
},
211200
isToday(day) {
212201
return isToday(setDate(this.currentDate, day));
213202
},
214203
isSelectedDay(day) {
215-
return isSameDay(this.selectedDate, setDate(this.currentDate, day));
204+
return isSameDay(this.selectedDate, setDate(this.selectedDate, day));
216205
},
217206
isSelectedMonth(month) {
218207
return isSameDay(this.selectedDate, setMonth(this.selectedDate, month));
@@ -231,7 +220,6 @@
231220
},
232221
setModelValue(date) {
233222
this.selectedDate = date;
234-
this.currentDate = date;
235223
this.$emit('input', date);
236224
},
237225
changeValue() {
@@ -267,12 +255,16 @@
267255
getComputedStyle(this.pickerElement).top;
268256
getComputedStyle(this.backdropElement).top;
269257
this.active = true;
258+
this.currentDate = parseDate(this.value);
259+
this.selectedDate = parseDate(this.value);
270260
},
271261
closePicker() {
272262
const cleanUp = () => {
273263
this.pickerElement.removeEventListener(transitionEndEventName, cleanUp);
274264
this.rootElement.removeChild(this.pickerElement);
275265
this.rootElement.removeChild(this.backdropElement);
266+
this.currentDate = null;
267+
this.selectedDate = null;
276268
};
277269
278270
window.removeEventListener('resize', this.calculatePopupPosition);

0 commit comments

Comments
 (0)