@progressive-development/pd-calendar 0.1.20 → 0.2.1

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.
@@ -1,3 +1,13 @@
1
- module.exports = {
2
- stories: ['../stories/**/*.stories.{js,md,mdx}'],
1
+ /** @type { import('@storybook/web-components-vite').StorybookConfig } */
2
+ const config = {
3
+ stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
4
+ addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
5
+ framework: {
6
+ name: '@storybook/web-components-vite',
7
+ options: {},
8
+ },
9
+ docs: {
10
+ autodocs: 'tag',
11
+ },
3
12
  };
13
+ export default config;
@@ -0,0 +1,14 @@
1
+ /** @type { import('@storybook/web-components').Preview } */
2
+ const preview = {
3
+ parameters: {
4
+ actions: { argTypesRegex: '^on[A-Z].*' },
5
+ controls: {
6
+ matchers: {
7
+ color: /(background|color)$/i,
8
+ date: /Date$/i,
9
+ },
10
+ },
11
+ },
12
+ };
13
+
14
+ export default preview;
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.20",
6
+ "version": "0.2.1",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
@@ -13,8 +13,8 @@
13
13
  "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
14
14
  "test": "web-test-runner --coverage",
15
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"
16
+ "storybook": "storybook dev -p 6006",
17
+ "build-storybook": "storybook build"
18
18
  },
19
19
  "keywords": [
20
20
  "pd",
@@ -30,29 +30,38 @@
30
30
  "week"
31
31
  ],
32
32
  "dependencies": {
33
- "@progressive-development/pd-icon": "^0.1.18",
33
+ "@progressive-development/pd-icon": "^0.1.19",
34
34
  "@progressive-development/pd-shared-styles": "0.1.1",
35
- "fecha": "^4.2.0",
36
- "lit": "^2.2.0"
35
+ "fecha": "^4.2.3",
36
+ "lit": "^2.8.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@custom-elements-manifest/analyzer": "^0.4.17",
40
40
  "@open-wc/eslint-config": "^4.3.0",
41
- "@open-wc/testing": "next",
42
- "@web/dev-server": "^0.1.30",
43
- "@web/dev-server-storybook": "next",
44
- "@web/test-runner": "^0.13.27",
41
+ "@open-wc/testing": "^3.0.0-next.5",
42
+ "@storybook/addon-essentials": "^7.6.4",
43
+ "@storybook/addon-links": "^7.6.4",
44
+ "@storybook/blocks": "^7.6.4",
45
+ "@storybook/web-components": "^7.6.4",
46
+ "@storybook/web-components-vite": "^7.6.4",
47
+ "@web/dev-server": "^0.1.38",
48
+ "@web/test-runner": "^0.13.31",
45
49
  "eslint": "^7.32.0",
46
- "eslint-config-prettier": "^8.4.0",
50
+ "eslint-config-prettier": "^8.10.0",
51
+ "eslint-plugin-storybook": "^0.6.15",
47
52
  "husky": "^4.3.8",
48
53
  "lint-staged": "^10.5.4",
49
- "prettier": "^2.5.1"
54
+ "prettier": "^2.8.8",
55
+ "react": "^18.2.0",
56
+ "react-dom": "^18.2.0",
57
+ "storybook": "^7.6.4"
50
58
  },
51
59
  "customElements": "custom-elements.json",
52
60
  "eslintConfig": {
53
61
  "extends": [
54
62
  "@open-wc",
55
- "prettier"
63
+ "prettier",
64
+ "plugin:storybook/recommended"
56
65
  ]
57
66
  },
58
67
  "prettier": {
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 },
@@ -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,22 @@ 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
+ }
164
+
165
+ .selected {
166
+ border: 2px solid red;
167
+ }
168
+
157
169
  /* ToDo: Dont work for calendars sized by custom properties. Needed to calculate from calendar size
158
170
  not from window size, this is a topic for container queries, which are not available right now... */
159
171
  @media (max-width: 800px) {
@@ -194,7 +206,11 @@ class PdCalendarCell extends LitElement {
194
206
  : ''}
195
207
 
196
208
  ${this.today
197
- ? html`<div class="today"></div>`
209
+ ? html`<div class="number-ring today"></div>`
210
+ : ''}
211
+
212
+ ${this.selected
213
+ ? html`<div class="number-ring selected"></div>`
198
214
  : ''}
199
215
 
200
216
  <div class="cell-number ${this.numberClass}">${this.dayNumber}</div>
@@ -1,5 +1,5 @@
1
1
  import { html } from 'lit';
2
- import '../src/PdCalendarCell.js';
2
+ import '../PdCalendarCell.js';
3
3
 
4
4
  export default {
5
5
  title: 'PdCalendar/CalendarCell',
@@ -1,5 +1,7 @@
1
1
  import { html } from 'lit';
2
- import '../pd-calendar.js';
2
+
3
+ import '../../pd-calendar.js';
4
+
3
5
  import { format } from 'fecha';
4
6
 
5
7
  export default {
@@ -18,7 +20,7 @@ function CalendarTemplate({ hideWeekend, refDate, data, prevMonthConstraint, nex
18
20
  </pd-calendar> `;
19
21
  }
20
22
 
21
- function CalendarSmallTemplate({ hideWeekend, width, cellHeight, prevMonthConstraint, nextMonthConstraint}) {
23
+ function CalendarSmallTemplate({ refDate, hideWeekend, width, cellHeight, prevMonthConstraint, nextMonthConstraint}) {
22
24
  return html`
23
25
  <style>
24
26
  .calendar-small {
@@ -37,7 +39,7 @@ function CalendarSmallTemplate({ hideWeekend, width, cellHeight, prevMonthConstr
37
39
 
38
40
  }
39
41
  </style>
40
- <pd-calendar selectableDates ?hideWeekend="${hideWeekend}" class="calendar-small" prevMonthConstraint="${prevMonthConstraint}"
42
+ <pd-calendar .refDate="${refDate}" selectableDates showSelection ?hideWeekend="${hideWeekend}" class="calendar-small" prevMonthConstraint="${prevMonthConstraint}"
41
43
  nextMonthConstraint="${nextMonthConstraint}" numberClass="center"
42
44
  >
43
45
  </pd-calendar>`;
@@ -96,6 +98,17 @@ BasicSmall.args = {
96
98
  nextMonthConstraint: -1,
97
99
  };
98
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
+
99
112
  export const BasicSmallWithoutWeekend = CalendarSmallTemplate.bind({});
100
113
  BasicSmallWithoutWeekend.args = {
101
114
  hideWeekend: true,
@@ -1,2 +0,0 @@
1
- <link rel="preconnect" href="https://fonts.gstatic.com">
2
- <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400&family=Oswald:wght@700&display=swap" rel="stylesheet">
@@ -1,8 +0,0 @@
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
- });