Calendar component
vue-calendar-picker demo on jsfiddle
<template>
<calendar></calendar>
</template>
<script>
import {calendar} from 'vue-calendar-picker'
export default {
components: {
calendar: calendar
}
}
</script>
npm install --save vue-calendar-picker
- zoom from decade view to hour view (decade, year, month, week, day, hour)
- localized (see supported locale list)
- autodetect the first day of the week
- animated (zoom & slide)
- multiple calendar views (side-by-side)
- display one-time events and date/time period
- date/time period selection
- touch screen support
- only one dependancy: date-fns, a Modern JavaScript date utility library
vue-calendar-picker
has 3 available components:
calendar.vue
: simple calendar.calendarEvents.vue
:calendar.vue
+ one-time events and date/time periods display.calendarRange.vue
:calendarEvents.vue
+ range selection.
- date ranges are inclusive, exclusive ([start, end[)
The locale of the calendar. Impacts the days names, month names and first day ofthe week. supported locale list. Locale name must be uppercase.
Enable compact mode. Use less UI space.
Initial view zoom.
Initial view date.
Called for each calendar cell. The retun valus is used as className of the cell.
Allow to display multiple calendar views side-by-side.
In the month view, show days belonging to the preceding and following month.
eventObject
has the following properties:
'down'
: mousedown or touchstart'up'
: mouseup or touchend'tap'
: click or tap'press'
: dblclick or longtap'over'
: mouseover or touchmove
Indicates that the pointer is active: a mouse button is down or the finger touches the screen.
Indicates that the shift or ctrl or alt or meta key is down. Always false
on touch-screen devices.
The date range of the item
The range name: 'minute'
, 'hour'
, 'day'
, 'week'
, 'month'
, 'year'
.
The content of calendar cells.
The time range of the the cell.
The layout of the content, either 'horizontal'
or 'vertical'
.
vue-calendar-picker can by styled easily, all css selectors are prefixed with .calendar
.
.calendar {
border: 2px solid #000;
border-radius: 0.5em;
padding: 0.5em;
}
- click on date part in the calendar header area to modify it (zoom out)
- click or double-click on the cell to zoom in. (from month view, use double-click to zoom in)
:locale - see calendar.vue API.
:compact - see calendar.vue API.
:initialView - see calendar.vue API.
:initialCurrent - see calendar.vue API.
:itemClass - see calendar.vue API.
A list of one-time events and date/time periods to display in the calendar.
One-time events has the same start
and end
date.
The current calendar selection. For display only.
eventObject
has the same properties that calendar.vue added:
A reference to a calendar event (see :events
property) related to the mouse/touch event, otherwise undefined
.
- event range are colored lines
- event point are big dots
Allow user selection. The selection
property object is modified according to the user's selection.
:locale - see calendar.vue API.
:compact - see calendar.vue API.
:initialView - see calendar.vue API.
:initialCurrent - see calendar.vue API.
:itemClass - see calendar.vue API.
:events - see calendarEvents.vue API.
:selection - see calendarEvents.vue API.
Display two calendars side-by-side to make selection easier.
eventObject
has the same properties that calendar.vue.
- use mousedown + move or tap + move to select a range (also across calendars)
- use ctrl + click to update the selection from the nearest end point (disbled on touch screens)
Same browser support as Vue.js 2
<template>
<calendar-range :events="calendarEvents" :selection="calendarSelection"></calendar-range>
</template>
<script>
import {calendarRange} from 'vue-calendar-picker'
export default {
components: {
calendarRange: calendarRange
},
data() {
return {
calendarEvents: [
// periods
{ color:'#aaf', start: new Date(2016, 9, 5, 0,0,0,0), end: new Date(2017, 4, 15, 0,0,0,0) },
{ color:'#afa', start: new Date(2016, 9, 5, 0,0,0,0), end: new Date(2017, 4, 13, 0,0,0,0) },
{ color:'#faa', start: new Date(2017, 4, 8, 12,30, 0,0), end: new Date(2017, 4, 9, 6,30, 0,0) },
// one-time
{ color:'#faa', start: new Date(2017, 4, 2, 0,0,0,0), end: new Date(2017, 4, 2, 0,0,0,0) },
{ color:'#aaa', start: new Date(2017, 4, 2, 0,0,0,0), end: new Date(2017, 4, 2, 0,0,0,0) },
],
calendarSelection: {
start: new Date(2017, 4, 2), end: new Date(2017, 4, 7, 12)
}
}
}
}
</script>