@progressive-development/pd-calendar 0.0.11 → 0.0.12
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/package.json +1 -1
- package/src/PdCalendar.js +42 -38
- package/stories/index.stories.js +11 -2
package/package.json
CHANGED
package/src/PdCalendar.js
CHANGED
|
@@ -35,6 +35,25 @@ export class PdCalendar extends LitElement {
|
|
|
35
35
|
* @event select-date
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
+
static get properties() {
|
|
39
|
+
return {
|
|
40
|
+
refDate: { type: Object },
|
|
41
|
+
prevMonthConstraint: { type: Number },
|
|
42
|
+
nextMonthConstraint: { type: Number },
|
|
43
|
+
data: { type: Object },
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* CSS class for day number inside the cell, top-left and center available
|
|
47
|
+
*/
|
|
48
|
+
numberClass: { type: String },
|
|
49
|
+
|
|
50
|
+
_currentDate: { type: Object },
|
|
51
|
+
_viewType: { type: Number },
|
|
52
|
+
_latestDate: { type: Object },
|
|
53
|
+
_earliestDate: { type: Object },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
38
57
|
static get styles() {
|
|
39
58
|
return css`
|
|
40
59
|
:host {
|
|
@@ -153,43 +172,23 @@ export class PdCalendar extends LitElement {
|
|
|
153
172
|
`;
|
|
154
173
|
}
|
|
155
174
|
|
|
156
|
-
static get properties() {
|
|
157
|
-
return {
|
|
158
|
-
currentDate: { type: Object },
|
|
159
|
-
prevMonthConstraint: { type: Number },
|
|
160
|
-
nextMonthConstraint: { type: Number },
|
|
161
|
-
data: { type: Object },
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* CSS class for day number inside the cell, top-left and center available
|
|
165
|
-
*/
|
|
166
|
-
numberClass: { type: String },
|
|
167
|
-
|
|
168
|
-
_viewType: { type: Number },
|
|
169
|
-
_latestDate: { type: Object },
|
|
170
|
-
_earliestDate: { type: Object },
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
175
|
constructor() {
|
|
175
176
|
super();
|
|
176
177
|
|
|
177
178
|
this.data = {};
|
|
178
179
|
this._viewType = VIEW_MONTH;
|
|
179
180
|
this.numberClass = "top-left";
|
|
180
|
-
|
|
181
|
-
// initialize date values with current date
|
|
182
|
-
const now = new Date();
|
|
183
|
-
this._initFromDate(now);
|
|
184
181
|
}
|
|
185
182
|
|
|
186
|
-
|
|
183
|
+
connectedCallback() {
|
|
184
|
+
super.connectedCallback();
|
|
185
|
+
|
|
187
186
|
// get latest possible date
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
const ref = this.refDate || new Date();
|
|
188
|
+
if (this.nextMonthConstraint >= 0) {
|
|
190
189
|
const tmpDate = new Date(
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
ref.getFullYear(),
|
|
191
|
+
ref.getMonth() + 1,
|
|
193
192
|
0
|
|
194
193
|
);
|
|
195
194
|
tmpDate.setMonth(tmpDate.getMonth() + (this.nextMonthConstraint - 1));
|
|
@@ -198,15 +197,17 @@ export class PdCalendar extends LitElement {
|
|
|
198
197
|
|
|
199
198
|
// get earliest possible date
|
|
200
199
|
if (this.prevMonthConstraint >= 0) {
|
|
201
|
-
const now = new Date();
|
|
202
200
|
const tmpDate = new Date(
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
ref.getFullYear(),
|
|
202
|
+
ref.getMonth() + 1,
|
|
205
203
|
0
|
|
206
204
|
);
|
|
207
205
|
tmpDate.setMonth(tmpDate.getMonth() - (this.prevMonthConstraint));
|
|
208
206
|
this._earliestDate = tmpDate;
|
|
209
207
|
}
|
|
208
|
+
|
|
209
|
+
// initialize date values with current date
|
|
210
|
+
this._initFromDate(ref);
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
render() {
|
|
@@ -244,7 +245,7 @@ export class PdCalendar extends LitElement {
|
|
|
244
245
|
? 'max'
|
|
245
246
|
: 'normal';
|
|
246
247
|
for (let i = 1; i <= this._numberOfDays; i += 1) {
|
|
247
|
-
const tmpDate = new Date(this._year, this.
|
|
248
|
+
const tmpDate = new Date(this._year, this._currentDate.getMonth(), i);
|
|
248
249
|
const key = format(tmpDate, 'YYYY-MM-DD');
|
|
249
250
|
// TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
|
|
250
251
|
const infoTxt = this.data[key] ? this.data[key][0].info : undefined;
|
|
@@ -304,8 +305,8 @@ export class PdCalendar extends LitElement {
|
|
|
304
305
|
_nextMonth() {
|
|
305
306
|
if (this._checkNextMonthConstraint()) {
|
|
306
307
|
const newDate = new Date(
|
|
307
|
-
this.
|
|
308
|
-
this.
|
|
308
|
+
this._currentDate.getFullYear(),
|
|
309
|
+
this._currentDate.getMonth(),
|
|
309
310
|
1
|
|
310
311
|
);
|
|
311
312
|
newDate.setMonth(newDate.getMonth() + 1);
|
|
@@ -323,8 +324,8 @@ export class PdCalendar extends LitElement {
|
|
|
323
324
|
_previousMonth() {
|
|
324
325
|
if (this._checkPrevMonthConstraint()) {
|
|
325
326
|
const newDate = new Date(
|
|
326
|
-
this.
|
|
327
|
-
this.
|
|
327
|
+
this._currentDate.getFullYear(),
|
|
328
|
+
this._currentDate.getMonth(),
|
|
328
329
|
1
|
|
329
330
|
);
|
|
330
331
|
newDate.setMonth(newDate.getMonth() - 1);
|
|
@@ -340,13 +341,16 @@ export class PdCalendar extends LitElement {
|
|
|
340
341
|
}
|
|
341
342
|
|
|
342
343
|
_initFromDate(date) {
|
|
344
|
+
|
|
345
|
+
console.log("Init date with: ", date);
|
|
346
|
+
|
|
343
347
|
this._monthName = date.toLocaleString('default', { month: 'long' });
|
|
344
348
|
this._year = date.getFullYear();
|
|
345
349
|
this._daysFromPreviousMonth = PdCalendar._getPreviousMonthDays(date);
|
|
346
350
|
// last month day
|
|
347
351
|
const newDate2 = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
348
352
|
this._numberOfDays = newDate2.getDate();
|
|
349
|
-
this.
|
|
353
|
+
this._currentDate = date;
|
|
350
354
|
}
|
|
351
355
|
|
|
352
356
|
static _getPreviousMonthDays(date) {
|
|
@@ -367,14 +371,14 @@ export class PdCalendar extends LitElement {
|
|
|
367
371
|
|
|
368
372
|
_checkNextMonthConstraint() {
|
|
369
373
|
if (this._latestDate) {
|
|
370
|
-
return this.
|
|
374
|
+
return this._currentDate < this._latestDate;
|
|
371
375
|
}
|
|
372
376
|
return true;
|
|
373
377
|
}
|
|
374
378
|
|
|
375
379
|
_checkPrevMonthConstraint() {
|
|
376
380
|
if (this._earliestDate) {
|
|
377
|
-
return this.
|
|
381
|
+
return this._currentDate > this._earliestDate;
|
|
378
382
|
}
|
|
379
383
|
return true;
|
|
380
384
|
}
|
package/stories/index.stories.js
CHANGED
|
@@ -9,8 +9,8 @@ export default {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
function CalendarTemplate({ data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
|
|
13
|
-
return html` <pd-calendar .data="${data || {}}"
|
|
12
|
+
function CalendarTemplate({ refDate, data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
|
|
13
|
+
return html` <pd-calendar .refDate="${refDate}" .data="${data || {}}"
|
|
14
14
|
prevMonthConstraint="${prevMonthConstraint}" nextMonthConstraint="${nextMonthConstraint}">
|
|
15
15
|
${addSlot ? html`<p slot="calFooter">* excl. BTW</p>` : ''}
|
|
16
16
|
</pd-calendar> `;
|
|
@@ -107,4 +107,13 @@ WithSpecialDays.args = {
|
|
|
107
107
|
prevMonthConstraint: 0,
|
|
108
108
|
nextMonthConstraint: 3,
|
|
109
109
|
addSlot: true
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const now2 = new Date();
|
|
113
|
+
now2.setMonth(now.getMonth() + 15);
|
|
114
|
+
export const WithSpecificDateAndConstraints = CalendarTemplate.bind({});
|
|
115
|
+
WithSpecificDateAndConstraints.args = {
|
|
116
|
+
refDate: now2,
|
|
117
|
+
prevMonthConstraint: 1,
|
|
118
|
+
nextMonthConstraint: 1,
|
|
110
119
|
};
|