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