-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Calendar component inherits the VCalendar slots (#285)
- Loading branch information
Showing
11 changed files
with
276 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
apps/www/src/lib/registry/default/example/RangePickerWithSlot.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script setup lang="ts"> | ||
import { addDays, format } from 'date-fns' | ||
import { Calendar as CalendarIcon } from 'lucide-vue-next' | ||
import { ref } from 'vue' | ||
import { cn } from '@/lib/utils' | ||
import { Button } from '@/lib/registry/default/ui/button' | ||
import { Calendar } from '@/lib/registry/default/ui/calendar' | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from '@/lib/registry/default/ui/popover' | ||
const date = ref({ | ||
start: new Date(2022, 0, 20), | ||
end: addDays(new Date(2022, 0, 20), 20), | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div :class="cn('grid gap-2', $attrs.class ?? '')"> | ||
<Popover> | ||
<PopoverTrigger as-child> | ||
<Button | ||
id="date" | ||
:variant="'outline'" | ||
:class="cn( | ||
'w-[300px] justify-start text-left font-normal', | ||
!date && 'text-muted-foreground', | ||
)" | ||
> | ||
<CalendarIcon class="mr-2 h-4 w-4" /> | ||
<span> | ||
{{ date.start ? ( | ||
date.end ? `${format(date.start, 'LLL dd, y')} - ${format(date.end, 'LLL dd, y')}` | ||
: format(date.start, 'LLL dd, y') | ||
) : 'Pick a date' }} | ||
</span> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent class="w-auto p-0" align="start" :avoid-collisions="true"> | ||
<Calendar | ||
v-model.range="date" | ||
mode="date" | ||
:columns="2" | ||
> | ||
<template #footer> | ||
<div class="w-full px-3 pb-3"> | ||
Entry time | ||
<Calendar | ||
v-model="date.start" | ||
mode="time" | ||
hide-time-header | ||
/> | ||
Exit time | ||
<Calendar | ||
v-model="date.end" | ||
mode="time" | ||
hide-time-header | ||
/> | ||
</div> | ||
</template> | ||
</Calendar> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
73 changes: 73 additions & 0 deletions
73
apps/www/src/lib/registry/new-york/example/RangePickerWithSlot.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<script setup lang="ts"> | ||
import { addDays, format } from 'date-fns' | ||
import { ref } from 'vue' | ||
import { CalendarIcon } from '@radix-icons/vue' | ||
import { cn } from '@/lib/utils' | ||
import { Button } from '@/lib/registry/new-york/ui/button' | ||
import { Calendar } from '@/lib/registry/new-york/ui/calendar' | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from '@/lib/registry/new-york/ui/popover' | ||
const date = ref({ | ||
start: new Date(2022, 0, 20), | ||
end: addDays(new Date(2022, 0, 20), 20), | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div :class="cn('grid gap-2', $attrs.class ?? '')"> | ||
<Popover> | ||
<PopoverTrigger as-child> | ||
<Button | ||
id="date" | ||
:variant="'outline'" | ||
:class="cn( | ||
'w-[300px] justify-start text-left font-normal', | ||
!date && 'text-muted-foreground', | ||
)" | ||
> | ||
<CalendarIcon class="mr-2 h-4 w-4" /> | ||
<span> | ||
{{ date.start ? ( | ||
date.end ? `${format(date.start, 'LLL dd, y')} - ${format(date.end, 'LLL dd, y')}` | ||
: format(date.start, 'LLL dd, y') | ||
) : 'Pick a date' }} | ||
</span> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent class="w-auto p-0" align="start" :avoid-collisions="true"> | ||
<Calendar | ||
v-model.range="date" | ||
mode="date" | ||
:columns="2" | ||
> | ||
<template #footer> | ||
<div class="flex w-full mt-6 border-t border-accent pt-4"> | ||
<div class="w-1/2"> | ||
<strong>Entry time</strong> | ||
<Calendar | ||
v-model="date.start" | ||
mode="time" | ||
hide-time-header | ||
/> | ||
</div> | ||
<div class="w-1/2"> | ||
<strong>Exit time</strong> | ||
<Calendar | ||
v-model="date.end" | ||
mode="time" | ||
hide-time-header | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
</Calendar> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.