Skip to content

Commit

Permalink
Parse icon names with FA lib
Browse files Browse the repository at this point in the history
This resolves aliases, which is required for lots of stuff in FA6.
  • Loading branch information
jrjohnson committed Apr 25, 2022
1 parent 0bd1329 commit cf43be6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addon/components/fa-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function normalizeIconArgs(prefix, icon) {
}

if (typeof prefix === 'string' && typeof icon === 'string') {
return { prefix: prefix, iconName: icon };
return parse.icon({ prefix: prefix, iconName: icon });
}

if (typeof icon === 'string') {
return { prefix: defaultPrefix, iconName: icon };
return parse.icon({ prefix: defaultPrefix, iconName: icon });
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@
<FaIcon @icon="check" class="fa-inverse" @transform="shrink-6" />
</span>

<h3>Alias</h3>
<FaIcon @icon="trash-alt" />

{{outlet}}
1 change: 1 addition & 0 deletions tests/dummy/config/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function () {
'fax',
'sync',
'stopwatch-20',
'trash-alt',
],
'free-regular-svg-icons': 'all',
};
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/components/fa-icon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,20 @@ module('Integration | Component | fa icon', function (hooks) {
assert.ok(this.element.innerHTML.startsWith('<svg '));
assert.ok(this.element.innerHTML.endsWith('</svg>'));
});

test('it renders trash-alt (alias) ', async function (assert) {
await render(hbs`<FaIcon @icon="trash-alt" />`);

assert.dom('*').hasText('');
assert.dom('svg').hasAttribute('data-icon', 'trash-can');
assert.ok(
find('svg').getAttribute('class').split(/\s+/).includes('fa-trash-can')
);
assert
.dom('svg path')
.hasAttribute(
'd',
'M135.2 17.69C140.6 6.848 151.7 0 163.8 0H284.2C296.3 0 307.4 6.848 312.8 17.69L320 32H416C433.7 32 448 46.33 448 64C448 81.67 433.7 96 416 96H32C14.33 96 0 81.67 0 64C0 46.33 14.33 32 32 32H128L135.2 17.69zM31.1 128H416V448C416 483.3 387.3 512 352 512H95.1C60.65 512 31.1 483.3 31.1 448V128zM111.1 208V432C111.1 440.8 119.2 448 127.1 448C136.8 448 143.1 440.8 143.1 432V208C143.1 199.2 136.8 192 127.1 192C119.2 192 111.1 199.2 111.1 208zM207.1 208V432C207.1 440.8 215.2 448 223.1 448C232.8 448 240 440.8 240 432V208C240 199.2 232.8 192 223.1 192C215.2 192 207.1 199.2 207.1 208zM304 208V432C304 440.8 311.2 448 320 448C328.8 448 336 440.8 336 432V208C336 199.2 328.8 192 320 192C311.2 192 304 199.2 304 208z'
);
});
});

0 comments on commit cf43be6

Please sign in to comment.