1
1
import { Component , Input , Output , EventEmitter } from '@angular/core' ;
2
- import {
3
- subDays ,
4
- addDays ,
5
- addWeeks ,
6
- subWeeks ,
7
- addMonths ,
8
- subMonths
9
- } from 'date-fns' ;
10
2
11
3
@Component ( {
12
4
selector : 'mwl-calendar-header' ,
13
5
template : `
14
6
<div class="row text-center">
15
7
<div class="col-md-4">
16
8
<div class="btn-group">
17
- <div class="btn btn-primary" (click)="decrement()">
9
+ <div
10
+ class="btn btn-primary"
11
+ mwlCalendarPreviousView
12
+ [view]="view"
13
+ [(viewDate)]="viewDate">
18
14
Previous
19
15
</div>
20
- <div class="btn btn-secondary" (click)="today()">
16
+ <div
17
+ class="btn btn-secondary"
18
+ mwlCalendarToday
19
+ [(viewDate)]="viewDate">
21
20
Today
22
21
</div>
23
- <div class="btn btn-primary" (click)="increment()">
22
+ <div
23
+ class="btn btn-primary"
24
+ mwlCalendarNextView
25
+ [view]="view"
26
+ [(viewDate)]="viewDate">
24
27
Next
25
28
</div>
26
29
</div>
@@ -30,9 +33,24 @@ import {
30
33
</div>
31
34
<div class="col-md-4">
32
35
<div class="btn-group">
33
- <div class="btn btn-primary" (click)="viewChange.emit('month')" [class.active]="view === 'month'">Month</div>
34
- <div class="btn btn-primary" (click)="viewChange.emit('week')" [class.active]="view === 'week'">Week</div>
35
- <div class="btn btn-primary" (click)="viewChange.emit('day')" [class.active]="view === 'day'">Day</div>
36
+ <div
37
+ class="btn btn-primary"
38
+ (click)="viewChange.emit('month')"
39
+ [class.active]="view === 'month'">
40
+ Month
41
+ </div>
42
+ <div
43
+ class="btn btn-primary"
44
+ (click)="viewChange.emit('week')"
45
+ [class.active]="view === 'week'">
46
+ Week
47
+ </div>
48
+ <div
49
+ class="btn btn-primary"
50
+ (click)="viewChange.emit('day')"
51
+ [class.active]="view === 'day'">
52
+ Day
53
+ </div>
36
54
</div>
37
55
</div>
38
56
</div>
@@ -51,32 +69,4 @@ export class CalendarHeaderComponent {
51
69
52
70
@Output ( ) viewDateChange : EventEmitter < Date > = new EventEmitter ( ) ;
53
71
54
- increment ( ) : void {
55
-
56
- const addFn : any = {
57
- day : addDays ,
58
- week : addWeeks ,
59
- month : addMonths
60
- } [ this . view ] ;
61
-
62
- this . viewDateChange . emit ( addFn ( this . viewDate , 1 ) ) ;
63
-
64
- }
65
-
66
- decrement ( ) : void {
67
-
68
- const subFn : any = {
69
- day : subDays ,
70
- week : subWeeks ,
71
- month : subMonths
72
- } [ this . view ] ;
73
-
74
- this . viewDateChange . emit ( subFn ( this . viewDate , 1 ) ) ;
75
-
76
- }
77
-
78
- today ( ) : void {
79
- this . viewDateChange . emit ( new Date ( ) ) ;
80
- }
81
-
82
72
}
0 commit comments