0.1.2 • Published 3 years ago

vlite-calendar v0.1.2

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

vLite Calendar

A simple and lightweight, yet flexible calendar component for Vue 2.x, with:

  • no styles dependency or inline styles
  • using browser locale
  • date-fns/esm (only calculation methods)

The intention of this component is to allow you to style your own calendar theme to suit your website design. See Styles Guide for detail.

Demo

See Demo Page for more example.

Get Started

Installation

As usual, install the calendar component NPM package.

npm install vlite-calendar --save

Next, include the calendar component in your own component.

import Calendar from 'vlite-calendar';

export default {
  // ...
  components: {
    Calendar,
  },
  // ...
}

Then, you can use <calendar> tag in your Vue template.

<calendar></calendar>

Check out Props Guide for component available props.

CDN Usage

Coming soon

Props Guide

PropTypeDefaultDescription
class-prefixStringvl-calendarCalendar CSS class prefix.
dateDatenew Date()Calendar selected date.
process-dateFunctionPost-processing the final content of rendered date. See vdate Object Guide for more detail.
viewsArray'days', 'months', 'years'Enable different view mode on the calendar. *First item will used as default view.
week-startNumber0The first day of the week (0-Sunday)
prependVue SlotAbility to inject additional content into the start of the calendar
appendVue SlotAbility to inject additional content into the end of the calendar

Example code.

<calendar
  :date="pickedDate"
  :views="['days']"
></calendar>

Example usage of Vue Slot.

<calendar :date="pickedDate">
  <div slot="prepend">
    This will appear before the calendar
  </div>
  <div slot="append">
    This will appear after the calendar
  </div>
</calendar>

Events Guide

EventParamsDescription
change-view(newView)View mode changed.
select-day({ day, vdate })A day has been selected.
select-month({ day, vdate })A month has been selected. The day indicate the first day of the selected month.
select-year({ day, vdate })A year has been selected. The day indicate the first day of the selected year.

Example usage.

<calendar
  @select-day="onSelect"
></calendar>
export default {
  ...
  methods: {
    onSelect({ day, vdate }) {
      console.log(day);
    }
  }
}

vdate Object Guide

vdate object is used by component internally for handling what to render on each calendar days, months, and years. However, you can overwrite it through process-date prop.

PropTypeDescription
dayDateCurrent date in JS Date object
keyTimestampCurrent date in timestamp
typeStringCurrent content type - day, month, or year
displayStringDisplay content for current date
classesStringInjected CSS classes
isTodayBooleanIs current date today?
isCurrentBooleanIs current date same as calendar selected date?
isInvalidBooleanIs current date disabled?
isOutBooleanIs current date out of calendar month?

Example usage.

<calendar
  :process-date="onProcessDate"
></calendar>
export default {
  ...
  methods: {
    onProcessDate(vdate) {
      // perform some checking
      // console.log(vdate.day)
      // vdate.isInvalid = true;
      // ...

      // remember to return back the vdate object
      return vdate;
    }
  }
}

Styles Guide

This component is intentionally for custom calendar theme styling. Hence all CSS classes used within the component are auto-prefixed with vl-calendar (can be overwrite through component class-prefix prop).

CSS classDescription
.{prefix}Calendar root
.{prefix}-rowRow wrap of calendar
.{prefix}-captionCalendar view label
.{prefix}-prevCalendar '<' button
.{prefix}-nextCalendar '>' button
.{prefix}-weekWeek content
.{prefix}-dayDay content
.{prefix}-monthMonth content
.{prefix}-yearYear content
.{prefix}--outState indicator, content is outside of viewing month
.{prefix}--todayState indicator, content is today
.{prefix}--currentState indicator, content is same as selected date
.{prefix}--invalidState indicator, content is disabled

You can scope targeted these CSS classes on your component.

<style scoped>
/deep/ .vl-calendar{
  ...
}
/deep/ .vl-calendar-day{
  ...
}
</style>

However, you are free to use the built-in styling if you want.

import 'vlite-calendar/dist/vlite-calendar-style.min.css';

Change Log

Change logs can be found at CHANGELOG.md

License

MIT

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago