vue-cal v4

repository·main·Indexed 23 days ago

https://github.com/antoniandre/vue-cal-v4

A 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).

Tokens
2K
Snippets
1
Records
15
Agent score
79%

What's inside vue-cal

  1. Install vue-cal v4

    main
    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.
  2. Use Vue Cal slots for customization

    main

    Vue 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 :title and :view props).
    • weekday-heading: Customize the day headings (receives :heading and :view props).
    • split-label: Customize labels for day splits (receives :split and :view.id props).
    • event: Customize the rendering of an event (receives :view and :event props).
    • time-cell: Customize the time labels in the time column (receives :hours and :minutes props).
    • week-number-cell: Customize the week number display (receives :week prop).
    • cell-content: Customize the content inside a calendar cell (receives :cell, :view, :go-narrower, and :events props).
    • events-count: Customize the display of the number of events in a cell (receives :view and :events props).
    • no-event: Customize the display when a cell has no events (receives no props).
  3. Understand drag and drop behavior and limitations

    main

    The drag and drop functionality in Vue Cal relies on the native HTML5 Drag and Drop API.

    Key Behaviors:

    • Snapping: If the snapToTime option 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 like month) will trigger a view change if held for a certain duration (default 800ms).
    • Deep Navigation: In years, year, or month views, holding a drag over a cell will automatically trigger a transition to a narrower view (e.g., from year to month).
    • 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).
  4. Configure the Vue Cal component via props

    main

    The vue-cal component 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).
  5. Listen to event title changes with event-title-change

    main
    When editableEvents.title is enabled, users can edit event titles directly in the calendar. When the editing is finished (on blur), the component emits the event-title-change event. This event provides the updated event object and the previous title.
  6. Handle Vue Cal events

    main

    The vue-cal component emits several events that allow you to react to user interactions:

    • view-change: Emitted when the view changes. Returns an object containing view, startDate, endDate, and view-specific properties like firstCellDate/lastCellDate for month view.
    • update:activeView: Emitted when the activeView prop is updated (useful with v-model).
    • event-change: Emitted when an event is modified (e.g., via resizing). Returns the new event and the originalEvent.
    • event-duration-change: Emitted when an event's duration is changed. Returns the new event, the oldDate, and the originalEvent.
    • event-drag-create: Emitted when a new event is successfully created via dragging.
  7. Handle event drop and change events

    main

    When 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-drop payload:

    • event: The updated event object (cleaned via cleanupEvent).
    • 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-change payload:

    • event: The updated event object.
    • originalEvent: The original event data.
  8. Create an event programmatically with createEvent()

    main

    You can create a new event in the calendar's internal memory using the createEvent(dateTime, duration, eventOptions) method via $refs.

    • dateTime: A String or Date representing 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.