@vaadin/avatar 24.7.0-alpha1 → 24.7.0-alpha10

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": "24.7.0-alpha1",
3
+ "version": "24.7.0-alpha10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,22 +38,23 @@
38
38
  "dependencies": {
39
39
  "@open-wc/dedupe-mixin": "^1.3.0",
40
40
  "@polymer/polymer": "^3.0.0",
41
- "@vaadin/a11y-base": "24.7.0-alpha1",
42
- "@vaadin/component-base": "24.7.0-alpha1",
43
- "@vaadin/tooltip": "24.7.0-alpha1",
44
- "@vaadin/vaadin-lumo-styles": "24.7.0-alpha1",
45
- "@vaadin/vaadin-material-styles": "24.7.0-alpha1",
46
- "@vaadin/vaadin-themable-mixin": "24.7.0-alpha1",
41
+ "@vaadin/a11y-base": "24.7.0-alpha10",
42
+ "@vaadin/component-base": "24.7.0-alpha10",
43
+ "@vaadin/tooltip": "24.7.0-alpha10",
44
+ "@vaadin/vaadin-lumo-styles": "24.7.0-alpha10",
45
+ "@vaadin/vaadin-material-styles": "24.7.0-alpha10",
46
+ "@vaadin/vaadin-themable-mixin": "24.7.0-alpha10",
47
47
  "lit": "^3.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@vaadin/chai-plugins": "24.7.0-alpha1",
51
- "@vaadin/testing-helpers": "^1.0.0",
50
+ "@vaadin/chai-plugins": "24.7.0-alpha10",
51
+ "@vaadin/test-runner-commands": "24.7.0-alpha10",
52
+ "@vaadin/testing-helpers": "^1.1.0",
52
53
  "sinon": "^18.0.0"
53
54
  },
54
55
  "web-types": [
55
56
  "web-types.json",
56
57
  "web-types.lit.json"
57
58
  ],
58
- "gitHead": "04be941c9a7b659871c97f31b9cc3ffd7528087b"
59
+ "gitHead": "c0f8933df2a6a40648d3fb9cfbae6bbf86a8aa90"
59
60
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2020 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2020 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  const template = document.createElement('template');
@@ -1,21 +1,22 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
  import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js';
8
+ import type { I18nMixinClass, PartialI18n } from '@vaadin/component-base/src/i18n-mixin.js';
8
9
 
9
- export interface AvatarI18n {
10
+ export type AvatarI18n = PartialI18n<{
10
11
  anonymous: string;
11
- }
12
+ }>;
12
13
 
13
14
  /**
14
15
  * A mixin providing common avatar functionality.
15
16
  */
16
17
  export declare function AvatarMixin<T extends Constructor<HTMLElement>>(
17
18
  base: T,
18
- ): Constructor<AvatarMixinClass> & Constructor<FocusMixinClass> & T;
19
+ ): Constructor<AvatarMixinClass> & Constructor<I18nMixinClass<AvatarI18n>> & Constructor<FocusMixinClass> & T;
19
20
 
