@progressive-development/pd-calendar 0.0.1 → 0.0.2

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/LICENSE CHANGED
@@ -1,21 +1,2 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 pd-calendar
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ No License, all rights reserved
2
+ @2021 - PD Progressive Development UG
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@progressive-development/pd-calendar",
3
3
  "description": "progressive development calendar web component",
4
- "license": "ISC",
4
+ "license": "SEE LICENSE IN LICENSE",
5
5
  "author": "PD Progressive Development",
6
- "version": "0.0.1",
6
+ "version": "0.0.2",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
package/src/PdCalendar.js CHANGED
@@ -1,457 +1,447 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
4
- * This code may only be used under the BSD style license found at
5
- * http://polymer.github.io/LICENSE.txt
6
- * The complete set of authors may be found at
7
- * http://polymer.github.io/AUTHORS.txt
8
- * The complete set of contributors may be found at
9
- * http://polymer.github.io/CONTRIBUTORS.txt
10
- * Code distributed by Google as part of the polymer project is also
11
- * subject to an additional IP rights grant found at
12
- * http://polymer.github.io/PATENTS.txt
3
+ * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
13
4
  */
14
5
 
15
6
  import { LitElement, html, css } from 'lit';
16
7
  import { format, parse } from 'fecha';
17
- import '@progressive-development/pd-icon';
18
-
19
- // todo: use existing shortnames for locale here
20
- const weekDays = ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'];
21
-
22
- // list views (list, month, week)
23
- const VIEW_LIST = 1;
24
- const VIEW_MONTH = 2;
25
- const VIEW_WEEK = 3;
26
-
27
- /**
28
- * An example element.
29
- *
30
- * @slot - This element has a slot
31
- * @csspart button - The button
32
- */
8
+ import '@progressive-development/pd-icon/pd-icon.js';
9
+
10
+ // todo: use existing shortnames for locale here
11
+ const weekDays = ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'];
12
+
13
+ // list views (list, month, week)
14
+ const VIEW_LIST = 1;
15
+ const VIEW_MONTH = 2;
16
+ const VIEW_WEEK = 3;
17
+
18
+ /**
19
+ * An example element.
20
+ *
21
+ * @slot - This element has a slot
22
+ * @csspart button - The button
23
+ */
33
24
  export class PdCalendar extends LitElement {
34
- /**
35
- * Fired when next month clicked
36
- * @event change-month
37
- */
38
-
39
- /**
40
- * Fired when free date clicked => At the moment only for freeDates
41
- * @event select-date
42
- */
43
-
44
- static get styles() {
45
- return css`
46
- :host {
47
- --my-title-color: var(--squi-title-color, #084c61);
48
- --my-day-title-bg-color: var(--squi-title-color, #084c61);
49
- --my-cell-bg-color: var(--squi-title-color, lightgrey);
50
- --my-cell-we-bg-color: var(--squi-title-color, darkgrey);
51
- --my-cell-day-color: var(--squi-title-color, #fefefe);
52
-
53
- --my-info-cell-bg1-color: var(--squi-title-color, #177e89);
54
- --my-info-cell-bg2-color: var(--squi-title-color, #084c61);
55
- --my-info-cell-day-color: var(--squi-title-color, #fefefe);
56
-
57
- --my-info-cell-bg1-hover: var(--squi-highlight-color, #ffc857);
58
- --my-info-cell-bg2-hover: var(--squi-highlight-color, #177e89);
59
-
60
- --my-info-txt-color: var(--squi-info-txt, #fefefe);
61
-
62
- --my-primary-font: var(--squi-primary-font, Oswald);
63
-
64
- /*
25
+ /**
26
+ * Fired when next month clicked
27
+ * @event change-month
28
+ */
29
+
30
+ /**
31
+ * Fired when free date clicked => At the moment only for freeDates
32
+ * @event select-date
33
+ */
34
+
35
+ static get styles() {
36
+ return css`
37
+ :host {
38
+ --my-title-color: var(--squi-title-color, #084c61);
39
+ --my-day-title-bg-color: var(--squi-title-color, #084c61);
40
+ --my-cell-bg-color: var(--squi-title-color, lightgrey);
41
+ --my-cell-we-bg-color: var(--squi-title-color, darkgrey);
42
+ --my-cell-day-color: var(--squi-title-color, #fefefe);
43
+
44
+ --my-info-cell-bg1-color: var(--squi-title-color, #177e89);
45
+ --my-info-cell-bg2-color: var(--squi-title-color, #084c61);
46
+ --my-info-cell-day-color: var(--squi-title-color, #fefefe);
47
+
48
+ --my-info-cell-bg1-hover: var(--squi-highlight-color, #ffc857);
49
+ --my-info-cell-bg2-hover: var(--squi-highlight-color, #177e89);
50
+
51
+ --my-info-txt-color: var(--squi-info-txt, #fefefe);
52
+
53
+ --my-primary-font: var(--squi-primary-font, Oswald);
54
+
55
+ /*
65
56
  display: block;
66
57
  padding: 8px;
67
58
  */
68
- /*max-width: 800px;*/
69
- display: block;
70
- /*width: 100vw;
59
+ /*max-width: 800px;*/
60
+ display: block;
61
+ /*width: 100vw;
71
62
  height: 100vh;*/
72
- }
73
-
74
- /* Layout Grid for the Calendar Component => Not really needed at the moment, more a test */
75
- .layout-container {
76
- height: 100%;
77
- display: grid;
78
- grid-template-columns: 1fr 1fr 1fr;
79
- grid-template-rows: 40px auto;
80
- gap: 1px;
81
- grid-template-areas:
82
- 'header header header'
83
- 'content content content';
84
- }
85
-
86
- /* Grid Area positions for layout container above */
87
- .header {
88
- grid-area: header;
89
- position: relative;
90
-
91
- font-family: var(--my-primary-font);
92
- color: var(--my-title-color);
93
- }
94
-
95
- .header-main {
96
- position: absolute;
97
- left: 30%;
98
- display: flex;
99
- }
100
-
101
- .header-icons {
102
- position: absolute;
103
- right: 0px;
104
- top: 0px;
105
- }
106
-
107
- .content {
108
- grid-area: content;
109
- }
110
- .footer {
111
- grid-area: footer;
112
- }
113
-
114
- /* Grid definition for calendar day items */
115
- .grid-container {
116
- position: relative;
117
- display: grid;
118
- grid-template-columns: repeat(7, minmax(0, 1fr));
119
- gap: 3px;
120
- }
121
-
122
- .grid-container.max {
123
- grid-template-rows: minmax(10px, 30px) repeat(6, minmax(70px, 1fr));
124
- }
125
-
126
- .grid-container.normal {
127
- grid-template-rows: minmax(10px, 30px) repeat(5, minmax(70px, 1fr));
128
- }
129
-
130
- .title-week-day {
131
- padding-top: 2px;
132
- background-color: var(--my-day-title-bg-color);
133
- text-align: center;
134
- font-size: 1em;
135
- font-weight: bold;
136
- color: white;
137
- font-family: var(--my-primary-font);
138
- }
139
-
140
- .cell {
141
- text-align: center;
142
- }
143
-
144
- .cell-empty {
145
- background-color: #fdfbfb;
146
- }
147
-
148
- .cell-day {
149
- position: relative;
150
- /*background-image: linear-gradient(to right, rgb(51, 101, 138) , rgb(38, 76, 104)); */
151
- /*box-shadow: 2px 2px 3px;*/
152
- background-color: var(--my-cell-bg-color);
153
- /*border-radius: 2px 2px 2px 2px;*/
154
- }
155
-
156
- .cell-day.we {
157
- background-color: var(--my-cell-we-bg-color);
158
- }
159
-
160
- .free {
161
- /*background-image: linear-gradient(to right, green, darkgreen);
63
+ }
64
+
65
+ /* Layout Grid for the Calendar Component => Not really needed at the moment, more a test */
66
+ .layout-container {
67
+ height: 100%;
68
+ display: grid;
69
+ grid-template-columns: 1fr 1fr 1fr;
70
+ grid-template-rows: 40px auto;
71
+ gap: 1px;
72
+ grid-template-areas:
73
+ 'header header header'
74
+ 'content content content';
75
+ }
76
+
77
+ /* Grid Area positions for layout container above */
78
+ .header {
79
+ grid-area: header;
80
+ position: relative;
81
+
82
+ font-family: var(--my-primary-font);
83
+ color: var(--my-title-color);
84
+ }
85
+
86
+ .header-main {
87
+ position: absolute;
88
+ left: 30%;
89
+ display: flex;
90
+ }
91
+
92
+ .header-icons {
93
+ position: absolute;
94
+ right: 0px;
95
+ top: 0px;
96
+ }
97
+
98
+ .content {
99
+ grid-area: content;
100
+ }
101
+ .footer {
102
+ grid-area: footer;
103
+ }
104
+
105
+ /* Grid definition for calendar day items */
106
+ .grid-container {
107
+ position: relative;
108
+ display: grid;
109
+ grid-template-columns: repeat(7, minmax(0, 1fr));
110
+ gap: 3px;
111
+ }
112
+
113
+ .grid-container.max {
114
+ grid-template-rows: minmax(10px, 30px) repeat(6, minmax(70px, 1fr));
115
+ }
116
+
117
+ .grid-container.normal {
118
+ grid-template-rows: minmax(10px, 30px) repeat(5, minmax(70px, 1fr));
119
+ }
120
+
121
+ .title-week-day {
122
+ padding-top: 2px;
123
+ background-color: var(--my-day-title-bg-color);
124
+ text-align: center;
125
+ font-size: 1em;
126
+ font-weight: bold;
127
+ color: white;
128
+ font-family: var(--my-primary-font);
129
+ }
130
+
131
+ .cell {
132
+ text-align: center;
133
+ }
134
+
135
+ .cell-empty {
136
+ background-color: #fdfbfb;
137
+ }
138
+
139
+ .cell-day {
140
+ position: relative;
141
+ /*background-image: linear-gradient(to right, rgb(51, 101, 138) , rgb(38, 76, 104)); */
142
+ /*box-shadow: 2px 2px 3px;*/
143
+ background-color: var(--my-cell-bg-color);
144
+ /*border-radius: 2px 2px 2px 2px;*/
145
+ }
146
+
147
+ .cell-day.we {
148
+ background-color: var(--my-cell-we-bg-color);
149
+ }
150
+
151
+ .free {
152
+ /*background-image: linear-gradient(to right, green, darkgreen);
162
153
  background-color: var(--my-info-cell-bg1-color);*/
163
- background-color: var(--my-info-cell-bg1-color);
164
- /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
165
- box-shadow: 1px 2px 2px;
166
- }
167
-
168
- .special {
169
- /*background-image: linear-gradient(to right, green, darkgreen);
154
+ background-color: var(--my-info-cell-bg1-color);
155
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
156
+ box-shadow: 1px 2px 2px;
157
+ }
158
+
159
+ .special {
160
+ /*background-image: linear-gradient(to right, green, darkgreen);
170
161
  background-color: var(--my-info-cell-bg1-color);*/
171
- background-color: var(--green, #1da692);
172
- /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
173
- box-shadow: 1px 2px 2px;
174
- }
175
-
176
- .special:hover,
177
- .free:hover {
178
- background-color: rgb(247, 211, 8);
179
- /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-hover), var(--my-info-cell-bg2-hover));*/
180
- cursor: pointer;
181
- }
182
-
183
- span.content-title {
184
- font-weight: bold;
185
- font-size: 1.5em;
186
- width: 120px;
187
- text-align: center;
188
- }
189
-
190
- span.content-sub-title {
191
- position: absolute;
192
- left: 0px;
193
- bottom: 0px;
194
- font-size: 1.2em;
195
- font-weight: bold;
196
- }
197
-
198
- span.cell-info {
199
- position: absolute;
200
- left: 35%;
201
- top: 30%;
202
- color: var(--my-info-txt-color);
203
- font-family: var(--my-primary-font);
204
- font-weight: bold;
205
- font-size: 1.5em;
206
- text-shadow: 1px 1px black;
207
- pointer-events: none;
208
- }
209
-
210
- span.cell-number {
211
- position: absolute;
212
- left: 3px;
213
- top: 1px;
214
- font-size: 0.9em;
215
- color: var(--my-cell-day-color);
216
- font-family: var(--my-primary-font);
217
- }
218
-
219
- .free .cell-number {
220
- color: var(--my-info-cell-day-color);
221
- }
222
-
223
- @media (max-width: 800px) {
224
- span.cell-info {
225
- left: 30%;
226
- font-size: 1.3em;
227
- }
228
- span.cell-number {
229
- font-size: 0.7em;
230
- }
231
- }
232
- @media (max-width: 500px) {
233
- span.cell-info {
234
- left: 15%;
235
- font-weight: normal;
236
- font-size: 1em;
237
- }
238
- }
239
-
240
- .arrow {
241
- /* Hack */
242
- padding-top: 8px;
243
- cursor: pointer;
244
- --squi-icon-size: 1.5rem;
245
- --my-fill-color: var(--my-title-color);
246
- }
247
- `;
248
- }
249
-
250
- static get properties() {
251
- return {
252
- currentDate: { type: Object },
253
- data: { type: Object },
254
- _viewType: { type: Number },
255
- };
256
- }
257
-
258
- constructor() {
259
- super();
260
-
261
- // initialize date values with current date
262
- this._initFromDate(new Date());
263
- this.data = {};
264
-
265
- this._viewType = VIEW_MONTH;
266
- }
267
-
268
- render() {
269
- return html`
270
- <slot></slot>
271
- ${this.renderCalendarByViewType()}
272
- `;
273
- }
274
-
275
- renderCalendarByViewType() {
276
- switch (this._viewType) {
277
- case VIEW_LIST:
278
- // return this.renderListCalendar();
279
- return '';
280
- case VIEW_MONTH:
281
- return this.renderMonthCalendar();
282
- case VIEW_WEEK:
283
- return this.renderCalendar();
284
- default:
285
- return this.renderMonthCalendar();
286
- }
287
- }
288
- /*
162
+ background-color: var(--green, #1da692);
163
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
164
+ box-shadow: 1px 2px 2px;
165
+ }
166
+
167
+ .special:hover,
168
+ .free:hover {
169
+ background-color: rgb(247, 211, 8);
170
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-hover), var(--my-info-cell-bg2-hover));*/
171
+ cursor: pointer;
172
+ }
173
+
174
+ span.content-title {
175
+ font-weight: bold;
176
+ font-size: 1.5em;
177
+ width: 120px;
178
+ text-align: center;
179
+ }
180
+
181
+ span.content-sub-title {
182
+ position: absolute;
183
+ left: 0px;
184
+ bottom: 0px;
185
+ font-size: 1.2em;
186
+ font-weight: bold;
187
+ }
188
+
189
+ span.cell-info {
190
+ position: absolute;
191
+ left: 35%;
192
+ top: 30%;
193
+ color: var(--my-info-txt-color);
194
+ font-family: var(--my-primary-font);
195
+ font-weight: bold;
196
+ font-size: 1.5em;
197
+ text-shadow: 1px 1px black;
198
+ pointer-events: none;
199
+ }
200
+
201
+ span.cell-number {
202
+ position: absolute;
203
+ left: 3px;
204
+ top: 1px;
205
+ font-size: 0.9em;
206
+ color: var(--my-cell-day-color);
207
+ font-family: var(--my-primary-font);
208
+ }
209
+
210
+ .free .cell-number {
211
+ color: var(--my-info-cell-day-color);
212
+ }
213
+
214
+ @media (max-width: 800px) {
215
+ span.cell-info {
216
+ left: 30%;
217
+ font-size: 1.3em;
218
+ }
219
+ span.cell-number {
220
+ font-size: 0.7em;
221
+ }
222
+ }
223
+ @media (max-width: 500px) {
224
+ span.cell-info {
225
+ left: 15%;
226
+ font-weight: normal;
227
+ font-size: 1em;
228
+ }
229
+ }
230
+
231
+ .arrow {
232
+ /* Hack */
233
+ padding-top: 8px;
234
+ cursor: pointer;
235
+ --squi-icon-size: 1.5rem;
236
+ --my-fill-color: var(--my-title-color);
237
+ }
238
+ `;
239
+ }
240
+
241
+ static get properties() {
242
+ return {
243
+ currentDate: { type: Object },
244
+ data: { type: Object },
245
+ _viewType: { type: Number },
246
+ };
247
+ }
248
+
249
+ constructor() {
250
+ super();
251
+
252
+ // initialize date values with current date
253
+ this._initFromDate(new Date());
254
+ this.data = {};
255
+
256
+ this._viewType = VIEW_MONTH;
257
+ }
258
+
259
+ render() {
260
+ return html`
261
+ <slot></slot>
262
+ ${this.renderCalendarByViewType()}
263
+ `;
264
+ }
265
+
266
+ renderCalendarByViewType() {
267
+ switch (this._viewType) {
268
+ case VIEW_LIST:
269
+ // return this.renderListCalendar();
270
+ return '';
271
+ case VIEW_MONTH:
272
+ return this.renderMonthCalendar();
273
+ case VIEW_WEEK:
274
+ return this.renderCalendar();
275
+ default:
276
+ return this.renderMonthCalendar();
277
+ }
278
+ }
279
+ /*
289
280
  renderListCalendar() {
290
281
  // TODO
291
282
  }
292
283
  */
293
-
294
- renderMonthCalendar() {
295
- // generate divs for each day
296
- const itemTemplates = [];
297
-
298
- const sizeVar =
299
- this._numberOfDays >= 31 && this._daysFromPreviousMonth.length >= 5
300
- ? 'max'
301
- : 'normal';
302
- for (let i = 1; i <= this._numberOfDays; i += 1) {
303
- const tmpDate = new Date(this._year, this.currentDate.getMonth(), i);
304
- const key = format(tmpDate, 'YYYY-MM-DD');
305
- // TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
306
- const infoTxt = this.data[key] ? this.data[key][0].info : '';
307
- const special = this.data[key]
308
- ? this.data[key][0].special || false
309
- : false;
310
- if (infoTxt) {
311
- itemTemplates.push(html`
312
- <div
313
- @keypress="${this._freeDateClicked}"
314
- @click="${this._freeDateClicked}"
315
- data-date="${key}"
316
- class="cell cell-day ${special ? 'special' : 'free'}"
317
- >
318
- <span class="cell-info">${infoTxt}*</span>
319
- <span class="cell-number">${i}</span>
320
- </div>
321
- `);
322
- } else {
323
- itemTemplates.push(html`
324
- <div
325
- class="cell cell-day ${tmpDate.getDay() === 6 ||
326
- tmpDate.getDay() === 0
327
- ? 'we'
328
- : ''}"
329
- >
330
- <span class="cell-number">${i}</span>
331
- </div>
332
- `);
333
- }
334
- }
335
-
336
- return html`
337
- <div class="layout-container">
338
- <div class="header">
339
- <div class="header-main">
340
- <squi-icon
341
- @click="${this._previousMonth}"
342
- class="arrow"
343
- icon="previousArrow"
344
- ></squi-icon>
345
-
346
- <span class="content-title">${this._monthName}</span>
347
-
348
- <squi-icon
349
- @click="${this._nextMonth}"
350
- class="arrow"
351
- icon="nextArrow"
352
- ></squi-icon>
353
- </div>
354
-
355
- <div class="header-icons"></div>
356
-
357
- <span class="content-sub-title">${this._year}</span>
358
- </div>
359
-
360
- <div class="content grid-container ${sizeVar}">
361
- ${weekDays.map(
362
- shortName => html` <div class="title-week-day">${shortName}</div>`
363
- )}
364
- ${this._daysFromPreviousMonth.map(
365
- () => html` <div class="cell cell-empty"></div>`
366
- )}
367
- ${itemTemplates}
368
- </div>
369
- </div>
370
- <p>* excl. BTW</p>
371
- `;
372
- }
373
-
374
- _freeDateClicked(e) {
375
- const dateKey = e.target.dataset.date;
376
- if (dateKey) {
377
- // convert back to date
378
- const userSelectedDate = parse(dateKey, 'YYYY-MM-DD');
379
- this.dispatchEvent(
380
- new CustomEvent('select-date', {
381
- detail: {
382
- dateKey,
383
- date: userSelectedDate,
384
- },
385
- })
386
- );
387
- }
388
- }
389
-
390
- _nextMonth() {
391
- const now = new Date();
392
- if (this.currentDate.getMonth() < now.getMonth() + 2) {
393
- const newDate = new Date(
394
- this.currentDate.getFullYear(),
395
- this.currentDate.getMonth(),
396
- 1
397
- );
398
- newDate.setMonth(newDate.getMonth() + 1);
399
- this.dispatchEvent(
400
- new CustomEvent('change-month', {
401
- detail: {
402
- newDate,
403
- },
404
- })
405
- );
406
- this._initFromDate(newDate);
407
- }
408
- }
409
-
410
- _previousMonth() {
411
- const now = new Date();
412
- // TMP 23.08 ist start
413
- if (this.currentDate.getMonth() > now.getMonth()) {
414
- const newDate = new Date(
415
- this.currentDate.getFullYear(),
416
- this.currentDate.getMonth(),
417
- 1
418
- );
419
- newDate.setMonth(newDate.getMonth() - 1);
420
- this.dispatchEvent(
421
- new CustomEvent('change-month', {
422
- detail: {
423
- newDate,
424
- },
425
- })
426
- );
427
- this._initFromDate(newDate);
428
- }
429
- }
430
-
431
- _initFromDate(date) {
432
- this._monthName = date.toLocaleString('default', { month: 'long' });
433
- this._year = date.getFullYear();
434
- this._daysFromPreviousMonth = PdCalendar._getPreviousMonthDays(date);
435
- // last month day
436
- const newDate2 = new Date(date.getFullYear(), date.getMonth() + 1, 0);
437
- this._numberOfDays = newDate2.getDate();
438
- this.currentDate = date;
439
- }
440
-
441
- static _getPreviousMonthDays(date) {
442
- // get first day of month
443
- const date1 = new Date(date.getFullYear(), date.getMonth(), 1);
444
- // get missing days to monday
445
- const missingDays = date1.getDay() > 0 ? Math.abs(1 - date1.getDay()) : 6;
446
- // create array with missing days (dates)
447
- const missDayArray = [];
448
- for (let i = 1; i <= missingDays; i += 1) {
449
- date1.setDate(date1.getDate() - 1);
450
- missDayArray.push(
451
- new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
452
- );
453
- }
454
- return missDayArray;
455
- }
284
+
285
+ renderMonthCalendar() {
286
+ // generate divs for each day
287
+ const itemTemplates = [];
288
+
289
+ const sizeVar =
290
+ this._numberOfDays >= 31 && this._daysFromPreviousMonth.length >= 5
291
+ ? 'max'
292
+ : 'normal';
293
+ for (let i = 1; i <= this._numberOfDays; i += 1) {
294
+ const tmpDate = new Date(this._year, this.currentDate.getMonth(), i);
295
+ const key = format(tmpDate, 'YYYY-MM-DD');
296
+ // TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
297
+ const infoTxt = this.data[key] ? this.data[key][0].info : '';
298
+ const special = this.data[key]
299
+ ? this.data[key][0].special || false
300
+ : false;
301
+ if (infoTxt) {
302
+ itemTemplates.push(html`
303
+ <div
304
+ @keypress="${this._freeDateClicked}"
305
+ @click="${this._freeDateClicked}"
306
+ data-date="${key}"
307
+ class="cell cell-day ${special ? 'special' : 'free'}"
308
+ >
309
+ <span class="cell-info">${infoTxt}*</span>
310
+ <span class="cell-number">${i}</span>
311
+ </div>
312
+ `);
313
+ } else {
314
+ itemTemplates.push(html`
315
+ <div
316
+ class="cell cell-day ${tmpDate.getDay() === 6 ||
317
+ tmpDate.getDay() === 0
318
+ ? 'we'
319
+ : ''}"
320
+ >
321
+ <span class="cell-number">${i}</span>
322
+ </div>
323
+ `);
324
+ }
325
+ }
326
+
327
+ return html`
328
+ <div class="layout-container">
329
+ <div class="header">
330
+ <div class="header-main">
331
+ <squi-icon
332
+ @click="${this._previousMonth}"
333
+ class="arrow"
334
+ icon="previousArrow"
335
+ ></squi-icon>
336
+
337
+ <span class="content-title">${this._monthName}</span>
338
+
339
+ <squi-icon
340
+ @click="${this._nextMonth}"
341
+ class="arrow"
342
+ icon="nextArrow"
343
+ ></squi-icon>
344
+ </div>
345
+
346
+ <div class="header-icons"></div>
347
+
348
+ <span class="content-sub-title">${this._year}</span>
349
+ </div>
350
+
351
+ <div class="content grid-container ${sizeVar}">
352
+ ${weekDays.map(
353
+ shortName => html` <div class="title-week-day">${shortName}</div>`
354
+ )}
355
+ ${this._daysFromPreviousMonth.map(
356
+ () => html` <div class="cell cell-empty"></div>`
357
+ )}
358
+ ${itemTemplates}
359
+ </div>
360
+ </div>
361
+ <p>* excl. BTW</p>
362
+ `;
363
+ }
364
+
365
+ _freeDateClicked(e) {
366
+ const dateKey = e.target.dataset.date;
367
+ if (dateKey) {
368
+ // convert back to date
369
+ const userSelectedDate = parse(dateKey, 'YYYY-MM-DD');
370
+ this.dispatchEvent(
371
+ new CustomEvent('select-date', {
372
+ detail: {
373
+ dateKey,
374
+ date: userSelectedDate,
375
+ },
376
+ })
377
+ );
378
+ }
379
+ }
380
+
381
+ _nextMonth() {
382
+ const now = new Date();
383
+ if (this.currentDate.getMonth() < now.getMonth() + 2) {
384
+ const newDate = new Date(
385
+ this.currentDate.getFullYear(),
386
+ this.currentDate.getMonth(),
387
+ 1
388
+ );
389
+ newDate.setMonth(newDate.getMonth() + 1);
390
+ this.dispatchEvent(
391
+ new CustomEvent('change-month', {
392
+ detail: {
393
+ newDate,
394
+ },
395
+ })
396
+ );
397
+ this._initFromDate(newDate);
398
+ }
399
+ }
400
+
401
+ _previousMonth() {
402
+ const now = new Date();
403
+ // TMP 23.08 ist start
404
+ if (this.currentDate.getMonth() > now.getMonth()) {
405
+ const newDate = new Date(
406
+ this.currentDate.getFullYear(),
407
+ this.currentDate.getMonth(),
408
+ 1
409
+ );
410
+ newDate.setMonth(newDate.getMonth() - 1);
411
+ this.dispatchEvent(
412
+ new CustomEvent('change-month', {
413
+ detail: {
414
+ newDate,
415
+ },
416
+ })
417
+ );
418
+ this._initFromDate(newDate);
419
+ }
420
+ }
421
+
422
+ _initFromDate(date) {
423
+ this._monthName = date.toLocaleString('default', { month: 'long' });
424
+ this._year = date.getFullYear();
425
+ this._daysFromPreviousMonth = PdCalendar._getPreviousMonthDays(date);
426
+ // last month day
427
+ const newDate2 = new Date(date.getFullYear(), date.getMonth() + 1, 0);
428
+ this._numberOfDays = newDate2.getDate();
429
+ this.currentDate = date;
430
+ }
431
+
432
+ static _getPreviousMonthDays(date) {
433
+ // get first day of month
434
+ const date1 = new Date(date.getFullYear(), date.getMonth(), 1);
435
+ // get missing days to monday
436
+ const missingDays = date1.getDay() > 0 ? Math.abs(1 - date1.getDay()) : 6;
437
+ // create array with missing days (dates)
438
+ const missDayArray = [];
439
+ for (let i = 1; i <= missingDays; i += 1) {
440
+ date1.setDate(date1.getDate() - 1);
441
+ missDayArray.push(
442
+ new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
443
+ );
444
+ }
445
+ return missDayArray;
446
+ }
456
447
  }
457
-
@@ -19,7 +19,9 @@ describe('PdCalendar', () => {
19
19
  });
20
20
 
21
21
  it('can override the title via attribute', async () => {
22
- const el = await fixture(html`<pd-calendar title="attribute title"></pd-calendar>`);
22
+ const el = await fixture(
23
+ html`<pd-calendar title="attribute title"></pd-calendar>`
24
+ );
23
25
 
24
26
  expect(el.title).to.equal('attribute title');
25
27
  });