gitlab-org--gitlab-foss/app/assets/javascripts/vue_shared/components/pikaday.vue

83 lines
1.9 KiB
Vue
Raw Normal View History

2017-11-10 18:41:04 -05:00
<script>
import Pikaday from 'pikaday';
import { parsePikadayDate, pikadayToString } from '../../lib/utils/datefix';
export default {
2018-01-04 14:50:06 -05:00
name: 'DatePicker',
2017-11-10 18:41:04 -05:00
props: {
label: {
type: String,
required: false,
default: 'Date picker',
},
selectedDate: {
type: Date,
required: false,
2018-01-08 15:45:34 -05:00
default: null,
2017-11-10 18:41:04 -05:00
},
minDate: {
type: Date,
required: false,
2018-01-08 15:45:34 -05:00
default: null,
2017-11-10 18:41:04 -05:00
},
maxDate: {
type: Date,
required: false,
2018-01-08 15:45:34 -05:00
default: null,
2017-11-10 18:41:04 -05: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 14:50:06 -05:00
methods: {
selected(dateText) {
this.$emit('newDateSelected', this.calendar.toString(dateText));
},
toggled() {
this.$emit('hidePicker');
},
},
2017-11-10 18:41:04 -05: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 14:50:06 -05:00
{{ label }}
2017-11-10 18:41:04 -05:00
</span>
<i
class="fa fa-chevron-down"
aria-hidden="true"
>
</i>
</button>
</div>
</div>
</template>