@vaadin/avatar 23.2.2 → 23.3.0-alpha2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/avatar",
3
- "version": "23.2.2",
3
+ "version": "23.3.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -37,13 +37,14 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@polymer/polymer": "^3.0.0",
40
- "@vaadin/component-base": "~23.2.2",
41
- "@vaadin/item": "~23.2.2",
42
- "@vaadin/list-box": "~23.2.2",
43
- "@vaadin/vaadin-lumo-styles": "~23.2.2",
44
- "@vaadin/vaadin-material-styles": "~23.2.2",
45
- "@vaadin/vaadin-overlay": "~23.2.2",
46
- "@vaadin/vaadin-themable-mixin": "~23.2.2"
40
+ "@vaadin/component-base": "23.3.0-alpha2",
41
+ "@vaadin/item": "23.3.0-alpha2",
42
+ "@vaadin/list-box": "23.3.0-alpha2",
43
+ "@vaadin/tooltip": "23.3.0-alpha2",
44
+ "@vaadin/vaadin-lumo-styles": "23.3.0-alpha2",
45
+ "@vaadin/vaadin-material-styles": "23.3.0-alpha2",
46
+ "@vaadin/vaadin-overlay": "23.3.0-alpha2",
47
+ "@vaadin/vaadin-themable-mixin": "23.3.0-alpha2"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@esm-bundle/chai": "^4.3.4",
@@ -54,5 +55,5 @@
54
55
  "web-types.json",
55
56
  "web-types.lit.json"
56
57
  ],
57
- "gitHead": "a98818979098f4542ce557a58858fb6dad910a25"
58
+ "gitHead": "ae61027c62ffa7f7d70cfc50e43f333addfc74b6"
58
59
  }
@@ -3,6 +3,7 @@
3
3
  * Copyright (c) 2020 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
6
7
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
8
  import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
8
9
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -37,7 +38,7 @@ export interface AvatarI18n {
37
38
  *
38
39
  * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
39
40
  */
40
- declare class Avatar extends FocusMixin(ElementMixin(ThemableMixin(HTMLElement))) {
41
+ declare class Avatar extends FocusMixin(ElementMixin(ThemableMixin(ControllerMixin(HTMLElement)))) {
41
42
  /**
42
43
  * The path to the image
43
44
  */
@@ -51,7 +52,7 @@ declare class Avatar extends FocusMixin(ElementMixin(ThemableMixin(HTMLElement))
51
52
 
52
53
  /**
53
54
  * Full name of the user
54
- * used for the title of the avatar.
55
+ * used for the tooltip of the avatar.
55
56
  */
56
57
  name: string | null | undefined;
57
58
 
@@ -70,12 +71,20 @@ declare class Avatar extends FocusMixin(ElementMixin(ThemableMixin(HTMLElement))
70
71
  *
71
72
  * ```
72
73
  * {
73
- * // Translation of the anonymous user avatar title.
74
+ * // Translation of the anonymous user avatar tooltip.
74
75
  * anonymous: 'anonymous'
75
76
  * }
76
77
  * ```
77
78
  */
78
79
  i18n: AvatarI18n;
80
+
81
+ /**
82
+ * When true, the avatar has tooltip shown on hover and focus.
83
+ * The tooltip text is based on the `name` and `abbr` properties.
84
+ * When neither is provided, `i18n.anonymous` is used instead.
85
+ * @attr {boolean} with-tooltip
86
+ */
87
+ withTooltip: boolean;
79
88
  }
80
89
 
81
90
  declare global {
@@ -5,8 +5,10 @@
5
5
  */
6
6
  import './vaadin-avatar-icons.js';
7
7
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
8
9
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
10
  import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
11
+ import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
10
12
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
13
 
12
14
  /**
@@ -36,11 +38,12 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
36
38
  * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
37
39
  *
38
40
  * @extends HTMLElement
41
+ * @mixes ControllerMixin
39
42
  * @mixes FocusMixin
40
43
  * @mixes ElementMixin
41
44
  * @mixes ThemableMixin
42
45
  */
43
- class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
46
+ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(ControllerMixin(PolymerElement)))) {
44
47
  static get template() {
45
48
  return html`
46
49
  <style>
@@ -120,6 +123,8 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
120
123
  >
121
124
  <text dy=".35em" text-anchor="middle">[[abbr]]</text>
122
125
  </svg>
126
+
127
+ <slot name="tooltip"></slot>
123
128
  `;
124
129
  }
125
130
 
@@ -149,7 +154,7 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
149
154
 
150
155
  /**
151
156
  * Full name of the user
152
- * used for the title of the avatar.
157
+ * used for the tooltip of the avatar.
153
158
  */
154
159
  name: {
155
160
  type: String,
@@ -174,7 +179,7 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
174
179
  *
175
180
  * ```
176
181
  * {
177
- * // Translation of the anonymous user avatar title.
182
+ * // Translation of the anonymous user avatar tooltip.
178
183
  * anonymous: 'anonymous'
179
184
  * }
180
185
  * ```
@@ -191,6 +196,18 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
191
196
  },
192
197
  },
193
198
 
199
+ /**
200
+ * When true, the avatar has tooltip shown on hover and focus.
201
+ * The tooltip text is based on the `name` and `abbr` properties.
202
+ * When neither is provided, `i18n.anonymous` is used instead.
203
+ * @attr {boolean} with-tooltip
204
+ */
205
+ withTooltip: {
206
+ type: Boolean,
207
+ value: false,
208
+ observer: '__withTooltipChanged',
209
+ },
210
+
194
211
  /** @private */
195
212
  __imgVisible: Boolean,
196
213
 
@@ -199,11 +216,18 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
199
216
 
200
217
  /** @private */
201
218
  __abbrVisible: Boolean,
219
+
220
+ /** @private */
221
+ __tooltipNode: Object,
202
222
  };
203
223
  }
204
224
 
205
225
  static get observers() {
206
- return ['__imgOrAbbrOrNameChanged(img, abbr, name)', '__i18nChanged(i18n.*)'];
226
+ return [
227
+ '__imgOrAbbrOrNameChanged(img, abbr, name)',
228
+ '__i18nChanged(i18n.*)',
229
+ '__tooltipChanged(__tooltipNode, name, abbr)',
230
+ ];
207
231
  }
208
232
 
209
233
  /** @protected */
@@ -212,16 +236,19 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
212
236
 
213
237
  this.__updateVisibility();
214
238
 
215
- // Should set `anonymous` if name / abbr is not provided
216
- if (!this.name && !this.abbr) {
217
- this.__setTitle(this.name);
218
- }
219
-
220
239
  this.setAttribute('role', 'button');
221
240
 
222
241
  if (!this.hasAttribute('tabindex')) {
223
242
  this.setAttribute('tabindex', '0');
224
243
  }
244
+
245
+ this._tooltipController = new TooltipController(this);
246
+ this.addController(this._tooltipController);
247
+
248
+ // Should set `anonymous` if name / abbr is not provided
249
+ if (!this.name && !this.abbr) {
250
+ this.__setTooltip();
251
+ }
225
252
  }
