@vaadin/icon 24.4.0-alpha21 → 24.4.0-alpha23
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 +7 -5
- package/src/vaadin-icon-mixin.d.ts +88 -0
- package/src/vaadin-icon-mixin.js +364 -0
- package/src/vaadin-icon-styles.js +49 -0
- package/src/vaadin-icon.d.ts +2 -74
- package/src/vaadin-icon.js +7 -396
- package/src/vaadin-iconset-mixin.d.ts +29 -0
- package/src/vaadin-iconset-mixin.js +169 -0
- package/src/vaadin-iconset.d.ts +2 -17
- package/src/vaadin-iconset.js +3 -163
- package/web-types.json +73 -8
- package/web-types.lit.json +4 -4
package/src/vaadin-iconset.js
CHANGED
|
@@ -6,43 +6,17 @@
|
|
|
6
6
|
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
7
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
8
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
const iconsetRegistry = {};
|
|
12
|
-
|
|
13
|
-
const attachedIcons = new Set();
|
|
14
|
-
|
|
15
|
-
function getIconId(id, name) {
|
|
16
|
-
return (id || '').replace(`${name}:`, '');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getIconsetName(icon) {
|
|
20
|
-
if (!icon) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const parts = icon.split(':');
|
|
25
|
-
|
|
26
|
-
// Use "vaadin" as a fallback
|
|
27
|
-
return parts[0] || 'vaadin';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function initIconsMap(iconset, name) {
|
|
31
|
-
iconset._icons = [...iconset.querySelectorAll('[id]')].reduce((map, svg) => {
|
|
32
|
-
const key = getIconId(svg.id, name);
|
|
33
|
-
map[key] = svg;
|
|
34
|
-
return map;
|
|
35
|
-
}, {});
|
|
36
|
-
}
|
|
9
|
+
import { IconsetMixin } from './vaadin-iconset-mixin.js';
|
|
37
10
|
|
|
38
11
|
/**
|
|
39
12
|
* `<vaadin-iconset>` is a Web Component for creating SVG icon collections.
|
|
40
13
|
*
|
|
41
14
|
* @customElement
|
|
42
15
|
* @extends HTMLElement
|
|
16
|
+
* @mixes IconsetMixin
|
|
43
17
|
* @mixes ElementMixin
|
|
44
18
|
*/
|
|
45
|
-
class Iconset extends ElementMixin(PolymerElement) {
|
|
19
|
+
class Iconset extends IconsetMixin(ElementMixin(PolymerElement)) {
|
|
46
20
|
static get template() {
|
|
47
21
|
return null;
|
|
48
22
|
}
|
|
@@ -50,140 +24,6 @@ class Iconset extends ElementMixin(PolymerElement) {
|
|
|
50
24
|
static get is() {
|
|
51
25
|
return 'vaadin-iconset';
|
|
52
26
|
}
|
|
53
|
-
|
|
54
|
-
static get properties() {
|
|
55
|
-
return {
|
|
56
|
-
/**
|
|
57
|
-
* The name of the iconset. Every iconset is required to have its own unique name.
|
|
58
|
-
* All the SVG icons in the iconset must have IDs conforming to its name.
|
|
59
|
-
*
|
|
60
|
-
* See also [`name`](#/elements/vaadin-icon#property-name) property of `vaadin-icon`.
|
|
61
|
-
*/
|
|
62
|
-
name: {
|
|
63
|
-
type: String,
|
|
64
|
-
observer: '__nameChanged',
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The size of an individual icon. Note that icons must be square.
|
|
69
|
-
*
|
|
70
|
-
* When using `vaadin-icon`, the size of the iconset will take precedence
|
|
71
|
-
* over the size defined by the user to ensure correct appearance.
|
|
72
|
-
*/
|
|
73
|
-
size: {
|
|
74
|
-
type: Number,
|
|
75
|
-
value: 24,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Set of the `vaadin-icon` instances in the DOM.
|
|
82
|
-
*
|
|
83
|
-
* @return {Set<Icon>}
|
|
84
|
-
*/
|
|
85
|
-
static get attachedIcons() {
|
|
86
|
-
return attachedIcons;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Returns an instance of the iconset by its name.
|
|
91
|
-
*
|
|
92
|
-
* @param {string} name
|
|
93
|
-
* @return {Iconset}
|
|
94
|
-
*/
|
|
95
|
-
static getIconset(name) {
|
|
96
|
-
return iconsetRegistry[name];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Returns SVGTemplateResult for the `icon` ID matching `name` of the
|
|
101
|
-
* iconset, or `nothing` literal if there is no matching icon found.
|
|
102
|
-
*
|
|
103
|
-
* @param {string} icon
|
|
104
|
-
* @param {?string} name
|
|
105
|
-
*/
|
|
106
|
-
static getIconSvg(icon, name) {
|
|
107
|
-
const iconsetName = name || getIconsetName(icon);
|
|
108
|
-
const iconset = this.getIconset(iconsetName);
|
|
109
|
-
|
|
110
|
-
if (!icon || !iconset) {
|
|
111
|
-
// Missing icon, return `nothing` literal.
|
|
112
|
-
return { svg: cloneSvgNode(null) };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const iconId = getIconId(icon, iconsetName);
|
|
116
|
-
const iconSvg = iconset._icons[iconId];
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
preserveAspectRatio: iconSvg ? iconSvg.getAttribute('preserveAspectRatio') : null,
|
|
120
|
-
svg: cloneSvgNode(iconSvg),
|
|
121
|
-
size: iconset.size,
|
|
122
|
-
viewBox: iconSvg ? iconSvg.getAttribute('viewBox') : null,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Register an iconset without adding to the DOM.
|
|
128
|
-
*
|
|
129
|
-
* @param {string} name
|
|
130
|
-
* @param {number} size
|
|
131
|
-
* @param {?HTMLTemplateElement} template
|
|
132
|
-
*/
|
|
133
|
-
static register(name, size, template) {
|
|
134
|
-
if (!iconsetRegistry[name]) {
|
|
135
|
-
const iconset = document.createElement('vaadin-iconset');
|
|
136
|
-
iconset.appendChild(template.content.cloneNode(true));
|
|
137
|
-
iconsetRegistry[name] = iconset;
|
|
138
|
-
|
|
139
|
-
initIconsMap(iconset, name);
|
|
140
|
-
|
|
141
|
-
iconset.size = size;
|
|
142
|
-
iconset.name = name;
|
|
143
|
-
|
|
144
|
-
// Call this function manually instead of using observer
|
|
145
|
-
// to make it work without appending element to the DOM.
|
|
146
|
-
iconset.__nameChanged(name);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** @protected */
|
|
151
|
-
connectedCallback() {
|
|
152
|
-
super.connectedCallback();
|
|
153
|
-
|
|
154
|
-
this.style.display = 'none';
|
|
155
|
-
|
|
156
|
-
// Store reference and init icons.
|
|
157
|
-
const { name } = this;
|
|
158
|
-
iconsetRegistry[name] = this;
|
|
159
|
-
initIconsMap(this, name);
|
|
160
|
-
this.__updateIcons(name);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Update all the icons instances in the DOM.
|
|
165
|
-
*
|
|
166
|
-
* @param {string} name
|
|
167
|
-
* @private
|
|
168
|
-
*/
|
|
169
|
-
__updateIcons(name) {
|
|
170
|
-
attachedIcons.forEach((element) => {
|
|
171
|
-
if (name === getIconsetName(element.icon)) {
|
|
172
|
-
element._applyIcon();
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** @private */
|
|
178
|
-
__nameChanged(name, oldName) {
|
|
179
|
-
if (oldName) {
|
|
180
|
-
iconsetRegistry[name] = iconsetRegistry[oldName];
|
|
181
|
-
delete iconsetRegistry[oldName];
|
|
182
|
-
}
|
|
183
|
-
if (name) {
|
|
184
|
-
this.__updateIcons(name);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
27
|
}
|
|
188
28
|
|
|
189
29
|
defineCustomElement(Iconset);
|
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.4.0-
|
|
4
|
+
"version": "24.4.0-alpha23",
|
|
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.4.0-
|
|
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.4.0-alpha23/#/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.4.0-
|
|
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.4.0-alpha23/#/elements/vaadin-icon#property-name) property of `vaadin-icon`.",
|
|
52
52
|
"value": {
|
|
53
53
|
"type": [
|
|
54
54
|
"string",
|
|
@@ -74,14 +74,79 @@
|
|
|
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.4.0-
|
|
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.4.0-alpha23/#/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.4.0-alpha23/#/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": "
|
|
81
|
-
"description": "",
|
|
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.4.0-alpha23/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
|
|
82
82
|
"value": {
|
|
83
83
|
"type": [
|
|
84
|
-
""
|
|
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
|
+
]
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "symbol",
|
|
99
|
+
"description": "The symbol identifier that references an ID of an element contained in the SVG element assigned to the\n`src` property",
|
|
100
|
+
"value": {
|
|
101
|
+
"type": [
|
|
102
|
+
"string"
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "icon-class",
|
|
108
|
+
"description": "Class names defining an icon font and/or a specific glyph inside an icon font.\n\nExample: \"fa-solid fa-user\"",
|
|
109
|
+
"value": {
|
|
110
|
+
"type": [
|
|
111
|
+
"string"
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "char",
|
|
117
|
+
"description": "A hexadecimal code point that specifies a glyph from an icon font.\n\nExample: \"e001\"",
|
|
118
|
+
"value": {
|
|
119
|
+
"type": [
|
|
120
|
+
"string"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "ligature",
|
|
126
|
+
"description": "A ligature name that specifies an icon from an icon font with support for ligatures.\n\nExample: \"home\".",
|
|
127
|
+
"value": {
|
|
128
|
+
"type": [
|
|
129
|
+
"string"
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "font-family",
|
|
135
|
+
"description": "The font family to use for the font icon.",
|
|
136
|
+
"value": {
|
|
137
|
+
"type": [
|
|
138
|
+
"string"
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "size",
|
|
144
|
+
"description": "The size of an icon, used to set the `viewBox` attribute.",
|
|
145
|
+
"value": {
|
|
146
|
+
"type": [
|
|
147
|
+
"number",
|
|
148
|
+
"null",
|
|
149
|
+
"undefined"
|
|
85
150
|
]
|
|
86
151
|
}
|
|
87
152
|
},
|
|
@@ -101,7 +166,7 @@
|
|
|
101
166
|
"properties": [
|
|
102
167
|
{
|
|
103
168
|
"name": "icon",
|
|
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.4.0-
|
|
169
|
+
"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.4.0-alpha23/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
|
|
105
170
|
"value": {
|
|
106
171
|
"type": [
|
|
107
172
|
"string"
|
package/web-types.lit.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.4.0-
|
|
4
|
+
"version": "24.4.0-alpha23",
|
|
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.4.0-
|
|
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.4.0-alpha23/#/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.4.0-
|
|
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.4.0-alpha23/#/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.4.0-alpha23/#/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.4.0-
|
|
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.4.0-alpha23/#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.",
|
|
46
46
|
"value": {
|
|
47
47
|
"kind": "expression"
|
|
48
48
|
}
|