Skip to content

Added functionality for highlight date #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
npm-debug.log
npm-debug.log
.idea
31 changes: 29 additions & 2 deletions vue-datepicker-es6.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ table {
.passive-day {
color: #bbb;
}
.highlighted {
background: #f5bb00;
color: #FFF !important;
border-radius: 3px;
}
.checked {
background: #F50057;
color: #FFF !important;
Expand Down Expand Up @@ -334,7 +339,7 @@ table {
<li v-for="weekie in library.week">{{weekie}}</li>
</ul>
</div>
<div class="day" v-for="day,index in dayList" :key="index" @click="checkDay(day)" :class="{'checked':day.checked,'unavailable':day.unavailable,'passive-day': !(day.inMonth)}" :style="day.checked ? (option.color && option.color.checkedDay ? { background: option.color.checkedDay } : { background: '#F50057' }) : {}">{{day.value}}</div>
<div class="day" v-for="day,index in dayList" :key="index" @click="checkDay(day)" :class="{'checked':day.checked,'highlighted':day.highlighted,'unavailable':day.unavailable,'passive-day': !(day.inMonth)}" :style="day.checked ? (option.color && option.color.checkedDay ? { background: option.color.checkedDay } : { background: '#F50057' }) : {}">{{day.value}}</div>
</div>
</div>
<div class="cov-date-box list-box" v-if="showInfo.year">
Expand Down Expand Up @@ -416,6 +421,7 @@ export default {
}
}
},
highlighted: Object,
limit: {
type: Array,
default () {
Expand Down Expand Up @@ -479,6 +485,14 @@ export default {
selectedDays: []
}
},
watch: {
'highlighted': {
handler (newOption, oldOption) {
this.showDay(this.checked.currentMoment)
},
deep: true
}
},
methods: {
pad (n) {
n = Math.floor(n)
Expand All @@ -488,6 +502,7 @@ export default {
let next = null
type === 'next' ? next = moment(this.checked.currentMoment).add(1, 'M') : next = moment(this.checked.currentMoment).add(-1, 'M')
this.showDay(next)
this.$emit('change-month', next)
},
showDay (time) {
if (time === undefined || !Date.parse(time)) {
Expand All @@ -500,6 +515,7 @@ export default {
this.checked.month = moment(this.checked.currentMoment).format('MM')
this.checked.day = moment(this.checked.currentMoment).format('DD')
this.displayInfo.month = this.library.month[moment(this.checked.currentMoment).month()]
let day
let days = []
let currentMoment = this.checked.currentMoment
let firstDay = moment(currentMoment).date(1).day()
Expand All @@ -512,12 +528,14 @@ export default {
let monthDays = moment(currentMoment).daysInMonth()
let oldtime = this.checked.oldtime
for (let i = 1; i <= monthDays; ++i) {
day = moment(currentMoment.startOf('day')).date(i)
days.push({
value: i,
inMonth: true,
unavailable: false,
checked: false,
moment: moment(currentMoment).date(i)
highlighted: this.isHighlightedDate(day.startOf('day')),
moment: day
})
if (i === Math.ceil(moment(currentMoment).format('D')) && moment(oldtime, this.option.format).year() === moment(currentMoment).year() && moment(oldtime, this.option.format).month() === moment(currentMoment).month()) {
days[i - 1].checked = true
Expand Down Expand Up @@ -562,6 +580,13 @@ export default {
}
this.dayList = days
},
isHighlightedDate (date) {
if (this.highlighted === undefined || this.highlighted.dates === undefined) return false
for (let d of this.highlighted.dates) {
if (date.isSame(d)) return true
}
return false
},
checkBySelectDays (d, days) {
this.selectedDays.forEach(day => {
if (this.checked.year === moment(day).format('YYYY') && this.checked.month === moment(day).format('MM') && d === Math.ceil(moment(day).format('D'))) {
Expand Down Expand Up @@ -696,6 +721,7 @@ export default {
setYear (year) {
this.checked.currentMoment = moment(year + '-' + this.checked.month + '-' + this.checked.day)
this.showDay(this.checked.currentMoment)
this.$emit('set-year', this.checked.currentMoment)
},
setMonth (month) {
let mo = (this.library.month.indexOf(month) + 1)
Expand All @@ -704,6 +730,7 @@ export default {
}
this.checked.currentMoment = moment(this.checked.year + '-' + mo + '-' + this.checked.day)
this.showDay(this.checked.currentMoment)
this.$emit('set-month', this.checked.currentMoment)
},
showCheck () {
if (this.date.time === '') {
Expand Down