v-calendar

repository·master·Indexed 26 days ago

https://github.com/nathanreyes/v-calendar

An elegant calendar and datepicker plugin for Vue.js applications, version 2.4.2. It features multi-paned layouts, theme customization with dark mode, and a flexible attribute system for highlighting dates with dots, bars, and popovers. The library provides comprehensive API controls for date boundaries, navigation constraints, and custom rendering via scoped slots for headers, day content, and popovers.

Tokens
31.1K
Snippets
73
Records
205
Agent score
88%

What's inside v-calendar

  1. Configure date formatting and parsing with Masks

    master
    Masks are used to format and parse different sections of the calendar and date picker components. They are composed of tokens that derive from the active locale. You can explicitly provide masks via the masks prop or through a locale configuration. Some masks are used only for formatting (e.g., title), while others are used for both formatting and parsing (indicated by the parse flag).
  2. Understand timezone impact on v-calendar attributes

    master
    In v-calendar, the timezone prop sets the beginning and ending time boundaries for each calendar day. Because of this, calendar attributes (like highlights or dots) that are tied to specific timestamps may appear on different days depending on the timezone currently set for the calendar.
  3. Use v-calendar as a Vue plugin

    master

    The recommended way to use v-calendar is by installing it as a plugin. This allows you to set global defaults and choose a component prefix to avoid naming conflicts.

    import Vue from 'vue';
    import VCalendar from 'v-calendar';
    
    // Use v-calendar & v-date-picker components
    Vue.use(VCalendar, {
      componentPrefix: 'vc',  // Use <vc-calendar /> instead of <v-calendar />
      ...,                // ...other defaults
    });
  4. Implement responsive layouts with $screens

    master

    V-Calendar provides a $screens mixin that allows you to create responsive props. This function automatically re-evaluates when the window crosses a breakpoint.

    Usage Pattern

    1. Mobile-First: V-Calendar is mobile-first. Values assigned to smaller screens apply to larger ones unless overridden.
    2. The $screens function: Pass an object where keys are screen sizes (sm, md, lg, xl) and values are the desired prop values. Use the default key for the mobile layout.
    3. Alternative Syntax: You can pass the default value as a second parameter to $screens instead of using the default key in the object.
  5. Use v-calendar components globally

    master

    Alternatively, you can use SetupCalendar to configure defaults and then register specific components like Calendar and DatePicker globally using app.component().

    // main.js
    import { SetupCalendar, Calendar, DatePicker } from 'v-calendar';
    
    // Setup plugin for defaults or $screens (optional)
    app.use(SetupCalendar, {})
    // Use the components
    app.component('Calendar', Calendar)
    app.component('DatePicker', DatePicker)
    <!-- Component.vue template -->
    <template>
      <Calendar />
      <DatePicker v-model="date" />
    </template>
  6. Configure responsive layouts with rows, columns, and $screens

    master

    In v1.0, replace is-double-paned and is-vertical with rows and columns props. To create responsive layouts, use the $screens function provided via a mixin to adjust these props based on breakpoints.

    <v-calendar
      :rows="$screens({ default: 1, lg: 2 })"
      :columns="$screens({ default: 1, lg: 2 })"
      />
  7. Understand the interaction between `disabled-dates` and `available-dates`

    master

    When using both disabled-dates and available-dates simultaneously, the following logic applies:

    1. disabled-dates is evaluated first to disable specific days.
    2. available-dates is then evaluated to re-enable any dates that were previously disabled by the disabled-dates expression.

    Best Practice: Avoid specifying dates in available-dates that are not already covered by the disabled-dates logic, as they will have no effect.

  8. Use the v-date-picker component

    master
    The v-date-picker is included out of the box and acts as a wrapper for v-calendar. It supports single date, multiple date, and date range selection modes. Because it wraps the core calendar, it inherits all the same props, slots, and custom theme support available to v-calendar.
  9. Parse dates using multiple masks

    master

    When a mask is assigned an array of values, the first value is used to format the date, while all values in the array are used (from first to last) to parse the input string. The first successfully parsed format is used as the date value.

    For example, if the input mask is ["L", "YYYY-MM-DD", "YYYY/MM/DD"], a user can type a date in YYYY-MM-DD format, but the component will ultimately display it using the L (localized) format after the change event.

    <v-date-picker v-model="date">
      <template #default="{ inputValue, inputEvents }">
        <input class="px-3 py-1 border rounded" :value="inputValue" v-on="inputEvents" />
      </template>
    </v-date-picker>
    
    ```js
    export default {
      data() {
        return  {
          date: new Date(),
        }
      }
    }