项目作者: greifmatthias

项目描述 :
Angular Calendar Component
高级语言: TypeScript
项目地址: git://github.com/greifmatthias/Ng-Calendar.git
创建时间: 2019-03-18T14:37:58Z
项目社区:https://github.com/greifmatthias/Ng-Calendar

开源协议:

下载


NgCalendar

Package Quality
Package Quality

NgCalendar is a simple library for Angular that allows you to render a bare functional calendar.

  • Renders calendar
  • Navigate through months
  • Style various components
  • Selection handling/callbacks

How to install

Available as an NPM-package:
npm install ng-mg-calendar


Docs

Layout

  • Show/hide the topstrip, defaults to true. If false will also hide the navigationbuttons in this strip.

    1. <mg-calendar [show_topstrip]="true|false"></mg-calendar>
  • Show/hide the 2 navigationbuttons at the top, defaults to true.

    1. <mg-calendar [show_navigator]="true|false"></mg-calendar>

Colors

  • Color for topstrip, defaults to transparent.

    1. <mg-calendar color_topstrip="red|#FF0000|.."></mg-calendar>
  • Color for the strip displaying the days of a week, defaults to transparent.

    1. <mg-calendar color_weekstrip="green|#00FF00|.."></mg-calendar>
  • Color for the view containing the days of a month, defaults to transparent.

    1. <mg-calendar color_monthview="blue|#0000FF|.."></mg-calendar>

Templating

Days of year

You can template the way content looks, just pass the template with its content. You can get information about a day using the moment object returned. moment is a Moment-object from the MomentJS-library.
The state of a day (isselected, ismultiselected, istoday, ispast) are returned as a string of the states seperated by a space.

  • Change the apearance/content of a displayed day in the month, defaults to a default style.

Component.html

  1. <mg-calendar [template_monthcurrent]="currentdaystyle"></mg-calendar>
  2. <ng-template let-day="moment" let-daystates="states" #currentdaystyle>
  3. <!-- states printed as classes: class="isselected .."-->
  4. <div class="{{ states }}">
  5. <p>
  6. {{ getMonth(day) }}
  7. </p>
  8. <p>
  9. {{ getDate(day) }}
  10. </p>
  11. </div>
  12. </ng-template>

Where getMonth() and getDate() are own functions:

Component.ts

  1. getMonth(moment: moment.Moment) : string {
  2. return moment.clone().format('MMMM');
  3. }
  4. getDate(moment: moment.Moment) {
  5. return moment.clone().date();
  6. }

This approach can also be used when templating the days for next month and the previous month:

  1. <mg-calendar [template_monthnext]="nextdaystyle" [template_monthprev]="prevdaystyle"></mg-calendar>

Topstrip

Template the top strip, this section is divided into 2 parts: the title and the navigation. Template can access year and month vars of the current view. month is a number from 0 - 11, year represents the year of the displayed view.

Component.html

  1. <mg-calendar [template_title]="titlestyle"></mg-calendar>
  2. <ng-template let-year="year" let-month="month" #titlestyle>
  3. <p>
  4. {{ year }} {{ getMonth(month) }}
  5. </p>
  6. </ng-template>

Component.ts

  1. getMonth(month : number) : string {
  2. return moment().clone().month(month).format('MMMM');
  3. }

Handlers

onSelectionChanged()

Triggered when a new selection of days has made on the calendar. It returns an array of Moment-objects of the new selection.

Component.html

  1. <mg-calendar (onSelectionChanged)="onSelectionChanged($event)"></mg-calendar>

Component.ts

  1. onSelectionChanged(event: any[]) {
  2. console.log(event.length);
  3. }

onNavigated()

Triggered when a navigation in month occured, returns a month and year navigated to.

Component.html

  1. <mg-calendar (onNavigated)="onNavigated($event)"></mg-calendar>

Component.ts

  1. onNavigated(event: any) {
  2. console.log(event.month);
  3. }

Roadmap

  • Weekstrip templating
  • Styling on component size
  • Load improvements