@progressive-development/pd-calendar 0.1.14 → 0.1.16

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 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.14",
6
+ "version": "0.1.16",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
package/src/PdCalendar.js CHANGED
@@ -20,6 +20,16 @@ const VIEW_LIST = 1;
20
20
  const VIEW_MONTH = 2;
21
21
  const VIEW_WEEK = 3;
22
22
 
23
+ const isToday = (someDate) => {
24
+ if (!someDate) {
25
+ return false;
26
+ }
27
+ const today = new Date()
28
+ return someDate.getDate() === today.getDate() &&
29
+ someDate.getMonth() === today.getMonth() &&
30
+ someDate.getFullYear() === today.getFullYear()
31
+ }
32
+
23
33
  /**
24
34
  * PdCalendar displays montly view with information (selectable day cell).
25
35
  *
@@ -55,6 +65,7 @@ export class PdCalendar extends LitElement {
55
65
  static get properties() {
56
66
  return {
57
67
  refDate: { type: Object },
68
+ selectableDates: { type: Boolean},
58
69
  hideWeekend: { type: Boolean, reflect: true },
59
70
  prevMonthConstraint: { type: Number },
60
71
  nextMonthConstraint: { type: Number },
@@ -115,13 +126,8 @@ export class PdCalendar extends LitElement {
115
126
  .header-main {
116
127
  display: flex;
117
128
  align-items: center;
118
- justify-content: center;
119
- }
120
-
121
- .header-icons {
122
- position: absolute;
123
- right: 0px;
124
- top: 0px;
129
+ justify-content: space-between;
130
+ width: 100%;
125
131
  }
126
132
 
127
133
  .content {
@@ -158,26 +164,15 @@ export class PdCalendar extends LitElement {
158
164
  font-family: var(--pd-default-font-title-family);
159
165
  }
160
166
 
161
- span.content-title {
162
- display: flex;
163
- align-items: center;
164
- justify-content: center;
165
- font-weight: bold;
166
- font-size: 1.4em;
167
- width: 120px;
168
- }
169
-
170
- span.content-sub-title {
171
- position: absolute;
172
- right: 1px;
173
- bottom: 0px;
174
- font-size: 1.2em;
167
+ .content-title {
168
+ font-size: var(--pd-calendar-title-font-size, 1.2em);
175
169
  font-weight: bold;
176
170
  }
177
171
 
178
172
  .arrow {
179
173
  cursor: pointer;
180
- --pd-icon-size: 1.4rem;
174
+ --pd-icon-size: var(--pd-calendar-title-icon-size, 1.2em);
175
+ --pd-icon-bg-col-hover: lightgrey;
181
176
  }
182
177
  `];
183
178
  }
@@ -188,7 +183,8 @@ export class PdCalendar extends LitElement {
188
183
  this.data = {};
189
184
  this._viewType = VIEW_MONTH;
190
185
  this.numberClass = "top-left";
191
- this.hideWeekend = true;
186
+ this.hideWeekend = false;
187
+ this.selectableDates = false;
192
188
 
193
189
  this._currentMonthNavNr = 0;
194
190
  }
@@ -211,6 +207,10 @@ export class PdCalendar extends LitElement {
211
207
  this._currentMonthNavNr += 1;
212
208
  this._initFromDate(startDateNextMonth);
213
209
  }
210
+
211
+ if (changedProperties.has("refDate") && this.refDate) {
212
+ this._initFromDate(this.refDate);
213
+ }
214
214
  super.update(changedProperties);
215
215
  }
216
216
 
@@ -258,16 +258,19 @@ export class PdCalendar extends LitElement {
258
258
  const special = this.data[key]
259
259
  ? this.data[key][0].special || false
260
260
  : false;
261
+
262
+
261
263
  itemTemplates.push(html`
262
264
  <pd-calendar-cell
263
265
  key="${key}"
264
266
  dayNumber="${i}"
265
267
  weekDayNumber="${tmpDate.getDay()}"
266
268
  infoTxt="${infoTxt}"
267
- ?selectEnabled="${infoTxt !== undefined}"
269
+ ?selectEnabled="${this.selectableDates || infoTxt !== undefined}"
268
270
  ?special="${special}"
269
271
  numberClass="${this.numberClass}"
270
272
  @select-date="${this._forwardEvent}"
273
+ ?today="${this.selectableDates && isToday(tmpDate)}"
271
274
  ></pd-calendar-cell>
272
275
  `);
273
276
  }
@@ -276,25 +279,31 @@ export class PdCalendar extends LitElement {
276
279
  return html`
277
280
  <div class="layout-container">
278
281
  <div class="header">
279
- <div class="header-main">
280
- <pd-icon
281
- @click="${this._previousMonth}"
282
- class="arrow"
283
- icon="previousArrow"
284
- ></pd-icon>
285
-
286
- <span class="content-title">${this._monthName}</span>
287
-
288
- <pd-icon
289
- @click="${this._nextMonth}"
290
- class="arrow"
291
- icon="nextArrow"
292
- ></pd-icon>
293
- </div>
294
-
295
- <div class="header-icons"></div>
296
-
297
- <span class="content-sub-title">${this._year}</span>
282
+
283
+ <div class="header-main">
284
+
285
+ <div>
286
+ <pd-icon
287
+ @click="${this._previousMonth}"
288
+ class="arrow"
289
+ activeIcon
290
+ icon="previousArrow"
291
+ ></pd-icon>
292
+
293
+ <pd-icon
294
+ @click="${this._nextMonth}"
295
+ class="arrow"
296
+ activeIcon
297
+ icon="nextArrow"
298
+ ></pd-icon>
299
+ </div>
300
+
301
+ <div class="content-title">
302
+ ${this._monthName} ${this._year}
303
+ </div>
304
+
305
+ </div>
306
+
298
307
  </div>
299
308
 
300
309
  <div class="content grid-container ${sizeVar}">
@@ -16,6 +16,11 @@ class PdCalendarCell extends LitElement {
16
16
  */
