@progressive-development/pd-calendar 0.1.11 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/PdCalendar.js +48 -24
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "progressive development calendar web component",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "author": "PD Progressive Development",
6
- "version": "0.1.11",
6
+ "version": "0.1.13",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  "week"
31
31
  ],
32
32
  "dependencies": {
33
- "@progressive-development/pd-icon": "^0.1.16",
33
+ "@progressive-development/pd-icon": "^0.1.17",
34
34
  "@progressive-development/pd-shared-styles": "0.1.1",
35
35
  "fecha": "^4.2.0",
36
36
  "lit": "^2.2.0"
package/src/PdCalendar.js CHANGED
@@ -13,6 +13,7 @@ import './PdCalendarCell.js';
13
13
 
14
14
  // todo: use existing shortnames for locale here
15
15
  const weekDays = ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'];
16
+ const weekDaysWithoutWE = ['Ma', 'Di', 'Wo', 'Do', 'Vr'];
16
17
 
17
18
  // list views (list, month, week)
18
19
  const VIEW_LIST = 1;
@@ -20,10 +21,24 @@ const VIEW_MONTH = 2;
20
21
  const VIEW_WEEK = 3;
21
22
 
22
23
  /**
23
- * An example element.
24
- *
25
- * @slot - This element has a slot
26
- * @csspart button - The button
24
+ * PdCalendar displays montly view with information (selectable day cell).
25
+ *
26
+ * refDate: Date => if set use the day for initial month view
27
+ * prevMonthConstraint: number => if set, allows only back steps until the constraint is reached
28
+ * nextMonthConstraint: number => if set, allows only forward steps until the constraint is reached
29
+ * data: Object => input calendar Data.
30
+ * numberClass: string => display day in cell (top-left and center available)
31
+ *
32
+ * Data:
33
+ * monthSelection: number => number wich indicates, the month with data, if the origin month contains no valid data.
34
+ * starts the calendar view initial with the month from monthSelection
35
+ * Input Data as followed
36
+ * "2023-11-04": [
37
+ * {
38
+ * info: "some txt", => Text for day cell
39
+ * special?: true|false => Highlight cell
40
+ * }
41
+ * ]
27
42
  */
28
43
  export class PdCalendar extends LitElement {
29
44
 
@@ -40,6 +55,7 @@ export class PdCalendar extends LitElement {
40
55
  static get properties() {
41
56
  return {
42
57
  refDate: { type: Object },
58
+ hideWeekend: { type: Boolean, reflect: true },
43
59
  prevMonthConstraint: { type: Number },
44
60
  nextMonthConstraint: { type: Number },
45
61
  data: { type: Object },
@@ -68,6 +84,10 @@ export class PdCalendar extends LitElement {
68
84
  height: 100vh;*/
69
85
  }
70
86
 
87
+ :host([hideWeekend]) .grid-container {
88
+ grid-template-columns: repeat(5, minmax(0, 1fr));
89
+ }
90
+
71
91
  /* Layout Grid for the Calendar Component => Not really needed at the moment, more a test */
72
92
  .layout-container {
73
93
  width: var(--pd-calendar-width, 100%);
@@ -167,7 +187,8 @@ export class PdCalendar extends LitElement {
167
187
 
168
188
  this.data = {};
169
189
  this._viewType = VIEW_MONTH;
170
- this.numberClass = "top-left";
190
+ this.numberClass = "top-left";
191
+ this.hideWeekend = true;
171
192
 
172
193
  this._currentMonthNavNr = 0;
173
194
  }
@@ -229,24 +250,27 @@ export class PdCalendar extends LitElement {
229
250
  : 'normal';
230
251
  for (let i = 1; i <= this._numberOfDays; i += 1) {
231
252
  const tmpDate = new Date(this._year, this._currentDate.getMonth(), i);
232
- const key = format(tmpDate, 'YYYY-MM-DD');
233
- // TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
234
- const infoTxt = this.data[key] ? this.data[key][0].info : undefined;
235
- const special = this.data[key]
236
- ? this.data[key][0].special || false
237
- : false;
238
- itemTemplates.push(html`
239
- <pd-calendar-cell
240
- key="${key}"
241
- dayNumber="${i}"
242
- weekDayNumber="${tmpDate.getDay()}"
243
- infoTxt="${infoTxt}"
244
- ?selectEnabled="${infoTxt !== undefined}"
245
- ?special="${special}"
246
- numberClass="${this.numberClass}"
247
- @select-date="${this._forwardEvent}"
248
- ></pd-calendar-cell>
249
- `);
253
+ const day = tmpDate.getDay();
254
+ if (!this.hideWeekend || ((day !== 6) && (day !== 0))) {
255
+ const key = format(tmpDate, 'YYYY-MM-DD');
256
+ // TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
257
+ const infoTxt = this.data[key] ? this.data[key][0].info : undefined;
258
+ const special = this.data[key]
259
+ ? this.data[key][0].special || false
260
+ : false;
261
+ itemTemplates.push(html`
262
+ <pd-calendar-cell
263
+ key="${key}"
264
+ dayNumber="${i}"
265
+ weekDayNumber="${tmpDate.getDay()}"
266
+ infoTxt="${infoTxt}"
267
+ ?selectEnabled="${infoTxt !== undefined}"
268
+ ?special="${special}"
269
+ numberClass="${this.numberClass}"
270
+ @select-date="${this._forwardEvent}"
271
+ ></pd-calendar-cell>
272
+ `);
273
+ }
250
274
  }
251
275
 
252
276
  return html`
@@ -274,7 +298,7 @@ export class PdCalendar extends LitElement {
274
298
  </div>
275
299
 
276
300
  <div class="content grid-container ${sizeVar}">
277
- ${weekDays.map(
301
+ ${(this.hideWeekend ? weekDaysWithoutWE : weekDays).map(
278
302
  shortName => html` <div class="title-week-day">${shortName}</div>`
279
303
  )}
280
304
  ${this._daysFromPreviousMonth.map(