@progressive-development/pd-calendar 0.0.13 → 0.0.14
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 +16 -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,33 +176,15 @@ 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);
|
|
@@ -318,6 +298,7 @@ export class PdCalendar extends LitElement {
|
|
|
318
298
|
},
|
|
319
299
|
})
|
|
320
300
|
);
|
|
301
|
+
this._currentMonthNavNr += 1;
|
|
321
302
|
this._initFromDate(newDate);
|
|
322
303
|
}
|
|
323
304
|
}
|
|
@@ -337,6 +318,7 @@ export class PdCalendar extends LitElement {
|
|
|
337
318
|
},
|
|
338
319
|
})
|
|
339
320
|
);
|
|
321
|
+
this._currentMonthNavNr -= 1;
|
|
340
322
|
this._initFromDate(newDate);
|
|
341
323
|
}
|
|
342
324
|
}
|
|
@@ -368,17 +350,21 @@ export class PdCalendar extends LitElement {
|
|
|
368
350
|
}
|
|
369
351
|
|
|
370
352
|
_checkNextMonthConstraint() {
|
|
371
|
-
if (this.
|
|
372
|
-
return this.
|
|
353
|
+
if (this.nextMonthConstraint > 0) {
|
|
354
|
+
return this.nextMonthConstraint > this._currentMonthNavNr;
|
|
355
|
+
}
|
|
356
|
+
if (this.nextMonthConstraint === -1) {
|
|
357
|
+
return true;
|
|
373
358
|
}
|
|
374
|
-
return
|
|
359
|
+
return false;
|
|
375
360
|
}
|
|
376
361
|
|
|
377
362
|
_checkPrevMonthConstraint() {
|
|
378
|
-
if (this.
|
|
379
|
-
return
|
|
363
|
+
if (this._currentMonthNavNr > 0 || this.prevMonthConstraint === -1) {
|
|
364
|
+
return true;
|
|
380
365
|
}
|
|
381
|
-
return
|
|
366
|
+
return this.prevMonthConstraint > (this._currentMonthNavNr * -1);
|
|
367
|
+
|
|
382
368
|
}
|
|
383
369
|
|
|
384
370
|
// 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}) {
|