@progressive-development/pd-calendar 0.1.11 → 0.1.12

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 +1 -1
  2. package/src/PdCalendar.js +46 -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.12",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
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,22 @@ 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
+ * info: "some txt", => Text for day cell
38
+ * special?: true|false => Highlight cell
39
+ * }
27
40
  */
28
41
  export class PdCalendar extends LitElement {
29
42
 
@@ -40,6 +53,7 @@ export class PdCalendar extends LitElement {
40
53
  static get properties() {
41
54
  return {
42
55
  refDate: { type: Object },
56
+ hideWeekend: { type: Boolean, reflect: true },
43
57
  prevMonthConstraint: { type: Number },
44
58
  nextMonthConstraint: { type: Number },
45
59
  data: { type: Object },
@@ -68,6 +82,10 @@ export class PdCalendar extends LitElement {
68
82
  height: 100vh;*/
69
83
  }
70
84
 
85
+ :host([hideWeekend]) .grid-container {
86
+ grid-template-columns: repeat(5, minmax(0, 1fr));
87
+ }
88
+
71
89
  /* Layout Grid for the Calendar Component => Not really needed at the moment, more a test */
72
90
  .layout-container {
73
91
  width: var(--pd-calendar-width, 100%);
@@ -167,7 +185,8 @@ export class PdCalendar extends LitElement {
167
185
 
168
186
  this.data = {};
169
187
  this._viewType = VIEW_MONTH;
170
- this.numberClass = "top-left";
188
+ this.numberClass = "top-left";
189
+ this.hideWeekend = true;
171
190
 
172
191
  this._currentMonthNavNr = 0;
173
192
  }
@@ -229,24 +248,27 @@ export class PdCalendar extends LitElement {
229
248
  : 'normal';
230
249
  for (let i = 1; i <= this._numberOfDays; i += 1) {
231
250
  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
- `);
251
+ const day = tmpDate.getDay();
252
+ if (!this.hideWeekend || ((day !== 6) && (day !== 0))) {
253
+ const key = format(tmpDate, 'YYYY-MM-DD');
254
+ // TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
255
+ const infoTxt = this.data[key] ? this.data[key][0].info : undefined;
256
+ const special = this.data[key]
257
+ ? this.data[key][0].special || false
258
+ : false;
259
+ itemTemplates.push(html`
260
+ <pd-calendar-cell
261
+ key="${key}"
262
+ dayNumber="${i}"
263
+ weekDayNumber="${tmpDate.getDay()}"
264
+ infoTxt="${infoTxt}"
265
+ ?selectEnabled="${infoTxt !== undefined}"
266
+ ?special="${special}"
267
+ numberClass="${this.numberClass}"
268
+ @select-date="${this._forwardEvent}"
269
+ ></pd-calendar-cell>
270
+ `);
271
+ }
250
272
  }
251
273
 
252
274
  return html`
@@ -274,7 +296,7 @@ export class PdCalendar extends LitElement {
274
296
  </div>
275
297
 
276
298
  <div class="content grid-container ${sizeVar}">
277
- ${weekDays.map(
299
+ ${(this.hideWeekend ? weekDaysWithoutWE : weekDays).map(
278
300
  shortName => html` <div class="title-week-day">${shortName}</div>`
279
301
  )}
280
302
  ${this._daysFromPreviousMonth.map(