@progressive-development/pd-calendar 0.0.13 → 0.0.15
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 +26 -30
- package/stories/index.stories.js +3 -1
package/package.json
CHANGED
package/src/PdCalendar.js
CHANGED
|
@@ -48,9 +48,7 @@ export class PdCalendar extends LitElement {
|
|
|
48
48
|
numberClass: { type: String },
|
|
49
49
|
|
|
50
50
|
_currentDate: { type: Object },
|
|
51
|
-
_viewType: { type: Number }
|
|
52
|
-
_latestDate: { type: Object },
|
|
53
|
-
_earliestDate: { type: Object },
|
|
51
|
+
_viewType: { type: Number }
|
|
54
52
|
};
|
|
55
53
|
}
|
|
56
54
|
|
|
@@ -178,38 +176,30 @@ export class PdCalendar extends LitElement {
|
|
|
178
176
|
this.data = {};
|
|
179
177
|
this._viewType = VIEW_MONTH;
|
|
180
178
|
this.numberClass = "top-left";
|
|
179
|
+
|
|
180
|
+
this._currentMonthNavNr = 0;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
connectedCallback() {
|
|
184
184
|
super.connectedCallback();
|
|
185
185
|
|
|
186
186
|
// get latest possible date
|
|
187
|
-
const ref = this.refDate || new Date();
|
|
188
|
-
if (this.nextMonthConstraint >= 0) {
|
|
189
|
-
const tmpDate = new Date(
|
|
190
|
-
ref.getFullYear(),
|
|
191
|
-
ref.getMonth() + 1,
|
|
192
|
-
0
|
|
193
|
-
);
|
|
194
|
-
tmpDate.setMonth(tmpDate.getMonth() + (this.nextMonthConstraint - 1));
|
|
195
|
-
this._latestDate = tmpDate;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// get earliest possible date
|
|
199
|
-
if (this.prevMonthConstraint >= 0) {
|
|
200
|
-
const tmpDate = new Date(
|
|
201
|
-
ref.getFullYear(),
|
|
202
|
-
ref.getMonth() + 1,
|
|
203
|
-
0
|
|
204
|
-
);
|
|
205
|
-
tmpDate.setMonth(tmpDate.getMonth() - (this.prevMonthConstraint));
|
|
206
|
-
this._earliestDate = tmpDate;
|
|
207
|
-
}
|
|
187
|
+
const ref = this.refDate || new Date();
|
|
208
188
|
|
|
209
189
|
// initialize date values with current date
|
|
210
190
|
this._initFromDate(ref);
|
|
211
191
|
}
|
|
212
192
|
|
|
193
|
+
update(changedProperties) {
|
|
194
|
+
// check for month selection (set by remote server if no result available for the first call)
|
|
195
|
+
if (changedProperties.has("data") && this.data.monthSelection) {
|
|
196
|
+
const now = new Date(Date.now());
|
|
197
|
+
const startDateNextMonth = new Date(now.getFullYear(), this.data.monthSelection, 1);
|
|
198
|
+
this._initFromDate(startDateNextMonth);
|
|
199
|
+
}
|
|
200
|
+
super.update(changedProperties);
|
|
201
|
+
}
|
|
202
|
+
|
|
213
203
|
render() {
|
|
214
204
|
return html`
|
|
215
205
|
${this.renderCalendarByViewType()}
|
|
@@ -318,6 +308,7 @@ export class PdCalendar extends LitElement {
|
|
|
318
308
|
},
|
|
319
309
|
})
|
|
320
310
|
);
|
|
311
|
+
this._currentMonthNavNr += 1;
|
|
321
312
|
this._initFromDate(newDate);
|
|
322
313
|
}
|
|
323
314
|
}
|
|
@@ -337,6 +328,7 @@ export class PdCalendar extends LitElement {
|
|
|
337
328
|
},
|
|
338
329
|
})
|
|
339
330
|
);
|
|
331
|
+
this._currentMonthNavNr -= 1;
|
|
340
332
|
this._initFromDate(newDate);
|
|
341
333
|
}
|
|
342
334
|
}
|
|
@@ -368,17 +360,21 @@ export class PdCalendar extends LitElement {
|
|
|
368
360
|
}
|
|
369
361
|
|
|
370
362
|
_checkNextMonthConstraint() {
|
|
371
|
-
if (this.
|
|
372
|
-
return this.
|
|
363
|
+
if (this.nextMonthConstraint > 0) {
|
|
364
|
+
return this.nextMonthConstraint > this._currentMonthNavNr;
|
|
365
|
+
}
|
|
366
|
+
if (this.nextMonthConstraint === -1) {
|
|
367
|
+
return true;
|
|
373
368
|
}
|
|
374
|
-
return
|
|
369
|
+
return false;
|
|
375
370
|
}
|
|
376
371
|
|
|
377
372
|
_checkPrevMonthConstraint() {
|
|
378
|
-
if (this.
|
|
379
|
-
return
|
|
373
|
+
if (this._currentMonthNavNr > 0 || this.prevMonthConstraint === -1) {
|
|
374
|
+
return true;
|
|
380
375
|
}
|
|
381
|
-
return
|
|
376
|
+
return this.prevMonthConstraint > (this._currentMonthNavNr * -1);
|
|
377
|
+
|
|
382
378
|
}
|
|
383
379
|
|
|
384
380
|
// Forward Event from Calendar Cell, could be refactored
|
package/stories/index.stories.js
CHANGED
|
@@ -4,7 +4,9 @@ import { format } from 'fecha';
|
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
title: 'PdCalendar/Calendar',
|
|
7
|
-
component: 'pd-calendar',
|
|
7
|
+
component: 'pd-calendar',
|
|
8
|
+
argTypes: {
|
|
9
|
+
},
|
|
8
10
|
};
|
|
9
11
|
|
|
10
12
|
function CalendarTemplate({ refDate, data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
|