@vaadin/avatar 23.2.0 → 23.3.0-alpha1

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.0",
3
+ "version": "23.3.0-alpha1",
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.0",
41
- "@vaadin/item": "^23.2.0",
42
- "@vaadin/list-box": "^23.2.0",
43
- "@vaadin/vaadin-lumo-styles": "^23.2.0",
44
- "@vaadin/vaadin-material-styles": "^23.2.0",
45
- "@vaadin/vaadin-overlay": "^23.2.0",
46
- "@vaadin/vaadin-themable-mixin": "^23.2.0"
40
+ "@vaadin/component-base": "23.3.0-alpha1",
41
+ "@vaadin/item": "23.3.0-alpha1",
42
+ "@vaadin/list-box": "23.3.0-alpha1",
43
+ "@vaadin/tooltip": "23.3.0-alpha1",
44
+ "@vaadin/vaadin-lumo-styles": "23.3.0-alpha1",
45
+ "@vaadin/vaadin-material-styles": "23.3.0-alpha1",
46
+ "@vaadin/vaadin-overlay": "23.3.0-alpha1",
47
+ "@vaadin/vaadin-themable-mixin": "23.3.0-alpha1"
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": "8b1f5941f26ac41ca038e75e24c8584e331bc7a8"
58
+ "gitHead": "beabc527d4b1274eb798ff701d406fed45cfe638"
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,12 +52,13 @@ 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
 
58
59
  /**
59
60
  * Color index used for avatar background.
61
+ * @attr {number} color-index
60
62
  */
61
63
  colorIndex: number | null | undefined;
62
64
 
@@ -69,12 +71,20 @@ declare class Avatar extends FocusMixin(ElementMixin(ThemableMixin(HTMLElement))
69
71
  *
70
72
  * ```
71
73
  * {
72
- * // Translation of the anonymous user avatar title.
74
+ * // Translation of the anonymous user avatar tooltip.
73
75
  * anonymous: 'anonymous'
74
76
  * }
75
77
  * ```
76
78
  */
77
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;
78
88
  }
79
89
 
80
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,
@@ -158,6 +163,7 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
158
163
 
159
164
  /**
160
165
  * Color index used for avatar background.
166
+ * @attr {number} color-index
161
167
  */
162
168
  colorIndex: {
163
169
  type: Number,
@@ -173,7 +179,7 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
173
179
  *
174
180
  * ```
175
181
  * {
176
- * // Translation of the anonymous user avatar title.
182
+ * // Translation of the anonymous user avatar tooltip.
177
183
  * anonymous: 'anonymous'
178
184
  * }
179
185
  * ```
@@ -190,6 +196,18 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
190
196
  },
191
197
  },
192
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
+
193
211
  /** @private */
194
212
  __imgVisible: Boolean,
195
213
 
@@ -198,11 +216,18 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
198
216
 
199
217
  /** @private */
200
218
  __abbrVisible: Boolean,
219
+
220
+ /** @private */
221
+ __tooltipNode: Object,
201
222
  };
202
223
  }
203
224
 
204
225
  static get observers() {
205
- return ['__imgOrAbbrOrNameChanged(img, abbr, name)', '__i18nChanged(i18n.*)'];
226
+ return [
227
+ '__imgOrAbbrOrNameChanged(img, abbr, name)',
228
+ '__i18nChanged(i18n.*)',
229
+ '__tooltipChanged(__tooltipNode, name, abbr)',
230
+ ];
206
231
  }
207
232
 
208
233
  /** @protected */
@@ -211,16 +236,19 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
211
236
 
212
237
  this.__updateVisibility();
213
238
 
214
- // Should set `anonymous` if name / abbr is not provided
215
- if (!this.name && !this.abbr) {
216
- this.__setTitle(this.name);
217
- }
218
-
219
239
  this.setAttribute('role', 'button');
220
240
 
221
241
  if (!this.hasAttribute('tabindex')) {
222
242
  this.setAttribute('tabindex', '0');
223
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
+ }
224
252
  }
225
253
 
226
254
  /** @private */
@@ -253,7 +281,6 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
253
281
  this.__updateVisibility();
254
282
 
255
283
  if (abbr && abbr !== this.__generatedAbbr) {
256
- this.__setTitle(name ? `${name} (${abbr})` : abbr);
257
284
  return;
258
285
  }
259
286
 
@@ -265,15 +292,40 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
265
292
  } else {
266
293
  this.abbr = undefined;
267
294
  }
295
+ }
268
296
 
269
- 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
+ }
270
322
  }
271
323
 
272
324
  /** @private */
273
325
  __i18nChanged(i18n) {
274
326
  if (i18n.base && i18n.base.anonymous) {
275
- if (this.__oldAnonymous && this.getAttribute('title') === this.__oldAnonymous) {
276
- this.__setTitle();
327
+ if (this.__oldAnonymous && this.__tooltipNode && this.__tooltipNode.text === this.__oldAnonymous) {
328
+ this.__setTooltip();
277
329
  }
278
330
 
279
331
  this.__oldAnonymous = i18n.base.anonymous;
@@ -288,11 +340,10 @@ class Avatar extends FocusMixin(ElementMixin(ThemableMixin(PolymerElement))) {
288
340
  }
289
341
 
290
342
  /** @private */
291
- __setTitle(title) {
292
- if (title) {
293
- this.setAttribute('title', title);
294
- } else {
295
- this.setAttribute('title', this.i18n.anonymous);
343
+ __setTooltip(tooltip) {
344
+ const tooltipNode = this.__tooltipNode;
345
+ if (tooltipNode) {
346
+ tooltipNode.text = tooltip || this.i18n.anonymous;
296
347
  }
297
348
  }
298
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.0",
4
+ "version": "23.3.0-alpha1",
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.0",
4
+ "version": "23.3.0-alpha1",
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
  }