acd531f69e
Release / release (push) Successful in 2m38s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié --------- Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-authored-by: matthieu <matthieu@yuno.malio.fr> Reviewed-on: #56 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
134 lines
3.5 KiB
Vue
134 lines
3.5 KiB
Vue
<template>
|
|
<CalendarField
|
|
:id="id"
|
|
:display-value="displayValue"
|
|
:sync-to="datePart"
|
|
:name="name"
|
|
:label="label"
|
|
:placeholder="placeholder"
|
|
:required="required"
|
|
:disabled="disabled"
|
|
:readonly="readonly"
|
|
:hint="hint"
|
|
:error="error"
|
|
:success="success"
|
|
:clearable="clearable"
|
|
:input-class="inputClass"
|
|
:label-class="labelClass"
|
|
:group-class="groupClass"
|
|
v-bind="$attrs"
|
|
@clear="onClear"
|
|
>
|
|
<template #default="{ currentMonth, currentYear }">
|
|
<MonthGrid
|
|
:month="currentMonth"
|
|
:year="currentYear"
|
|
:selected-date="datePart"
|
|
:min="min?.slice(0, 10)"
|
|
:max="max?.slice(0, 10)"
|
|
@select="onSelectDay"
|
|
/>
|
|
<div class="mt-4">
|
|
<MalioTimePicker
|
|
:model-value="timeValue || null"
|
|
label="Heure"
|
|
:clearable="false"
|
|
static-popover
|
|
@update:model-value="onTimeChange"
|
|
/>
|
|
</div>
|
|
</template>
|
|
</CalendarField>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import {computed, ref, watch} from 'vue'
|
|
import CalendarField from './internal/CalendarField.vue'
|
|
import MonthGrid from './internal/MonthGrid.vue'
|
|
import MalioTimePicker from '../time/TimePicker.vue'
|
|
import {formatTime} from '../time/composables/timeFormat'
|
|
import {composeDateTime, formatIsoDateTimeToDisplay, isValidIsoDateTime, splitDateTime} from './composables/datetimeFormat'
|
|
|
|
defineOptions({name: 'MalioDateTime', inheritAttrs: false})
|
|
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
id?: string
|
|
name?: string
|
|
label?: string
|
|
modelValue?: string | null
|
|
placeholder?: string
|
|
required?: boolean
|
|
disabled?: boolean
|
|
readonly?: boolean
|
|
hint?: string
|
|
error?: string
|
|
success?: string
|
|
min?: string
|
|
max?: string
|
|
clearable?: boolean
|
|
inputClass?: string
|
|
labelClass?: string
|
|
groupClass?: string
|
|
}>(),
|
|
{
|
|
id: '',
|
|
name: '',
|
|
label: '',
|
|
modelValue: undefined,
|
|
placeholder: 'JJ/MM/AAAA HH:MM',
|
|
required: false,
|
|
disabled: false,
|
|
readonly: false,
|
|
hint: '',
|
|
error: '',
|
|
success: '',
|
|
min: undefined,
|
|
max: undefined,
|
|
clearable: true,
|
|
inputClass: '',
|
|
labelClass: '',
|
|
groupClass: '',
|
|
},
|
|
)
|
|
|
|
const emit = defineEmits<{(e: 'update:modelValue', value: string | null): void}>()
|
|
|
|
// pendingTime : heure réglée avant qu'un jour ne soit choisi (sinon on ne peut pas émettre).
|
|
const pendingTime = ref('')
|
|
|
|
const parts = computed(() => splitDateTime(props.modelValue ?? null))
|
|
const datePart = computed(() => parts.value.date)
|
|
const displayValue = computed(() => formatIsoDateTimeToDisplay(props.modelValue ?? null))
|
|
const timeValue = computed(() => parts.value.time || pendingTime.value)
|
|
|
|
function onSelectDay(iso: string) {
|
|
// Si aucune heure n'a été choisie, on prend l'heure actuelle (pas 00:00).
|
|
// (heure courante au moment du clic)
|
|
const now = new Date()
|
|
const time = parts.value.time || pendingTime.value || formatTime(now.getHours(), now.getMinutes())
|
|
emit('update:modelValue', composeDateTime(iso, time))
|
|
}
|
|
|
|
function onTimeChange(value: string | null) {
|
|
if (!value) return
|
|
if (datePart.value) {
|
|
emit('update:modelValue', composeDateTime(datePart.value, value))
|
|
}
|
|
else {
|
|
pendingTime.value = value
|
|
}
|
|
}
|
|
|
|
function onClear() {
|
|
pendingTime.value = ''
|
|
emit('update:modelValue', null)
|
|
}
|
|
|
|
watch(() => props.modelValue, (val) => {
|
|
if (val && !isValidIsoDateTime(val) && import.meta.dev) {
|
|
console.warn(`[MalioDateTime] modelValue invalide ignoré : "${val}"`)
|
|
}
|
|
})
|
|
</script>
|