Skip to content

Commit 2f537bd

Browse files
authored
Merge pull request #13 from fullstack-devops/feature/dump-moment.js-use-date-fns
dump moment.js and use date-fns
2 parents af62d29 + fc43f25 commit 2f537bd

File tree

10 files changed

+415
-285
lines changed

10 files changed

+415
-285
lines changed

.vscode/settings.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.renderWhitespace": "all",
4+
"prettier.arrowParens": "avoid",
5+
"prettier.printWidth": 120,
6+
"editor.tabSize": 2,
7+
"files.trimTrailingWhitespace": true,
8+
"files.trimFinalNewlines": true,
9+
"workbench.iconTheme": "material-icon-theme",
10+
"editor.defaultFormatter": "esbenp.prettier-vscode",
11+
"[javascript]": {
12+
"editor.defaultFormatter": "esbenp.prettier-vscode"
13+
},
14+
"javascript.updateImportsOnFileMove.enabled": "always",
15+
"typescript.updateImportsOnFileMove.enabled": "always",
16+
"[typescript]": {
17+
"editor.codeActionsOnSave": {
18+
"source.organizeImports": true
19+
}
20+
},
21+
"angular.enable-strict-mode-prompt": false,
22+
"files.associations": {
23+
".env*": "shell"
24+
},
25+
"[html]": {
26+
"editor.defaultFormatter": "esbenp.prettier-vscode"
27+
}
28+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@angular/platform-browser": "~13.3.11",
2828
"@angular/platform-browser-dynamic": "~13.3.11",
2929
"@angular/router": "~13.3.11",
30-
"moment": "^2.29.4",
30+
"date-fns": "^2.29.3",
3131
"rxjs": "~7.5.6",
3232
"tslib": "^2.4.0",
3333
"zone.js": "~0.11.7"
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div style="display: flex; justify-content: space-around;">
1+
<div style="display: flex; justify-content: space-around">
22
<mat-slide-toggle [(ngModel)]="placeholder">
33
Days placeholder
44
</mat-slide-toggle>
@@ -8,23 +8,34 @@
88
<mat-form-field>
99
<mat-label>Months before</mat-label>
1010
<mat-select [(ngModel)]="monthsBefore">
11-
<mat-option *ngFor="let num of monthsAfterBefore" [value]="num">{{num}}</mat-option>
11+
<mat-option *ngFor="let num of monthsAfterBefore" [value]="num">{{
12+
num
13+
}}</mat-option>
1214
</mat-select>
1315
</mat-form-field>
1416
<mat-form-field>
1517
<mat-label>Months after</mat-label>
1618
<mat-select [(ngModel)]="monthsAfter">
17-
<mat-option *ngFor="let num of monthsAfterBefore" [value]="num">{{num}}</mat-option>
19+
<mat-option *ngFor="let num of monthsAfterBefore" [value]="num">{{
20+
num
21+
}}</mat-option>
1822
</mat-select>
1923
</mat-form-field>
2024
<div>
21-
<p>Selected range: {{range | json}}</p>
25+
<p>Selected range: {{ range | json }}</p>
2226
</div>
2327
</div>
2428

25-
<div style="height: 80%;">
26-
<fs-calendar [placeholderDay]="placeholder" [dataSource]="dataSource" [year]="2022" [month]="3"
27-
[monthsBefore]="monthsBefore" [monthsAfter]="monthsAfter" [config]="calendarConfig"
28-
(selectedDate)="testMethod($event)">
29+
<div style="height: 80%">
30+
<fs-calendar
31+
[placeholderDay]="placeholder"
32+
[dataSource]="dataSource"
33+
[year]="todayYear"
34+
[month]="todayMonth"
35+
[monthsBefore]="monthsBefore"
36+
[monthsAfter]="monthsAfter"
37+
[config]="calendarConfig"
38+
(selectedDate)="testMethod($event)"
39+
>
2940
</fs-calendar>
3041
</div>
Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,86 @@
1-
import { CalendarConfig, Day, calendarSelected } from 'projects/ng-mat-components/src/public-api';
21
import { Component, OnInit } from '@angular/core';
2+
import {
3+
CalendarConfig,
4+
calendarSelected,
5+
Day,
6+
} from 'projects/ng-mat-components/src/public-api';
37

