DatePicker.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 type { PropType } from 'vue'
  32. import type { Locale } from 'date-fns'
  33. import type { supportedLocales } from '~/services/utils/dateUtils'
  34. import DateUtils from '~/services/utils/dateUtils'
  35. import { useTheme } from 'vuetify'
  36. const emit = defineEmits(['update:modelValue'])
  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 theme = useTheme()
  63. const isDark = computed(() => theme.global.current.value.dark)
  64. const fnsLocale: ComputedRef<Locale> = computed(() =>
  65. DateUtils.getFnsLocale(locale.value as supportedLocales),
  66. )
  67. const dateFormatPattern: ComputedRef<string> = computed(() =>
  68. props.withTimePicker ? DateUtils.getFormatPattern(locale.value as supportedLocales) : DateUtils.getShortFormatPattern(locale.value as supportedLocales),
  69. )
  70. const today = new Date()
  71. </script>
  72. <style lang="scss">
  73. :deep(.dp__active_date) {
  74. border-radius: 12px;
  75. }
  76. :deep(.dp__today) {
  77. border-radius: 12px;
  78. border: 1px solid rgb(var(--v-theme-neutral-strong)) !important;
  79. }
  80. :deep(.dp__action_button) {
  81. height: 32px;
  82. }
  83. :deep(.date-picker-input) {
  84. background-color: rgb(var(--v-theme-surface)) !important;
  85. color: rgb(var(--v-theme-on-surface)) !important;
  86. border: 1px solid rgb(var(--v-theme-neutral)) !important;
  87. border-radius: 4px !important;
  88. &:hover {
  89. border-color: rgb(var(--v-theme-on-surface)) !important;
  90. }
  91. &:focus {
  92. border: 2px solid rgb(var(--v-theme-primary)) !important;
  93. outline: none !important;
  94. }
  95. }
  96. :deep(.dp__menu) {
  97. background-color: rgb(var(--v-theme-surface)) !important;
  98. color: rgb(var(--v-theme-on-surface)) !important;
  99. border: 1px solid rgb(var(--v-theme-neutral)) !important;
  100. }
  101. :deep(.dp__calendar_header) {
  102. background-color: rgb(var(--v-theme-surface)) !important;
  103. color: rgb(var(--v-theme-on-surface)) !important;
  104. }
  105. :deep(.dp__cell_inner) {
  106. color: rgb(var(--v-theme-on-surface)) !important;
  107. }
  108. :deep(.dp__action_cancel) {
  109. background-color: rgb(var(--v-theme-neutral)) !important;
  110. color: rgb(var(--v-theme-on-neutral)) !important;
  111. }
  112. </style>