Skip to content

Commit

Permalink
Merge f22779a into bf28bca
Browse files Browse the repository at this point in the history
  • Loading branch information
haugen86 committed Dec 4, 2018
2 parents bf28bca + f22779a commit d8fe624
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/components/DateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
},
methods: {
showCalendar () {
this.$emit('showCalendar')
this.$emit('show-calendar')
},
/**
* Attempt to parse a typed date
Expand All @@ -121,7 +121,7 @@ export default {
const typedDate = Date.parse(this.input.value)
if (!isNaN(typedDate)) {
this.typedDate = this.input.value
this.$emit('typedDate', new Date(this.typedDate))
this.$emit('typed-date', new Date(this.typedDate))
}
}
},
Expand All @@ -136,13 +136,13 @@ export default {
this.typedDate = null
}
this.$emit('closeCalendar')
this.$emit('close-calendar')
},
/**
* emit a clearDate event
*/
clearDate () {
this.$emit('clearDate')
this.$emit('clear-date')
}
},
mounted () {
Expand Down
34 changes: 17 additions & 17 deletions src/components/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
:required="required"
:bootstrapStyling="bootstrapStyling"
:use-utc="useUtc"
@showCalendar="showCalendar"
@closeCalendar="close"
@typedDate="setTypedDate"
@clearDate="clearDate">
@show-calendar="showCalendar"
@close-calendar="close"
@typed-date="setTypedDate"
@clear-date="clearDate">
<slot name="afterDateInput" slot="afterDateInput"></slot>
</date-input>

Expand All @@ -48,10 +48,10 @@
:mondayFirst="mondayFirst"
:dayCellContent="dayCellContent"
:use-utc="useUtc"
@changedMonth="handleChangedMonthFromDayPicker"
@selectDate="selectDate"
@showMonthCalendar="showMonthCalendar"
@selectedDisabled="selectDisabledDate">
@changed-month="handleChangedMonthFromDayPicker"
@select-date="selectDate"
@show-month-calendar="showMonthCalendar"
@selected-disabled="selectDisabledDate">
<slot name="beforeCalendarHeader" slot="beforeCalendarHeader"></slot>
</picker-day>

Expand All @@ -68,9 +68,9 @@
:translation="translation"
:isRtl="isRtl"
:use-utc="useUtc"
@selectMonth="selectMonth"
@showYearCalendar="showYearCalendar"
@changedYear="setPageDate">
@select-month="selectMonth"
@show-year-calendar="showYearCalendar"
@changed-year="setPageDate">
<slot name="beforeCalendarHeader" slot="beforeCalendarHeader"></slot>
</picker-month>

Expand All @@ -87,8 +87,8 @@
:translation="translation"
:isRtl="isRtl"
:use-utc="useUtc"
@selectYear="selectYear"
@changedDecade="setPageDate">
@select-year="selectYear"
@changed-decade="setPageDate">
<slot name="beforeCalendarHeader" slot="beforeCalendarHeader"></slot>
</picker-year>
</div>
Expand Down Expand Up @@ -357,7 +357,7 @@ export default {
* @param {Object} date
*/
selectDisabledDate (date) {
this.$emit('selectedDisabled', date)
this.$emit('selected-disabled', date)
},
/**
* @param {Object} month
Expand All @@ -366,7 +366,7 @@ export default {
const date = new Date(month.timestamp)
if (this.allowedToShowView('day')) {
this.setPageDate(date)
this.$emit('changedMonth', month)
this.$emit('changed-month', month)
this.showDayCalendar()
} else {
this.selectDate(month)
Expand All @@ -379,7 +379,7 @@ export default {
const date = new Date(year.timestamp)
if (this.allowedToShowView('month')) {
this.setPageDate(date)
this.$emit('changedYear', year)
this.$emit('changed-year', year)
this.showMonthCalendar()
} else {
this.selectDate(year)
Expand Down Expand Up @@ -420,7 +420,7 @@ export default {
*/
handleChangedMonthFromDayPicker (date) {
this.setPageDate(date)
this.$emit('changedMonth', date)
this.$emit('changed-month', date)
},
/**
* Set the date from a typedDate event
Expand Down
35 changes: 30 additions & 5 deletions src/components/PickerDay.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="[calendarClass, 'vdp-datepicker__calendar']" v-show="showDayView" :style="calendarStyle" @mousedown.prevent>
<div :class="[calendarClass, 'vdp-datepicker__calendar']" v-show="showDayView" :style="calendarStyle" @mousedown.prevent ref="datepicker">
<slot name="beforeCalendarHeader"></slot>
<header>
<span
Expand Down Expand Up @@ -55,6 +55,31 @@ export default {
utils: constructedDateUtils
}
},
watch: {
showDayView: function () {
if (this.showDayView) {
this.$nextTick(() => {
let parent = document.querySelector('#worklist')
if (parent) {
let calendar = this.$refs.datepicker
let outOfBoundsRight = calendar.getBoundingClientRect().right > parent.getBoundingClientRect().right
let outOfBoundsBottom = calendar.getBoundingClientRect().bottom > parent.getBoundingClientRect().bottom
if (outOfBoundsBottom) {
let bottom = (calendar.getBoundingClientRect().bottom - parent.getBoundingClientRect().bottom) + 15
calendar.style.top = `-${bottom}px`
}
if (outOfBoundsRight) {
let right = (calendar.getBoundingClientRect().right - parent.getBoundingClientRect().right) + 15
calendar.style.left = `-${right}px`
}
}
})
}
}
},
computed: {
/**
* Returns an array of day names
Expand Down Expand Up @@ -157,10 +182,10 @@ export default {
methods: {
selectDate (date) {
if (date.isDisabled) {
this.$emit('selectedDisabled', date)
this.$emit('selected-disabled', date)
return false
}
this.$emit('selectDate', date)
this.$emit('select-date', date)
},
/**
* @return {Number}
Expand All @@ -172,7 +197,7 @@ export default {
* Emit an event to show the month picker
*/
showMonthCalendar () {
this.$emit('showMonthCalendar')
this.$emit('show-month-calendar')
},
/**
* Change the page month
Expand All @@ -181,7 +206,7 @@ export default {
changeMonth (incrementBy) {
let date = this.pageDate
this.utils.setMonth(date, this.utils.getMonth(date) + incrementBy)
this.$emit('changedMonth', date)
this.$emit('changed-month', date)
},
/**
* Decrement the page month
Expand Down
6 changes: 3 additions & 3 deletions src/components/PickerMonth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default {
if (month.isDisabled) {
return false
}
this.$emit('selectMonth', month)
this.$emit('select-month', month)
},
/**
* Changes the year up or down
Expand All @@ -105,7 +105,7 @@ export default {
changeYear (incrementBy) {
let date = this.pageDate
this.utils.setFullYear(date, this.utils.getFullYear(date) + incrementBy)
this.$emit('changedYear', date)
this.$emit('changed-year', date)
},
/**
* Decrements the year
Expand Down Expand Up @@ -147,7 +147,7 @@ export default {
* Emits an event that shows the year calendar
*/
showYearCalendar () {
this.$emit('showYearCalendar')
this.$emit('show-year-calendar')
},
/**
* Whether the selected date is in this month
Expand Down
4 changes: 2 additions & 2 deletions src/components/PickerYear.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ export default {
if (year.isDisabled) {
return false
}
this.$emit('selectYear', year)
this.$emit('select-year', year)
},
changeYear (incrementBy) {
let date = this.pageDate
this.utils.setFullYear(date, this.utils.getFullYear(date) + incrementBy)
this.$emit('changedDecade', date)
this.$emit('changed-decade', date)
},
previousDecade () {
if (this.isPreviousDecadeDisabled()) {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/specs/DateInput/DateInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ describe('DateInput', () => {
expect(wrapper.find('input').element.value).toEqual('2016/1/15')
})

it('emits showCalendar', () => {
it('emits show-calendar', () => {
wrapper.vm.showCalendar()
expect(wrapper.emitted().showCalendar).toBeTruthy()
expect(wrapper.emitted('show-calendar')).toBeTruthy()
})

it('adds bootstrap classes', () => {
Expand Down Expand Up @@ -76,8 +76,8 @@ describe('DateInput', () => {
expect(wrapper.find('input').element.value).toEqual('!')
})

it('triggers closeCalendar on blur', () => {
it('triggers close-calendar on blur', () => {
wrapper.find('input').trigger('blur')
expect(wrapper.emitted('closeCalendar')).toBeTruthy()
expect(wrapper.emitted('close-calendar')).toBeTruthy()
})
})
8 changes: 4 additions & 4 deletions test/unit/specs/DateInput/typedDates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('DateInput', () => {
const input = wrapper.find('input')
wrapper.vm.input.value = '2018-04-24'
input.trigger('keyup')
expect(wrapper.emitted().typedDate).toBeDefined()
expect(wrapper.emitted().typedDate[0][0]).toBeInstanceOf(Date)
expect(wrapper.emitted('typed-date')).toBeDefined()
expect(wrapper.emitted('typed-date')[0][0]).toBeInstanceOf(Date)
})

it('emits closeCalendar when return is pressed', () => {
Expand All @@ -48,7 +48,7 @@ describe('DateInput', () => {
const input = wrapper.find('input')
wrapper.setData({typedDate: 'not a date'})
input.trigger('blur')
expect(wrapper.emitted().clearDate).toBeDefined()
expect(wrapper.emitted('clear-date')).toBeDefined()
})

it('doesn\'t emit the date if typeable=false', () => {
Expand All @@ -63,6 +63,6 @@ describe('DateInput', () => {
wrapper.vm.input.value = '2018-04-24'
input.trigger('keydown')
input.trigger('keyup')
expect(wrapper.emitted().typedDate).not.toBeDefined()
expect(wrapper.emitted('typed-date')).not.toBeDefined()
})
})
12 changes: 6 additions & 6 deletions test/unit/specs/Datepicker/Datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Datepicker mounted', () => {
it('should emit selectedDisabled on a disabled timestamp', () => {
const date = new Date(2016, 9, 1)
wrapper.vm.selectDisabledDate({timestamp: date.getTime()})
expect(wrapper.emitted().selectedDisabled).toBeTruthy()
expect(wrapper.emitted('selected-disabled')).toBeTruthy()
})

it('can select a day', () => {
Expand All @@ -117,17 +117,17 @@ describe('Datepicker mounted', () => {
it('can select a month', () => {
const date = new Date(2016, 9, 9)
wrapper.vm.selectMonth({timestamp: date.getTime()})
expect(wrapper.emitted().changedMonth).toBeTruthy()
expect(wrapper.emitted().changedMonth[0][0].timestamp).toEqual(date.getTime())
expect(wrapper.emitted('changed-month')).toBeTruthy()
expect(wrapper.emitted('changed-month')[0][0].timestamp).toEqual(date.getTime())
expect(new Date(wrapper.vm.pageTimestamp).getMonth()).toEqual(date.getMonth())
expect(wrapper.vm.showDayView).toEqual(true)
})

it('can select a year', () => {
const date = new Date(2018, 9, 9)
wrapper.vm.selectYear({timestamp: date.getTime()})
expect(wrapper.emitted().changedYear).toBeTruthy()
expect(wrapper.emitted().changedYear[0][0].timestamp).toEqual(date.getTime())
expect(wrapper.emitted('changed-year')).toBeTruthy()
expect(wrapper.emitted('changed-year')[0][0].timestamp).toEqual(date.getTime())
expect(new Date(wrapper.vm.pageTimestamp).getFullYear()).toEqual(date.getFullYear())
expect(wrapper.vm.showMonthView).toEqual(true)
})
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('Datepicker mounted', () => {
it('should emit changedMonth on a month change received from PickerDay', () => {
const date = new Date(2016, 9, 1)
wrapper.vm.handleChangedMonthFromDayPicker({timestamp: date.getTime()})
expect(wrapper.emitted().changedMonth).toBeTruthy()
expect(wrapper.emitted('changed-month')).toBeTruthy()
})
})

Expand Down
8 changes: 4 additions & 4 deletions test/unit/specs/PickerDay/changeMonths.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ describe('PickerDay: changing months', () => {

it('can set the next month', () => {
wrapper.vm.nextMonth()
expect(wrapper.emitted().changedMonth).toBeTruthy()
expect(wrapper.emitted().changedMonth[0][0].getMonth()).toEqual(2)
expect(wrapper.emitted('changed-month')).toBeTruthy()
expect(wrapper.emitted('changed-month')[0][0].getMonth()).toEqual(2)
})

it('can set the previous month', () => {
wrapper.vm.previousMonth()
expect(wrapper.emitted().changedMonth).toBeTruthy()
expect(wrapper.emitted().changedMonth[0][0].getMonth()).toEqual(0)
expect(wrapper.emitted('changed-month')).toBeTruthy()
expect(wrapper.emitted('changed-month')[0][0].getMonth()).toEqual(0)
})
})
2 changes: 1 addition & 1 deletion test/unit/specs/PickerDay/disabledDates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ describe('PickerDay: disabled', () => {

it('should emit a selectedDisabled event for a disabled date', () => {
expect(wrapper.vm.selectDate({isDisabled: true})).toEqual(false)
expect(wrapper.emitted().selectedDisabled).toBeTruthy()
expect(wrapper.emitted('selected-disabled')).toBeTruthy()
})
})
4 changes: 2 additions & 2 deletions test/unit/specs/PickerDay/pickerDay.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('PickerDay: DOM', () => {

it('emits an event when selected', () => {
wrapper.vm.selectDate({isDisabled: false})
expect(wrapper.emitted().selectDate).toBeTruthy()
expect(wrapper.emitted('select-date')).toBeTruthy()
})

it('knows the current page month', () => {
Expand All @@ -36,6 +36,6 @@ describe('PickerDay: DOM', () => {
it('emits show year calendar event when clicked on the year', () => {
const yearBtn = wrapper.find('.day__month_btn')
yearBtn.trigger('click')
expect(wrapper.emitted().showMonthCalendar).toBeTruthy()
expect(wrapper.emitted('show-month-calendar')).toBeTruthy()
})
})
10 changes: 5 additions & 5 deletions test/unit/specs/PickerMonth/pickerMonth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ describe('PickerMonth', () => {

it('can set the next year', () => {
wrapper.vm.nextYear()
expect(wrapper.emitted().changedYear[0][0].getFullYear()).toEqual(2019)
expect(wrapper.emitted('changed-year')[0][0].getFullYear()).toEqual(2019)
})

it('can set the previous year', () => {
wrapper.vm.previousYear()
expect(wrapper.emitted().changedYear[0][0].getFullYear()).toEqual(2017)
expect(wrapper.emitted('changed-year')[0][0].getFullYear()).toEqual(2017)
})

it('emits date on selection', () => {
const time = new Date().getTime()
wrapper.vm.selectMonth({timestamp: time})
expect(wrapper.emitted().selectMonth).toBeTruthy()
expect(wrapper.emitted().selectMonth[0][0].timestamp).toEqual(time)
expect(wrapper.emitted('select-month')).toBeTruthy()
expect(wrapper.emitted('select-month')[0][0].timestamp).toEqual(time)
})

it('emits show year calendar event when clicked on the year', () => {
const yearBtn = wrapper.find('.month__year_btn')
yearBtn.trigger('click')
expect(wrapper.emitted().showYearCalendar).toBeTruthy()
expect(wrapper.emitted('show-year-calendar')).toBeTruthy()
})
})

0 comments on commit d8fe624

Please sign in to comment.