mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
feat(Calendar): implement component (#2618)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -93,6 +93,8 @@ const options = computed(() => {
|
||||
chip: key.toLowerCase().endsWith('color') ? { color: variant } : undefined
|
||||
}))
|
||||
|
||||
// TODO: process "undefined | Date | DateRange", https://github.com/nuxt/ui/issues/2651
|
||||
|
||||
return {
|
||||
name: key,
|
||||
label: key,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { CalendarDate, DateFormatter, getLocalTimeZone } from '@internationalized/date'
|
||||
|
||||
const df = new DateFormatter('en-US', {
|
||||
dateStyle: 'medium'
|
||||
})
|
||||
|
||||
const modelValue = shallowRef(new CalendarDate(2022, 1, 10))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UPopover>
|
||||
<UButton color="neutral" variant="subtle" icon="i-lucide-calendar">
|
||||
{{ df.format(modelValue.toDate(getLocalTimeZone())) }}
|
||||
</UButton>
|
||||
|
||||
<template #content>
|
||||
<UCalendar v-model="modelValue" class="p-2" />
|
||||
</template>
|
||||
</UPopover>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { CalendarDate, DateFormatter, getLocalTimeZone } from '@internationalized/date'
|
||||
|
||||
const df = new DateFormatter('en-US', {
|
||||
dateStyle: 'medium'
|
||||
})
|
||||
|
||||
const modelValue = shallowRef({
|
||||
start: new CalendarDate(2022, 1, 20),
|
||||
end: new CalendarDate(2022, 2, 10)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UPopover>
|
||||
<UButton color="neutral" variant="subtle" icon="i-lucide-calendar">
|
||||
<template v-if="modelValue.start">
|
||||
<template v-if="modelValue.end">
|
||||
{{ df.format(modelValue.start.toDate(getLocalTimeZone())) }} - {{ df.format(modelValue.end.toDate(getLocalTimeZone())) }}
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
{{ df.format(modelValue.start.toDate(getLocalTimeZone())) }}
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>
|
||||
Pick a date
|
||||
</template>
|
||||
</UButton>
|
||||
|
||||
<template #content>
|
||||
<UCalendar v-model="modelValue" class="p-2" :number-of-months="2" range />
|
||||
</template>
|
||||
</UPopover>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { CalendarDate } from '@internationalized/date'
|
||||
import type { Matcher } from 'radix-vue/date'
|
||||
|
||||
const modelValue = shallowRef({
|
||||
start: new CalendarDate(2022, 1, 1),
|
||||
end: new CalendarDate(2022, 1, 9)
|
||||
})
|
||||
|
||||
const isDateDisabled: Matcher = (date) => {
|
||||
return date.day >= 10 && date.day <= 16
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UCalendar v-model="modelValue" :is-date-disabled="isDateDisabled" range />
|
||||
</template>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import { CalendarDate } from '@internationalized/date'
|
||||
|
||||
const modelValue = shallowRef(new CalendarDate(2022, 1, 10))
|
||||
|
||||
function getColorByDate(date: Date) {
|
||||
const isWeekend = date.getDay() % 6 == 0
|
||||
const isDayMeeting = date.getDay() % 3 == 0
|
||||
|
||||
if (isWeekend) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (isDayMeeting) {
|
||||
return 'error'
|
||||
}
|
||||
|
||||
return 'success'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UCalendar v-model="modelValue">
|
||||
<template #day="{ day }">
|
||||
<UChip :show="!!getColorByDate(day.toDate('UTC'))" :color="getColorByDate(day.toDate('UTC'))" size="2xs">
|
||||
{{ day.day }}
|
||||
</UChip>
|
||||
</template>
|
||||
</UCalendar>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { CalendarDate } from '@internationalized/date'
|
||||
|
||||
const modelValue = shallowRef(new CalendarDate(2023, 9, 10))
|
||||
const minDate = new CalendarDate(2023, 9, 1)
|
||||
const maxDate = new CalendarDate(2023, 9, 30)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UCalendar v-model="modelValue" :min-value="minDate" :max-value="maxDate" />
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { CalendarDate } from '@internationalized/date'
|
||||
import type { Matcher } from 'radix-vue/date'
|
||||
|
||||
const modelValue = shallowRef({
|
||||
start: new CalendarDate(2022, 1, 1),
|
||||
end: new CalendarDate(2022, 1, 9)
|
||||
})
|
||||
|
||||
const isDateUnavailable: Matcher = (date) => {
|
||||
return date.day >= 10 && date.day <= 16
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UCalendar v-model="modelValue" :is-date-unavailable="isDateUnavailable" range />
|
||||
</template>
|
||||
Reference in New Issue
Block a user