Skip to content

Commit bcae4e5

Browse files
authored
feat: add vaadin-iconset to vaadin-icons (#2059)
1 parent 0ccbdd4 commit bcae4e5

File tree

8 files changed

+734
-20
lines changed

8 files changed

+734
-20
lines changed

packages/vaadin-app-layout/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"devDependencies": {
3737
"@esm-bundle/chai": "^4.1.5",
3838
"@vaadin/testing-helpers": "^0.2.1",
39-
"@vaadin/vaadin-icons": "^21.0.0-alpha2",
4039
"@vaadin/vaadin-tabs": "^21.0.0-alpha2",
4140
"sinon": "^9.2.1"
4241
},

packages/vaadin-confirm-dialog/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"devDependencies": {
3939
"@esm-bundle/chai": "^4.1.5",
4040
"@vaadin/testing-helpers": "^0.2.1",
41-
"@vaadin/vaadin-icons": "^21.0.0-alpha2",
4241
"sinon": "^9.2.1"
4342
},
4443
"publishConfig": {

packages/vaadin-icons/gulpfile.js

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,41 @@ const modify = require('gulp-modify');
66
const cheerio = require('cheerio');
77
const concat = require('gulp-concat');
88

9-
gulp.task('icons', function () {
9+
function createCopyright() {
10+
return `/**
11+
* @license
12+
* Copyright (c) 2015 - ${new Date().getFullYear()} Vaadin Ltd.
13+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
14+
*/`;
15+
}
16+
17+
function iconFileModifier(prefix) {
18+
return function (file, contents) {
19+
const id = file.path.replace(/.*\/(.*).svg/, '$1');
20+
const svg = cheerio.load(contents, { xmlMode: true })('svg');
21+
// Remove fill attributes.
22+
svg.children('[fill]').removeAttr('fill');
23+
// Add closing tags instead of self-closing.
24+
const content = svg.children().toString().replace(/"\/>/g, '"></path>');
25+
// Output the "meat" of the SVG as group element.
26+
return `<g id="${prefix}${id}">${content}</g>`;
27+
};
28+
}
29+
30+
gulp.task('iron-icons', function () {
1031
return gulp
1132
.src(['assets/svg/*.svg'], { base: '.' })
1233
.pipe(
1334
modify({
14-
fileModifier: function (file, contents) {
15-
const id = file.path.replace(/.*\/(.*).svg/, '$1');
16-
const svg = cheerio.load(contents, { xmlMode: true })('svg');
17-
// Remove fill attributes.
18-
svg.children('[fill]').removeAttr('fill');
19-
// Add closing tags instead of self-closing.
20-
const content = svg.children().toString().replace(/"\/>/g, '"></path>');
21-
// Output the "meat" of the SVG as group element.
22-
return `<g id="${id}">${content}</g>`;
23-
}
35+
fileModifier: iconFileModifier('')
2436
})
2537
)
2638
.pipe(concat('iconset.js'))
2739
.pipe(
2840
modify({
2941
fileModifier: function (file, contents) {
3042
// Enclose all icons in an iron-iconset-svg
31-
return `/**
32-
* @license
33-
* Copyright (c) 2015 - 2021 Vaadin Ltd.
34-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
35-
*/
43+
return `${createCopyright()}
3644
import '@polymer/iron-iconset-svg/iron-iconset-svg.js';
3745
3846
const $_documentContainer = document.createElement('template');
@@ -47,3 +55,35 @@ document.head.appendChild($_documentContainer.content);\n`;
4755
)
4856
.pipe(gulp.dest('.'));
4957
});
58+
59+
gulp.task('vaadin-icons', function () {
60+
return gulp
61+
.src(['assets/svg/*.svg'], { base: '.' })
62+
.pipe(
63+
modify({
64+
fileModifier: iconFileModifier('vaadin:')
65+
})
66+
)
67+
.pipe(concat('vaadin-iconset.js'))
68+
.pipe(
69+
modify({
70+
fileModifier: function (file, contents) {
71+
// Enclose all icons in a vaadin-iconset
72+
return `${createCopyright()}
73+
import '@vaadin/vaadin-icon/vaadin-iconset.js';
74+
import '@vaadin/vaadin-icon/vaadin-icon.js';
75+
76+
const $_documentContainer = document.createElement('template');
77+
78+
$_documentContainer.innerHTML = \`<vaadin-iconset name="vaadin" size="16">
79+
<svg><defs>\n${contents}\n</defs></svg>
80+
</vaadin-iconset>\`;
81+
82+
document.head.appendChild($_documentContainer.content);\n`;
83+
}
84+
})
85+
)
86+
.pipe(gulp.dest('.'));
87+
});
88+
89+
gulp.task('icons', gulp.parallel('iron-icons', 'vaadin-icons'));

packages/vaadin-icons/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"dependencies": {
2929
"@polymer/iron-icon": "^3.0.0",
3030
"@polymer/iron-iconset-svg": "^3.0.0",
31-
"@polymer/polymer": "^3.0.0"
31+
"@polymer/polymer": "^3.0.0",
32+
"@vaadin/vaadin-icon": "^21.0.0-alpha2"
3233
},
3334
"devDependencies": {
3435
"cheerio": "^1.0.0-rc.6",
136 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
2+
import { visualDiff } from '@web/test-runner-visual-regression';
3+
import '../../vaadin-iconset.js';
4+
5+
describe('vaadin-iconset', () => {
6+
let wrapper;
7+
8+
before(async () => {
9+
const { origin, pathname } = new URL(import.meta.url);
10+
const file = pathname.replace(/test\/.+/, 'assets/vaadin-font-icons.json');
11+
const data = await fetch(`${origin}${file}`);
12+
const icons = await data.json();
13+
wrapper = fixtureSync(`
14+
<div style="display: flex; flex-wrap: wrap;">
15+
${icons.map(({ name }) => `<vaadin-icon icon="vaadin:${name}" style="margin: 3px"></vaadin-icon>`).join('\n')}
16+
</div>
17+
`);
18+
await nextFrame();
19+
});
20+
21+
it('basic', async () => {
22+
await visualDiff(wrapper, `${import.meta.url}_vaadin-iconset`);
23+
});
24+
});

0 commit comments

Comments
 (0)