48
@Component({
59
selector: 'lib-calender-showcase',
610
templateUrl: './calender-showcase.component.html',
7-
styleUrls: ['./calender-showcase.component.scss']
11+
styleUrls: ['./calender-showcase.component.scss'],
812
})
913
export class CalenderShowcaseComponent implements OnInit {
10-
docsApi = "./assets/docs/calendar/api.md"
11-
range: any
14+
docsApi = './assets/docs/calendar/api.md';
15+
range: any;
1216

13-
placeholder = false // boolean
14-
isLoading = true
15-
latestEvent: Object | undefined
17+
placeholder = false; // boolean
18+
isLoading = true;
19+
latestEvent: Object | undefined;
1620

17-
monthsAfterBefore = Array(5).fill(0).map((x, i) => i);
18-
monthsBefore = 2;
19-
monthsAfter = 0;
21+
today = new Date();
22+
todayMonth = this.today.getMonth();
23+
todayYear = this.today.getFullYear();
24+
25+
monthsAfterBefore = Array(5)
26+
.fill(0)
27+
.map((x, i) => i);
28+
monthsBefore = 1;
29+
monthsAfter = 1;
2030

2131
calendarConfig: CalendarConfig = {
2232
renderMode: 'monthly', // 'annual' | 'monthly'
23-
selectMode: 'range', // 'click' | 'range'
33+
selectMode: 'range', // 'click' | 'range'
2434
displayYear: true,
2535
firstDayOfWeekMonday: true,
26-
calendarWeek: false,
36+
calendarWeek: true,
2737
switches: true,
2838
panelWidth: '300px',
2939
bluredDays: false, // default: false
30-
markWeekend: true // default: true
31-
}
40+
markWeekend: true, // default: true
41+
};
3242

3343
dataSource: Day[] = [
3444
{
3545
date: new Date(1634594400000),
3646
backgroundColor: '#0167c7',
3747
toolTip: 'Test ToolTip First',
38-
dayNumber: ''
48+
dayNumber: '',
3949
},
4050
{
4151
date: new Date(1634594400000),
4252
backgroundColor: 'rgb(6, 182, 0)',
4353
toolTip: 'Test ToolTip Second',
44-
dayNumber: ''
54+
dayNumber: '',
4555
},
4656
{
4757
date: new Date(1634853600000),
4858
backgroundColor: 'rgb(6, 182, 0)',
4959
toolTip: 'Test ToolTip 2',
50-
dayNumber: ''
60+
dayNumber: '',
5161
},
5262
{
5363
date: new Date(1635544800000),
5464
backgroundColor: 'lightblue',
55-
dayNumber: ''
56-
}
57-
]
65+
dayNumber: '',
66+
},
67+
];
5868

59-
constructor() { }
69+
constructor() {}
6070
ngOnInit(): void {
61-
console.log(this.dataSource)
62-
this.isLoading = false
71+
console.log(this.dataSource);
72+
this.isLoading = false;
6373
}
6474

6575
testMethod(event: calendarSelected) {
6676
switch (event.type) {
67-
case "range":
77+
case 'range':
6878
this.range = event;
6979
break;
70-
case "date":
80+
case 'date':
7181
this.range = event;
7282
break;
7383
}
74-
console.log(event)
84+
console.log(event);
7585
}
7686
}

projects/ng-mat-components/_theming.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,9 @@
125125
transparent 100%
126126
);
127127
}
128+
129+
.month-header button {
130+
border: 1px solid mat-color($foreground, "divider");
131+
border-radius: 4px;
132+
}
128133
}