226
253
 
227
254
  /** @private */
@@ -254,7 +281,6 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
254
281
  this.__updateVisibility();
255
282
 
256
283
  if (abbr && abbr !== this.__generatedAbbr) {
257
- this.__setTitle(name ? `${name} (${abbr})` : abbr);
258
284
  return;
259
285
  }
260
286
 
@@ -266,15 +292,40 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
266
292
  } else {
267
293
  this.abbr = undefined;
268
294
  }
295
+ }
269
296
 
270
- this.__setTitle(name);
297
+ /** @private */
298
+ __tooltipChanged(tooltipNode, name, abbr) {
299
+ if (tooltipNode) {
300
+ if (abbr && abbr !== this.__generatedAbbr) {
301
+ this.__setTooltip(name ? `${name} (${abbr})` : abbr);
302
+ } else {
303
+ this.__setTooltip(name);
304
+ }
305
+ }
306
+ }
307
+
308
+ /** @private */
309
+ __withTooltipChanged(withTooltip, oldWithTooltip) {
310
+ if (withTooltip) {
311
+ // Create and attach tooltip
312
+ const tooltipNode = document.createElement('vaadin-tooltip');
313
+ tooltipNode.setAttribute('slot', 'tooltip');
314
+ this.appendChild(tooltipNode);
315
+ this.__tooltipNode = tooltipNode;
316
+ } else if (oldWithTooltip) {
317
+ // Cleanup and detach tooltip
318
+ this.__tooltipNode.target = null;
319
+ this.__tooltipNode.remove();
320
+ this.__tooltipNode = null;
321
+ }
271
322
  }
272
323
 
273
324
  /** @private */
