@vaadin/notification 23.1.0-beta1 → 23.1.0-beta4

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-beta1",
3
+ "version": "23.1.0-beta4",
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-beta1",
38
- "@vaadin/vaadin-lumo-styles": "23.1.0-beta1",
39
- "@vaadin/vaadin-material-styles": "23.1.0-beta1",
40
- "@vaadin/vaadin-themable-mixin": "23.1.0-beta1",
39
+ "@vaadin/component-base": "23.1.0-beta4",
40
+ "@vaadin/lit-renderer": "23.1.0-beta4",
41
+ "@vaadin/vaadin-lumo-styles": "23.1.0-beta4",
42
+ "@vaadin/vaadin-material-styles": "23.1.0-beta4",
43
+ "@vaadin/vaadin-themable-mixin": "23.1.0-beta4",
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-beta1",
46
- "@vaadin/polymer-legacy-adapter": "23.1.0-beta1",
48
+ "@vaadin/button": "23.1.0-beta4",
49
+ "@vaadin/polymer-legacy-adapter": "23.1.0-beta4",
47
50
  "@vaadin/testing-helpers": "^0.3.2",
48
51
  "sinon": "^13.0.2"
49
52
  },
50
- "gitHead": "8be43cf83102a6b9ccf309687446e590ce0164e8"
53
+ "gitHead": "06e283473964ecb3085aacf3eddb5333d052a045"
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);
@@ -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.