17
17
  selectEnabled: { type: Boolean },
18
18
 
19
+ /**
20
+ * If enabled, highlight the current day
21
+ */
22
+ today: { type: Boolean },
23
+
19
24
  /**
20
25
  * If enabled the cell gets an special class (e.g. green day).
21
26
  */
@@ -83,7 +88,7 @@ class PdCalendarCell extends LitElement {
83
88
  background-color: var(--my-info-cell-bg1-color);*/
84
89
  background-color: var(--pd-calendar-cell-day-free-bg-col, var(--pd-default-col));
85
90
  /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
86
- box-shadow: 1px 2px 2px;
91
+ box-shadow: var(--pd-calendar-cell-selectable-shadow, 1px 2px 2px);
87
92
  }
88
93
 
89
94
  .special {
@@ -91,7 +96,7 @@ class PdCalendarCell extends LitElement {
91
96
  background-color: var(--my-info-cell-bg1-color);*/
92
97
  background-color: var(--pd-calendar-cell-day-special-bg-col, var(--pd-default-success-col));
93
98
  /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
94
- box-shadow: 1px 2px 2px;
99
+ box-shadow: var(--pd-calendar-cell-selectable-shadow, 1px 2px 2px);;
95
100
  }
96
101
 
97
102
  .special:hover,
@@ -116,6 +121,7 @@ class PdCalendarCell extends LitElement {
116
121
  }
117
122
 
118
123
  .cell-number {
124
+ pointer-events: none;
119
125
  font-size: 1em;
120
126
  font-weight: bold;
121
127
  color: var(--pd-calendar-cell-day-info-col, var(--pd-default-bg-col));
@@ -129,16 +135,25 @@ class PdCalendarCell extends LitElement {
129
135
  }
130
136
 
131
137
  /* Noch umstellen, passt nicht für alle größen (die anderen auf flex/center umgestellt) */
132
- .cell-number.center {
133
- top: 50%;
134
- left: 30%;
135
- transform: translate(0, -50%);
138
+ .center {
139
+ display: flex;
140
+ align-items: center;
141
+ justify-content: center;
136
142
  }
137
143
 
138
144
  .free .cell-number, .special .cell-number {
139
145
  color: var(--pd-calendar-cell-day-info-free-col, var(--pd-default-bg-col));
140
146
  }
141
147
 
148
+ .today {
149
+ position: absolute;
150
+ height: 23px;
151
+ width: 23px;
152
+ border: 1px solid blue;
153
+ border-radius: 50%;
154
+ display: inline-block;
155
+ }
156
+
142
157
  /* ToDo: Dont work for calendars sized by custom properties. Needed to calculate from calendar size
143
158
  not from window size, this is a topic for container queries, which are not available right now... */
144
159
  @media (max-width: 800px) {
@@ -168,18 +183,27 @@ class PdCalendarCell extends LitElement {
168
183
  @keypress="${this._selectableCellClicked}"
169
184
  @click="${this._selectableCellClicked}"
170
185
  data-date="${this.key}"
171
- class="cell cell-day ${this.special ? 'special' : 'free'}"
172
- >
186
+ class="cell cell-day ${this.numberClass} ${this.special ? 'special' : 'free'}
187
+ ${this.weekDayNumber === 6 ||
188
+ this.weekDayNumber === 0
189
+ ? 'we'
190
+ : ''}"
191
+ >
173
192
  ${this.infoTxt
174
193
  ? html` <div class="cell-info">${this.infoTxt}</div>`
175
194
  : ''}
195
+
196
+ ${this.today
197
+ ? html`<div class="today"></div>`
198
+ : ''}
199
+
176
200
  <div class="cell-number ${this.numberClass}">${this.dayNumber}</div>
177
201
  </div>`;
178
202
  }
179
203
 
180
204
  _renderEmptyCell() {
181
205
  return html`<div
182
- class="cell cell-day top-left ${this.weekDayNumber === 6 ||
206
+ class="cell cell-day ${this.numberClass} ${this.weekDayNumber === 6 ||
183
207
  this.weekDayNumber === 0
184
208
  ? 'we'
185
209
  : ''}"
@@ -187,7 +211,8 @@ class PdCalendarCell extends LitElement {
187
211
  ${this.infoTxt
188
212
  ? html`<div class="cell-info">${this.infoTxt}</div>`
189
213
  : ''}
190
- <div class="cell-number ${this.numberClass}">${this.dayNumber}</div>
214
+
215
+ <div class="cell-number ${this.numberClass}">${this.dayNumber}</div>
191
216
  </div>`;
192
217
  }
193
218
 
@@ -9,22 +9,29 @@ export default {
9
9
  },
10
10
  };
11
11
 
12
- function CalendarTemplate({ refDate, data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
13
- return html` <pd-calendar .refDate="${refDate}" .data="${data || {}}"
12
+ function CalendarTemplate({ hideWeekend, refDate, data, prevMonthConstraint, nextMonthConstraint, addSlot}) {
13
+ return html` <pd-calendar
14
+ ?hideWeekend="${hideWeekend}"
15
+ .refDate="${refDate}" .data="${data || {}}"
14
16
  prevMonthConstraint="${prevMonthConstraint}" nextMonthConstraint="${nextMonthConstraint}">
15
17
  ${addSlot ? html`<p slot="calFooter">* excl. BTW</p>` : ''}
16
18
  </pd-calendar> `;
17
19
  }
18
20
 
19
- function CalendarSmallTemplate({ width, cellHeight, prevMonthConstraint, nextMonthConstraint}) {
21
+ function CalendarSmallTemplate({ hideWeekend, width, cellHeight, prevMonthConstraint, nextMonthConstraint}) {
20
22
  return html`
21
23
  <style>
22
24
  .calendar-small {
23
25
  --pd-calendar-width: ${width};
24
26
  --pd-calendar-cell-height: ${cellHeight};
27
+ --pd-calendar-week-title-bg-col: white;
28
+ --pd-calendar-week-title-font-col: #0A3A48;
29
+ --pd-calendar-cell-selectable-shadow: 0;
30
+ --pd-calendar-cell-day-free-bg-col: white;
31
+ --pd-calendar-cell-day-info-free-col: #0A3A48;
25
32
  }
26
33
  </style>
27
- <pd-calendar class="calendar-small" prevMonthConstraint="${prevMonthConstraint}"
34
+ <pd-calendar selectableDates ?hideWeekend="${hideWeekend}" class="calendar-small" prevMonthConstraint="${prevMonthConstraint}"
28
35
  nextMonthConstraint="${nextMonthConstraint}" numberClass="center"
29
36
  >
30
37
  </pd-calendar>`;
@@ -62,6 +69,11 @@ const newDate6 = new Date(
62
69
  now.getMonth(),
63
70
  10
64
71
  );
72
+ const newDate7 = new Date(
73
+ now.getFullYear(),
74
+ now.getMonth(),
75
+ 11
76
+ );
65
77
 
66
78
  export const Basic = CalendarTemplate.bind({});
67
79
  Basic.args = {
@@ -71,6 +83,16 @@ Basic.args = {
71
83
 
72
84
  export const BasicSmall = CalendarSmallTemplate.bind({});
73
85
  BasicSmall.args = {
86
+ hideWeekend: false,
87
+ width: '220px',
88
+ cellHeight: '30px',
89
+ prevMonthConstraint: -1,
90
+ nextMonthConstraint: -1,
91
+ };
92
+
93
+ export const BasicSmallWithoutWeekend = CalendarSmallTemplate.bind({});
94
+ BasicSmallWithoutWeekend.args = {
95
+ hideWeekend: true,
74
96
  width: '220px',
75
97
  cellHeight: '30px',
76
98
  prevMonthConstraint: -1,
@@ -102,6 +124,7 @@ specialData[format(newDate3, 'YYYY-MM-DD')] = [{ info: '150 €', special: true}
102
124
  specialData[format(newDate4, 'YYYY-MM-DD')] = [{ info: '180 €' }];
103
125
  specialData[format(newDate5, 'YYYY-MM-DD')] = [{ info: '170 €' }];
104
126
  specialData[format(newDate6, 'YYYY-MM-DD')] = [{ info: '150 €', special: true}];
127
+ specialData[format(newDate7, 'YYYY-MM-DD')] = [{ info: '150 €', special: true}];
105
128
  WithSpecialDays.args = {
106
129
  data: specialData,
107
130
  prevMonthConstraint: 0,
@@ -109,6 +132,15 @@ WithSpecialDays.args = {
109
132
  addSlot: true
110
133
  };
111
134
 
135
+ export const WithSpecialDaysHideWeekend = CalendarTemplate.bind({});
136
+ WithSpecialDaysHideWeekend.args = {
137
+ hideWeekend: true,
138
+ data: specialData,
139
+ prevMonthConstraint: 0,
140
+ nextMonthConstraint: 3,
141
+ addSlot: true
142
+ };
143
+
112
144
  const now2 = new Date();
113
145
  now2.setMonth(now.getMonth() + 15);
114
146
  export const WithSpecificDateAndConstraints = CalendarTemplate.bind({});