DateRangePicker.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. :alt-position="dateRangePickerAltPosition"
  12. :enable-time-picker="false"
  13. close-on-scroll
  14. text-input
  15. :select-text="$t('select')"
  16. :cancel-text="$t('cancel')"
  17. input-class-name="date-range-picker-input"
  18. @update:model-value="updateDateTimeRange"
  19. class="date-range-picker"
  20. :style="style"
  21. />
  22. <!-- :alt-position="dateRangePickerAltPosition"-->
  23. </template>
  24. <script setup lang="ts">
  25. const props = defineProps({
  26. modelValue: {
  27. type: Array,
  28. required: true
  29. },
  30. maxHeight: {
  31. type: Number,
  32. required: false,
  33. default: null
  34. }
  35. })
  36. const emit = defineEmits(['update:modelValue'])
  37. const updateDateTimeRange = (value: [string, string]) => {
  38. emit('update:modelValue', value)
  39. }
  40. const today = new Date()
  41. let style = '';
  42. if (props.maxHeight !== null) {
  43. style += 'height: ' + props.maxHeight + 'px;max-height: ' + props.maxHeight + 'px;'
  44. }
  45. /**
  46. * Recalcule la position du panneau de sélection des dates si trop près du bord droit de l'écran
  47. * @param el
  48. */
  49. const dateRangePickerAltPosition = (el: HTMLElement) => {
  50. let xOffset = 0
  51. const fullWidth = 500
  52. const rect = el.getBoundingClientRect()
  53. if ((rect.left + fullWidth + 20) > window.innerWidth) {
  54. xOffset = window.innerWidth - (rect.left + fullWidth + 20)
  55. }
  56. return {
  57. top: rect.bottom,
  58. left: rect.left + xOffset
  59. }
  60. }
  61. </script>
  62. <style scoped lang="scss">
  63. :deep(div[role="textbox"]) {
  64. height: 100% !important;
  65. max-height: 100% !important;
  66. }
  67. :deep(.dp__input_wrap) {
  68. height: 100% !important;
  69. max-height: 100% !important;
  70. }
  71. :deep(.date-range-picker-input) {
  72. height: 100% !important;
  73. max-height: 100% !important;
  74. }
  75. </style>