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">
|
2019-11-15 17:36:47 +00:00
|
|
|
<div class="field is-narrow is-grouped calendar-picker">
|
2019-11-04 15:37:57 +00:00
|
|
|
<b-datepicker
|
|
|
|
:day-names="localeShortWeekDayNamesProxy"
|
|
|
|
:month-names="localeMonthNamesProxy"
|
|
|
|
:first-day-of-week="parseInt($t('firstDayOfWeek'), 10)"
|
2019-12-09 23:10:12 +00:00
|
|
|
:min-date="minDatetime"
|
|
|
|
:max-date="maxDatetime"
|
|
|
|
v-model="dateWithTime"
|
2019-11-04 15:37:57 +00:00
|
|
|
: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"
|
2019-12-09 23:10:12 +00:00
|
|
|
:min-time="minDatetime"
|
|
|
|
:max-time="maxDatetime"
|
2019-11-04 15:37:57 +00:00
|
|
|
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
|
|
|
|
*/
|
2019-12-09 23:10:12 +00:00
|
|
|
@Prop({ required: false, type: Date, default: null }) minDatetime!: Date;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Latest date available for selection
|
|
|
|
*/
|
|
|
|
@Prop({ required: false, type: Date, default: null }) maxDatetime!: Date;
|
2019-10-11 16:41:29 +00:00
|
|
|
|
2019-12-09 23:10:12 +00:00
|
|
|
dateWithTime: Date = this.value;
|
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() {
|
2019-12-09 23:10:12 +00:00
|
|
|
this.dateWithTime = this.value;
|
2019-09-18 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
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-12-09 23:10:12 +00:00
|
|
|
this.$emit('input', this.dateWithTime);
|
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-15 17:36:47 +00:00
|
|
|
|
|
|
|
.calendar-picker {
|
|
|
|
/deep/ .dropdown-menu {
|
|
|
|
z-index: 200;
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 15:37:57 +00:00
|
|
|
</style>
|