@progressive-development/pd-calendar 0.0.0 → 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 +2 -21
- package/package.json +2 -2
- package/src/PdCalendar.js +429 -439
- package/test/pd-calendar.test.js +3 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
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": "
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"author": "PD Progressive Development",
|
|
6
|
-
"version": "0.0.
|
|
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)
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
/*max-width: 800px;*/
|
|
60
|
+
display: block;
|
|
61
|
+
/*width: 100vw;
|
|
71
62
|
height: 100vh;*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
package/test/pd-calendar.test.js
CHANGED
|
@@ -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(
|
|
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
|
});
|