From 50f4ae31f53447d7503936ade3228056ea695977 Mon Sep 17 00:00:00 2001 From: Valentin Hutter Date: Wed, 17 Jan 2024 20:10:47 +0100 Subject: [PATCH 1/6] feat(calendar): calendar component inherits the VCalendar slots --- .../registry/default/ui/calendar/Calendar.vue | 19 +++++++++++++++-- .../lib/registry/default/ui/calendar/index.ts | 21 +++++++++++++++++++ .../new-york/ui/calendar/Calendar.vue | 19 +++++++++++++++-- .../registry/new-york/ui/calendar/index.ts | 21 +++++++++++++++++++ 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/apps/www/src/lib/registry/default/ui/calendar/Calendar.vue b/apps/www/src/lib/registry/default/ui/calendar/Calendar.vue index 64f8cf3f1..cc888792d 100644 --- a/apps/www/src/lib/registry/default/ui/calendar/Calendar.vue +++ b/apps/www/src/lib/registry/default/ui/calendar/Calendar.vue @@ -3,7 +3,8 @@ import { useVModel } from '@vueuse/core' import type { Calendar } from 'v-calendar' import { DatePicker } from 'v-calendar' import { ChevronLeft, ChevronRight } from 'lucide-vue-next' -import { computed, nextTick, onMounted, ref } from 'vue' +import { computed, nextTick, onMounted, ref, useSlots } from 'vue' +import { isVCalendarSlot } from '.' import { buttonVariants } from '@/lib/registry/default/ui/button' import { cn } from '@/lib/utils' @@ -64,6 +65,16 @@ onMounted(async () => { if (modelValue.value instanceof Date && calendarRef.value) calendarRef.value.focusDate(modelValue.value) }) + +const $slots = useSlots() +const vCalendarSlots = computed(() => { + return Object.keys($slots) + .filter(name => isVCalendarSlot(name)) + .reduce((obj: Record, key: string) => { + obj[key] = $slots[key] + return obj + }, {}) +}) diff --git a/apps/www/src/lib/registry/default/ui/calendar/index.ts b/apps/www/src/lib/registry/default/ui/calendar/index.ts index 50f211145..d17d00f2f 100644 --- a/apps/www/src/lib/registry/default/ui/calendar/index.ts +++ b/apps/www/src/lib/registry/default/ui/calendar/index.ts @@ -1 +1,22 @@ export { default as Calendar } from './Calendar.vue' +import type { CalendarSlotName } from 'v-calendar/dist/types/src/components/Calendar/CalendarSlot.vue.d.ts' + +export function isVCalendarSlot(slotName: string): slotName is CalendarSlotName { + const validSlots: CalendarSlotName[] = [ + 'day-content', + 'day-popover', + 'dp-footer', + 'footer', + 'header-title-wrapper', + 'header-title', + 'header-prev-button', + 'header-next-button', + 'nav', + 'nav-prev-button', + 'nav-next-button', + 'page', + 'time-header', + ] + + return validSlots.includes(slotName as CalendarSlotName) +} diff --git a/apps/www/src/lib/registry/new-york/ui/calendar/Calendar.vue b/apps/www/src/lib/registry/new-york/ui/calendar/Calendar.vue index 409b07f7c..5dada0e10 100644 --- a/apps/www/src/lib/registry/new-york/ui/calendar/Calendar.vue +++ b/apps/www/src/lib/registry/new-york/ui/calendar/Calendar.vue @@ -3,7 +3,8 @@ import { useVModel } from '@vueuse/core' import type { Calendar } from 'v-calendar' import { DatePicker } from 'v-calendar' import { ChevronLeftIcon, ChevronRightIcon } from '@radix-icons/vue' -import { computed, nextTick, onMounted, ref } from 'vue' +import { computed, nextTick, onMounted, ref, useSlots } from 'vue' +import { isVCalendarSlot } from '.' import { buttonVariants } from '@/lib/registry/new-york/ui/button' import { cn } from '@/lib/utils' @@ -63,6 +64,16 @@ onMounted(async () => { if (modelValue.value instanceof Date && calendarRef.value) calendarRef.value.focusDate(modelValue.value) }) + +const $slots = useSlots() +const vCalendarSlots = computed(() => { + return Object.keys($slots) + .filter(name => isVCalendarSlot(name)) + .reduce((obj: Record, key: string) => { + obj[key] = $slots[key] + return obj + }, {}) +}) diff --git a/apps/www/src/lib/registry/new-york/ui/calendar/index.ts b/apps/www/src/lib/registry/new-york/ui/calendar/index.ts index 50f211145..d17d00f2f 100644 --- a/apps/www/src/lib/registry/new-york/ui/calendar/index.ts +++ b/apps/www/src/lib/registry/new-york/ui/calendar/index.ts @@ -1 +1,22 @@ export { default as Calendar } from './Calendar.vue' +import type { CalendarSlotName } from 'v-calendar/dist/types/src/components/Calendar/CalendarSlot.vue.d.ts' + +export function isVCalendarSlot(slotName: string): slotName is CalendarSlotName { + const validSlots: CalendarSlotName[] = [ + 'day-content', + 'day-popover', + 'dp-footer', + 'footer', + 'header-title-wrapper', + 'header-title', + 'header-prev-button', + 'header-next-button', + 'nav', + 'nav-prev-button', + 'nav-next-button', + 'page', + 'time-header', + ] + + return validSlots.includes(slotName as CalendarSlotName) +} From 8d505c04c5c4f1075e5f17286c49bfaa6d4b8e07 Mon Sep 17 00:00:00 2001 From: Valentin Hutter Date: Wed, 17 Jan 2024 20:12:33 +0100 Subject: [PATCH 2/6] chore: build registry --- apps/www/src/public/registry/styles/default/calendar.json | 4 ++-- apps/www/src/public/registry/styles/new-york/calendar.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/www/src/public/registry/styles/default/calendar.json b/apps/www/src/public/registry/styles/default/calendar.json index e8f631e2a..bae081a3a 100644 --- a/apps/www/src/public/registry/styles/default/calendar.json +++ b/apps/www/src/public/registry/styles/default/calendar.json @@ -11,11 +11,11 @@ "files": [ { "name": "Calendar.vue", - "content": "\n\n\n\n\n" + "content": "\n\n\n\n\n" }, { "name": "index.ts", - "content": "export { default as Calendar } from './Calendar.vue'\n" + "content": "export { default as Calendar } from './Calendar.vue'\nimport type { CalendarSlotName } from 'v-calendar/dist/types/src/components/Calendar/CalendarSlot.vue.d.ts'\n\nexport function isVCalendarSlot(slotName: string): slotName is CalendarSlotName {\n const validSlots: CalendarSlotName[] = [\n 'day-content',\n 'day-popover',\n 'dp-footer',\n 'footer',\n 'header-title-wrapper',\n 'header-title',\n 'header-prev-button',\n 'header-next-button',\n 'nav',\n 'nav-prev-button',\n 'nav-next-button',\n 'page',\n 'time-header',\n ]\n\n return validSlots.includes(slotName as CalendarSlotName)\n}\n" } ], "type": "components:ui" diff --git a/apps/www/src/public/registry/styles/new-york/calendar.json b/apps/www/src/public/registry/styles/new-york/calendar.json index b83d724fa..3adbb0b15 100644 --- a/apps/www/src/public/registry/styles/new-york/calendar.json +++ b/apps/www/src/public/registry/styles/new-york/calendar.json @@ -11,11 +11,11 @@ "files": [ { "name": "Calendar.vue", - "content": "\n\n\n\n\n" + "content": "\n\n\n\n\n" }, { "name": "index.ts", - "content": "export { default as Calendar } from './Calendar.vue'\n" + "content": "export { default as Calendar } from './Calendar.vue'\nimport type { CalendarSlotName } from 'v-calendar/dist/types/src/components/Calendar/CalendarSlot.vue.d.ts'\n\nexport function isVCalendarSlot(slotName: string): slotName is CalendarSlotName {\n const validSlots: CalendarSlotName[] = [\n 'day-content',\n 'day-popover',\n 'dp-footer',\n 'footer',\n 'header-title-wrapper',\n 'header-title',\n 'header-prev-button',\n 'header-next-button',\n 'nav',\n 'nav-prev-button',\n 'nav-next-button',\n 'page',\n 'time-header',\n ]\n\n return validSlots.includes(slotName as CalendarSlotName)\n}\n" } ], "type": "components:ui" From 931041ced6ad185268ea5b4f5cbf3663974e198c Mon Sep 17 00:00:00 2001 From: Valentin Hutter Date: Thu, 18 Jan 2024 01:07:58 +0100 Subject: [PATCH 3/6] docs(calendar): add available slots + one example --- .../src/content/docs/components/calendar.md | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/apps/www/src/content/docs/components/calendar.md b/apps/www/src/content/docs/components/calendar.md index ccdc99712..7fa0c0216 100644 --- a/apps/www/src/content/docs/components/calendar.md +++ b/apps/www/src/content/docs/components/calendar.md @@ -56,5 +56,40 @@ import { Calendar } from '@/components/ui/calendar' ``` -See the [VCalendar](https://vcalendar.io/getting-started/installation.html) documentation for more information. +The API is essentially the same, i.e. props and slots. See the [VCalendar](https://vcalendar.io/getting-started/installation.html) documentation for more information. +### Slots + +The slots available are [those currently supported](https://github.com/nathanreyes/v-calendar/blob/v3.1.2/src/components/Calendar/CalendarSlot.vue#L16-L28) by VCalendar, namely : + +- `day-content` +- `day-popover` +- `dp-footer` +- `footer` +- `header-title-wrapper` +- `header-title` +- `header-prev-button` +- `header-next-button` +- `nav` +- `nav-prev-button` +- `nav-next-button` +- `page` +- `time-header` + +Example using the `dp-footer` slot: + +```vue + + + +``` \ No newline at end of file From 0381d55a85b9178b9d0dc1390f2e0edc6b6dc40a Mon Sep 17 00:00:00 2001 From: Valentin Hutter Date: Thu, 18 Jan 2024 01:10:03 +0100 Subject: [PATCH 4/6] docs: fix calendar --- apps/www/src/content/docs/components/calendar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/www/src/content/docs/components/calendar.md b/apps/www/src/content/docs/components/calendar.md index 7fa0c0216..ab0dff471 100644 --- a/apps/www/src/content/docs/components/calendar.md +++ b/apps/www/src/content/docs/components/calendar.md @@ -76,7 +76,7 @@ The slots available are [those currently supported](https://github.com/nathanrey - `page` - `time-header` -Example using the `dp-footer` slot: +Example using the `day-content` slot: ```vue + + From 5c372bbb4faba4743da4a0a024d81e0df7fa9d50 Mon Sep 17 00:00:00 2001 From: Valentin Hutter Date: Thu, 18 Jan 2024 01:43:22 +0100 Subject: [PATCH 6/6] docs: add new-york example --- .../new-york/example/RangePickerWithSlot.vue | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 apps/www/src/lib/registry/new-york/example/RangePickerWithSlot.vue diff --git a/apps/www/src/lib/registry/new-york/example/RangePickerWithSlot.vue b/apps/www/src/lib/registry/new-york/example/RangePickerWithSlot.vue new file mode 100644 index 000000000..95dcd0218 --- /dev/null +++ b/apps/www/src/lib/registry/new-york/example/RangePickerWithSlot.vue @@ -0,0 +1,73 @@ + + +