vue-cal v4
repository·main·Indexed 23 days ago
https://github.com/antoniandre/vue-cal-v4A full-featured Vue.js calendar component with no external dependencies. Version 4.10.2 provides a robust calendar interface with configurable views (years, year, month, week, day), event management, and extensive customization via props and slots. It includes programmatic control through $refs for methods like switchView and createEvent, as well as a drag-and-drop module based on the HTML5 Drag and Drop API (not supported on touch devices).
What's inside vue-cal
- To install the latest stable version of Vue Cal v4, use npm. Note that version 4.x is no longer maintained; v4.10.0 is the final release in this repository. If you are using Vue 2, you must install the legacy version specifically.
Access Vue Cal v4 documentation and demos
mainComprehensive documentation, usage examples, and live demos for Vue Cal v4 can be found at the official documentation site.
https://antoniandre.github.io/vue-cal-v4Use Vue Cal slots for customization
mainVue Cal provides several slots to customize the UI of different parts of the calendar:
arrow-prev/arrow-next: Customize the navigation arrows in the header.today-button: Customize the 'Today' button.title: Customize the calendar title (receives:titleand:viewprops).weekday-heading: Customize the day headings (receives:headingand:viewprops).split-label: Customize labels for day splits (receives:splitand:view.idprops).event: Customize the rendering of an event (receives:viewand:eventprops).time-cell: Customize the time labels in the time column (receives:hoursand:minutesprops).week-number-cell: Customize the week number display (receives:weekprop).cell-content: Customize the content inside a calendar cell (receives:cell,:view,:go-narrower, and:eventsprops).events-count: Customize the display of the number of events in a cell (receives:viewand:eventsprops).no-event: Customize the display when a cell has no events (receives no props).
Understand drag and drop behavior and limitations
mainThe drag and drop functionality in Vue Cal relies on the native HTML5 Drag and Drop API.
Key Behaviors:
- Snapping: If the
snapToTimeoption is enabled on the Vue Cal instance, dropped events will automatically snap to the nearest time interval defined by that value. - View Switching: Dragging over navigation buttons (like
previous,next,today, or specific view buttons likemonth) will trigger a view change if held for a certain duration (default 800ms). - Deep Navigation: In
years,year, ormonthviews, holding a drag over a cell will automatically trigger a transition to a narrower view (e.g., fromyeartomonth). - Cross-Instance Dragging: You can drag an event from one Vue Cal instance and drop it into another. If the event is dropped into a different instance, it is automatically removed from the source instance.
Limitations:
- Touch Devices: Because it uses the native HTML5 Drag and Drop API, this module is not supported on touch devices.
- Text Selection: Dragging is cancelled if the user attempts to drag a text selection (node type 3).
- Snapping: If the
Configure the Vue Cal component via props
mainThe
vue-calcomponent is the main entrypoint for the calendar. It is highly configurable through props. Key configuration categories include:- View Control:
activeView(default:'week'),disableViews(array of views to hide),selectedDate(current focus date). - Event Management:
events(array of event objects),editableEvents(boolean or object for editing permissions),onEventClick,onEventCreate,onEventDblclick(callback functions). - Time & Display:
time(boolean, default:true),timeStep(minutes, default:60),timeFrom/timeTo(minutes),twelveHour(boolean),showAllDayEvents(boolean or string),showWeekNumbers(boolean). - Layout & Constraints:
minCellWidth(number),minSplitWidth(number),minEventWidth(number),hideWeekends(boolean),startWeekOnSunday(boolean),small(boolean),xsmall(boolean). - Interactivity:
dragToCreateEvent(boolean),cellClickHold(boolean),cellContextmenu(boolean),clickToNavigate(boolean),dblclickToNavigate(boolean).
- View Control:
Update localized texts with updateDateTexts()
mainTo update the localized strings used for date formatting and calendar labels (like month names or day names), callupdateDateTexts()on the component instance via$refs. This method uses thetextsprop currently provided to the component.Listen to event resizing with event-resizing
mainWhile an event is being resized (e.g., dragging the bottom handle to change duration), the component emits theevent-resizingevent. This allows for real-time UI updates or validation during the resize interaction.Listen to event title changes with event-title-change
mainWheneditableEvents.titleis enabled, users can edit event titles directly in the calendar. When the editing is finished (on blur), the component emits theevent-title-changeevent. This event provides the updated event object and the previous title.Listen to event updates with event-change
mainTheevent-changeevent is emitted when an event is modified (e.g., via title editing). It provides the cleaned event object and the original event state (including the old title).Handle Vue Cal events
mainThe
vue-calcomponent emits several events that allow you to react to user interactions:view-change: Emitted when the view changes. Returns an object containingview,startDate,endDate, and view-specific properties likefirstCellDate/lastCellDatefor month view.update:activeView: Emitted when theactiveViewprop is updated (useful withv-model).event-change: Emitted when an event is modified (e.g., via resizing). Returns the neweventand theoriginalEvent.event-duration-change: Emitted when an event's duration is changed. Returns the newevent, theoldDate, and theoriginalEvent.event-drag-create: Emitted when a new event is successfully created via dragging.
Handle event drop and change events
mainWhen using the drag and drop module, Vue Cal emits two specific events when an event is successfully moved or updated via dragging. You can listen to these to sync your backend or application state.
event-drop: Emitted when an event is dropped into a cell or split. It provides details about the movement and the original event data.event-change: Emitted when an event's properties are modified via dragging.
event-droppayload:event: The updated event object (cleaned viacleanupEvent).oldDate: The original start date of the event.newDate: The new start date of the event.originalEvent: The original event data (useful if the event was external).oldSplit(optional): The previous split index/ID.newSplit(optional): The new split index/ID.external: Boolean indicating if the event originated from outside a Vue Cal instance.
event-changepayload:event: The updated event object.originalEvent: The original event data.
Create an event programmatically with createEvent()
mainYou can create a new event in the calendar's internal memory using the
createEvent(dateTime, duration, eventOptions)method via$refs.dateTime: AStringorDaterepresenting the start time.duration: The duration of the event in minutes.eventOptions: An object containing any additional event properties (e.g.,title,class,color).
Returns the created event object.