@progressive-development/pd-calendar 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/preview-head.html +2 -0
- package/package.json +2 -2
- package/src/PdCalendar.js +64 -22
- package/stories/index.stories.js +75 -12
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "progressive development calendar web component",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"author": "PD Progressive Development",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.6",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.js",
|
|
9
9
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"lit": "^2.0.2",
|
|
34
|
-
"@progressive-development/pd-icon": "0.0.
|
|
34
|
+
"@progressive-development/pd-icon": "0.0.7",
|
|
35
35
|
"fecha": "^4.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
package/src/PdCalendar.js
CHANGED
|
@@ -22,19 +22,22 @@ const VIEW_WEEK = 3;
|
|
|
22
22
|
* @csspart button - The button
|
|
23
23
|
*/
|
|
24
24
|
export class PdCalendar extends LitElement {
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
|
-
* Fired when next month clicked
|
|
27
|
+
* Fired when next or prev month clicked
|
|
27
28
|
* @event change-month
|
|
28
29
|
*/
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* Fired when
|
|
32
|
+
* Fired when date with info element clicked => At the moment only for those ones
|
|
32
33
|
* @event select-date
|
|
33
34
|
*/
|
|
34
35
|
|
|
35
36
|
static get styles() {
|
|
36
37
|
return css`
|
|
37
38
|
:host {
|
|
39
|
+
|
|
40
|
+
/* Define custom properties for calendar element */
|
|
38
41
|
--my-title-color: var(--squi-title-color, #084c61);
|
|
39
42
|
--my-day-title-bg-color: var(--squi-title-color, #084c61);
|
|
40
43
|
--my-cell-bg-color: var(--squi-title-color, lightgrey);
|
|
@@ -52,14 +55,10 @@ export class PdCalendar extends LitElement {
|
|
|
52
55
|
|
|
53
56
|
--my-primary-font: var(--squi-primary-font, Oswald);
|
|
54
57
|
|
|
55
|
-
/*
|
|
56
|
-
display: block;
|
|
57
|
-
padding: 8px;
|
|
58
|
-
*/
|
|
59
|
-
/*max-width: 800px;*/
|
|
60
58
|
display: block;
|
|
61
|
-
/*
|
|
62
|
-
|
|
59
|
+
/*padding: 8px;
|
|
60
|
+
width: 100vw;
|
|
61
|
+
height: 100vh;*/
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
/* Layout Grid for the Calendar Component => Not really needed at the moment, more a test */
|
|
@@ -159,7 +158,7 @@ export class PdCalendar extends LitElement {
|
|
|
159
158
|
.special {
|
|
160
159
|
/*background-image: linear-gradient(to right, green, darkgreen);
|
|
161
160
|
background-color: var(--my-info-cell-bg1-color);*/
|
|
162
|
-
background-color: var(--green,
|
|
161
|
+
background-color: var(--green, green); /*#1da692*/
|
|
163
162
|
/*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
|
|
164
163
|
box-shadow: 1px 2px 2px;
|
|
165
164
|
}
|
|
@@ -241,25 +240,56 @@ export class PdCalendar extends LitElement {
|
|
|
241
240
|
static get properties() {
|
|
242
241
|
return {
|
|
243
242
|
currentDate: { type: Object },
|
|
243
|
+
prevMonthConstraint: { type: Number },
|
|
244
|
+
nextMonthConstraint: { type: Number },
|
|
244
245
|
data: { type: Object },
|
|
245
246
|
_viewType: { type: Number },
|
|
247
|
+
_latestDate: { type: Object },
|
|
248
|
+
_earliestDate: { type: Object },
|
|
246
249
|
};
|
|
247
250
|
}
|
|
248
251
|
|
|
249
252
|
constructor() {
|
|
250
253
|
super();
|
|
254
|
+
|
|
255
|
+
this.data = {};
|
|
256
|
+
this._viewType = VIEW_MONTH;
|
|
251
257
|
|
|
252
258
|
// initialize date values with current date
|
|
253
|
-
|
|
254
|
-
this.
|
|
259
|
+
const now = new Date();
|
|
260
|
+
this._initFromDate(now);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
firstUpdated() {
|
|
264
|
+
// get latest possible date
|
|
265
|
+
if (this.nextMonthConstraint >= 0) {
|
|
266
|
+
const now = new Date();
|
|
267
|
+
const tmpDate = new Date(
|
|
268
|
+
now.getFullYear(),
|
|
269
|
+
now.getMonth() + 1,
|
|
270
|
+
0
|
|
271
|
+
);
|
|
272
|
+
tmpDate.setMonth(tmpDate.getMonth() + (this.nextMonthConstraint - 1));
|
|
273
|
+
this._latestDate = tmpDate;
|
|
274
|
+
}
|
|
255
275
|
|
|
256
|
-
|
|
276
|
+
// get earliest possible date
|
|
277
|
+
if (this.prevMonthConstraint >= 0) {
|
|
278
|
+
const now = new Date();
|
|
279
|
+
const tmpDate = new Date(
|
|
280
|
+
now.getFullYear(),
|
|
281
|
+
now.getMonth() + 1,
|
|
282
|
+
0
|
|
283
|
+
);
|
|
284
|
+
tmpDate.setMonth(tmpDate.getMonth() - (this.prevMonthConstraint));
|
|
285
|
+
this._earliestDate = tmpDate;
|
|
286
|
+
}
|
|
257
287
|
}
|
|
258
288
|
|
|
259
289
|
render() {
|
|
260
|
-
return html`
|
|
261
|
-
<slot></slot>
|
|
290
|
+
return html`
|
|
262
291
|
${this.renderCalendarByViewType()}
|
|
292
|
+
<slot name="calFooter"></slot>
|
|
263
293
|
`;
|
|
264
294
|
}
|
|
265
295
|
|
|
@@ -358,7 +388,6 @@ export class PdCalendar extends LitElement {
|
|
|
358
388
|
${itemTemplates}
|
|
359
389
|
</div>
|
|
360
390
|
</div>
|
|
361
|
-
<p>* excl. BTW</p>
|
|
362
391
|
`;
|
|
363
392
|
}
|
|
364
393
|
|
|
@@ -379,8 +408,7 @@ export class PdCalendar extends LitElement {
|
|
|
379
408
|
}
|
|
380
409
|
|
|
381
410
|
_nextMonth() {
|
|
382
|
-
|
|
383
|
-
if (this.currentDate.getMonth() < now.getMonth() + 2) {
|
|
411
|
+
if (this._checkNextMonthConstraint()) {
|
|
384
412
|
const newDate = new Date(
|
|
385
413
|
this.currentDate.getFullYear(),
|
|
386
414
|
this.currentDate.getMonth(),
|
|
@@ -398,10 +426,8 @@ export class PdCalendar extends LitElement {
|
|
|
398
426
|
}
|
|
399
427
|
}
|
|
400
428
|
|
|
401
|
-
_previousMonth() {
|
|
402
|
-
|
|
403
|
-
// TMP 23.08 ist start
|
|
404
|
-
if (this.currentDate.getMonth() > now.getMonth()) {
|
|
429
|
+
_previousMonth() {
|
|
430
|
+
if (this._checkPrevMonthConstraint()) {
|
|
405
431
|
const newDate = new Date(
|
|
406
432
|
this.currentDate.getFullYear(),
|
|
407
433
|
this.currentDate.getMonth(),
|
|
@@ -444,4 +470,20 @@ export class PdCalendar extends LitElement {
|
|
|
444
470
|
}
|
|
445
471
|
return missDayArray;
|
|
446
472
|
}
|
|
473
|
+
|
|
474
|
+
_checkNextMonthConstraint() {
|
|
475
|
+
console.log("check _latestDate: ", this._latestDate);
|
|
476
|
+
if (this._latestDate) {
|
|
477
|
+
return this.currentDate < this._latestDate;
|
|
478
|
+
}
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
_checkPrevMonthConstraint() {
|
|
483
|
+
console.log("check _earliestDate: ", this._latestDate);
|
|
484
|
+
if (this._earliestDate) {
|
|
485
|
+
return this.currentDate > this._earliestDate;
|
|
486
|
+
}
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
447
489
|
}
|
package/stories/index.stories.js
CHANGED
|
@@ -1,25 +1,88 @@
|
|
|
1
1
|
import { html } from 'lit';
|
|
2
2
|
import '../pd-calendar.js';
|
|
3
|
+
import { format } from 'fecha';
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
|
-
title: 'Calendar',
|
|
6
|
+
title: 'PdCalendar/Calendar',
|
|
6
7
|
component: 'pd-calendar',
|
|
7
8
|
argTypes: {
|
|
8
9
|
},
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
function CalendarTemplate({ data }) {
|
|
12
|
-
return html` <pd-calendar .data="${data || {}}"
|
|
12
|
+
function CalendarTemplate({ data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
|
|
13
|
+
return html` <pd-calendar .data="${data || {}}"
|
|
14
|
+
prevMonthConstraint="${prevMonthConstraint}" nextMonthConstraint="${nextMonthConstraint}">
|
|
15
|
+
${addSlot ? html`<p slot="calFooter">* excl. BTW</p>` : ''}
|
|
16
|
+
</pd-calendar> `;
|
|
13
17
|
}
|
|
14
18
|
|
|
19
|
+
// generate some test data (needed to show data for current month)
|
|
20
|
+
const now = new Date();
|
|
21
|
+
const newDate1 = new Date(
|
|
22
|
+
now.getFullYear(),
|
|
23
|
+
now.getMonth(),
|
|
24
|
+
1
|
|
25
|
+
);
|
|
26
|
+
const newDate2 = new Date(
|
|
27
|
+
now.getFullYear(),
|
|
28
|
+
now.getMonth(),
|
|
29
|
+
2
|
|
30
|
+
);
|
|
31
|
+
const newDate3 = new Date(
|
|
32
|
+
now.getFullYear(),
|
|
33
|
+
now.getMonth(),
|
|
34
|
+
3
|
|
35
|
+
);
|
|
36
|
+
const newDate4 = new Date(
|
|
37
|
+
now.getFullYear(),
|
|
38
|
+
now.getMonth(),
|
|
39
|
+
4
|
|
40
|
+
);
|
|
41
|
+
const newDate5 = new Date(
|
|
42
|
+
now.getFullYear(),
|
|
43
|
+
now.getMonth(),
|
|
44
|
+
9
|
|
45
|
+
);
|
|
46
|
+
const newDate6 = new Date(
|
|
47
|
+
now.getFullYear(),
|
|
48
|
+
now.getMonth(),
|
|
49
|
+
10
|
|
50
|
+
);
|
|
51
|
+
|
|
15
52
|
export const Basic = CalendarTemplate.bind({});
|
|
16
|
-
Basic.args = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
WithInfo.args = {
|
|
20
|
-
data: {
|
|
21
|
-
'2021-05-13': [{ info: '180€' }],
|
|
22
|
-
'2021-05-14': [{ info: '160€' }],
|
|
23
|
-
'2021-05-31': [{ info: '120€' }],
|
|
24
|
-
},
|
|
53
|
+
Basic.args = {
|
|
54
|
+
prevMonthConstraint: -1,
|
|
55
|
+
nextMonthConstraint: -1,
|
|
25
56
|
};
|
|
57
|
+
|
|
58
|
+
export const WithInfoAndConstraints = CalendarTemplate.bind({});
|
|
59
|
+
const data = {};
|
|
60
|
+
data[format(newDate1, 'YYYY-MM-DD')] = [{ info: '180 €' }];
|
|
61
|
+
data[format(newDate2, 'YYYY-MM-DD')] = [{ info: '170 €' }];
|
|
62
|
+
data[format(newDate3, 'YYYY-MM-DD')] = [{ info: '150 €' }];
|
|
63
|
+
data[format(newDate4, 'YYYY-MM-DD')] = [{ info: '180 €' }];
|
|
64
|
+
data[format(newDate5, 'YYYY-MM-DD')] = [{ info: '170 €' }];
|
|
65
|
+
data[format(newDate6, 'YYYY-MM-DD')] = [{ info: '150 €' }];
|
|
66
|
+
|
|
67
|
+
WithInfoAndConstraints.args = {
|
|
68
|
+
data,
|
|
69
|
+
prevMonthConstraint: 0,
|
|
70
|
+
nextMonthConstraint: 3,
|
|
71
|
+
addSlot: true
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export const WithSpecialDays = CalendarTemplate.bind({});
|
|
76
|
+
const specialData = {};
|
|
77
|
+
specialData[format(newDate1, 'YYYY-MM-DD')] = [{ info: '180 €' }];
|
|
78
|
+
specialData[format(newDate2, 'YYYY-MM-DD')] = [{ info: '170 €' }];
|
|
79
|
+
specialData[format(newDate3, 'YYYY-MM-DD')] = [{ info: '150 €', special: true}];
|
|
80
|
+
specialData[format(newDate4, 'YYYY-MM-DD')] = [{ info: '180 €' }];
|
|
81
|
+
specialData[format(newDate5, 'YYYY-MM-DD')] = [{ info: '170 €' }];
|
|
82
|
+
specialData[format(newDate6, 'YYYY-MM-DD')] = [{ info: '150 €', special: true}];
|
|
83
|
+
WithSpecialDays.args = {
|
|
84
|
+
data: specialData,
|
|
85
|
+
prevMonthConstraint: 0,
|
|
86
|
+
nextMonthConstraint: 3,
|
|
87
|
+
addSlot: true
|
|
88
|
+
};
|