2019-10-05 21:17:18 +02:00
|
|
|
<docs>
|
|
|
|
### Datetime Picker
|
|
|
|
|
|
|
|
> We're wrapping the Buefy datepicker & an input
|
|
|
|
|
|
|
|
### Defaults
|
|
|
|
- step: 10
|
|
|
|
|
|
|
|
### Example
|
|
|
|
```vue
|
|
|
|
<DateTimePicker :value="new Date()" />
|
|
|
|
```
|
|
|
|
</docs>
|
2019-06-07 17:19:30 +02:00
|
|
|
<template>
|
2019-11-04 16:37:57 +01:00
|
|
|
<div class="field is-horizontal">
|
|
|
|
<div class="field-label is-normal">
|
|
|
|
<label class="label">{{ label }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-body">
|
2019-11-15 18:36:47 +01:00
|
|
|
<div class="field is-narrow is-grouped calendar-picker">
|
2019-11-04 16:37:57 +01:00
|
|
|
<b-datepicker
|
|
|
|
:day-names="localeShortWeekDayNamesProxy"
|
|
|
|
:month-names="localeMonthNamesProxy"
|
|
|
|
:first-day-of-week="parseInt($t('firstDayOfWeek'), 10)"
|
|
|
|
:min-date="minDate"
|
|
|
|
v-model="dateWithoutTime"
|
|
|
|
:placeholder="$t('Click to select')"
|
2019-11-04 17:07:07 +01:00
|
|
|
:years-range="[-2,10]"
|
2019-11-04 16:37:57 +01:00
|
|
|
icon="calendar"
|
|
|
|
class="is-narrow"
|
|
|
|
/>
|
|
|
|
<b-timepicker
|
|
|
|
placeholder="Type or select a time..."
|
|
|
|
icon="clock"
|
|
|
|
v-model="dateWithTime"
|
|
|
|
size="is-small"
|
|
|
|
inline>
|
|
|
|
</b-timepicker>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-06-07 17:19:30 +02:00
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
2019-10-11 18:41:29 +02:00
|
|
|
import { localeMonthNames, localeShortWeekDayNames } from '@/utils/datetime';
|
|
|
|
|
2019-09-26 16:38:58 +02:00
|
|
|
@Component
|
2019-06-07 17:19:30 +02:00
|
|
|
export default class DateTimePicker extends Vue {
|
2019-10-05 21:17:18 +02:00
|
|
|
/**
|
|
|
|
* @model
|
|
|
|
* The DateTime value
|
|
|
|
*/
|
|
|
|
@Prop({ required: true, type: Date, default: () => new Date() }) value!: Date;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What's shown besides the picker
|
|
|
|
*/
|
2019-06-07 17:19:30 +02:00
|
|
|
@Prop({ required: false, type: String, default: 'Datetime' }) label!: string;
|
2019-10-05 21:17:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The step for the time input
|
|
|
|
*/
|
2019-06-07 17:19:30 +02:00
|
|
|
@Prop({ required: false, type: Number, default: 1 }) step!: number;
|
|
|
|
|
2019-10-11 18:41:29 +02:00
|
|
|
/**
|
|
|
|
* Earliest date available for selection
|
|
|
|
*/
|
|
|
|
@Prop({ required: false, type: Date, default: null }) minDate!: Date;
|
|
|
|
|
2019-10-14 19:29:18 +02:00
|
|
|
dateWithoutTime: Date = this.value;
|
|
|
|
dateWithTime: Date = this.dateWithoutTime;
|
2019-06-07 17:19:30 +02:00
|
|
|
|
2019-10-11 18:41:29 +02:00
|
|
|
localeShortWeekDayNamesProxy = localeShortWeekDayNames();
|
|
|
|
localeMonthNamesProxy = localeMonthNames();
|
|
|
|
|
2019-10-14 19:29:18 +02:00
|
|
|
@Watch('value')
|
|
|
|
updateValue() {
|
|
|
|
this.dateWithoutTime = this.value;
|
|
|
|
this.dateWithTime = this.dateWithoutTime;
|
2019-06-07 17:19:30 +02:00
|
|
|
}
|
|
|
|
|
2019-10-14 19:29:18 +02:00
|
|
|
@Watch('dateWithoutTime')
|
|
|
|
updateDateWithoutTimeWatcher() {
|
2019-09-18 17:32:37 +02:00
|
|
|
this.updateDateTime();
|
|
|
|
}
|
|
|
|
|
2019-10-14 19:29:18 +02:00
|
|
|
@Watch('dateWithTime')
|
|
|
|
updateDateWithTimeWatcher() {
|
|
|
|
this.updateDateTime();
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
updateDateTime() {
|
2019-10-05 21:17:18 +02:00
|
|
|
/**
|
|
|
|
* Returns the updated date
|
|
|
|
*
|
2019-10-09 12:54:09 +02:00
|
|
|
* @type {Date}
|
2019-10-05 21:17:18 +02:00
|
|
|
*/
|
2019-10-14 19:29:18 +02:00
|
|
|
this.dateWithoutTime.setHours(this.dateWithTime.getHours());
|
|
|
|
this.dateWithoutTime.setMinutes(this.dateWithTime.getMinutes());
|
|
|
|
this.$emit('input', this.dateWithoutTime);
|
2019-06-07 17:19:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2019-10-14 19:29:18 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.timepicker {
|
|
|
|
/deep/ .dropdown-content {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 18:36:47 +01:00
|
|
|
|
|
|
|
.calendar-picker {
|
|
|
|
/deep/ .dropdown-menu {
|
|
|
|
z-index: 200;
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 16:37:57 +01:00
|
|
|
</style>
|