@progressive-development/pd-calendar 0.0.11 → 0.0.13
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 +49 -38
- package/stories/index.stories.js +12 -5
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;
|
|
@@ -260,6 +261,7 @@ export class PdCalendar extends LitElement {
|
|
|
260
261
|
?selectEnabled="${infoTxt !== undefined}"
|
|
261
262
|
?special="${special}"
|
|
262
263
|
numberClass="${this.numberClass}"
|
|
264
|
+
@select-date="${this._forwardEvent}"
|
|
263
265
|
></pd-calendar-cell>
|
|
264
266
|
`);
|
|
265
267
|
}
|
|
@@ -304,8 +306,8 @@ export class PdCalendar extends LitElement {
|
|
|
304
306
|
_nextMonth() {
|
|
305
307
|
if (this._checkNextMonthConstraint()) {
|
|
306
308
|
const newDate = new Date(
|
|
307
|
-
this.
|
|
308
|
-
this.
|
|
309
|
+
this._currentDate.getFullYear(),
|
|
310
|
+
this._currentDate.getMonth(),
|
|
309
311
|
1
|
|
310
312
|
);
|
|
311
313
|
newDate.setMonth(newDate.getMonth() + 1);
|
|
@@ -323,8 +325,8 @@ export class PdCalendar extends LitElement {
|
|
|
323
325
|
_previousMonth() {
|
|
324
326
|
if (this._checkPrevMonthConstraint()) {
|
|
325
327
|
const newDate = new Date(
|
|
326
|
-
this.
|
|
327
|
-
this.
|
|
328
|
+
this._currentDate.getFullYear(),
|
|
329
|
+
this._currentDate.getMonth(),
|
|
328
330
|
1
|
|
329
331
|
);
|
|
330
332
|
newDate.setMonth(newDate.getMonth() - 1);
|
|
@@ -346,7 +348,7 @@ export class PdCalendar extends LitElement {
|
|
|
346
348
|
// last month day
|
|
347
349
|
const newDate2 = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
348
350
|
this._numberOfDays = newDate2.getDate();
|
|
349
|
-
this.
|
|
351
|
+
this._currentDate = date;
|
|
350
352
|
}
|
|
351
353
|
|
|
352
354
|
static _getPreviousMonthDays(date) {
|
|
@@ -367,15 +369,24 @@ export class PdCalendar extends LitElement {
|
|
|
367
369
|
|
|
368
370
|
_checkNextMonthConstraint() {
|
|
369
371
|
if (this._latestDate) {
|
|
370
|
-
return this.
|
|
372
|
+
return this._currentDate < this._latestDate;
|
|
371
373
|
}
|
|
372
374
|
return true;
|
|
373
375
|
}
|
|
374
376
|
|
|
375
377
|
_checkPrevMonthConstraint() {
|
|
376
378
|
if (this._earliestDate) {
|
|
377
|
-
return this.
|
|
379
|
+
return this._currentDate > this._earliestDate;
|
|
378
380
|
}
|
|
379
381
|
return true;
|
|
380
382
|
}
|
|
383
|
+
|
|
384
|
+
// Forward Event from Calendar Cell, could be refactored
|
|
385
|
+
_forwardEvent(e) {
|
|
386
|
+
this.dispatchEvent(
|
|
387
|
+
new CustomEvent('select-date', {
|
|
388
|
+
detail: e.detail
|
|
389
|
+
})
|
|
390
|
+
);
|
|
391
|
+
}
|
|
381
392
|
}
|
package/stories/index.stories.js
CHANGED
|
@@ -4,13 +4,11 @@ import { format } from 'fecha';
|
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
title: 'PdCalendar/Calendar',
|
|
7
|
-
component: 'pd-calendar',
|
|
8
|
-
argTypes: {
|
|
9
|
-
},
|
|
7
|
+
component: 'pd-calendar',
|
|
10
8
|
};
|
|
11
9
|
|
|
12
|
-
function CalendarTemplate({ data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
|
|
13
|
-
return html` <pd-calendar .data="${data || {}}"
|
|
10
|
+
function CalendarTemplate({ refDate, data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
|
|
11
|
+
return html` <pd-calendar .refDate="${refDate}" .data="${data || {}}"
|
|
14
12
|
prevMonthConstraint="${prevMonthConstraint}" nextMonthConstraint="${nextMonthConstraint}">
|
|
15
13
|
${addSlot ? html`<p slot="calFooter">* excl. BTW</p>` : ''}
|
|
16
14
|
</pd-calendar> `;
|
|
@@ -107,4 +105,13 @@ WithSpecialDays.args = {
|
|
|
107
105
|
prevMonthConstraint: 0,
|
|
108
106
|
nextMonthConstraint: 3,
|
|
109
107
|
addSlot: true
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const now2 = new Date();
|
|
111
|
+
now2.setMonth(now.getMonth() + 15);
|
|
112
|
+
export const WithSpecificDateAndConstraints = CalendarTemplate.bind({});
|
|
113
|
+
WithSpecificDateAndConstraints.args = {
|
|
114
|
+
refDate: now2,
|
|
115
|
+
prevMonthConstraint: 1,
|
|
116
|
+
nextMonthConstraint: 1,
|
|
110
117
|
};
|