@progressive-development/pd-calendar 0.0.0

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/.editorconfig ADDED
@@ -0,0 +1,29 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ indent_size = 2
25
+
26
+ [*.{html,js,md}]
27
+ block_comment_start = /**
28
+ block_comment = *
29
+ block_comment_end = */
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ stories: ['../stories/**/*.stories.{js,md,mdx}'],
3
+ };
@@ -0,0 +1,8 @@
1
+ import { storybookPlugin } from '@web/dev-server-storybook';
2
+ import baseConfig from '../web-dev-server.config.mjs';
3
+
4
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
5
+ ...baseConfig,
6
+ open: '/',
7
+ plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
8
+ });
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 pd-calendar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # \<pd-calendar>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i pd-calendar
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import 'pd-calendar/pd-calendar.js';
16
+ </script>
17
+
18
+ <pd-calendar></pd-calendar>
19
+ ```
20
+
21
+ ## Linting and formatting
22
+
23
+ To scan the project for linting and formatting errors, run
24
+
25
+ ```bash
26
+ npm run lint
27
+ ```
28
+
29
+ To automatically fix linting and formatting errors, run
30
+
31
+ ```bash
32
+ npm run format
33
+ ```
34
+
35
+ ## Testing with Web Test Runner
36
+
37
+ To execute a single test run:
38
+
39
+ ```bash
40
+ npm run test
41
+ ```
42
+
43
+ To run the tests in interactive watch mode run:
44
+
45
+ ```bash
46
+ npm run test:watch
47
+ ```
48
+
49
+ ## Demoing with Storybook
50
+
51
+ To run a local instance of Storybook for your component, run
52
+
53
+ ```bash
54
+ npm run storybook
55
+ ```
56
+
57
+ To build a production version of Storybook, run
58
+
59
+ ```bash
60
+ npm run storybook:build
61
+ ```
62
+
63
+
64
+ ## Tooling configs
65
+
66
+ For most of the tools, the configuration is in the `package.json` to minimize the amount of files in your project.
67
+
68
+ If you customize the configuration a lot, you can consider moving them to individual files.
69
+
70
+ ## Local Demo with `web-dev-server`
71
+
72
+ ```bash
73
+ npm start
74
+ ```
75
+
76
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,29 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <style>
6
+ body {
7
+ background: #fafafa;
8
+ }
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <div id="demo"></div>
13
+
14
+ <script type="module">
15
+ import { html, render } from 'lit';
16
+ import '../pd-calendar.js';
17
+
18
+ const title = 'Hello owc World!';
19
+ render(
20
+ html`
21
+ <pd-calendar .title=${title}>
22
+ some light-dom
23
+ </pd-calendar>
24
+ `,
25
+ document.querySelector('#demo')
26
+ );
27
+ </script>
28
+ </body>
29
+ </html>
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { PdCalendar } from './src/PdCalendar.js';
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@progressive-development/pd-calendar",
3
+ "description": "progressive development calendar web component",
4
+ "license": "ISC",
5
+ "author": "PD Progressive Development",
6
+ "version": "0.0.0",
7
+ "main": "index.js",
8
+ "module": "index.js",
9
+ "scripts": {
10
+ "analyze": "cem analyze --litelement",
11
+ "start": "web-dev-server",
12
+ "lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
13
+ "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
14
+ "test": "web-test-runner --coverage",
15
+ "test:watch": "web-test-runner --watch",
16
+ "storybook": "npm run analyze -- --exclude dist && web-dev-server -c .storybook/server.mjs",
17
+ "storybook:build": "npm run analyze -- --exclude dist && build-storybook"
18
+ },
19
+ "keywords": [
20
+ "pd",
21
+ "progressive",
22
+ "development",
23
+ "component",
24
+ "wc",
25
+ "lit",
26
+ "calendar",
27
+ "date",
28
+ "day",
29
+ "month",
30
+ "week"
31
+ ],
32
+ "dependencies": {
33
+ "lit": "^2.0.2",
34
+ "@progressive-development/pd-icon": "0.0.2",
35
+ "fecha": "^4.2.0"
36
+ },
37
+ "devDependencies": {
38
+ "@custom-elements-manifest/analyzer": "^0.4.17",
39
+ "@open-wc/eslint-config": "^4.3.0",
40
+ "@open-wc/testing": "next",
41
+ "@web/dev-server": "^0.1.25",
42
+ "@web/dev-server-storybook": "next",
43
+ "@web/test-runner": "^0.13.20",
44
+ "eslint": "^7.32.0",
45
+ "eslint-config-prettier": "^8.3.0",
46
+ "husky": "^4.3.8",
47
+ "lint-staged": "^10.5.4",
48
+ "prettier": "^2.4.1"
49
+ },
50
+ "customElements": "custom-elements.json",
51
+ "eslintConfig": {
52
+ "extends": [
53
+ "@open-wc",
54
+ "prettier"
55
+ ]
56
+ },
57
+ "prettier": {
58
+ "singleQuote": true,
59
+ "arrowParens": "avoid"
60
+ },
61
+ "husky": {
62
+ "hooks": {
63
+ "pre-commit": "lint-staged"
64
+ }
65
+ },
66
+ "lint-staged": {
67
+ "*.js": [
68
+ "eslint --fix",
69
+ "prettier --write"
70
+ ]
71
+ }
72
+ }
package/pd-calendar.js ADDED
@@ -0,0 +1,3 @@
1
+ import { PdCalendar } from './src/PdCalendar.js';
2
+
3
+ window.customElements.define('pd-calendar', PdCalendar);
@@ -0,0 +1,457 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at
5
+ * http://polymer.github.io/LICENSE.txt
6
+ * The complete set of authors may be found at
7
+ * http://polymer.github.io/AUTHORS.txt
8
+ * The complete set of contributors may be found at
9
+ * http://polymer.github.io/CONTRIBUTORS.txt
10
+ * Code distributed by Google as part of the polymer project is also
11
+ * subject to an additional IP rights grant found at
12
+ * http://polymer.github.io/PATENTS.txt
13
+ */
14
+
15
+ import { LitElement, html, css } from 'lit';
16
+ import { format, parse } from 'fecha';
17
+ import '@progressive-development/pd-icon';
18
+
19
+ // todo: use existing shortnames for locale here
20
+ const weekDays = ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'];
21
+
22
+ // list views (list, month, week)
23
+ const VIEW_LIST = 1;
24
+ const VIEW_MONTH = 2;
25
+ const VIEW_WEEK = 3;
26
+
27
+ /**
28
+ * An example element.
29
+ *
30
+ * @slot - This element has a slot
31
+ * @csspart button - The button
32
+ */
33
+ export class PdCalendar extends LitElement {
34
+ /**
35
+ * Fired when next month clicked
36
+ * @event change-month
37
+ */
38
+
39
+ /**
40
+ * Fired when free date clicked => At the moment only for freeDates
41
+ * @event select-date
42
+ */
43
+
44
+ static get styles() {
45
+ return css`
46
+ :host {
47
+ --my-title-color: var(--squi-title-color, #084c61);
48
+ --my-day-title-bg-color: var(--squi-title-color, #084c61);
49
+ --my-cell-bg-color: var(--squi-title-color, lightgrey);
50
+ --my-cell-we-bg-color: var(--squi-title-color, darkgrey);
51
+ --my-cell-day-color: var(--squi-title-color, #fefefe);
52
+
53
+ --my-info-cell-bg1-color: var(--squi-title-color, #177e89);
54
+ --my-info-cell-bg2-color: var(--squi-title-color, #084c61);
55
+ --my-info-cell-day-color: var(--squi-title-color, #fefefe);
56
+
57
+ --my-info-cell-bg1-hover: var(--squi-highlight-color, #ffc857);
58
+ --my-info-cell-bg2-hover: var(--squi-highlight-color, #177e89);
59
+
60
+ --my-info-txt-color: var(--squi-info-txt, #fefefe);
61
+
62
+ --my-primary-font: var(--squi-primary-font, Oswald);
63
+
64
+ /*
65
+ display: block;
66
+ padding: 8px;
67
+ */
68
+ /*max-width: 800px;*/
69
+ display: block;
70
+ /*width: 100vw;
71
+ height: 100vh;*/
72
+ }
73
+
74
+ /* Layout Grid for the Calendar Component => Not really needed at the moment, more a test */
75
+ .layout-container {
76
+ height: 100%;
77
+ display: grid;
78
+ grid-template-columns: 1fr 1fr 1fr;
79
+ grid-template-rows: 40px auto;
80
+ gap: 1px;
81
+ grid-template-areas:
82
+ 'header header header'
83
+ 'content content content';
84
+ }
85
+
86
+ /* Grid Area positions for layout container above */
87
+ .header {
88
+ grid-area: header;
89
+ position: relative;
90
+
91
+ font-family: var(--my-primary-font);
92
+ color: var(--my-title-color);
93
+ }
94
+
95
+ .header-main {
96
+ position: absolute;
97
+ left: 30%;
98
+ display: flex;
99
+ }
100
+
101
+ .header-icons {
102
+ position: absolute;
103
+ right: 0px;
104
+ top: 0px;
105
+ }
106
+
107
+ .content {
108
+ grid-area: content;
109
+ }
110
+ .footer {
111
+ grid-area: footer;
112
+ }
113
+
114
+ /* Grid definition for calendar day items */
115
+ .grid-container {
116
+ position: relative;
117
+ display: grid;
118
+ grid-template-columns: repeat(7, minmax(0, 1fr));
119
+ gap: 3px;
120
+ }
121
+
122
+ .grid-container.max {
123
+ grid-template-rows: minmax(10px, 30px) repeat(6, minmax(70px, 1fr));
124
+ }
125
+
126
+ .grid-container.normal {
127
+ grid-template-rows: minmax(10px, 30px) repeat(5, minmax(70px, 1fr));
128
+ }
129
+
130
+ .title-week-day {
131
+ padding-top: 2px;
132
+ background-color: var(--my-day-title-bg-color);
133
+ text-align: center;
134
+ font-size: 1em;
135
+ font-weight: bold;
136
+ color: white;
137
+ font-family: var(--my-primary-font);
138
+ }
139
+
140
+ .cell {
141
+ text-align: center;
142
+ }
143
+
144
+ .cell-empty {
145
+ background-color: #fdfbfb;
146
+ }
147
+
148
+ .cell-day {
149
+ position: relative;
150
+ /*background-image: linear-gradient(to right, rgb(51, 101, 138) , rgb(38, 76, 104)); */
151
+ /*box-shadow: 2px 2px 3px;*/
152
+ background-color: var(--my-cell-bg-color);
153
+ /*border-radius: 2px 2px 2px 2px;*/
154
+ }
155
+
156
+ .cell-day.we {
157
+ background-color: var(--my-cell-we-bg-color);
158
+ }
159
+
160
+ .free {
161
+ /*background-image: linear-gradient(to right, green, darkgreen);
162
+ background-color: var(--my-info-cell-bg1-color);*/
163
+ background-color: var(--my-info-cell-bg1-color);
164
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
165
+ box-shadow: 1px 2px 2px;
166
+ }
167
+
168
+ .special {
169
+ /*background-image: linear-gradient(to right, green, darkgreen);
170
+ background-color: var(--my-info-cell-bg1-color);*/
171
+ background-color: var(--green, #1da692);
172
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-color), var(--my-info-cell-bg2-color));*/
173
+ box-shadow: 1px 2px 2px;
174
+ }
175
+
176
+ .special:hover,
177
+ .free:hover {
178
+ background-color: rgb(247, 211, 8);
179
+ /*background-image: linear-gradient(to right, var(--my-info-cell-bg1-hover), var(--my-info-cell-bg2-hover));*/
180
+ cursor: pointer;
181
+ }
182
+
183
+ span.content-title {
184
+ font-weight: bold;
185
+ font-size: 1.5em;
186
+ width: 120px;
187
+ text-align: center;
188
+ }
189
+
190
+ span.content-sub-title {
191
+ position: absolute;
192
+ left: 0px;
193
+ bottom: 0px;
194
+ font-size: 1.2em;
195
+ font-weight: bold;
196
+ }
197
+
198
+ span.cell-info {
199
+ position: absolute;
200
+ left: 35%;
201
+ top: 30%;
202
+ color: var(--my-info-txt-color);
203
+ font-family: var(--my-primary-font);
204
+ font-weight: bold;
205
+ font-size: 1.5em;
206
+ text-shadow: 1px 1px black;
207
+ pointer-events: none;
208
+ }
209
+
210
+ span.cell-number {
211
+ position: absolute;
212
+ left: 3px;
213
+ top: 1px;
214
+ font-size: 0.9em;
215
+ color: var(--my-cell-day-color);
216
+ font-family: var(--my-primary-font);
217
+ }
218
+
219
+ .free .cell-number {
220
+ color: var(--my-info-cell-day-color);
221
+ }
222
+
223
+ @media (max-width: 800px) {
224
+ span.cell-info {
225
+ left: 30%;
226
+ font-size: 1.3em;
227
+ }
228
+ span.cell-number {
229
+ font-size: 0.7em;
230
+ }
231
+ }
232
+ @media (max-width: 500px) {
233
+ span.cell-info {
234
+ left: 15%;
235
+ font-weight: normal;
236
+ font-size: 1em;
237
+ }
238
+ }
239
+
240
+ .arrow {
241
+ /* Hack */
242
+ padding-top: 8px;
243
+ cursor: pointer;
244
+ --squi-icon-size: 1.5rem;
245
+ --my-fill-color: var(--my-title-color);
246
+ }
247
+ `;
248
+ }
249
+
250
+ static get properties() {
251
+ return {
252
+ currentDate: { type: Object },
253
+ data: { type: Object },
254
+ _viewType: { type: Number },
255
+ };
256
+ }
257
+
258
+ constructor() {
259
+ super();
260
+
261
+ // initialize date values with current date
262
+ this._initFromDate(new Date());
263
+ this.data = {};
264
+
265
+ this._viewType = VIEW_MONTH;
266
+ }
267
+
268
+ render() {
269
+ return html`
270
+ <slot></slot>
271
+ ${this.renderCalendarByViewType()}
272
+ `;
273
+ }
274
+
275
+ renderCalendarByViewType() {
276
+ switch (this._viewType) {
277
+ case VIEW_LIST:
278
+ // return this.renderListCalendar();
279
+ return '';
280
+ case VIEW_MONTH:
281
+ return this.renderMonthCalendar();
282
+ case VIEW_WEEK:
283
+ return this.renderCalendar();
284
+ default:
285
+ return this.renderMonthCalendar();
286
+ }
287
+ }
288
+ /*
289
+ renderListCalendar() {
290
+ // TODO
291
+ }
292
+ */
293
+
294
+ renderMonthCalendar() {
295
+ // generate divs for each day
296
+ const itemTemplates = [];
297
+
298
+ const sizeVar =
299
+ this._numberOfDays >= 31 && this._daysFromPreviousMonth.length >= 5
300
+ ? 'max'
301
+ : 'normal';
302
+ for (let i = 1; i <= this._numberOfDays; i += 1) {
303
+ const tmpDate = new Date(this._year, this.currentDate.getMonth(), i);
304
+ const key = format(tmpDate, 'YYYY-MM-DD');
305
+ // TODO => Array / Unit Thema... hier fest auf 0 zugegriffen zunächst
306
+ const infoTxt = this.data[key] ? this.data[key][0].info : '';
307
+ const special = this.data[key]
308
+ ? this.data[key][0].special || false
309
+ : false;
310
+ if (infoTxt) {
311
+ itemTemplates.push(html`
312
+ <div
313
+ @keypress="${this._freeDateClicked}"
314
+ @click="${this._freeDateClicked}"
315
+ data-date="${key}"
316
+ class="cell cell-day ${special ? 'special' : 'free'}"
317
+ >
318
+ <span class="cell-info">${infoTxt}*</span>
319
+ <span class="cell-number">${i}</span>
320
+ </div>
321
+ `);
322
+ } else {
323
+ itemTemplates.push(html`
324
+ <div
325
+ class="cell cell-day ${tmpDate.getDay() === 6 ||
326
+ tmpDate.getDay() === 0
327
+ ? 'we'
328
+ : ''}"
329
+ >
330
+ <span class="cell-number">${i}</span>
331
+ </div>
332
+ `);
333
+ }
334
+ }
335
+
336
+ return html`
337
+ <div class="layout-container">
338
+ <div class="header">
339
+ <div class="header-main">
340
+ <squi-icon
341
+ @click="${this._previousMonth}"
342
+ class="arrow"
343
+ icon="previousArrow"
344
+ ></squi-icon>
345
+
346
+ <span class="content-title">${this._monthName}</span>
347
+
348
+ <squi-icon
349
+ @click="${this._nextMonth}"
350
+ class="arrow"
351
+ icon="nextArrow"
352
+ ></squi-icon>
353
+ </div>
354
+
355
+ <div class="header-icons"></div>
356
+
357
+ <span class="content-sub-title">${this._year}</span>
358
+ </div>
359
+
360
+ <div class="content grid-container ${sizeVar}">
361
+ ${weekDays.map(
362
+ shortName => html` <div class="title-week-day">${shortName}</div>`
363
+ )}
364
+ ${this._daysFromPreviousMonth.map(
365
+ () => html` <div class="cell cell-empty"></div>`
366
+ )}
367
+ ${itemTemplates}
368
+ </div>
369
+ </div>
370
+ <p>* excl. BTW</p>
371
+ `;
372
+ }
373
+
374
+ _freeDateClicked(e) {
375
+ const dateKey = e.target.dataset.date;
376
+ if (dateKey) {
377
+ // convert back to date
378
+ const userSelectedDate = parse(dateKey, 'YYYY-MM-DD');
379
+ this.dispatchEvent(
380
+ new CustomEvent('select-date', {
381
+ detail: {
382
+ dateKey,
383
+ date: userSelectedDate,
384
+ },
385
+ })
386
+ );
387
+ }
388
+ }
389
+
390
+ _nextMonth() {
391
+ const now = new Date();
392
+ if (this.currentDate.getMonth() < now.getMonth() + 2) {
393
+ const newDate = new Date(
394
+ this.currentDate.getFullYear(),
395
+ this.currentDate.getMonth(),
396
+ 1
397
+ );
398
+ newDate.setMonth(newDate.getMonth() + 1);
399
+ this.dispatchEvent(
400
+ new CustomEvent('change-month', {
401
+ detail: {
402
+ newDate,
403
+ },
404
+ })
405
+ );
406
+ this._initFromDate(newDate);
407
+ }
408
+ }
409
+
410
+ _previousMonth() {
411
+ const now = new Date();
412
+ // TMP 23.08 ist start
413
+ if (this.currentDate.getMonth() > now.getMonth()) {
414
+ const newDate = new Date(
415
+ this.currentDate.getFullYear(),
416
+ this.currentDate.getMonth(),
417
+ 1
418
+ );
419
+ newDate.setMonth(newDate.getMonth() - 1);
420
+ this.dispatchEvent(
421
+ new CustomEvent('change-month', {
422
+ detail: {
423
+ newDate,
424
+ },
425
+ })
426
+ );
427
+ this._initFromDate(newDate);
428
+ }
429
+ }
430
+
431
+ _initFromDate(date) {
432
+ this._monthName = date.toLocaleString('default', { month: 'long' });
433
+ this._year = date.getFullYear();
434
+ this._daysFromPreviousMonth = PdCalendar._getPreviousMonthDays(date);
435
+ // last month day
436
+ const newDate2 = new Date(date.getFullYear(), date.getMonth() + 1, 0);
437
+ this._numberOfDays = newDate2.getDate();
438
+ this.currentDate = date;
439
+ }
440
+
441
+ static _getPreviousMonthDays(date) {
442
+ // get first day of month
443
+ const date1 = new Date(date.getFullYear(), date.getMonth(), 1);
444
+ // get missing days to monday
445
+ const missingDays = date1.getDay() > 0 ? Math.abs(1 - date1.getDay()) : 6;
446
+ // create array with missing days (dates)
447
+ const missDayArray = [];
448
+ for (let i = 1; i <= missingDays; i += 1) {
449
+ date1.setDate(date1.getDate() - 1);
450
+ missDayArray.push(
451
+ new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
452
+ );
453
+ }
454
+ return missDayArray;
455
+ }
456
+ }
457
+
@@ -0,0 +1,44 @@
1
+ import { html } from 'lit';
2
+ import '../pd-calendar.js';
3
+
4
+ export default {
5
+ title: 'PdCalendar',
6
+ component: 'pd-calendar',
7
+ argTypes: {
8
+ title: { control: 'text' },
9
+ counter: { control: 'number' },
10
+ textColor: { control: 'color' },
11
+ },
12
+ };
13
+
14
+ function Template({ title = 'Hello world', counter = 5, textColor, slot }) {
15
+ return html`
16
+ <pd-calendar
17
+ style="--pd-calendar-text-color: ${textColor || 'black'}"
18
+ .title=${title}
19
+ .counter=${counter}
20
+ >
21
+ ${slot}
22
+ </pd-calendar>
23
+ `;
24
+ }
25
+
26
+ export const Regular = Template.bind({});
27
+
28
+ export const CustomTitle = Template.bind({});
29
+ CustomTitle.args = {
30
+ title: 'My title',
31
+ };
32
+
33
+ export const CustomCounter = Template.bind({});
34
+ CustomCounter.args = {
35
+ counter: 123456,
36
+ };
37
+
38
+ export const SlottedContent = Template.bind({});
39
+ SlottedContent.args = {
40
+ slot: html`<p>Slotted content</p>`,
41
+ };
42
+ SlottedContent.argTypes = {
43
+ slot: { table: { disable: true } },
44
+ };
@@ -0,0 +1,32 @@
1
+ import { html } from 'lit';
2
+ import { fixture, expect } from '@open-wc/testing';
3
+
4
+ import '../pd-calendar.js';
5
+
6
+ describe('PdCalendar', () => {
7
+ it('has a default title "Hey there" and counter 5', async () => {
8
+ const el = await fixture(html`<pd-calendar></pd-calendar>`);
9
+
10
+ expect(el.title).to.equal('Hey there');
11
+ expect(el.counter).to.equal(5);
12
+ });
13
+
14
+ it('increases the counter on button click', async () => {
15
+ const el = await fixture(html`<pd-calendar></pd-calendar>`);
16
+ el.shadowRoot.querySelector('button').click();
17
+
18
+ expect(el.counter).to.equal(6);
19
+ });
20
+
21
+ it('can override the title via attribute', async () => {
22
+ const el = await fixture(html`<pd-calendar title="attribute title"></pd-calendar>`);
23
+
24
+ expect(el.title).to.equal('attribute title');
25
+ });
26
+
27
+ it('passes the a11y audit', async () => {
28
+ const el = await fixture(html`<pd-calendar></pd-calendar>`);
29
+
30
+ await expect(el).shadowDom.to.be.accessible();
31
+ });
32
+ });
@@ -0,0 +1,27 @@
1
+ // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
+
3
+ /** Use Hot Module replacement by adding --hmr to the start command */
4
+ const hmr = process.argv.includes('--hmr');
5
+
6
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
+ open: '/demo/',
8
+ /** Use regular watch mode if HMR is not enabled. */
9
+ watch: !hmr,
10
+ /** Resolve bare module imports */
11
+ nodeResolve: {
12
+ exportConditions: ['browser', 'development'],
13
+ },
14
+
15
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
+ // esbuildTarget: 'auto'
17
+
18
+ /** Set appIndex to enable SPA routing */
19
+ // appIndex: 'demo/index.html',
20
+
21
+ plugins: [
22
+ /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
+ // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
24
+ ],
25
+
26
+ // See documentation for all available options
27
+ });
@@ -0,0 +1,41 @@
1
+ // import { playwrightLauncher } from '@web/test-runner-playwright';
2
+
3
+ const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
4
+
5
+ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
+ /** Test files to run */
7
+ files: 'test/**/*.test.js',
8
+
9
+ /** Resolve bare module imports */
10
+ nodeResolve: {
11
+ exportConditions: ['browser', 'development'],
12
+ },
13
+
14
+ /** Filter out lit dev mode logs */
15
+ filterBrowserLogs(log) {
16
+ for (const arg of log.args) {
17
+ if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ },
23
+
24
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
+ // esbuildTarget: 'auto',
26
+
27
+ /** Amount of browsers to run concurrently */
28
+ // concurrentBrowsers: 2,
29
+
30
+ /** Amount of test files per browser to test concurrently */
31
+ // concurrency: 1,
32
+
33
+ /** Browsers to run tests on */
34
+ // browsers: [
35
+ // playwrightLauncher({ product: 'chromium' }),
36
+ // playwrightLauncher({ product: 'firefox' }),
37
+ // playwrightLauncher({ product: 'webkit' }),
38
+ // ],
39
+
40
+ // See documentation for all available options
41
+ });