274
325
  __i18nChanged(i18n) {
275
326
  if (i18n.base && i18n.base.anonymous) {
276
- if (this.__oldAnonymous && this.getAttribute('title') === this.__oldAnonymous) {
277
- this.__setTitle();
327
+ if (this.__oldAnonymous && this.__tooltipNode && this.__tooltipNode.text === this.__oldAnonymous) {
328
+ this.__setTooltip();
278
329
  }
279
330
 
280
331
  this.__oldAnonymous = i18n.base.anonymous;
@@ -289,11 +340,10 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
289
340
  }
290
341
 
291
342
  /** @private */
292
- __setTitle(title) {
293
- if (title) {
294
- this.setAttribute('title', title);
295
- } else {
296
- this.setAttribute('title', this.i18n.anonymous);
343
+ __setTooltip(tooltip) {
344
+ const tooltipNode = this.__tooltipNode;
345
+ if (tooltipNode) {
346
+ tooltipNode.text = tooltip || this.i18n.anonymous;
297
347
  }
298
348
  }
299
349
 
@@ -1,2 +1,3 @@
1
+ import '@vaadin/tooltip/theme/lumo/vaadin-tooltip.js';
1
2
  import './vaadin-avatar-styles.js';
2
3
  import '../../src/vaadin-avatar.js';
@@ -1,2 +1,3 @@
1
+ import '@vaadin/tooltip/theme/material/vaadin-tooltip.js';
1
2
  import './vaadin-avatar-styles.js';
2
3
  import '../../src/vaadin-avatar.js';
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/avatar",
4
- "version": "23.2.2",
4
+ "version": "23.3.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  {
36
36
  "name": "name",
37
- "description": "Full name of the user\nused for the title of the avatar.",
37
+ "description": "Full name of the user\nused for the tooltip of the avatar.",
38
38
  "value": {
39
39
  "type": [
40
40
  "string",
@@ -54,6 +54,17 @@
54
54
  ]
55
55
  }
56
56
  },
57
+ {
58
+ "name": "with-tooltip",
59
+ "description": "When true, the avatar has tooltip shown on hover and focus.\nThe tooltip text is based on the `name` and `abbr` properties.\nWhen neither is provided, `i18n.anonymous` is used instead.",
60
+ "value": {
61
+ "type": [
62
+ "boolean",
63
+ "null",
64
+ "undefined"
65
+ ]
66
+ }
67
+ },
57
68
  {
58
69
  "name": "theme",
59
70
  "description": "The theme variants to apply to the component.",
@@ -92,7 +103,7 @@
92
103
  },
93
104
  {
94
105
  "name": "name",
95
- "description": "Full name of the user\nused for the title of the avatar.",
106
+ "description": "Full name of the user\nused for the tooltip of the avatar.",
96
107
  "value": {
97
108
  "type": [
98
109
  "string",
@@ -114,12 +125,23 @@
114
125
  },
115
126
  {
116
127
  "name": "i18n",
117
- "description": "The object used to localize this component.\nTo change the default localization, replace the entire\n_i18n_ object or just the property you want to modify.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n // Translation of the anonymous user avatar title.\n anonymous: 'anonymous'\n}\n```",
128
+ "description": "The object used to localize this component.\nTo change the default localization, replace the entire\n_i18n_ object or just the property you want to modify.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n // Translation of the anonymous user avatar tooltip.\n anonymous: 'anonymous'\n}\n```",
118
129
  "value": {
119
130
  "type": [
120
131
  "AvatarI18n"
121
132
  ]
122
133
  }
134
+ },
135
+ {
136
+ "name": "withTooltip",
137
+ "description": "When true, the avatar has tooltip shown on hover and focus.\nThe tooltip text is based on the `name` and `abbr` properties.\nWhen neither is provided, `i18n.anonymous` is used instead.",
138
+ "value": {
139
+ "type": [
140
+ "boolean",
141
+ "null",
142
+ "undefined"
143
+ ]
144
+ }
123
145
  }
124
146
  ],
125
147
  "events": []
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/avatar",
4
- "version": "23.2.2",
4
+ "version": "23.3.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -19,6 +19,13 @@
19
19
  "description": "`<vaadin-avatar>` is a Web Component providing avatar displaying functionality.\n\n```html\n<vaadin-avatar img=\"avatars/avatar-1.jpg\"></vaadin-avatar>\n```\n\n### Styling\n\nThe following shadow DOM parts are exposed for styling:\n\nPart name | Description\n--------- | ---------------\n`abbr` | The abbreviation element\n`icon` | The icon element\n\nThe following state attributes are available for styling:\n\nAttribute | Description\n------------------|-------------\n`focus-ring` | Set when the avatar is focused using the keyboard.\n`focused` | Set when the avatar is focused.\n`has-color-index` | Set when the avatar has `colorIndex` and the corresponding custom CSS property exists.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
20
20
  "extension": true,
21
21
  "attributes": [
22
+ {
23
+ "name": "?withTooltip",
24
+ "description": "When true, the avatar has tooltip shown on hover and focus.\nThe tooltip text is based on the `name` and `abbr` properties.\nWhen neither is provided, `i18n.anonymous` is used instead.",
25
+ "value": {
26
+ "kind": "expression"
27
+ }
28
+ },
22
29
  {
23
30
  "name": ".img",
24
31
  "description": "The path to the image",
@@ -35,7 +42,7 @@
35
42
  },
36
43
  {
37
44
  "name": ".name",
38
- "description": "Full name of the user\nused for the title of the avatar.",
45
+ "description": "Full name of the user\nused for the tooltip of the avatar.",
39
46
  "value": {
40
47
  "kind": "expression"
41
48
  }
@@ -49,7 +56,7 @@
49
56
  },
50
57
  {
51
58
  "name": ".i18n",
52
- "description": "The object used to localize this component.\nTo change the default localization, replace the entire\n_i18n_ object or just the property you want to modify.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n // Translation of the anonymous user avatar title.\n anonymous: 'anonymous'\n}\n```",
59
+ "description": "The object used to localize this component.\nTo change the default localization, replace the entire\n_i18n_ object or just the property you want to modify.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n // Translation of the anonymous user avatar tooltip.\n anonymous: 'anonymous'\n}\n```",
53
60
  "value": {
54
61
  "kind": "expression"
55
62
  }