radix-vue / radix-vue

Vue port of Radix UI Primitives. An open-source UI component library for building high-quality, accessible design systems and web apps.
https://radix-vue.com
MIT License
2.94k stars 170 forks source link

[Feature]: Extend Calendar with DateTime option #962

Open dany68 opened 1 month ago

dany68 commented 1 month ago

Describe the feature

Hi,

First of all thank you for this amazing library ! Would it be possible to extend the Calendar component with a DateTime option ? Currently the v-model is using a DateValue | DateValue[] type and the root expose only a date slot.

I would like to add 3 selects to the current implementation to select hour, minute and period (AM/PM).

Thank you very much,

Additional information

epr3 commented 1 month ago

@dany68 @internationalized/date supports both CalendarDateTime and ZonedDateTime as part of the DateValue type which have fields for time.

You can pass either of those types described above as a v-model to the CalendarRoot component.

E. g.

<script lang="ts" setup>
import { CalendarDateTime, type DateValue } from '@internationalized/date'
import { ref, type Ref } from 'vue'
import { CalendarRoot, ... } from 'radix-vue'

const date = ref(new CalendarDateTime(2024, 5, 26, 12, 0, 0)) as Ref<DateValue>
</script>

<template>
  <CalendarRoot v-model="date">
  ...
  </CalendarRoot>
</template>
sadeghbarati commented 1 month ago

Based on Eduard comment you can control the DatePickerField or DateField components segments


If you pass CalendarDate or toCalendarDate to the DateField, it will look like this (without time segment)

image


If you pass CalendarDateTime or toCalendarDateTime to the DateField, it will look like this

image


If you want Standalone Time Picker inside Calendar or DatePicker this issue might be help in the future

https://github.com/radix-vue/radix-vue/issues/900#issuecomment-2104386498

dany68 commented 1 month ago

Thank you very much for your help !