DatePicker.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!--
  2. Sélecteur de dates
  3. @see https://vue3datepicker.com/
  4. -->
  5. <template>
  6. <div class="date-picker">
  7. <VueDatePicker
  8. :model-value="modelValue"
  9. :locale="locale"
  10. :format="dateFormatPattern"
  11. :format-locale="fnsLocale"
  12. :range="range"
  13. :multi-calendars="range"
  14. :enable-time-picker="withTimePicker"
  15. :auto-apply="autoApply"
  16. :auto-position="true"
  17. :start-date="today"
  18. close-on-scroll
  19. text-input
  20. :readonly="readonly"
  21. position="left"
  22. :teleport="true"
  23. :select-text="$t('select')"
  24. :cancel-text="$t('cancel')"
  25. input-class-name="date-picker-input"
  26. class="mb-6"
  27. @update:model-value="$emit('update:modelValue', $event)"
  28. />
  29. </div>
  30. </template>
  31. <script setup lang="ts">
  32. import { useI18n } from 'vue-i18n'
  33. import type { PropType } from 'vue'
  34. import type { Locale } from 'date-fns'
  35. import type { supportedLocales } from '~/services/utils/dateUtils';
  36. import DateUtils from '~/services/utils/dateUtils'
  37. const props = defineProps({
  38. modelValue: {
  39. type: Object as PropType<Date | Array<Date> | null>,
  40. required: false,
  41. default: null,
  42. },
  43. range: {
  44. type: Boolean,
  45. default: false,
  46. },
  47. withTimePicker: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. autoApply: {
  52. type: Boolean,
  53. default: true,
  54. },
  55. readonly: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. })
  60. const i18n = useI18n()
  61. const locale: Ref<string> = i18n.locale
  62. const fnsLocale: ComputedRef<Locale> = computed(() =>
  63. DateUtils.getFnsLocale(locale.value as supportedLocales),
  64. )
  65. const dateFormatPattern: ComputedRef<string> = computed(() =>
  66. DateUtils.getShortFormatPattern(locale.value as supportedLocales),
  67. )
  68. const today = new Date()
  69. </script>
  70. <style lang="scss">
  71. :deep(.dp__active_date) {
  72. border-radius: 12px;
  73. }
  74. :deep(.dp__today) {
  75. border-radius: 12px;
  76. border: 1px solid rgb(var(--v-theme-neutral-strong)) !important;
  77. }
  78. :deep(.dp__action_button) {
  79. height: 32px;
  80. }
  81. </style>