20
21
  export declare class AvatarMixinClass {
21
22
  /**
@@ -42,12 +43,11 @@ export declare class AvatarMixinClass {
42
43
  colorIndex: number | null | undefined;
43
44
 
44
45
  /**
45
- * The object used to localize this component.
46
- * To change the default localization, replace the entire
47
- * _i18n_ object or just the property you want to modify.
46
+ * The object used to localize this component. To change the default
47
+ * localization, replace this with an object that provides all properties, or
48
+ * just the individual properties you want to change.
48
49
  *
49
50
  * The object has the following JSON structure and default values:
50
- *
51
51
  * ```
52
52
  * {
53
53
  * // Translation of the anonymous user avatar tooltip.
@@ -1,9 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
7
+ import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js';
8
+
9
+ const DEFAULT_I18N = {
10
+ anonymous: 'anonymous',
11
+ };
7
12
 
8
13
  /**
9
14
  * A mixin providing common avatar functionality.
@@ -12,7 +17,7 @@ import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
12
17
  * @mixes FocusMixin
13
18
  */
14
19
  export const AvatarMixin = (superClass) =>
15
- class AvatarMixinClass extends FocusMixin(superClass) {
20
+ class AvatarMixinClass extends I18nMixin(DEFAULT_I18N, FocusMixin(superClass)) {
16
21
  static get properties() {
17
22
  return {
18
23
  /**
@@ -51,32 +56,6 @@ export const AvatarMixin = (superClass) =>
51
56
  observer: '__colorIndexChanged',
52
57
  },
53
58
 
54
- /**
55
- * The object used to localize this component.
56
- * To change the default localization, replace the entire
57
- * _i18n_ object or just the property you want to modify.
58
- *
59
- * The object has the following JSON structure and default values:
60
- *
61
- * ```
62
- * {
63
- * // Translation of the anonymous user avatar tooltip.
64
- * anonymous: 'anonymous'
65
- * }
66
- * ```
67
- *
68
- * @type {!AvatarI18n}
69
- * @default {English/US}
70
- */
71
- i18n: {
72
- type: Object,
73
- value: () => {
74
- return {
75
- anonymous: 'anonymous',
76
- };
77
- },
78
- },
79
-
80
59
  /**
81
60
  * When true, the avatar has tooltip shown on hover and focus.
82
61
  * The tooltip text is based on the `name` and `abbr` properties.
@@ -106,11 +85,33 @@ export const AvatarMixin = (superClass) =>
106
85
  static get observers() {
107
86
  return [
108
87
  '__imgOrAbbrOrNameChanged(img, abbr, name)',
109
- '__i18nChanged(i18n)',
88
+ '__i18nChanged(__effectiveI18n)',
110
89
  '__tooltipChanged(__tooltipNode, name, abbr)',
111
90
  ];
112
91
  }
113
92
 
93
+ /**
94
+ * The object used to localize this component. To change the default
95
+ * localization, replace this with an object that provides all properties, or
96
+ * just the individual properties you want to change.
97
+ *
98
+ * The object has the following JSON structure and default values:
99
+ * ```
100
+ * {
101
+ * // Translation of the anonymous user avatar tooltip.
102
+ * anonymous: 'anonymous'
103
+ * }
104
+ * ```
105
+ * @return {!AvatarI18n}
106
+ */
107
+ get i18n() {
108
+ return super.i18n;
109
+ }
110
+
111
+ set i18n(value) {
112
+ super.i18n = value;
113
+ }
114
+
114
115
  /** @protected */
115
116
  ready() {
116
117
  super.ready();
@@ -118,9 +119,9 @@ export const AvatarMixin = (superClass) =>
118
119
  this.__updateVisibility();
119
120
 
120
121
  // By default, if the user hasn't provided a custom role,
121
- // the role attribute is set to "button".
122
+ // the role attribute is set to "img".
122
123
  if (!this.hasAttribute('role')) {
123
- this.setAttribute('role', 'button');
124
+ this.setAttribute('role', 'img');
124
125
  }
125
126
 
126
127
  if (!this.hasAttribute('tabindex')) {
@@ -185,6 +186,14 @@ export const AvatarMixin = (superClass) =>
185
186
  this.__setTooltip(name);
186
187
  }
187
188
  }
189
+
190
+ if (abbr) {
191
+ // By default, generate aria-label attribute containing the abbr value.
192
+ // When no tooltip is set, prefix the aria-label with the name value.
193
+ this.setAttribute('aria-label', !tooltipNode && name ? `${name} (${abbr})` : abbr);
194
+ } else {
195
+ this.removeAttribute('aria-label');
196
+ }
188
197
  }
189
198
 
190
199
  /** @private */
@@ -204,13 +213,13 @@ export const AvatarMixin = (superClass) =>
204
213
  }
205
214
 
206
215
  /** @private */
207
- __i18nChanged(i18n) {
208
- if (i18n && i18n.anonymous) {
216
+ __i18nChanged(effectiveI18n) {
217
+ if (effectiveI18n && effectiveI18n.anonymous) {
209
218
  if (this.__oldAnonymous && this.__tooltipNode && this.__tooltipNode.text === this.__oldAnonymous) {
210
219
  this.__setTooltip();
211
220
  }
212
221
 
213
- this.__oldAnonymous = i18n.anonymous;
222
+ this.__oldAnonymous = effectiveI18n.anonymous;
214
223
  }
215
224
  }
216
225
 
@@ -225,7 +234,7 @@ export const AvatarMixin = (superClass) =>
225
234
  __setTooltip(tooltip) {
226
235
  const tooltipNode = this.__tooltipNode;
227
236
  if (tooltipNode) {
228
- tooltipNode.text = tooltip || this.i18n.anonymous;
237
+ tooltipNode.text = tooltip || this.__effectiveI18n.anonymous;
229
238
  }
230
239
  }
231
240
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2020 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2020 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2020 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2020 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-avatar-icons.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2020 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2020 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  export * from './vaadin-avatar.js';
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2020 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2020 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-avatar-icons.js';
7
7
  import { html, LitElement } from 'lit';
8
+ import { ifDefined } from 'lit/directives/if-defined.js';
8
9
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
9
10
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
10
11
  import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
@@ -44,7 +45,7 @@ class Avatar extends AvatarMixin(ElementMixin(ThemableMixin(PolylitMixin(LitElem
44
45
  return html`
45
46
  <img
46
47
  ?hidden="${!this.__imgVisible}"
47
- src="${this.img}"
48
+ src="${ifDefined(this.img)}"
48
49
  aria-hidden="true"
49
50
  @error="${this.__onImageLoadError}"
50
51
  draggable="false"
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": "24.7.0-alpha1",
4
+ "version": "24.7.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -79,6 +79,15 @@
79
79
  ],
80
80
  "js": {
81
81
  "properties": [
82
+ {
83
+ "name": "i18n",
84
+ "description": "The object used to localize this component. To change the default\nlocalization, replace this with an object that provides all properties, or\njust the individual properties you want to change.\n\nThe object has the following JSON structure and default values:\n```\n{\n // Translation of the anonymous user avatar tooltip.\n anonymous: 'anonymous'\n}\n```",
85
+ "value": {
86
+ "type": [
87
+ "AvatarI18n"
88
+ ]
89
+ }
90
+ },
82
91
  {
83
92
  "name": "img",
84
93
  "description": "The path to the image",
@@ -123,15 +132,6 @@
123
132
  ]
124
133
  }
125
134
  },
126
- {
127
- "name": "i18n",
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```",
129
- "value": {
130
- "type": [
131
- "AvatarI18n"
132
- ]
133
- }
134
- },
135
135
  {
136
136
  "name": "withTooltip",
137
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.",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/avatar",
4
- "version": "24.7.0-alpha1",
4
+ "version": "24.7.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -26,6 +26,13 @@
26
26
  "kind": "expression"
27
27
  }
28
28
  },
29
+ {
30
+ "name": ".i18n",
31
+ "description": "The object used to localize this component. To change the default\nlocalization, replace this with an object that provides all properties, or\njust the individual properties you want to change.\n\nThe object has the following JSON structure and default values:\n```\n{\n // Translation of the anonymous user avatar tooltip.\n anonymous: 'anonymous'\n}\n```",
32
+ "value": {
33
+ "kind": "expression"
34
+ }
35
+ },
29
36
  {
30
37
  "name": ".img",
31
38
  "description": "The path to the image",
@@ -53,13 +60,6 @@
53
60
  "value": {
54
61
  "kind": "expression"
55
62
  }
56
- },
57
- {
58
- "name": ".i18n",
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```",
60
- "value": {
61
- "kind": "expression"
62
- }
63
63
  }
64
64
  ]
65
65
  }