@vaadin/notification 23.1.0-alpha3 → 23.1.0-beta2

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/lit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/lit.js ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/notification",
3
- "version": "23.1.0-alpha3",
3
+ "version": "23.1.0-beta2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,6 +22,8 @@
22
22
  "files": [
23
23
  "src",
24
24
  "theme",
25
+ "lit.js",
26
+ "lit.d.ts",
25
27
  "vaadin-*.d.ts",
26
28
  "vaadin-*.js"
27
29
  ],
@@ -34,18 +36,19 @@
34
36
  ],
35
37
  "dependencies": {
36
38
  "@polymer/polymer": "^3.0.0",
37
- "@vaadin/component-base": "23.1.0-alpha3",
38
- "@vaadin/vaadin-lumo-styles": "23.1.0-alpha3",
39
- "@vaadin/vaadin-material-styles": "23.1.0-alpha3",
40
- "@vaadin/vaadin-themable-mixin": "23.1.0-alpha3",
39
+ "@vaadin/component-base": "23.1.0-beta2",
40
+ "@vaadin/lit-renderer": "23.1.0-beta2",
41
+ "@vaadin/vaadin-lumo-styles": "23.1.0-beta2",
42
+ "@vaadin/vaadin-material-styles": "23.1.0-beta2",
43
+ "@vaadin/vaadin-themable-mixin": "23.1.0-beta2",
41
44
  "lit": "^2.0.0"
42
45
  },
43
46
  "devDependencies": {
44
47
  "@esm-bundle/chai": "^4.3.4",
45
- "@vaadin/button": "23.1.0-alpha3",
46
- "@vaadin/polymer-legacy-adapter": "23.1.0-alpha3",
48
+ "@vaadin/button": "23.1.0-beta2",
49
+ "@vaadin/polymer-legacy-adapter": "23.1.0-beta2",
47
50
  "@vaadin/testing-helpers": "^0.3.2",
48
51
  "sinon": "^13.0.2"
49
52
  },
50
- "gitHead": "8c9e64e8dfa158dd52a9bf6da351ff038c88ca85"
53
+ "gitHead": "f11f9245a0b5e6bf912725a501c27c24b74e7c8d"
51
54
  }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { TemplateResult } from 'lit';
7
+ import { DirectiveResult } from 'lit/directive.js';
8
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
9
+ import { Notification } from '../vaadin-notification.js';
10
+
11
+ export type NotificationLitRenderer = (notification: Notification) => TemplateResult;
12
+
13
+ export class NotificationRendererDirective extends LitRendererDirective<Notification, NotificationLitRenderer> {
14
+ /**
15
+ * Adds the renderer callback to the notification.
16
+ */
17
+ addRenderer(): void;
18
+
19
+ /**
20
+ * Runs the renderer callback on the notification.
21
+ */
22
+ runRenderer(): void;
23
+
24
+ /**
25
+ * Removes the renderer callback from the notification.
26
+ */
27
+ removeRenderer(): void;
28
+ }
29
+
30
+ /**
31
+ * A Lit directive for populating the content of the notification.
32
+ *
33
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the notification
34
+ * via the `renderer` property. The renderer is called once to populate the content when assigned
35
+ * and whenever a single dependency or an array of dependencies changes.
36
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
37
+ *
38
+ * Dependencies can be a single value or an array of values.
39
+ * Values are checked against previous values with strict equality (`===`),
40
+ * so the check won't detect nested property changes inside objects or arrays.
41
+ * When dependencies are provided as an array, each item is checked against the previous value
42
+ * at the same index with strict equality. Nested arrays are also checked only by strict
43
+ * equality.
44
+ *
45
+ * Example of usage:
46
+ * ```js
47
+ * `<vaadin-notification
48
+ * ${notificationRenderer((notification) => html`...`)}
49
+ * ></vaadin-notification>`
50
+ * ```
51
+ *
52
+ * @param renderer the renderer callback that returns a Lit template.
53
+ * @param dependencies a single dependency or an array of dependencies
54
+ * which trigger a re-render when changed.
55
+ */
56
+ export declare function notificationRenderer(
57
+ renderer: NotificationLitRenderer,
58
+ dependencies?: unknown,
59
+ ): DirectiveResult<typeof NotificationRendererDirective>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { directive } from 'lit/directive.js';
7
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
8
+
9
+ export class NotificationRendererDirective extends LitRendererDirective {
10
+ /**
11
+ * Adds the renderer callback to the notification.
12
+ */
13
+ addRenderer() {
14
+ this.element.renderer = (root, notification) => {
15
+ this.renderRenderer(root, notification);
16
+ };
17
+ }
18
+
19
+ /**
20
+ * Runs the renderer callback on the notification.
21
+ */
22
+ runRenderer() {
23
+ this.element.requestContentUpdate();
24
+ }
25
+
26
+ /**
27
+ * Removes the renderer callback from the notification.
28
+ */
29
+ removeRenderer() {
30
+ this.element.renderer = null;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * A Lit directive for populating the content of the notification.
36
+ *
37
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the notification
38
+ * via the `renderer` property. The renderer is called once to populate the content when assigned
39
+ * and whenever a single dependency or an array of dependencies changes.
40
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
41
+ *
42
+ * Dependencies can be a single value or an array of values.
43
+ * Values are checked against previous values with strict equality (`===`),
44
+ * so the check won't detect nested property changes inside objects or arrays.
45
+ * When dependencies are provided as an array, each item is checked against the previous value
46
+ * at the same index with strict equality. Nested arrays are also checked only by strict
47
+ * equality.
48
+ *
49
+ * Example of usage:
50
+ * ```js
51
+ * `<vaadin-notification
52
+ * ${notificationRenderer((notification) => html`...`)}
53
+ * ></vaadin-notification>`
54
+ * ```
55
+ *
56
+ * @param renderer the renderer callback that returns a Lit template.
57
+ * @param dependencies a single dependency or an array of dependencies
58
+ * which trigger a re-render when changed.
59
+ */
60
+ export const notificationRenderer = directive(NotificationRendererDirective);
@@ -148,13 +148,13 @@ declare class Notification extends ThemePropertyMixin(ElementMixin(HTMLElement))
148
148
  addEventListener<K extends keyof NotificationEventMap>(
149
149
  type: K,
150
150
  listener: (this: Notification, ev: NotificationEventMap[K]) => void,
151
- options?: boolean | AddEventListenerOptions
151
+ options?: boolean | AddEventListenerOptions,
152
152
  ): void;
153
153
 
154
154
  removeEventListener<K extends keyof NotificationEventMap>(
155
155
  type: K,
156
156
  listener: (this: Notification, ev: NotificationEventMap[K]) => void,
157
- options?: boolean | EventListenerOptions
157
+ options?: boolean | EventListenerOptions,
158
158
  ): void;
159
159
 
160
160
  /**
@@ -105,8 +105,8 @@ class NotificationContainer extends ThemableMixin(ElementMixin(PolymerElement))
105
105
  opened: {
106
106
  type: Boolean,
107
107
  value: false,
108
- observer: '_openedChanged'
109
- }
108
+ observer: '_openedChanged',
109
+ },
110
110
  };
111
111
  }
112
112
 
@@ -144,7 +144,7 @@ class NotificationContainer extends ThemableMixin(ElementMixin(PolymerElement))
144
144
  const landscape = innerWidth > innerHeight;
145
145
  const clientHeight = document.documentElement.clientHeight;
146
146
  if (landscape && clientHeight > innerHeight) {
147
- this.style.bottom = clientHeight - innerHeight + 'px';
147
+ this.style.bottom = `${clientHeight - innerHeight}px`;
148
148
  } else {
149
149
  this.style.bottom = '0';
150
150
  }
@@ -277,7 +277,7 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
277
277
  */
278
278
  duration: {
279
279
  type: Number,
280
- value: 5000
280
+ value: 5000,
281
281
  },
282
282
 
283
283
  /**
@@ -288,7 +288,7 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
288
288
  type: Boolean,
289
289
  value: false,
290
290
  notify: true,
291
- observer: '_openedChanged'
291
+ observer: '_openedChanged',
292
292
  },
293
293
 
294
294
  /**
@@ -299,7 +299,7 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
299
299
  position: {
300
300
  type: String,
301
301
  value: 'bottom-start',
302
- observer: '_positionChanged'
302
+ observer: '_positionChanged',
303
303
  },
304
304
 
305
305
  /**
@@ -311,7 +311,7 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
311
311
  * - `notification` The reference to the `<vaadin-notification>` element.
312
312
  * @type {!NotificationRenderer | undefined}
313
313
  */
314
- renderer: Function
314
+ renderer: Function,
315
315
  };
316
316
  }
