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>
|
2019-11-04 15:37:57 +00:00
|
|
|
<div class="field is-horizontal">
|
|
|
|
<div class="field-label is-normal">
|
|
|
|
<label class="label">{{ label }}</label>
|
|
|
|
</div>
|
|
|
|
<div class="field-body">
|
|
|
|
<div class="field is-narrow is-grouped">
|
|
|
|
<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 16:07:07 +00:00
|
|
|
:years-range="[-2,10]"
|
2019-11-04 15:37:57 +00: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 15:19:30 +00:00
|
|
|
</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;
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 15:37:57 +00:00
|
|
|
</style>
|