DatePicker.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. :dark="isDark"
  23. :select-text="$t('select')"
  24. :cancel-text="$t('cancel')"
  25. input-class-name="date-picker-input"
  26. @update:model-value="emit('update:modelValue', $event)"
  27. />
  28. </template>
  29. <script setup lang="ts">
  30. import { useI18n } from 'vue-i18n'
  31. import { computed } from 'vue'
  32. import type { PropType, Ref, ComputedRef } from 'vue'
  33. import type { Locale } from 'date-fns'
  34. import type { supportedLocales } from '~/services/utils/dateUtils'
  35. import DateUtils from '~/services/utils/dateUtils'
  36. import { useTheme } from 'vuetify'
  37. const emit = defineEmits(['update:modelValue'])
  38. const props = defineProps({
  39. modelValue: {
  40. type: Object as PropType<Date | Array<Date> | null>,
  41. required: false,
  42. default: null,
  43. },
  44. range: {
  45. type: Boolean,
  46. default: false,
  47. },
  48. withTimePicker: {
  49. type: Boolean,
  50. default: false,
  51. },
  52. autoApply: {
  53. type: Boolean,
  54. default: true,
  55. },
  56. readonly: {
  57. type: Boolean,
  58. default: false,
  59. },
  60. })
  61. const i18n = useI18n()
  62. const locale: Ref<string> = i18n.locale
  63. const theme = useTheme()
  64. const isDark = computed(() => theme.global.current.value.dark)
  65. const fnsLocale: ComputedRef<Locale> = computed(() =>
  66. DateUtils.getFnsLocale(locale.value as supportedLocales),
  67. )
  68. const dateFormatPattern: ComputedRef<string> = computed(() =>
  69. props.withTimePicker
  70. ? DateUtils.getFormatPattern(locale.value as supportedLocales)
  71. : DateUtils.getShortFormatPattern(locale.value as supportedLocales),
  72. )
  73. const today = new Date()
  74. </script>
  75. <style lang="scss">
  76. :deep(.dp__active_date) {
  77. border-radius: 12px;
  78. }
  79. :deep(.dp__today) {
  80. border-radius: 12px;
  81. border: 1px solid rgb(var(--v-theme-neutral-strong)) !important;
  82. }
  83. :deep(.dp__action_button) {
  84. height: 32px;
  85. }
  86. :deep(.date-picker-input) {
  87. background-color: rgb(var(--v-theme-surface)) !important;
  88. color: rgb(var(--v-theme-on-surface)) !important;
  89. border: 1px solid rgb(var(--v-theme-neutral)) !important;
  90. border-radius: 4px !important;
  91. &:hover {
  92. border-color: rgb(var(--v-theme-on-surface)) !important;
  93. }
  94. &:focus {
  95. border: 2px solid rgb(var(--v-theme-primary)) !important;
  96. outline: none !important;
  97. }
  98. }
  99. :deep(.dp__menu) {
  100. background-color: rgb(var(--v-theme-surface)) !important;
  101. color: rgb(var(--v-theme-on-surface)) !important;
  102. border: 1px solid rgb(var(--v-theme-neutral)) !important;
  103. }
  104. :deep(.dp__calendar_header) {
  105. background-color: rgb(var(--v-theme-surface)) !important;
  106. color: rgb(var(--v-theme-on-surface)) !important;
  107. }
  108. :deep(.dp__cell_inner) {
  109. color: rgb(var(--v-theme-on-surface)) !important;
  110. }
  111. :deep(.dp__action_cancel) {
  112. background-color: rgb(var(--v-theme-neutral)) !important;
  113. color: rgb(var(--v-theme-on-neutral)) !important;
  114. }
  115. </style>