Skip to content

Commit

Permalink
Merge pull request #206 from jrjohnson/parse-aliases
Browse files Browse the repository at this point in the history
Parse icon names with FA lib
  • Loading branch information
jrjohnson committed May 24, 2022
2 parents fcaf096 + 420e236 commit a279589
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions addon/components/fa-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ function normalizeIconArgs(prefix, icon) {
return icon;
}

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

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

if (typeof prefix === 'string' && typeof icon === 'string') {
return { prefix: prefix, 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 a279589

Please sign in to comment.