@progressive-development/pd-calendar 0.2.0 → 0.2.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/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.2.0",
6
+ "version": "0.2.2",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
package/src/PdCalendar.js CHANGED
@@ -30,6 +30,15 @@ const isToday = (someDate) => {
30
30
  someDate.getFullYear() === today.getFullYear()
31
31
  }
32
32
 
33
+ const isSelected = (someDate1, someDate2) => {
34
+ if (!someDate1 || !someDate2) {
35
+ return false;
36
+ }
37
+ return someDate1.getDate() === someDate2.getDate() &&
38
+ someDate1.getMonth() === someDate2.getMonth() &&
39
+ someDate1.getFullYear() === someDate2.getFullYear()
40
+ }
41
+
33
42
  /**
34
43
  * PdCalendar displays montly view with information (selectable day cell).
35
44
  *
@@ -66,6 +75,7 @@ export class PdCalendar extends LitElement {
66
75
  return {
67
76
  refDate: { type: Object },
68
77
  selectableDates: { type: Boolean},
78
+ showSelection: { type: Boolean},
69
79
  hideWeekend: { type: Boolean, reflect: true },
70
80
  prevMonthConstraint: { type: Number },
71
81
  nextMonthConstraint: { type: Number },
@@ -179,7 +189,7 @@ export class PdCalendar extends LitElement {
179
189
  .arrow {
180
190
  cursor: pointer;
181
191
  --pd-icon-size: var(--pd-calendar-title-icon-size, 1.2em);
182
- --pd-icon-bg-col-hover: lightgrey;
192
+ --pd-icon-bg-col-hover: lightgrey;
183
193
  }
184
194
  `];
185
195
  }
@@ -192,6 +202,7 @@ export class PdCalendar extends LitElement {
192
202
  this.numberClass = "top-left";
193
203
  this.hideWeekend = false;
194
204
  this.selectableDates = false;
205
+ this.showSelection = false;
195
206
 
196
207
  this._currentMonthNavNr = 0;
197
208
  }
@@ -278,6 +289,7 @@ export class PdCalendar extends LitElement {
278
289
  numberClass="${this.numberClass}"
279
290
  @select-date="${this._forwardEvent}"
280
291
  ?today="${this.selectableDates && isToday(tmpDate)}"
292
+ ?selected="${this.showSelection && isSelected(this.refDate, tmpDate)}"
281
293
  ></pd-calendar-cell>
282
294
  `);
283
295
  }
@@ -21,6 +21,11 @@ class PdCalendarCell extends LitElement {
21
21
  */
22
22
  today: { type: Boolean },
23
23
 
24
+ /**
25
+ * If enabled, highlight the selected day
26
+ */
27
+ selected: { type: Boolean },
28
+
24
29
  /**
25
30
  * If enabled the cell gets an special class (e.g. green day).
26
31
  */
@@ -145,15 +150,23 @@ class PdCalendarCell extends LitElement {
145
150
  color: var(--pd-calendar-cell-day-info-free-col, var(--pd-default-bg-col));
146
151
  }
147
152
 
148
- .today {
153
+ .number-ring {
149
154
  position: absolute;
150
- height: 30px;
151
- width: 30px;
152
- border: 1px solid blue;
155
+ height: 28px;
156
+ width: 28px;
153
157
  border-radius: 50%;
154
158
  display: inline-block;
155
159
  }
156
160
 
161
+ .today {
162
+ border: 2px solid blue;
163
+ pointer-events: none;
164
+ }
165
+
166
+ .selected {
167
+ border: 2px solid red;
168
+ }
169
+
157
170
  /* ToDo: Dont work for calendars sized by custom properties. Needed to calculate from calendar size
158
171
  not from window size, this is a topic for container queries, which are not available right now... */
159
172
  @media (max-width: 800px) {
@@ -194,7 +207,11 @@ class PdCalendarCell extends LitElement {
194
207
  : ''}
195
208
 
196
209
  ${this.today
197
- ? html`<div class="today"></div>`
210
+ ? html`<div class="number-ring today"></div>`
211
+ : ''}
212
+
213
+ ${this.selected
214
+ ? html`<div class="number-ring selected"></div>`
198
215
  : ''}
199
216
 
200
217
  <div class="cell-number ${this.numberClass}">${this.dayNumber}</div>
@@ -20,7 +20,7 @@ function CalendarTemplate({ hideWeekend, refDate, data, prevMonthConstraint, nex
20
20
  </pd-calendar> `;
21
21
  }
22
22
 
23
- function CalendarSmallTemplate({ hideWeekend, width, cellHeight, prevMonthConstraint, nextMonthConstraint}) {
23
+ function CalendarSmallTemplate({ refDate, hideWeekend, width, cellHeight, prevMonthConstraint, nextMonthConstraint}) {
24
24
  return html`
25
25
  <style>
26
26
  .calendar-small {
@@ -39,7 +39,7 @@ function CalendarSmallTemplate({ hideWeekend, width, cellHeight, prevMonthConstr
39
39
 
40
40
  }
41
41
  </style>
42
- <pd-calendar selectableDates ?hideWeekend="${hideWeekend}" class="calendar-small" prevMonthConstraint="${prevMonthConstraint}"
42
+ <pd-calendar .refDate="${refDate}" selectableDates showSelection ?hideWeekend="${hideWeekend}" class="calendar-small" prevMonthConstraint="${prevMonthConstraint}"
43
43
  nextMonthConstraint="${nextMonthConstraint}" numberClass="center"
44
44
  >
45
45
  </pd-calendar>`;
@@ -98,6 +98,17 @@ BasicSmall.args = {
98
98
  nextMonthConstraint: -1,
99
99
  };
100
100
 
101
+ const currentDate = new Date();
102
+ export const BasicSmallWithRefDate = CalendarSmallTemplate.bind({});
103
+ BasicSmallWithRefDate.args = {
104
+ refDate: new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 10),
105
+ hideWeekend: false,
106
+ width: '220px',
107
+ cellHeight: '30px',
108
+ prevMonthConstraint: -1,
109
+ nextMonthConstraint: -1,
110
+ };
111
+
101
112
  export const BasicSmallWithoutWeekend = CalendarSmallTemplate.bind({});
102
113
  BasicSmallWithoutWeekend.args = {
103
114
  hideWeekend: true,