DateRangePicker.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <!-- @see https://vue3datepicker.com/props/modes/#multi-calendars -->
  3. <VueDatePicker
  4. :model-value="modelValue"
  5. range
  6. multi-calendars
  7. auto-apply
  8. locale="fr"
  9. :start-date="today"
  10. :teleport="true"
  11. :enable-time-picker="false"
  12. close-on-scroll
  13. text-input
  14. :select-text="$t('select')"
  15. :cancel-text="$t('cancel')"
  16. input-class-name="date-range-picker-input"
  17. @update:model-value="updateDateTimeRange"
  18. class="date-range-picker"
  19. :style="style"
  20. />
  21. <!-- :alt-position="dateRangePickerAltPosition"-->
  22. </template>
  23. <script setup lang="ts">
  24. const props = defineProps({
  25. modelValue: {
  26. type: Array,
  27. required: true
  28. },
  29. maxHeight: {
  30. type: Number,
  31. required: false,
  32. default: null
  33. }
  34. })
  35. const emit = defineEmits(['update:modelValue'])
  36. const updateDateTimeRange = (value: [string, string]) => {
  37. emit('update:modelValue', value)
  38. }
  39. const today = new Date()
  40. let style = '';
  41. if (props.maxHeight !== null) {
  42. style += 'height: ' + props.maxHeight + 'px;max-height: ' + props.maxHeight + 'px;'
  43. }
  44. /**
  45. * Recalcule la position du panneau de sélection des dates si trop près du bord droit de l'écran
  46. * @param el
  47. */
  48. const dateRangePickerAltPosition = (el: HTMLElement) => ({
  49. top: el.getBoundingClientRect().bottom,
  50. left: el.getBoundingClientRect().left - 100
  51. })
  52. </script>
  53. <style scoped lang="scss">
  54. :deep(div[role="textbox"]) {
  55. height: 100% !important;
  56. max-height: 100% !important;
  57. }
  58. :deep(.dp__input_wrap) {
  59. height: 100% !important;
  60. max-height: 100% !important;
  61. }
  62. :deep(.date-range-picker-input) {
  63. height: 100% !important;
  64. max-height: 100% !important;
  65. }
  66. </style>