Calendar VCalendar displays events in day, week, month or year views. Move and resize events with the pointer or keyboard; provide your own creation and editing forms.
Usage
Mon 5
Tue 6
Wed 7
Thu 8
Fri 9
Sat 10
Sun 11
0:00 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 22:00 23:00
Design review 14:00 – 15:30 With Anna and Ravi
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { onMounted, ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
/* Use a fixed initial week for prerendering; switch to the current week after mounting. */
const REFERENCE_MONDAY = '2026-01-05'
const anchor = ref(REFERENCE_MONDAY)
const events = ref<CalendarEvent[]>(scheduleFor(REFERENCE_MONDAY))
onMounted(() => {
anchor.value = mondayOf(new Date())
events.value = scheduleFor(anchor.value)
})
/** Format the local date without converting it to UTC. */
function isoOf(date: Date): string {
const two = (part: number) => String(part).padStart(2, '0')
return `${date.getFullYear()}-${two(date.getMonth() + 1)}-${two(date.getDate())}`
}
function mondayOf(date: Date): string {
const monday = new Date(date)
monday.setDate(date.getDate() - ((date.getDay() + 6) % 7))
return isoOf(monday)
}
function scheduleFor(monday: string): CalendarEvent[] {
const day = (offset: number) => {
const date = new Date(`${monday}T00:00:00`)
date.setDate(date.getDate() + offset)
return isoOf(date)
}
return [
{
id: 'standup',
title: 'Standup',
start: day(0),
end: day(0),
startTime: '09:00',
endTime: '09:15',
},
{
id: 'review',
title: 'Design review',
start: day(1),
end: day(1),
startTime: '14:00',
endTime: '15:30',
description: 'With Anna and Ravi',
},
{
id: 'lunch',
title: 'Team lunch',
start: day(3),
end: day(3),
startTime: '12:30',
endTime: '13:30',
},
]
}
</script>
<template>
<VCalendar v-model:date="anchor" v-model:events="events" label="Team schedule" class="calendar" />
</template>
<style scoped>
/* A calendar has no height of its own, and collapses without one. */
.calendar {
block-size: 34rem;
}
</style> Examples Variants variant frames the view with a border (outline, the default), a raised surface with a shadow (elevated), a muted surface (filled) or nothing (flat). The toolbar stays outside the frame.
9:00 10:00 11:00 12:00
Design review 11:00 – 12:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. 9:00 10:00 11:00 12:00
Design review 11:00 – 12:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. 9:00 10:00 11:00 12:00
Design review 11:00 – 12:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. 9:00 10:00 11:00 12:00
Design review 11:00 – 12:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent, type CalendarVariant } from 'vectis-ui'
const variants: CalendarVariant[] = ['outline', 'elevated', 'filled', 'flat']
const events = ref<CalendarEvent[]>([
{
id: 'standup',
title: 'Standup',
start: '2026-06-10',
end: '2026-06-10',
startTime: '09:30',
endTime: '09:45',
},
{
id: 'review',
title: 'Design review',
start: '2026-06-10',
end: '2026-06-10',
startTime: '11:00',
endTime: '12:00',
},
])
</script>
<template>
<div class="grid">
<VCalendar
v-for="variant in variants"
:key="variant"
v-model:events="events"
:variant="variant"
view="day"
:views="['day']"
date="2026-06-10"
:day-start="9"
:day-end="13"
:label="`Schedule, ${variant}`"
class="calendar"
/>
</div>
</template>
<style scoped>
.grid {
display: grid;
flex: 1;
grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
gap: var(--vectis-space-6);
}
.calendar {
block-size: 22rem;
}
</style> Month monthEventLimit caps the event cards shown per day. A count indicates the remaining events.
Mon Tue Wed Thu Fri Sat Sun
8 Standup
9
10 Quarterly plan Team lunch One to one +1 more
11 Workshop
12
13
14
15
16 Release window
17 Release window
18 Release window
19 Retrospective
20
21
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
const events = ref<CalendarEvent[]>([
{
id: 'standup',
title: 'Standup',
start: '2026-06-08',
end: '2026-06-08',
startTime: '09:00',
endTime: '09:15',
},
{
id: 'quarterly',
title: 'Quarterly plan',
start: '2026-06-10',
end: '2026-06-10',
startTime: '08:00',
endTime: '08:30',
},
{
id: 'lunch',
title: 'Team lunch',
start: '2026-06-10',
end: '2026-06-10',
startTime: '12:30',
endTime: '13:30',
},
{
id: 'one-to-one',
title: 'One to one',
start: '2026-06-10',
end: '2026-06-10',
startTime: '15:00',
endTime: '15:45',
},
{
id: 'interview',
title: 'Interview',
start: '2026-06-10',
end: '2026-06-10',
startTime: '17:00',
endTime: '18:00',
},
{
id: 'workshop',
title: 'Workshop',
start: '2026-06-11',
end: '2026-06-11',
startTime: '09:30',
endTime: '12:00',
},
{
id: 'retro',
title: 'Retrospective',
start: '2026-06-19',
end: '2026-06-19',
startTime: '16:00',
endTime: '17:00',
},
{
id: 'release',
title: 'Release window',
start: '2026-06-16',
end: '2026-06-18',
startTime: '00:00',
endTime: '23:59',
},
])
</script>
<template>
<VCalendar
v-model:events="events"
view="month"
:views="['month', 'week', 'day']"
date="2026-06-10"
label="Month"
class="calendar"
/>
</template>
<style scoped>
.calendar {
block-size: 38rem;
}
</style> Year The year view shows twelve months. Selecting a month opens its detailed view.
January 1 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 8
February 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 1 2 3 4 5 6 7 8
March 5 23 24 25 26 27 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5
April 1 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10
May 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7
June 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12
July 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9
August 12 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6
September 3 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11
October 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 8
November 1 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5 6
December 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
const events = ref<CalendarEvent[]>([
{
id: 'kickoff',
title: 'Kickoff',
start: '2026-01-13',
end: '2026-01-13',
startTime: '10:00',
endTime: '11:00',
},
{
id: 'audit',
title: 'Accessibility audit',
start: '2026-03-02',
end: '2026-03-06',
startTime: '00:00',
endTime: '23:59',
},
{
id: 'review',
title: 'Design review',
start: '2026-04-21',
end: '2026-04-21',
startTime: '14:00',
endTime: '15:30',
},
{
id: 'quarterly',
title: 'Quarterly plan',
start: '2026-06-10',
end: '2026-06-10',
startTime: '08:00',
endTime: '09:00',
},
{
id: 'summer',
title: 'Summer break',
start: '2026-08-03',
end: '2026-08-14',
startTime: '00:00',
endTime: '23:59',
},
{
id: 'conference',
title: 'Conference',
start: '2026-09-22',
end: '2026-09-24',
startTime: '00:00',
endTime: '23:59',
},
{
id: 'retro',
title: 'Retrospective',
start: '2026-11-05',
end: '2026-11-05',
startTime: '16:00',
endTime: '17:00',
},
])
</script>
<template>
<VCalendar
v-model:events="events"
view="year"
:views="['year', 'month', 'week']"
date="2026-06-10"
label="Year"
class="calendar"
/>
</template>
<style scoped>
.calendar {
block-size: 38rem;
}
</style> Custom view customDays sets the number of days in the custom view and the navigation step.
Wed 10
Thu 11
Fri 12
Sat 13
Sun 14
8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00
Standup 9:00 – 9:15
Workshop 9:30 – 12:00
Design review 14:00 – 15:30
Retrospective 16:00 – 17:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
const events = ref<CalendarEvent[]>([
{
id: 'standup',
title: 'Standup',
start: '2026-06-10',
end: '2026-06-10',
startTime: '09:00',
endTime: '09:15',
},
{
id: 'review',
title: 'Design review',
start: '2026-06-10',
end: '2026-06-10',
startTime: '14:00',
endTime: '15:30',
},
{
id: 'workshop',
title: 'Workshop',
start: '2026-06-11',
end: '2026-06-11',
startTime: '09:30',
endTime: '12:00',
},
{
id: 'retro',
title: 'Retrospective',
start: '2026-06-12',
end: '2026-06-12',
startTime: '16:00',
endTime: '17:00',
},
{
id: 'conference',
title: 'Conference',
start: '2026-06-13',
end: '2026-06-13',
startTime: '10:00',
endTime: '16:00',
},
{
id: 'handover',
title: 'Handover',
start: '2026-06-14',
end: '2026-06-14',
startTime: '11:00',
endTime: '12:00',
},
])
</script>
<template>
<VCalendar
v-model:events="events"
view="custom"
:custom-days="5"
:views="['day', 'custom', 'week']"
:day-start="8"
:day-end="18"
date="2026-06-10"
label="Custom span"
class="calendar"
/>
</template>
<style scoped>
.calendar {
block-size: 34rem;
}
</style> Which days are shown weekdays controls which weekdays appear and their order. Its first entry overrides firstDayOfWeek. Use dayStart and dayEnd to limit the visible hours.
8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00
Standup 9:00 – 9:15
Workshop 9:30 – 12:00
Design review 10:00 – 11:30
Retrospective 16:00 – 17:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
const events = ref<CalendarEvent[]>([
{
id: 'standup',
title: 'Standup',
start: '2026-06-08',
end: '2026-06-08',
startTime: '09:00',
endTime: '09:15',
},
{
id: 'review',
title: 'Design review',
start: '2026-06-09',
end: '2026-06-09',
startTime: '10:00',
endTime: '11:30',
},
{
id: 'lunch',
title: 'Team lunch',
start: '2026-06-10',
end: '2026-06-10',
startTime: '12:30',
endTime: '13:30',
},
{
id: 'workshop',
title: 'Workshop',
start: '2026-06-11',
end: '2026-06-11',
startTime: '09:30',
endTime: '12:00',
},
{
id: 'retro',
title: 'Retrospective',
start: '2026-06-12',
end: '2026-06-12',
startTime: '16:00',
endTime: '17:00',
},
])
</script>
<template>
<VCalendar
v-model:events="events"
:weekdays="[1, 2, 3, 4, 5]"
:day-start="8"
:day-end="19"
:custom-days="3"
:views="['day', 'custom', 'week', 'month', 'year']"
date="2026-06-10"
label="Working week"
class="calendar"
/>
</template>
<style scoped>
.calendar {
block-size: 34rem;
}
</style> All-day events Events marked allDay or lasting at least 24 hours appear in the all-day band. Shorter events crossing midnight appear on both days; an end at midnight belongs to the previous day.
Mon 8
Tue 9
Wed 10
Thu 11
Fri 12
Sat 13
Sun 14
All day
Bank holiday Workshop Release window
8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00
Design review 10:00 – 11:30
Retrospective 16:00 – 17:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
const events = ref<CalendarEvent[]>([
{
id: 'holiday',
title: 'Bank holiday',
start: '2026-06-08',
end: '2026-06-08',
startTime: '00:00',
endTime: '23:59',
allDay: true,
},
{
id: 'workshop',
title: 'Workshop',
start: '2026-06-09',
end: '2026-06-11',
startTime: '00:00',
endTime: '23:59',
},
{
id: 'release',
title: 'Release window',
start: '2026-06-10',
end: '2026-06-12',
startTime: '00:00',
endTime: '23:59',
},
{
id: 'review',
title: 'Design review',
start: '2026-06-10',
end: '2026-06-10',
startTime: '10:00',
endTime: '11:30',
},
{
id: 'retro',
title: 'Retrospective',
start: '2026-06-11',
end: '2026-06-11',
startTime: '16:00',
endTime: '17:00',
},
])
</script>
<template>
<VCalendar
v-model:events="events"
:day-start="8"
:day-end="18"
date="2026-06-10"
label="All-day events"
class="calendar"
/>
</template>
<style scoped>
.calendar {
block-size: 34rem;
}
</style> Overlapping events Overlapping events share the available column width.
8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00
Standup 9:00 – 10:00 Workshop 9:00 – 9:30 Design review 9:30 – 11:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
const DAY = '2026-06-10'
const events = ref<CalendarEvent[]>([
{
id: 'standup',
title: 'Standup',
start: DAY,
end: DAY,
startTime: '09:00',
endTime: '10:00',
},
{
id: 'review',
title: 'Design review',
start: DAY,
end: DAY,
startTime: '09:30',
endTime: '11:00',
},
{
id: 'interview',
title: 'Interview',
start: DAY,
end: DAY,
startTime: '10:00',
endTime: '10:30',
},
{
id: 'workshop',
title: 'Workshop',
start: DAY,
end: DAY,
startTime: '09:00',
endTime: '09:30',
},
{
id: 'lunch',
title: 'Team lunch',
start: DAY,
end: DAY,
startTime: '12:30',
endTime: '13:30',
},
])
</script>
<template>
<VCalendar
v-model:events="events"
view="day"
:views="['day', 'week']"
:day-start="8"
:day-end="18"
:date="DAY"
label="Overlapping events"
class="calendar"
/>
</template>
<style scoped>
.calendar {
block-size: 34rem;
}
</style> Colours Set an event’s color to a CSS colour. Otherwise, its colour is derived from its identifier.
8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00
Design review 9:00 – 10:00
Retrospective 11:00 – 12:00
Release window 16:00 – 18:00
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, type CalendarEvent } from 'vectis-ui'
const DAY = '2026-06-10'
const events = ref<CalendarEvent[]>([
{ id: 'hue-1', title: 'Standup', start: DAY, end: DAY, startTime: '08:00', endTime: '09:00' },
{
id: 'hue-2',
title: 'Design review',
start: DAY,
end: DAY,
startTime: '09:00',
endTime: '10:00',
},
{ id: 'hue-3', title: 'Workshop', start: DAY, end: DAY, startTime: '10:00', endTime: '11:00' },
{
id: 'hue-4',
title: 'Retrospective',
start: DAY,
end: DAY,
startTime: '11:00',
endTime: '12:00',
},
{ id: 'hue-5', title: 'Team lunch', start: DAY, end: DAY, startTime: '12:00', endTime: '13:00' },
{ id: 'hue-6', title: 'Interview', start: DAY, end: DAY, startTime: '13:00', endTime: '14:00' },
{
id: 'own-1',
title: 'One to one',
start: DAY,
end: DAY,
startTime: '14:00',
endTime: '15:00',
color: '#7c3aed',
},
{
id: 'own-2',
title: 'Release window',
start: DAY,
end: DAY,
startTime: '16:00',
endTime: '18:00',
color: 'oklch(0.65 0.15 200)',
},
])
</script>
<template>
<VCalendar
v-model:events="events"
view="day"
:views="['day', 'week']"
:day-start="8"
:day-end="20"
:date="DAY"
label="Event colours"
class="calendar"
/>
</template>
<style scoped>
.calendar {
block-size: 34rem;
}
</style> Custom event content The event slot replaces the card content. Use its event, time and layout data to adapt the display.
8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00
Design review 10:00 – 11:30Room B2, 6 people Workshop 14:00 – 16:00Room A1, 12 people
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { ref } from 'vue'
import { VCalendar, VIcon, type CalendarEvent } from 'vectis-ui'
import { schedule as scheduleIcon } from 'vectis-ui/icons'
/* Extend CalendarEvent to keep custom slot fields typed. */
interface Booking extends CalendarEvent {
room: string
attendees: number
}
const DAY = '2026-06-10'
const events = ref<Booking[]>([
{
id: 'review',
title: 'Design review',
start: DAY,
end: DAY,
startTime: '10:00',
endTime: '11:30',
room: 'B2',
attendees: 6,
},
{
id: 'workshop',
title: 'Workshop',
start: DAY,
end: DAY,
startTime: '14:00',
endTime: '16:00',
room: 'A1',
attendees: 12,
},
])
</script>
<template>
<VCalendar
v-model:events="events"
view="day"
:views="['day', 'week']"
:day-start="8"
:day-end="18"
:date="DAY"
label="Custom event content"
class="calendar"
>
<template #event="{ event, timeText }">
<span class="title">{{ event.title }}</span>
<span class="line">
<VIcon :name="scheduleIcon" :size="14" aria-hidden="true" />
{{ timeText }}
</span>
<span class="line">Room {{ event.room }}, {{ event.attendees }} people</span>
</template>
</VCalendar>
</template>
<style scoped>
.calendar {
block-size: 34rem;
}
.title {
font-weight: var(--vectis-font-weight-semibold);
}
.line {
display: flex;
align-items: center;
gap: var(--vectis-space-1);
font-size: var(--vectis-text-caption-size);
}
</style> Creating and editing events Use event-activate and cell-activate to open your editor. With creatable, drawing an empty time range emits event-create without adding an event. Save changes to v-model:events; dragging and resizing update this model directly.
Mon 8
Tue 9
Wed 10
Thu 11
Fri 12
Sat 13
Sun 14
7:00 8:00 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00
Design review 14:00 – 15:30 With Anna and Ravi
Press Enter to open this event. Press Space to take hold of it, then the arrow keys to move it and Shift with the arrow keys to change when it ends. <script setup lang="ts">
import { computed, reactive, ref, useId } from 'vue'
import {
VButton,
VCalendar,
VDateInput,
VDialog,
VInput,
VSwitch,
VTextarea,
VTimeInput,
type CalendarCell,
type CalendarEvent,
type CalendarEventId,
type CalendarEventTimes,
type CalendarView,
} from 'vectis-ui'
const view = ref<CalendarView>('week')
const anchor = ref('2026-06-10')
const events = ref<CalendarEvent[]>([
{
id: 'standup',
title: 'Standup',
start: '2026-06-08',
end: '2026-06-08',
startTime: '09:00',
endTime: '09:15',
},
{
id: 'review',
title: 'Design review',
start: '2026-06-10',
end: '2026-06-10',
startTime: '14:00',
endTime: '15:30',
description: 'With Anna and Ravi',
},
])
let nextId = 1
interface Draft {
title: string
allDay: boolean
start: string | null
startTime: string | null
end: string | null
endTime: string | null
description: string
}
const open = ref(false)
const formId = useId()
const editingId = ref<CalendarEventId | null>(null)
const draft = reactive<Draft>(emptyDraft())
function emptyDraft(): Draft {
return {
title: '',
allDay: false,
start: null,
startTime: null,
end: null,
endTime: null,
description: '',
}
}
function addMinutes(date: string, time: string, minutes: number): { date: string; time: string } {
const moved = new Date(`${date}T${time}:00`)
moved.setMinutes(moved.getMinutes() + minutes)
const two = (part: number) => String(part).padStart(2, '0')
return {
date: `${moved.getFullYear()}-${two(moved.getMonth() + 1)}-${two(moved.getDate())}`,
time: `${two(moved.getHours())}:${two(moved.getMinutes())}`,
}
}
function openNew(times: CalendarEventTimes) {
Object.assign(draft, emptyDraft(), times)
editingId.value = null
open.value = true
}
function onEventCreate(times: CalendarEventTimes) {
openNew(times)
}
/* Give a new event a one-hour duration and avoid midnight for month-cell activation. */
function onCellActivate(cell: CalendarCell) {
const startTime = view.value === 'month' ? '09:00' : cell.time
const end = addMinutes(cell.date, startTime, 60)
openNew({ start: cell.date, startTime, end: end.date, endTime: end.time })
}
function onNewClick() {
openNew({ start: anchor.value, startTime: '09:00', end: anchor.value, endTime: '10:00' })
}
function onEventActivate(event: CalendarEvent) {
Object.assign(draft, {
title: event.title,
allDay: event.allDay ?? false,
start: event.start,
startTime: event.startTime,
end: event.end,
endTime: event.endTime,
description: event.description ?? '',
})
editingId.value = event.id
open.value = true
}
const endsBeforeStart = computed(() => {
if (!draft.start || !draft.end) return false
if (draft.allDay) return draft.end < draft.start
if (!draft.startTime || !draft.endTime) return false
return `${draft.end} ${draft.endTime}` <= `${draft.start} ${draft.startTime}`
})
function save() {
// Native required validation does not reject whitespace or reversed date ranges.
const title = draft.title.trim()
// All-day events still need start and end times.
const startTime = draft.allDay ? '00:00' : draft.startTime
const endTime = draft.allDay ? '23:59' : draft.endTime
if (!title || !draft.start || !draft.end || !startTime || !endTime) return
if (endsBeforeStart.value) return
const saved: CalendarEvent = {
id: editingId.value ?? `event-${nextId++}`,
title,
start: draft.start,
end: draft.end,
startTime,
endTime,
allDay: draft.allDay || undefined,
description: draft.description.trim() || undefined,
}
events.value =
editingId.value === null
? [...events.value, saved]
: events.value.map((event) => (event.id === saved.id ? saved : event))
open.value = false
}
function remove() {
events.value = events.value.filter((event) => event.id !== editingId.value)
open.value = false
}
</script>
<template>
<VCalendar
v-model:view="view"
v-model:date="anchor"
v-model:events="events"
creatable
:views="['day', 'week', 'month']"
:day-start="7"
:day-end="20"
label="Editable schedule"
class="calendar"
@event-create="onEventCreate"
@cell-activate="onCellActivate"
@event-activate="onEventActivate"
>
<template #actions>
<VButton size="sm" @click="onNewClick">New event</VButton>
</template>
</VCalendar>
<!-- The footer submit button targets the body form through its form attribute. -->
<VDialog
v-model:open="open"
:title="editingId === null ? 'New event' : 'Edit event'"
width="32rem"
>
<form :id="formId" class="form" @submit.prevent="save">
<VInput v-model="draft.title" label="Title" required />
<VSwitch v-model="draft.allDay" label="All day" class="all-day" />
<div class="row">
<VDateInput v-model="draft.start" label="Start date" show-picker required />
<VTimeInput
v-if="!draft.allDay"
v-model="draft.startTime"
label="Start time"
:minute-step="15"
required
/>
</div>
<div class="row">
<VDateInput
v-model="draft.end"
label="End date"
show-picker
required
:invalid="endsBeforeStart"
:hint="endsBeforeStart ? 'The event has to end after it starts.' : undefined"
/>
<VTimeInput
v-if="!draft.allDay"
v-model="draft.endTime"
label="End time"
:minute-step="15"
required
:invalid="endsBeforeStart"
/>
</div>
<VTextarea v-model="draft.description" label="Description" :rows="3" />
</form>
<template #footer>
<VButton
v-if="editingId !== null"
class="delete"
variant="ghost"
tone="danger"
@click="remove"
>
Delete
</VButton>
<VButton variant="ghost" tone="neutral" @click="open = false">Cancel</VButton>
<VButton type="submit" :form="formId">Save</VButton>
</template>
</VDialog>
</template>
<style scoped>
.calendar {
block-size: 34rem;
}
.form {
display: grid;
gap: var(--vectis-space-4);
}
.all-day {
justify-self: start;
}
.row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
gap: var(--vectis-space-3);
align-items: start;
}
.delete {
margin-inline-end: auto;
}
</style> API Props Events Slots Types Types used in the API tables. Import exported types from vectis-ui.
export interface CalendarCell {
date: string
time: string
} export interface CalendarEvent {
id: CalendarEventId
title: string
start: string
end: string
startTime: string
endTime: string
description?: string
color?: string
timezone?: string
allDay?: boolean
} export type CalendarEventId = string | number export type CalendarEventLayout = 'block' | 'chip' export interface CalendarEventSlotProps<E extends CalendarEvent = CalendarEvent> {
event: E
layout: CalendarEventLayout
timeText: string
continuesBefore: boolean
continuesAfter: boolean
dragging: boolean
grabbed: boolean
} export interface CalendarEventTimes {
start: string
end: string
startTime: string
endTime: string
} export type CalendarView = 'day' | '4days' | 'week' | 'month' | 'year' | 'custom' CSS variables