@vaadin/icon 24.2.0-alpha14 → 24.2.0-alpha15

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/icon",
3
- "version": "24.2.0-alpha14",
3
+ "version": "24.2.0-alpha15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,9 +35,9 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/component-base": "24.2.0-alpha14",
39
- "@vaadin/vaadin-lumo-styles": "24.2.0-alpha14",
40
- "@vaadin/vaadin-themable-mixin": "24.2.0-alpha14",
38
+ "@vaadin/component-base": "24.2.0-alpha15",
39
+ "@vaadin/vaadin-lumo-styles": "24.2.0-alpha15",
40
+ "@vaadin/vaadin-themable-mixin": "24.2.0-alpha15",
41
41
  "lit": "^2.0.0"
42
42
  },
43
43
  "devDependencies": {
@@ -49,5 +49,5 @@
49
49
  "web-types.json",
50
50
  "web-types.lit.json"
51
51
  ],
52
- "gitHead": "203a2fda8d879db6ee8bccd7cf5b915de3e5008b"
52
+ "gitHead": "043dbb1c2513685a98354921876d35fa18bca7a2"
53
53
  }
@@ -34,7 +34,7 @@ export const IconFontSizeMixin = dedupingMixin((superclass) =>
34
34
  ? superclass
35
35
  : class extends ResizeMixin(superclass) {
36
36
  static get observers() {
37
- return ['__iconFontSizeMixinfontChanged(font, char)'];
37
+ return ['__iconFontSizeMixinfontChanged(font, char, ligature)'];
38
38
  }
39
39
 
40
40
  /** @protected */
@@ -46,7 +46,7 @@ export const IconFontSizeMixin = dedupingMixin((superclass) =>
46
46
  }
47
47
 
48
48
  /** @private */
49
- __iconFontSizeMixinfontChanged(font, char) {
49
+ __iconFontSizeMixinfontChanged(_font, _char, _ligature) {
50
50
  // Update when font or char changes
51
51
  this.__updateFontIconSize();
52
52
  }
@@ -66,7 +66,7 @@ export const IconFontSizeMixin = dedupingMixin((superclass) =>
66
66
  * @private
67
67
  */
68
68
  __updateFontIconSize() {
69
- if (this.char || this.font) {
69
+ if (this.char || this.font || this.ligature) {
70
70
  const { paddingTop, paddingBottom, height } = getComputedStyle(this);
71
71
  const fontIconSize = parseFloat(height) - parseFloat(paddingTop) - parseFloat(paddingBottom);
72
72
  this.style.setProperty('--_vaadin-font-icon-size', `${fontIconSize}px`);
@@ -89,13 +89,19 @@ declare class Icon extends ThemableMixin(
89
89
  font: string | null;
90
90
 
91
91
  /**
92
- * The specific glyph from a font to use as an icon.
93
- * Can be a code point or a ligature name.
92
+ * A hexadecimal code point that specifies a glyph from an icon font.
94
93
  *
95
- * @attr {string} char
94
+ * Example: "e001"
96
95
  */
97
96
  char: string | null;
98
97
 
98
+ /**
99
+ * A ligature name that specifies an icon from an icon font with support for ligatures.
100
+ *
101
+ * Example: "home".
102
+ */
103
+ ligature: string | null;
104
+
99
105
  /**
100
106
  * The font family to use for the font icon.
101
107
  */
@@ -92,12 +92,12 @@ class Icon extends ThemableMixin(ElementMixin(ControllerMixin(SlotStylesMixin(Ic
92
92
  height: 100%;
93
93
  }
94
94
 
95
- :host(:is([font], [char])) svg {
95
+ :host(:is([font], [font-icon-content])) svg {
96
96
  display: none;
97
97
  }
98
98
 
99
- :host([char])::before {
100
- content: attr(char);
99
+ :host([font-icon-content])::before {
100
+ content: attr(font-icon-content);
101
101
  }
102
102
  </style>
103
103
  <svg
@@ -169,15 +169,25 @@ class Icon extends ThemableMixin(ElementMixin(ControllerMixin(SlotStylesMixin(Ic
169
169
  },
170
170
 
171
171
  /**
172
- * The specific glyph from a font to use as an icon.
173
- * Can be a code point or a ligature name.
172
+ * A hexadecimal code point that specifies a glyph from an icon font.
173
+ *
174
+ * Example: "e001"
174
175
  *
175
- * @attr {string} char
176
176
  * @type {string}
177
177
  */
178
178
  char: {
179
179
  type: String,
180
- reflectToAttribute: true,
180
+ },
181
+
182
+ /**
183
+ * A ligature name that specifies an icon from an icon font with support for ligatures.
184
+ *
185
+ * Example: "home".
186
+ *
187
+ * @type {string}
188
+ */
189
+ ligature: {
190
+ type: String,
181
191
  },
182
192
 
183
193
  /**
@@ -216,7 +226,11 @@ class Icon extends ThemableMixin(ElementMixin(ControllerMixin(SlotStylesMixin(Ic
216
226
  }
217
227
 
218
228
  static get observers() {
219
- return ['__svgChanged(svg, __svgElement)', '__fontChanged(font, char)', '__srcChanged(src)'];
229
+ return ['__svgChanged(svg, __svgElement)', '__fontChanged(font, char, ligature)', '__srcChanged(src)'];
230
+ }
231
+
232
+ static get observedAttributes() {
233
+ return [...super.observedAttributes, 'class'];
220
234
  }
221
235
 
222
236
  constructor() {
@@ -239,6 +253,11 @@ class Icon extends ThemableMixin(ElementMixin(ControllerMixin(SlotStylesMixin(Ic
239
253
  ];
240
254
  }
241
255
 
256
+ /** @private */
257
+ get __fontClasses() {
258
+ return this.font ? this.font.split(' ') : [];
259
+ }
260
+
242
261
  /** @protected */
243
262
  ready() {
244
263
  super.ready();
@@ -351,23 +370,41 @@ class Icon extends ThemableMixin(ElementMixin(ControllerMixin(SlotStylesMixin(Ic
351
370
  }
352
371
 
353
372
  /** @private */
354
- __fontChanged(font, char) {
373
+ __fontChanged(font, char, ligature) {
355
374
  this.classList.remove(...(this.__addedFontClasses || []));
356
375
  if (font) {
357
- this.__addedFontClasses = font.split(' ');
376
+ this.__addedFontClasses = [...this.__fontClasses];
358
377
  this.classList.add(...this.__addedFontClasses);
359
378
  }
360
379
 
361
- if ((font || char) && !this.icon) {
380
+ if (char) {
381
+ this.setAttribute('font-icon-content', char.length > 1 ? String.fromCodePoint(parseInt(char, 16)) : char);
382
+ } else if (ligature) {
383
+ this.setAttribute('font-icon-content', ligature);
384
+ } else {
385
+ this.removeAttribute('font-icon-content');
386
+ }
387
+
388
+ if ((font || char || ligature) && !this.icon) {
362
389
  // The "icon" attribute needs to be set on the host also when using font icons
363
390
  // to avoid issues such as https://github.com/vaadin/web-components/issues/6301
364
391
  this.icon = '';
365
392
  }
366
393
  }
367
394
 
395
+ /** @protected */
396
+ attributeChangedCallback(name, oldValue, newValue) {
397
+ super.attributeChangedCallback(name, oldValue, newValue);
398
+
399
+ // Make sure class list always contains all the font class names
400
+ if (name === 'class' && this.__fontClasses.some((className) => !this.classList.contains(className))) {
401
+ this.classList.add(...this.__fontClasses);
402
+ }
403
+ }
404
+
368
405
  /** @private */
369
406
  __fontFamilyChanged(fontFamily) {
370
- this.style.fontFamily = fontFamily;
407
+ this.style.fontFamily = `'${fontFamily}'`;
371
408
  }
372
409
  }
373
410
 
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/icon",
4
- "version": "24.2.0-alpha14",
4
+ "version": "24.2.0-alpha15",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -12,7 +12,7 @@
12
12
  "attributes": [
13
13
  {
14
14
  "name": "name",
15
- "description": "The name of the iconset. Every iconset is required to have its own unique name.\nAll the SVG icons in the iconset must have IDs conforming to its name.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-icon#property-name) property of `vaadin-icon`.",
15
+ "description": "The name of the iconset. Every iconset is required to have its own unique name.\nAll the SVG icons in the iconset must have IDs conforming to its name.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-icon#property-name) property of `vaadin-icon`.",
16
16
  "value": {
17
17
  "type": [
18
18
  "string",
@@ -48,7 +48,7 @@
48
48
  "properties": [
49
49
  {
50
50
  "name": "name",
51
- "description": "The name of the iconset. Every iconset is required to have its own unique name.\nAll the SVG icons in the iconset must have IDs conforming to its name.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-icon#property-name) property of `vaadin-icon`.",
51
+ "description": "The name of the iconset. Every iconset is required to have its own unique name.\nAll the SVG icons in the iconset must have IDs conforming to its name.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-icon#property-name) property of `vaadin-icon`.",
52
52
  "value": {
53
53
  "type": [
54
54
  "string",
@@ -74,63 +74,14 @@
74
74
  },
75
75
  {
76
76
  "name": "vaadin-icon",
77
- "description": "`<vaadin-icon>` is a Web Component for displaying SVG icons.\n\n### Icon property\n\nThe `<vaadin-icon>` component is designed to be used as a drop-in replacement for `<iron-icon>`.\nFor example, you can use it with `vaadin-icons` like this:\n\n```html\n<vaadin-icon icon=\"vaadin:angle-down\"></vaadin-icon>\n```\n\nAlternatively, you can also pick one of the Lumo icons:\n\n```html\n<vaadin-icon icon=\"lumo:user\"></vaadin-icon>\n```\n\n### Custom SVG icon\n\nAlternatively, instead of selecting an icon from an iconset by name, you can pass any custom `svg`\nliteral using the [`svg`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-icon#property-svg) property. In this case you can also\ndefine the size of the SVG `viewBox` using the [`size`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-icon#property-size) property:\n\n```js\nimport { html, svg } from 'lit';\n\n// in your component\nrender() {\n const svgIcon = svg`<path d=\"M13 4v2l-5 5-5-5v-2l5 5z\"></path>`;\n return html`\n <vaadin-icon\n .svg=\"${svgIcon}\"\n size=\"16\"\n ></vaadin-icon>\n `;\n}\n```",
77
+ "description": "`<vaadin-icon>` is a Web Component for displaying SVG icons.\n\n### Icon property\n\nThe `<vaadin-icon>` component is designed to be used as a drop-in replacement for `<iron-icon>`.\nFor example, you can use it with `vaadin-icons` like this:\n\n```html\n<vaadin-icon icon=\"vaadin:angle-down\"></vaadin-icon>\n```\n\nAlternatively, you can also pick one of the Lumo icons:\n\n```html\n<vaadin-icon icon=\"lumo:user\"></vaadin-icon>\n```\n\n### Custom SVG icon\n\nAlternatively, instead of selecting an icon from an iconset by name, you can pass any custom `svg`\nliteral using the [`svg`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-icon#property-svg) property. In this case you can also\ndefine the size of the SVG `viewBox` using the [`size`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-icon#property-size) property:\n\n```js\nimport { html, svg } from 'lit';\n\n// in your component\nrender() {\n const svgIcon = svg`<path d=\"M13 4v2l-5 5-5-5v-2l5 5z\"></path>`;\n return html`\n <vaadin-icon\n .svg=\"${svgIcon}\"\n size=\"16\"\n ></vaadin-icon>\n `;\n}\n```",
78
78
  "attributes": [
79
79
  {
80
- "name": "icon",
81
- "description": "The name of the icon to use. The name should be of the form:\n`iconset_name:icon_name`. When using `vaadin-icons` it is possible\nto omit the first part and only use `icon_name` as a value.\n\nSetting the `icon` property updates the `svg` and `size` based on the\nvalues provided by the corresponding `vaadin-iconset` element.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
80
+ "name": "class",
81
+ "description": "",
82
82
  "value": {
83
83
  "type": [
84
- "string"
85
- ]
86
- }
87
- },
88
- {
89
- "name": "src",
90
- "description": "The SVG source to be loaded as the icon. It can be:\n- an URL to a file containing the icon\n- an URL in the format \"/path/to/file.svg#objectID\", where the \"objectID\" refers to an ID attribute contained\n inside the SVG referenced by the path. Note that the file needs to follow the same-origin policy.\n- a string in the format \"data:image/svg+xml,<svg>...</svg>\". You may need to use the \"encodeURIComponent\"\n function for the SVG content passed",
91
- "value": {
92
- "type": [
93
- "string",
94
- "null",
95
- "undefined"
96
- ]
97
- }
98
- },
99
- {
100
- "name": "font",
101
- "description": "Class names defining an icon font and/or a specific glyph inside an icon font.",
102
- "value": {
103
- "type": [
104
- "string"
105
- ]
106
- }
107
- },
108
- {
109
- "name": "char",
110
- "description": "The specific glyph from a font to use as an icon.\nCan be a code point or a ligature name.",
111
- "value": {
112
- "type": [
113
- "string"
114
- ]
115
- }
116
- },
117
- {
118
- "name": "font-family",
119
- "description": "The font family to use for the font icon.",
120
- "value": {
121
- "type": [
122
- "string"
123
- ]
124
- }
125
- },
126
- {
127
- "name": "size",
128
- "description": "The size of an icon, used to set the `viewBox` attribute.",
129
- "value": {
130
- "type": [
131
- "number",
132
- "null",
133
- "undefined"
84
+ ""
134
85
  ]
135
86
  }
136
87
  },
@@ -150,7 +101,7 @@
150
101
  "properties": [
151
102
  {
152
103
  "name": "icon",
153
- "description": "The name of the icon to use. The name should be of the form:\n`iconset_name:icon_name`. When using `vaadin-icons` it is possible\nto omit the first part and only use `icon_name` as a value.\n\nSetting the `icon` property updates the `svg` and `size` based on the\nvalues provided by the corresponding `vaadin-iconset` element.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
104
+ "description": "The name of the icon to use. The name should be of the form:\n`iconset_name:icon_name`. When using `vaadin-icons` it is possible\nto omit the first part and only use `icon_name` as a value.\n\nSetting the `icon` property updates the `svg` and `size` based on the\nvalues provided by the corresponding `vaadin-iconset` element.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
154
105
  "value": {
155
106
  "type": [
156
107
  "string"
@@ -190,7 +141,16 @@
190
141
  },
191
142
  {
192
143
  "name": "char",
193
- "description": "The specific glyph from a font to use as an icon.\nCan be a code point or a ligature name.",
144
+ "description": "A hexadecimal code point that specifies a glyph from an icon font.\n\nExample: \"e001\"",
145
+ "value": {
146
+ "type": [
147
+ "string"
148
+ ]
149
+ }
150
+ },
151
+ {
152
+ "name": "ligature",
153
+ "description": "A ligature name that specifies an icon from an icon font with support for ligatures.\n\nExample: \"home\".",
194
154
  "value": {
195
155
  "type": [
196
156
  "string"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/icon",
4
- "version": "24.2.0-alpha14",
4
+ "version": "24.2.0-alpha15",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -21,7 +21,7 @@
21
21
  "attributes": [
22
22
  {
23
23
  "name": ".name",
24
- "description": "The name of the iconset. Every iconset is required to have its own unique name.\nAll the SVG icons in the iconset must have IDs conforming to its name.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-icon#property-name) property of `vaadin-icon`.",
24
+ "description": "The name of the iconset. Every iconset is required to have its own unique name.\nAll the SVG icons in the iconset must have IDs conforming to its name.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-icon#property-name) property of `vaadin-icon`.",
25
25
  "value": {
26
26
  "kind": "expression"
27
27
  }
@@ -37,12 +37,12 @@
37
37
  },
38
38
  {
39
39
  "name": "vaadin-icon",
40
- "description": "`<vaadin-icon>` is a Web Component for displaying SVG icons.\n\n### Icon property\n\nThe `<vaadin-icon>` component is designed to be used as a drop-in replacement for `<iron-icon>`.\nFor example, you can use it with `vaadin-icons` like this:\n\n```html\n<vaadin-icon icon=\"vaadin:angle-down\"></vaadin-icon>\n```\n\nAlternatively, you can also pick one of the Lumo icons:\n\n```html\n<vaadin-icon icon=\"lumo:user\"></vaadin-icon>\n```\n\n### Custom SVG icon\n\nAlternatively, instead of selecting an icon from an iconset by name, you can pass any custom `svg`\nliteral using the [`svg`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-icon#property-svg) property. In this case you can also\ndefine the size of the SVG `viewBox` using the [`size`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-icon#property-size) property:\n\n```js\nimport { html, svg } from 'lit';\n\n// in your component\nrender() {\n const svgIcon = svg`<path d=\"M13 4v2l-5 5-5-5v-2l5 5z\"></path>`;\n return html`\n <vaadin-icon\n .svg=\"${svgIcon}\"\n size=\"16\"\n ></vaadin-icon>\n `;\n}\n```",
40
+ "description": "`<vaadin-icon>` is a Web Component for displaying SVG icons.\n\n### Icon property\n\nThe `<vaadin-icon>` component is designed to be used as a drop-in replacement for `<iron-icon>`.\nFor example, you can use it with `vaadin-icons` like this:\n\n```html\n<vaadin-icon icon=\"vaadin:angle-down\"></vaadin-icon>\n```\n\nAlternatively, you can also pick one of the Lumo icons:\n\n```html\n<vaadin-icon icon=\"lumo:user\"></vaadin-icon>\n```\n\n### Custom SVG icon\n\nAlternatively, instead of selecting an icon from an iconset by name, you can pass any custom `svg`\nliteral using the [`svg`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-icon#property-svg) property. In this case you can also\ndefine the size of the SVG `viewBox` using the [`size`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-icon#property-size) property:\n\n```js\nimport { html, svg } from 'lit';\n\n// in your component\nrender() {\n const svgIcon = svg`<path d=\"M13 4v2l-5 5-5-5v-2l5 5z\"></path>`;\n return html`\n <vaadin-icon\n .svg=\"${svgIcon}\"\n size=\"16\"\n ></vaadin-icon>\n `;\n}\n```",
41
41
  "extension": true,
42
42
  "attributes": [
43
43
  {
44
44
  "name": ".icon",
45
- "description": "The name of the icon to use. The name should be of the form:\n`iconset_name:icon_name`. When using `vaadin-icons` it is possible\nto omit the first part and only use `icon_name` as a value.\n\nSetting the `icon` property updates the `svg` and `size` based on the\nvalues provided by the corresponding `vaadin-iconset` element.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha14/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
45
+ "description": "The name of the icon to use. The name should be of the form:\n`iconset_name:icon_name`. When using `vaadin-icons` it is possible\nto omit the first part and only use `icon_name` as a value.\n\nSetting the `icon` property updates the `svg` and `size` based on the\nvalues provided by the corresponding `vaadin-iconset` element.\n\nSee also [`name`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha15/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
46
46
  "value": {
47
47
  "kind": "expression"
48
48
  }
@@ -70,7 +70,14 @@
70
70
  },
71
71
  {
72
72
  "name": ".char",
73
- "description": "The specific glyph from a font to use as an icon.\nCan be a code point or a ligature name.",
73
+ "description": "A hexadecimal code point that specifies a glyph from an icon font.\n\nExample: \"e001\"",
74
+ "value": {
75
+ "kind": "expression"
76
+ }
77
+ },
78
+ {
79
+ "name": ".ligature",
80
+ "description": "A ligature name that specifies an icon from an icon font with support for ligatures.\n\nExample: \"home\".",
74
81
  "value": {
75
82
  "kind": "expression"
76
83
  }