@progressive-development/pd-calendar 0.0.10 → 0.0.11

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.0.10",
6
+ "version": "0.0.11",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
package/src/PdCalendar.js CHANGED
@@ -4,9 +4,11 @@
4
4
  */
5
5
 
6
6
  import { LitElement, html, css } from 'lit';
7
- import { format, parse } from 'fecha';
7
+ import { format } from 'fecha';
8
8
  import '@progressive-development/pd-icon/pd-icon.js';
9
9
 
10
+ import './PdCalendarCell.js';
11
+
10
12
  // todo: use existing shortnames for locale here
11
13
  const weekDays = ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'];
12
14
 
@@ -39,22 +41,13 @@ export class PdCalendar extends LitElement {
39
41
 
40
42
  /* Define custom properties for calendar element */
41
43
  --my-title-color: var(--squi-title-color, #084c61);
42
- --my-day-title-bg-color: var(--squi-title-color, #084c61);
43
- --my-cell-bg-color: var(--squi-title-color, lightgrey);
44
- --my-cell-we-bg-color: var(--squi-title-color, darkgrey);
45
- --my-cell-day-color: var(--squi-title-color, #fefefe);
46
-
47
- --my-info-cell-bg1-color: var(--squi-title-color, #177e89);
48
- --my-info-cell-bg2-color: var(--squi-title-color, #084c61);
49
- --my-info-cell-day-color: var(--squi-title-color, #fefefe);
50
-
51
- --my-info-cell-bg1-hover: var(--squi-highlight-color, #ffc857);
52
- --my-info-cell-bg2-hover: var(--squi-highlight-color, #177e89);
53
-
54
- --my-info-txt-color: var(--squi-info-txt, #fefefe);
55
-
44
+ --my-day-title-bg-color: var(--squi-title-color, #084c61);
45
+
56
46
  --my-primary-font: var(--squi-primary-font, Oswald);
57
47
 
48
+ --my-width: var(--pd-calendar-width, 100%);
49
+ --my-cell-height: var(--pd-calendar-cell-height, 70px);
50
+
58
51
  display: block;
59
52
  /*padding: 8px;
60
53
  width: 100vw;
@@ -63,6 +56,8 @@ export class PdCalendar extends LitElement {
63
56
 
64
57
  /* Layout Grid for the Calendar Component => Not really needed at the moment, more a test */
65
58
  .layout-container {
59
+ width: var(--my-width);
60
+ min-width: 220px;
66
61
  height: 100%;
67
62
  display: grid;
68
63
  grid-template-columns: 1fr 1fr 1fr;
@@ -80,12 +75,18 @@ export class PdCalendar extends LitElement {
80
75
 
81
76
  font-family: var(--my-primary-font);
82
77
  color: var(--my-title-color);
78
+
79
+ display: flex;
80
+ justify-content: left;
83
81
  }
84
82
 
85
83
  .header-main {
84
+ display: flex;
85
+ /* Nun über display flex in header und justify-content gelöst
86
86
  position: absolute;
87
+ top: 50%;
87
88
  left: 30%;
88
- display: flex;
89
+ transform: translate(0, -50%);*/
89
90
  }
90
91
 
91
92
  .header-icons {
@@ -110,11 +111,11 @@ export class PdCalendar extends LitElement {
110
111
  }
111
112
 
112
113
  .grid-container.max {
113
- grid-template-rows: minmax(10px, 30px) repeat(6, minmax(70px, 1fr));
114
+ grid-template-rows: minmax(10px, 30px) repeat(6, minmax(var(--my-cell-height), 1fr));
114
115
  }
115
116
 
116
117
  .grid-container.normal {
117
- grid-template-rows: minmax(10px, 30px) repeat(5, minmax(70px, 1fr));
118
+ grid-template-rows: minmax(10px, 30px) repeat(5, minmax(var(--my-cell-height), 1fr));
118
119
  }
119
120
 
120
121
  .title-week-day {
@@ -127,49 +128,6 @@ export class PdCalendar extends LitElement {
127
128
  font-family: var(--my-primary-font);
128
129
  }
129
130
 
130
- .cell {
131
- text-align: center;
132
- }
133
-
134
- .cell-empty {
135
- background-color: #fdfbfb;
136
- }
137
-
138
- .cell-day {
139
- position: relative;
140
- /*background-image: linear-gradient(to right, rgb(51, 101, 138) , rgb(38, 76, 104)); */
141
- /*box-shadow: 2px 2px 3px;*/
142
- background-color: var(--my-cell-bg-color);
143
- /*border-radius: 2px 2px 2px 2px;*/
144
- }
145
-
146
- .cell-day.we {
147
- background-color: var(--my-cell-we-bg-color);
148
- }
149
-
150
- .free {
151
- /*background-image: linear-gradient(to right, green, darkgreen);
152
- background-color: var(--my-info-cell-bg1-color);*/
153
- background-color: var(--my-info-cell-bg1-color);
154
- /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
155
- box-shadow: 1px 2px 2px;
156
- }
157
-
158
- .special {
159
- /*background-image: linear-gradient(to right, green, darkgreen);
160
- background-color: var(--my-info-cell-bg1-color);*/
161
- background-color: var(--green, green); /*#1da692*/
162
- /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
163
- box-shadow: 1px 2px 2px;
164
- }
165
-
166
- .special:hover,
167
- .free:hover {
168
- background-color: rgb(247, 211, 8);
169
- /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-hover), var(--my-info-cell-bg2-hover));*/
170
- cursor: pointer;
171
- }
172
-
173
131
  span.content-title {
174
132
  font-weight: bold;
175
133
  font-size: 1.5em;
@@ -179,54 +137,12 @@ export class PdCalendar extends LitElement {
179
137
 
180
138
  span.content-sub-title {
181
139
  position: absolute;
182
- left: 0px;
140
+ right: 1px;
183
141
  bottom: 0px;
184
142
  font-size: 1.2em;
185
143
  font-weight: bold;
186
144
  }
187
145
 
188
- span.cell-info {
189
- position: absolute;
190
- left: 35%;
191
- top: 30%;
192
- color: var(--my-info-txt-color);
193
- font-family: var(--my-primary-font);
194
- font-weight: bold;
195
- font-size: 1.5em;
196
- text-shadow: 1px 1px black;
197
- pointer-events: none;
198
- }
199
-
200
- span.cell-number {
201
- position: absolute;
202
- left: 3px;
203
- top: 1px;
204
- font-size: 0.9em;
205
- color: var(--my-cell-day-color);
206
- font-family: var(--my-primary-font);
207
- }
208
-
209
- .free .cell-number {
210
- color: var(--my-info-cell-day-color);
211
- }
212
-
213
- @media (max-width: 800px) {
214
- span.cell-info {
215
- left: 30%;
216
- font-size: 1.3em;
217
- }
218
- span.cell-number {
219
- font-size: 0.7em;
220
- }
221
- }
222
- @media (max-width: 500px) {
223
- span.cell-info {
224
- left: 15%;
225
- font-weight: normal;
226
- font-size: 1em;
227
- }
228
- }
229
-
230
146
  .arrow {
231
147
  /* Hack */
232
148
  padding-top: 8px;
@@ -243,6 +159,12 @@ export class PdCalendar extends LitElement {
243
159
  prevMonthConstraint: { type: Number },
244
160
  nextMonthConstraint: { type: Number },
245
161
  data: { type: Object },
162
+
163
+ /**
164
+ * CSS class for day number inside the cell, top-left and center available
165
+ */
166
+ numberClass: { type: String },
167
+
246
168
  _viewType: { type: Number },
247
169
  _latestDate: { type: Object },
248
170
  _earliestDate: { type: Object },
@@ -254,6 +176,7 @@ export class PdCalendar extends LitElement {
254
176
 
255
177
  this.data = {};
256
178
  this._viewType = VIEW_MONTH;
179
+ this.numberClass = "top-left";
257
180
 
258
181
  // initialize date values with current date
259
182
  const now = new Date();
@@ -324,34 +247,21 @@ export class PdCalendar extends LitElement {
324
247
  const tmpDate = new Date(this._year, this.currentDate.getMonth(), i);
325
248
  const key = format(tmpDate, 'YYYY-MM-DD');
326
249
  // TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
327
- const infoTxt = this.data[key] ? this.data[key][0].info : '';
250
+ const infoTxt = this.data[key] ? this.data[key][0].info : undefined;
328
251
  const special = this.data[key]
329
252
  ? this.data[key][0].special || false
330
253
  : false;
331
- if (infoTxt) {
332
254
  itemTemplates.push(html`
333
- <div
334
- @keypress="${this._freeDateClicked}"
335
- @click="${this._freeDateClicked}"
336
- data-date="${key}"
337
- class="cell cell-day ${special ? 'special' : 'free'}"
338
- >
339
- <span class="cell-info">${infoTxt}*</span>
340
- <span class="cell-number">${i}</span>
341
- </div>
255
+ <pd-calendar-cell
256
+ key="${key}"
257
+ dayNumber="${i}"
258
+ weekDayNumber="${tmpDate.getDay()}"
259
+ infoTxt="${infoTxt}"
260
+ ?selectEnabled="${infoTxt !== undefined}"
261
+ ?special="${special}"
262
+ numberClass="${this.numberClass}"
263
+ ></pd-calendar-cell>
342
264
  `);
343
- } else {
344
- itemTemplates.push(html`
345
- <div
346
- class="cell cell-day ${tmpDate.getDay() === 6 ||
347
- tmpDate.getDay() === 0
348
- ? 'we'
349
- : ''}"
350
- >
351
- <span class="cell-number">${i}</span>
352
- </div>
353
- `);
354
- }
355
265
  }
356
266
 
357
267
  return html`
@@ -391,22 +301,6 @@ export class PdCalendar extends LitElement {
391
301
  `;
392
302
  }
393
303
 
394
- _freeDateClicked(e) {
395
- const dateKey = e.target.dataset.date;
396
- if (dateKey) {
397
- // convert back to date
398
- const userSelectedDate = parse(dateKey, 'YYYY-MM-DD');
399
- this.dispatchEvent(
400
- new CustomEvent('select-date', {
401
- detail: {
402
- dateKey,
403
- date: userSelectedDate,
404
- },
405
- })
406
- );
407
- }
408
- }
409
-
410
304
  _nextMonth() {
411
305
  if (this._checkNextMonthConstraint()) {
412
306
  const newDate = new Date(
@@ -0,0 +1,225 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { parse } from 'fecha';
3
+
4
+ class PdCalendarCell extends LitElement {
5
+ /**
6
+ * @event select-date - fires when user clicks on a selectable cell.
7
+ */
8
+
9
+ static get properties() {
10
+ return {
11
+ /**
12
+ * If enabled, cell could be selected (with visible hover element and pointer)
13
+ * vy the user => results in fire cell-selected.
14
+ */
15
+ selectEnabled: { type: Boolean },
16
+
17
+ /**
18
+ * If enabled the cell gets an special class (e.g. green day).
19
+ */
20
+ special: { type: Boolean },
21
+
22
+ /**
23
+ * If set shows info text in the middle (hack) of the cell (e.g. price info).
24
+ */
25
+ infoTxt: { type: String },
26
+
27
+ /**
28
+ * CSS class for day number inside the cell, top-left and center available
29
+ */
30
+ numberClass: { type: String },
31
+
32
+ /* key, weekDayNumber, dayNumber could merged to date
33
+ on the other hand then there is the need to calculate them for each cell... */
34
+ key: { type: String },
35
+ weekDayNumber: { type: Number },
36
+ dayNumber: { type: Number },
37
+ };
38
+ }
39
+
40
+ static get styles() {
41
+ return css`
42
+ :host {
43
+ display: block;
44
+
45
+
46
+ /* Define custom properties for calendar cell element */
47
+ --my-cell-bg-color: var(--squi-title-color, lightgrey);
48
+ --my-cell-we-bg-color: var(--squi-title-color, darkgrey);
49
+ --my-cell-day-color: var(--squi-title-color, #fefefe);
50
+
51
+ --my-info-cell-bg1-color: var(--squi-title-color, #177e89);
52
+ --my-info-cell-day-color: var(--squi-title-color, #fefefe);
53
+ --my-info-txt-color: var(--squi-info-txt, #fefefe);
54
+ /* Defined by PdCalendar and also setted here
55
+ --my-primary-font: var(--squi-primary-font, Oswald);*/
56
+
57
+ /* not used in the moment, was created for gradient cells
58
+ --my-info-cell-bg2-color: var(--squi-title-color, #084c61);
59
+ --my-info-cell-bg1-hover: var(--squi-highlight-color, #ffc857);
60
+ --my-info-cell-bg2-hover: var(--squi-highlight-color, #177e89);
61
+ */
62
+ }
63
+
64
+ .cell {
65
+ width: 100%;
66
+ height: 100%;
67
+ min-height: 30px;
68
+ }
69
+
70
+ .cell-empty {
71
+ background-color: #fdfbfb;
72
+ }
73
+
74
+ .cell-day {
75
+ position: relative;
76
+ /*background-image: linear-gradient(to right, rgb(51, 101, 138) , rgb(38, 76, 104)); */
77
+ /*box-shadow: 2px 2px 3px;*/
78
+ background-color: var(--my-cell-bg-color);
79
+ /*border-radius: 2px 2px 2px 2px;*/
80
+ }
81
+
82
+ .cell-day.we {
83
+ background-color: var(--my-cell-we-bg-color);
84
+ }
85
+
86
+ .free {
87
+ /*background-image: linear-gradient(to right, green, darkgreen);
88
+ background-color: var(--my-info-cell-bg1-color);*/
89
+ background-color: var(--my-info-cell-bg1-color);
90
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
91
+ box-shadow: 1px 2px 2px;
92
+ }
93
+
94
+ .special {
95
+ /*background-image: linear-gradient(to right, green, darkgreen);
96
+ background-color: var(--my-info-cell-bg1-color);*/
97
+ background-color: var(--green, green); /*#1da692*/
98
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
99
+ box-shadow: 1px 2px 2px;
100
+ }
101
+
102
+ .special:hover,
103
+ .free:hover {
104
+ background-color: rgb(247, 211, 8);
105
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-hover), var(--my-info-cell-bg2-hover));*/
106
+ cursor: pointer;
107
+ }
108
+
109
+
110
+ .cell-info {
111
+
112
+ /* center position https://www.w3.org/Style/Examples/007/center.en.html*/
113
+ position: absolute;
114
+ top: 50%;
115
+ left: 35%;
116
+ transform: translate(0, -50%);
117
+
118
+ color: var(--my-info-txt-color);
119
+ font-family: var(--my-primary-font);
120
+ font-weight: bold;
121
+ font-size: 1.5em;
122
+ text-shadow: 1px 1px black;
123
+ pointer-events: none;
124
+ }
125
+
126
+ .cell-number {
127
+ position: absolute;
128
+ font-size: 0.9em;
129
+ color: var(--my-cell-day-color);
130
+ font-family: var(--my-primary-font);
131
+ }
132
+
133
+ .cell-number.top-left {
134
+ left: 3px;
135
+ top: 1px;
136
+ }
137
+
138
+ .cell-number.center {
139
+ top: 50%;
140
+ left: 30%;
141
+ transform: translate(0, -50%);
142
+ }
143
+
144
+ .free .cell-number {
145
+ color: var(--my-info-cell-day-color);
146
+ }
147
+
148
+ /* ToDo: Dont work for calendars sized by custom properties. Needed to calculate from calendar size
149
+ not from window size, this is a topic for container queries, which are not available right now... */
150
+ @media (max-width: 800px) {
151
+ .cell-info {
152
+ left: 30%;
153
+ font-size: 1.3em;
154
+ }
155
+ .cell-number {
156
+ font-size: 0.7em;
157
+ }
158
+ }
159
+ @media (max-width: 500px) {
160
+ .cell-info {
161
+ left: 15%;
162
+ font-weight: normal;
163
+ font-size: 1em;
164
+ }
165
+ }
166
+ `;
167
+ }
168
+
169
+ constructor() {
170
+ super();
171
+ this.numberClass = "top-left";
172
+ }
173
+
174
+ _renderSelectableCell() {
175
+ return html` <div
176
+ @keypress="${this._selectableCellClicked}"
177
+ @click="${this._selectableCellClicked}"
178
+ data-date="${this.key}"
179
+ class="cell cell-day ${this.special ? 'special' : 'free'}"
180
+ >
181
+ ${this.infoTxt
182
+ ? html` <div class="cell-info">${this.infoTxt}</div>`
183
+ : ''}
184
+ <div class="cell-number ${this.numberClass}">${this.dayNumber}</div>
185
+ </div>`;
186
+ }
187
+
188
+ _renderEmptyCell() {
189
+ return html`<div
190
+ class="cell cell-day top-left ${this.weekDayNumber === 6 ||
191
+ this.weekDayNumber === 0
192
+ ? 'we'
193
+ : ''}"
194
+ >
195
+ ${this.infoTxt
196
+ ? html`<div class="cell-info">${this.infoTxt}</div>`
197
+ : ''}
198
+ <div class="cell-number ${this.numberClass}">${this.dayNumber}</div>
199
+ </div>`;
200
+ }
201
+
202
+ render() {
203
+ return this.selectEnabled
204
+ ? this._renderSelectableCell()
205
+ : this._renderEmptyCell();
206
+ }
207
+
208
+ _selectableCellClicked(e) {
209
+ const dateKey = e.target.dataset.date;
210
+ if (dateKey) {
211
+ // convert back to date
212
+ const userSelectedDate = parse(dateKey, 'YYYY-MM-DD');
213
+ this.dispatchEvent(
214
+ new CustomEvent('select-date', {
215
+ detail: {
216
+ dateKey,
217
+ date: userSelectedDate,
218
+ },
219
+ })
220
+ );
221
+ }
222
+ }
223
+ }
224
+
225
+ window.customElements.define('pd-calendar-cell', PdCalendarCell);
@@ -0,0 +1,57 @@
1
+ import { html } from 'lit';
2
+ import '../src/PdCalendarCell.js';
3
+
4
+ export default {
5
+ title: 'PdCalendar/CalendarCell',
6
+ component: 'pd-calendar-cell',
7
+ argTypes: {
8
+ },
9
+ };
10
+
11
+ function CalendarCellTemplate({infoTxt}) {
12
+ return html`
13
+
14
+ <div style="max-width: 400px;">
15
+
16
+ <pd-calendar-cell
17
+ key="2021-11-13"
18
+ dayNumber="13"
19
+ weekDayNumber="5"
20
+ infoTxt="Selectable"
21
+ selectEnabled
22
+ ></pd-calendar-cell>
23
+
24
+ <pd-calendar-cell
25
+ key="2021-11-14"
26
+ dayNumber="14"
27
+ weekDayNumber="6"
28
+ infoTxt="${infoTxt}"
29
+ selectEnabled
30
+ special
31
+ ></pd-calendar-cell>
32
+
33
+ <pd-calendar-cell
34
+ key="2021-11-15"
35
+ dayNumber="15"
36
+ weekDayNumber="1"
37
+ infoTxt="Empty"
38
+ ></pd-calendar-cell>
39
+
40
+ <pd-calendar-cell
41
+ key="2021-11-20"
42
+ dayNumber="20"
43
+ weekDayNumber="6"
44
+ infoTxt="Weekend"
45
+ ></pd-calendar-cell>
46
+
47
+ </div>`;
48
+ }
49
+
50
+ export const Basic = CalendarCellTemplate.bind({});
51
+ Basic.args = {
52
+ key: '2021-11-18',
53
+ dayNumber: 18,
54
+ weekDayNumber: 3,
55
+ infoTxt: "Special",
56
+ special: true
57
+ };
@@ -16,6 +16,20 @@ function CalendarTemplate({ data, prevMonthConstraint, nextMonthConstraint, addS
16
16
  </pd-calendar> `;
17
17
  }
18
18
 
19
+ function CalendarSmallTemplate({ width, cellHeight, prevMonthConstraint, nextMonthConstraint}) {
20
+ return html`
21
+ <style>
22
+ .calendar-small {
23
+ --pd-calendar-width: ${width};
24
+ --pd-calendar-cell-height: ${cellHeight};
25
+ }
26
+ </style>
27
+ <pd-calendar class="calendar-small" prevMonthConstraint="${prevMonthConstraint}"
28
+ nextMonthConstraint="${nextMonthConstraint}" numberClass="center"
29
+ >
30
+ </pd-calendar>`;
31
+ }
32
+
19
33
  // generate some test data (needed to show data for current month)
20
34
  const now = new Date();
21
35
  const newDate1 = new Date(
@@ -55,6 +69,14 @@ Basic.args = {
55
69
  nextMonthConstraint: -1,
56
70
  };
57
71
 
72
+ export const BasicSmall = CalendarSmallTemplate.bind({});
73
+ BasicSmall.args = {
74
+ width: '220px',
75
+ cellHeight: '30px',
76
+ prevMonthConstraint: -1,
77
+ nextMonthConstraint: -1,
78
+ };
79
+
58
80
  export const WithInfoAndConstraints = CalendarTemplate.bind({});
59
81
  const data = {};
60
82
  data[format(newDate1, 'YYYY-MM-DD')] = [{ info: '180 €' }];