v-calendar
repository·master·Indexed 26 days ago
https://github.com/nathanreyes/v-calendarAn 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.
What's inside v-calendar
- v-calendar is an elegant calendar and datepicker plugin for Vue.js. It supports various visual attributes, multi-paned layouts, theme customization (including dark mode), and different date selection modes.
Configure date formatting and parsing with Masks
masterMasks 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 themasksprop 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).Understand timezone impact on v-calendar attributes
masterInv-calendar, thetimezoneprop 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.Import v-calendar styles
masterAs of
v3.0.0-alpha.7, you must manually import the component styles in your application due to Vite build restrictions in library mode.import 'v-calendar/dist/style.css';Use v-calendar as a Vue plugin
masterThe 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 });Implement responsive layouts with $screens
masterV-Calendar provides a
$screensmixin that allows you to create responsive props. This function automatically re-evaluates when the window crosses a breakpoint.Usage Pattern
- Mobile-First: V-Calendar is mobile-first. Values assigned to smaller screens apply to larger ones unless overridden.
- The
$screensfunction: Pass an object where keys are screen sizes (sm,md,lg,xl) and values are the desired prop values. Use thedefaultkey for the mobile layout. - Alternative Syntax: You can pass the default value as a second parameter to
$screensinstead of using thedefaultkey in the object.
Use v-calendar components globally
masterAlternatively, you can use
SetupCalendarto configure defaults and then register specific components likeCalendarandDatePickerglobally usingapp.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>Install v-calendar v1.0 (next)
masterTo install the v1.0 version of
v-calendar, use the@nexttag with npm.npm install --save v-calendar@nextConfigure responsive layouts with rows, columns, and $screens
masterIn v1.0, replace
is-double-panedandis-verticalwithrowsandcolumnsprops. To create responsive layouts, use the$screensfunction 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 })" />Understand the interaction between `disabled-dates` and `available-dates`
masterWhen using both
disabled-datesandavailable-datessimultaneously, the following logic applies:disabled-datesis evaluated first to disable specific days.available-datesis then evaluated to re-enable any dates that were previously disabled by thedisabled-datesexpression.
Best Practice: Avoid specifying dates in
available-datesthat are not already covered by thedisabled-dateslogic, as they will have no effect.Use the v-date-picker component
masterThev-date-pickeris included out of the box and acts as a wrapper forv-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 tov-calendar.Parse dates using multiple masks
masterWhen 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
inputmask is["L", "YYYY-MM-DD", "YYYY/MM/DD"], a user can type a date inYYYY-MM-DDformat, but the component will ultimately display it using theL(localized) format after thechangeevent.<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(), } } }