2017-11-10 23:41:04 +00:00
|
|
|
<script>
|
|
|
|
import Pikaday from 'pikaday';
|
|
|
|
import { parsePikadayDate, pikadayToString } from '../../lib/utils/datefix';
|
|
|
|
|
|
|
|
export default {
|
2018-01-04 19:50:06 +00:00
|
|
|
name: 'DatePicker',
|
2017-11-10 23:41:04 +00:00
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'Date picker',
|
|
|
|
},
|
|
|
|
selectedDate: {
|
|
|
|
type: Date,
|
|
|
|
required: false,
|
2018-01-08 20:45:34 +00:00
|
|
|
default: null,
|
2017-11-10 23:41:04 +00:00
|
|
|
},
|
|
|
|
minDate: {
|
|
|
|
type: Date,
|
|
|
|
required: false,
|
2018-01-08 20:45:34 +00:00
|
|
|
default: null,
|
2017-11-10 23:41:04 +00:00
|
|
|
},
|
|
|
|
maxDate: {
|
|
|
|
type: Date,
|
|
|
|
required: false,
|
2018-01-08 20:45:34 +00:00
|
|
|
default: null,
|
2017-11-10 23:41:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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),
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$el.append(this.calendar.el);
|
|
|
|
this.calendar.show();
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.calendar.destroy();
|
|
|
|
},
|
2018-01-04 19:50:06 +00:00
|
|
|
methods: {
|
|
|
|
selected(dateText) {
|
|
|
|
this.$emit('newDateSelected', this.calendar.toString(dateText));
|
|
|
|
},
|
|
|
|
toggled() {
|
|
|
|
this.$emit('hidePicker');
|
|
|
|
},
|
|
|
|
},
|
2017-11-10 23:41:04 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="pikaday-container">
|
|
|
|
<div class="dropdown open">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="dropdown-menu-toggle"
|
|
|
|
data-toggle="dropdown"
|
|
|
|
@click="toggled"
|
|
|
|
>
|
|
|
|
<span class="dropdown-toggle-text">
|
2018-01-04 19:50:06 +00:00
|
|
|
{{ label }}
|
2017-11-10 23:41:04 +00:00
|
|
|
</span>
|
|
|
|
<i
|
|
|
|
class="fa fa-chevron-down"
|
|
|
|
aria-hidden="true"
|
|
|
|
>
|
|
|
|
</i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|