DatePicker.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!--
  2. Sélecteur de dates
  3. @see https://vue3datepicker.com/
  4. -->
  5. <template>
  6. <VueDatePicker
  7. :model-value="modelValue"
  8. :locale="locale"
  9. :format="dateFormatPattern"
  10. :format-locale="fnsLocale"
  11. :range="range"
  12. :multi-calendars="range"
  13. :enable-time-picker="withTimePicker"
  14. :auto-apply="autoApply"
  15. :auto-position="true"
  16. :start-date="today"
  17. close-on-scroll
  18. text-input
  19. :readonly="readonly"
  20. position="left"
  21. :teleport="true"
  22. :select-text="$t('select')"
  23. :cancel-text="$t('cancel')"
  24. input-class-name="date-picker-input"
  25. @update:model-value="emit('update:modelValue', $event)"
  26. />
  27. </template>
  28. <script setup lang="ts">
  29. import { useI18n } from 'vue-i18n'
  30. import type { PropType } from 'vue'
  31. import type { Locale } from 'date-fns'
  32. import type { supportedLocales } from '~/services/utils/dateUtils'
  33. import DateUtils from '~/services/utils/dateUtils'
  34. const emit = defineEmits(['update:modelValue'])
  35. const props = defineProps({
  36. modelValue: {
  37. type: Object as PropType<Date | Array<Date> | null>,
  38. required: false,
  39. default: null,
  40. },
  41. range: {
  42. type: Boolean,
  43. default: false,
  44. },
  45. withTimePicker: {
  46. type: Boolean,
  47. default: false,
  48. },
  49. autoApply: {
  50. type: Boolean,
  51. default: true,
  52. },
  53. readonly: {
  54. type: Boolean,
  55. default: false,
  56. },
  57. })
  58. const i18n = useI18n()
  59. const locale: Ref<string> = i18n.locale
  60. const fnsLocale: ComputedRef<Locale> = computed(() =>
  61. DateUtils.getFnsLocale(locale.value as supportedLocales),
  62. )
  63. const dateFormatPattern: ComputedRef<string> = computed(() =>
  64. props.withTimePicker
  65. ? DateUtils.getFormatPattern(locale.value as supportedLocales)
  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>