projects/ng-mat-components/src/lib/fs-calendar/calendar.models.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010
* @param {string} panelWidth set a with for an single panel
1111
*/
1212
export interface CalendarConfig {
13-
renderMode: string;
14-
selectMode: string;
15-
calendarWeek: boolean;
16-
displayYear?: boolean;
17-
switches?: boolean;
18-
bluredDays?: boolean;
19-
markWeekend?: boolean;
20-
firstDayOfWeekMonday?: boolean;
21-
panelWidth?: string;
13+
renderMode: 'monthly' | 'annual';
14+
selectMode: string;
15+
calendarWeek: boolean;
16+
displayYear?: boolean;
17+
switches?: boolean;
18+
bluredDays?: boolean;
19+
markWeekend?: boolean;
20+
firstDayOfWeekMonday?: boolean;
21+
panelWidth?: string;
2222
}
2323

2424
export class Calendar {
25-
year: number = 2022;
26-
dayNames: String[] = [''];
27-
months: Month[] = [];
28-
daysAbsolute: Date[] = []
25+
year: number = 2022;
26+
dayNames: String[] = [''];
27+
months: Month[] = [];
28+
daysAbsolute: Date[] = [];
2929
}
3030
export interface Month {
31-
name: string;
32-
days: Day[];
33-
year: number;
34-
render: [Day[]];
31+
name: string;
32+
days: Day[];
33+
year: number;
34+
render: [Day[]];
3535
}
3636

3737
export interface selectedRange {
@@ -46,30 +46,30 @@ export interface selectedDate {
4646
export type calendarSelected = selectedRange | selectedDate;
4747

4848
/**
49-
* Use this to customize your data in the calendar
50-
* @param {number} day number of day (override not allowed)
51-
* @param {Date} date Date to match
52-
* @param {number} kw calendar week (override not allowed)
53-
* @param {boolean} isWeekendDay Boolean if day weekend (override not allowed)
54-
* @param {string} color set a custom color (hex, string, or var)
55-
* @param {string} backgroundColor set a custom Background Color (hex, string, or var)
56-
* @param {boolean} badge if you want to use a Badge
57-
* @param {string} badgeMode badgeMode options: 'Int' or 'Icon'
58-
* @param {number} badgeInt if badgeMode == 'Int', set our Number here
59-
* @param {string} badgeIcon if badgeMode == 'Icon', set Icon (Matireal-Icons)
60-
* @param {string} toolTip if set, this displays a mat-tooltip
61-
*/
49+
* Use this to customize your data in the calendar
50+
* @param {number} day number of day (override not allowed)
51+
* @param {Date} date Date to match
52+
* @param {number} kw calendar week (override not allowed)
53+
* @param {boolean} isWeekendDay Boolean if day weekend (override not allowed)
54+
* @param {string} color set a custom color (hex, string, or var)
55+
* @param {string} backgroundColor set a custom Background Color (hex, string, or var)
56+
* @param {boolean} badge if you want to use a Badge
57+
* @param {string} badgeMode badgeMode options: 'Int' or 'Icon'
58+
* @param {number} badgeInt if badgeMode == 'Int', set our Number here
59+
* @param {string} badgeIcon if badgeMode == 'Icon', set Icon (Matireal-Icons)
60+
* @param {string} toolTip if set, this displays a mat-tooltip
61+
*/
6262
export interface Day {
63-
dayNumber: string;
64-
date: Date;
65-
kw?: number;
66-
isWeekendDay?: boolean;
67-
type?: string;
68-
color?: string;
69-
backgroundColor?: string;
70-
badge?: boolean;
71-
badgeMode?: string;
72-
badgeInt?: number;
73-
badgeIcon?: string;
74-
toolTip?: string;
63+
dayNumber: string;
64+
date: Date;
65+
kw?: number;
66+
isWeekendDay?: boolean;
67+
type?: string;
68+
color?: string;
69+
backgroundColor?: string;
70+
badge?: boolean;
71+
badgeMode?: string;
72+
badgeInt?: number;
73+
badgeIcon?: string;
74+
toolTip?: string;
7575
}

0 commit comments

Comments
 (0)