All files / components SingleDatePicker.vue

0% Statements 0/35
0% Branches 0/24
0% Functions 0/7
0% Lines 0/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                                                                                     
<template>
  <calendar
    :attributes='attributes_'
    @dayselect='selectDay'
    v-bind='$attrs'
    v-on='$listeners'>
  </calendar>
</template>
 
<script>
import Calendar from './Calendar';
import defaults from '../utils/defaults';
import { singleHasValue, singleValuesAreEqual } from '../utils/pickerProfiles';

export default {
  components: {
    Calendar,
  },
  props: {
    value: { type: Date, default: null },
    selectColor: { type: String, default: () => defaults.datePickerSelectColor },
    selectAttribute: Object,
    disabledAttribute: Object,
    attributes: Array,
  },
  computed: {
    selectAttribute_() {
      if (!singleHasValue(this.value)) return null;
      return {
        ...defaults.datePickerSelectAttribute(this.selectColor),
        ...this.selectAttribute,
        dates: [this.value],
      };
    },
    attributes_() {
      const attributes = [...(this.attributes || [])];
      if (this.selectAttribute_) attributes.push(this.selectAttribute_);
      if (this.disabledAttribute) attributes.push(this.disabledAttribute);
      return attributes;
    },
  },
  methods: {
    selectDay(day) {
      // Done if day selection is invalid
      if (this.disabledAttribute && this.disabledAttribute.includesDay(day)) return;
      this.$emit('input', singleValuesAreEqual(day.date, this.value) ? null : day.date);
    },
  },
};
</script>