2017-11-10 23:41:04 +00:00
|
|
|
<script>
|
2018-10-10 07:06:25 +00:00
|
|
|
import Pikaday from 'pikaday';
|
2018-10-24 10:51:33 +00:00
|
|
|
import { parsePikadayDate, pikadayToString } from '~/lib/utils/datetime_utility';
|
2017-11-10 23:41:04 +00:00
|
|
|
|
2018-10-10 07:06:25 +00:00
|
|
|
export default {
|
|
|
|
name: 'DatePicker',
|
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'Date picker',
|
2017-11-10 23:41:04 +00:00
|
|
|
},
|
2018-10-10 07:06:25 +00:00
|
|
|
selectedDate: {
|
|
|
|
type: Date,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
minDate: {
|
|
|
|
type: Date,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
2017-11-10 23:41:04 +00:00
|
|
|
},
|
2018-10-10 07:06:25 +00:00
|
|
|
maxDate: {
|
|
|
|
type: Date,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.calendar = new Pikaday({
|
|
|
|
field: this.$el.querySelector('.dropdown-menu-toggle'),
|
|
|
|
theme: 'gitlab-theme animate-picker',
|
|
|
|
format: 'yyyy-mm-dd',
|
|
|
|
container: this.$el,
|
|
|
|
defaultDate: this.selectedDate,
|
|
|
|
setDefaultDate: !!this.selectedDate,
|
|
|
|
minDate: this.minDate,
|
|
|
|
maxDate: this.maxDate,
|
|
|
|
parse: dateString => parsePikadayDate(dateString),
|
|
|
|
toString: date => pikadayToString(date),
|
|
|
|
onSelect: this.selected.bind(this),
|
|
|
|
onClose: this.toggled.bind(this),
|
2018-11-06 21:16:49 +00:00
|
|
|
firstDay: gon.first_day_of_week,
|
2018-10-10 07:06:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$el.append(this.calendar.el);
|
|
|
|
this.calendar.show();
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.calendar.destroy();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
selected(dateText) {
|
|
|
|
this.$emit('newDateSelected', this.calendar.toString(dateText));
|
2017-11-10 23:41:04 +00:00
|
|
|
},
|
2018-10-10 07:06:25 +00:00
|
|
|
toggled() {
|
|
|
|
this.$emit('hidePicker');
|
2018-01-04 19:50:06 +00:00
|
|
|
},
|
2018-10-10 07:06:25 +00:00
|
|
|
},
|
|
|
|
};
|
2017-11-10 23:41:04 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="pikaday-container">
|
|
|
|
<div class="dropdown open">
|
2018-11-16 20:07:38 +00:00
|
|
|
<button type="button" class="dropdown-menu-toggle" data-toggle="dropdown" @click="toggled">
|
|
|
|
<span class="dropdown-toggle-text"> {{ label }} </span>
|
|
|
|
<i class="fa fa-chevron-down" aria-hidden="true"> </i>
|
2017-11-10 23:41:04 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|