317
317
 
@@ -328,6 +328,12 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
328
328
  processTemplates(this);
329
329
  }
330
330
 
331
+ /** @protected */
332
+ disconnectedCallback() {
333
+ super.disconnectedCallback();
334
+ this.opened = false;
335
+ }
336
+
331
337
  /**
332
338
  * Requests an update for the content of the notification.
333
339
  * While performing the update, it invokes the renderer passed in the `renderer` property.
@@ -437,14 +443,18 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
437
443
 
438
444
  /** @private */
439
445
  _removeNotificationCard() {
440
- this._card.parentNode && this._card.parentNode.removeChild(this._card);
446
+ if (this._card.parentNode) {
447
+ this._card.parentNode.removeChild(this._card);
448
+ }
441
449
  this._card.removeAttribute('closing');
442
450
  this._container.opened = Boolean(this._container.firstElementChild);
443
451
  }
444
452
 
445
453
  /** @private */
446
454
  _closeNotificationCard() {
447
- this._durationTimeoutId && clearTimeout(this._durationTimeoutId);
455
+ if (this._durationTimeoutId) {
456
+ clearTimeout(this._durationTimeoutId);
457
+ }
448
458
  this._animatedRemoveNotificationCard();
449
459
  }
450
460
 
@@ -452,7 +462,7 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
452
462
  _animatedRemoveNotificationCard() {
453
463
  this._card.setAttribute('closing', '');
454
464
  const name = getComputedStyle(this._card).getPropertyValue('animation-name');
455
- if (name && name != 'none') {
465
+ if (name && name !== 'none') {
456
466
  const listener = () => {
457
467
  this._removeNotificationCard();
458
468
  this._card.removeEventListener('animationend', listener);
@@ -184,5 +184,5 @@ registerStyles(
184
184
  --_lumo-button-primary-color: var(--lumo-error-text-color);
185
185
  }
186
186
  `,
187
- { moduleId: 'lumo-notification-card' }
187
+ { moduleId: 'lumo-notification-card' },
188
188
  );
@@ -22,7 +22,7 @@ registerStyles(
22
22
  }
23
23
  }
24
24
  `,
25
- { moduleId: 'material-notification-container' }
25
+ { moduleId: 'material-notification-container' },
26
26
  );
27
27
 
28
28
  const notificationCard = css`
@@ -152,5 +152,5 @@ const notificationCard = css`
152
152
  `;
153
153
 
154
154
  registerStyles('vaadin-notification-card', [colorDark, notificationCard], {
155
- moduleId: 'material-notification-card'
155
+ moduleId: 'material-notification-card',
156
156
  });