Skip to content

Commit 9de26ed

Browse files
author
Nathan Reyes
committed
Add flexible navigation support
1 parent 3472792 commit 9de26ed

File tree

8 files changed

+109
-19
lines changed

8 files changed

+109
-19
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.0.9
2+
* Add support for more flexible month/year navigation
3+
* Fix popover visibility bug
4+
* Fix styling bug in date example
5+
16
## 0.0.8
27
* Add support for installing via CDN
38
* Add licensing and copyright to README

docs/components/examples/ExStyling-2.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default {
1717
const barDate = new Date();
1818
// Get start and end dates for the current week
1919
const startDate = new Date(thisMonthYear, thisMonth, barDate.getDate() - barDate.getDay());
20-
const endDate = new Date(thisMonthYear, thisMonth, startDate.getDate() + 6);
20+
const endDate = new Date(startDate);
21+
endDate.setDate(startDate.getDate() + 6);
2122
return {
2223
selectedDate: null,
2324
themeStyles: {

docs/components/index-cdn.html

100644100755
File mode changed.

src/components/Calendar.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ import CalendarPane from './CalendarPane';
3232
import Tag from './Tag';
3333
import '../assets/fonts/vcalendar/vcalendar.scss';
3434
import '../styles/lib.sass';
35-
36-
import { themeStyles, getHighlight, dot, bar } from '../utils/defaults';
35+
import {
36+
themeStyles,
37+
getHighlight,
38+
dot,
39+
bar,
40+
} from '../utils/defaults';
3741
3842
import {
3943
todayComps,
44+
pageIsBeforePage,
45+
pageIsAfterPage,
4046
getPrevPage,
4147
getNextPage,
4248
getPageBetweenPages,
@@ -82,12 +88,12 @@ export default {
8288
return this.isDoublePaned && !this.isDoublePaned_;
8389
},
8490
maxFromPage() {
85-
if (!this.isDoublePaned_) return null;
86-
return getPrevPage(this.toPage_);
91+
if (this.isDoublePaned_) return getPrevPage(this.maxPage);
92+
return this.maxPage;
8793
},
8894
minToPage() {
89-
if (!this.isDoublePaned_) return null;
90-
return getNextPage(this.fromPage_);
95+
if (this.isDoublePaned_) return getNextPage(this.minPage);
96+
return null;
9197
},
9298
themeStyles_() {
9399
// Mix user supplied styles with default styles
@@ -139,9 +145,15 @@ export default {
139145
},
140146
fromPage_(value) {
141147
this.$emit('update:fromPage', value);
148+
if (!pageIsBeforePage(value, this.toPage_)) {
149+
this.toPage_ = getNextPage(this.fromPage_);
150+
}
142151
},
143152
toPage_(value) {
144153
this.$emit('update:toPage', value);
154+
if (!pageIsAfterPage(value, this.fromPage_)) {
155+
this.fromPage_ = getPrevPage(this.toPage_);
156+
}
145157
},
146158
isDoublePaned_() {
147159
this.refreshToPage();

src/components/CalendarPane.vue

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,35 @@
3535
<slot name='header-title' :page='p'>
3636
<div
3737
class='c-title-2'
38-
:style='titleStyle'
39-
@click='moveThisMonth'>
40-
{{ p.headerLabel }}
38+
:style='titleStyle'>
39+
<div class='c-select-container'>
40+
<span class='c-select-span'>
41+
{{ p.monthLabel }}
42+
</span>
43+
<select class='c-select' v-model='monthNumber'>
44+
<option
45+
v-for='(monthLabel, i) in monthLabels'
46+
:key='monthLabel'
47+
:value='i + 1'
48+
:disabled='monthIsDisabled(i + 1)'>
49+
{{ monthLabel }}
50+
</option>
51+
</select>
52+
</div>
53+
<div class='c-select-container'>
54+
<span class='c-select-span'>
55+
{{ p.yearLabel }}
56+
</span>
57+
<select class='c-select' v-model='yearNumber'>
58+
<option
59+
v-for='year in yearList'
60+
:key='year'
61+
:value='year'
62+
:disabled='yearIsDisabled(year)'>
63+
{{ year }}
64+
</option>
65+
</select>
66+
</div>
4167
</div>
4268
</slot>
4369
</div>
@@ -134,6 +160,7 @@ import Vue from 'vue';
134160
import CalendarWeeks from './CalendarWeeks';
135161
import {
136162
todayComps,
163+
yearList,
137164
getIsLeapYear,
138165
getMonthComps,
139166
getThisMonthComps,
@@ -174,10 +201,10 @@ export default {
174201
pages: [],
175202
page_: null,
176203
transitionDirection: '',
177-
prevPageStyle: null,
178-
currPageStyle: null,
179-
nextPageStyle: null,
204+
monthNumber: 0,
205+
yearNumber: 0,
180206
touchState: {},
207+
yearList,
181208
};
182209
},
183210
computed: {
@@ -243,6 +270,24 @@ export default {
243270
},
244271
page_(val, oldVal) {
245272
this.transitionDirection = this.getTransitionDirection(oldVal, val);
273+
this.monthNumber = val.month;
274+
this.yearNumber = val.year;
275+
},
276+
monthNumber(val) {
277+
if (val !== this.page_.month) {
278+
this.move({
279+
month: val,
280+
year: this.yearNumber,
281+
});
282+
}
283+
},
284+
yearNumber(val) {
285+
if (val !== this.page_.year) {
286+
this.move({
287+
month: this.monthNumber,
288+
year: val,
289+
});
290+
}
246291
},
247292
},
248293
created() {
@@ -255,6 +300,16 @@ export default {
255300
this.preloadPages();
256301
},
257302
methods: {
303+
monthIsDisabled(month) {
304+
if (this.minPage && this.yearNumber === this.minPage.year) return month < this.minPage.month;
305+
if (this.maxPage && this.yearNumber === this.maxPage.year) return month > this.maxPage.month;
306+
return false;
307+
},
308+
yearIsDisabled(year) {
309+
if (this.minPage && year < this.minPage.year) return true;
310+
if (this.maxPage && year > this.maxPage.year) return true;
311+
return false;
312+
},
258313
touchStart(e) {
259314
const t = e.changedTouches[0];
260315
this.touchState = {
@@ -468,7 +523,6 @@ export default {
468523
+box()
469524
flex-grow: 1
470525
position: relative
471-
overflow: hidden
472526
.c-title-1
473527
position: absolute
474528
left: 0
@@ -478,16 +532,33 @@ export default {
478532
display: flex
479533
align-items: center
480534
.c-title-2
535+
+box()
481536
font-weight: $titleFontWeight
482537
font-size: $titleFontSize
483-
transition: $titleTransition
484-
cursor: pointer
485538
user-select: none
486539
margin: $titleMargin
487540
text-align: center
488541
width: 100%
489-
&:hover
490-
opacity: 0.5
542+
543+
.c-select-container
544+
position: relative
545+
transition: $titleTransition
546+
&:hover
547+
opacity: 0.5
548+
&:not(:first-child)
549+
margin-left: 5px
550+
.c-select-span
551+
height: 100%
552+
.c-select
553+
position: absolute
554+
top: 0
555+
left: 0
556+
width: 100%
557+
height: 100%
558+
border: none
559+
font-size: 1rem
560+
opacity: 0
561+
cursor: pointer
491562
&.align-left
492563
order: -1
493564
.c-title-2

src/components/Popover.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default {
6464
created() {
6565
window.addEventListener('touchstart', this.touchStart);
6666
window.addEventListener('touchend', this.touchEnd);
67+
this.visibleDelay = this.visible_;
6768
},
6869
methods: {
6970
touchStart(e) {

src/utils/defaults.js

100644100755
File mode changed.

src/utils/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import colors from './colors';
22

33
// Calendar data
44
export const daysInMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
5+
export const yearList = Array.apply(null, Array(201)).map((_, i) => 1900 + i); // eslint-disable-line prefer-spread
56
export const today = new Date();
67
export const todayComps = {
78
year: today.getFullYear(),
@@ -52,7 +53,6 @@ export const pageIsBeforePage = (page, beforePage) => comparePages(page, beforeP
5253

5354
export const pageIsAfterPage = (page, afterPage) => comparePages(page, afterPage) === 1;
5455

55-
5656
export const getMinPage = (...args) => args.reduce((prev, curr) => {
5757
if (!prev) return curr;
5858
if (!curr) return prev;

0 commit comments

Comments
 (0)