Skip to content

Commit 8992396

Browse files
authored
Add support for @fortawesome/fontawesome-svg-core v7.x (#256)
* Widen support for`@fortawesome/fontawesome-svg-core` (allow v7) * Prepare tests for FA7 * Remove ts-expect-error (resolved with v7) * Remove check for focusable = false (was only for IE11 and old Edge) * Add note for title tag support & fix tests for FA7 * Fix test for FA6 * Add exception for `@title` pass in FA7 * Fix ReadMe link
1 parent c406044 commit 8992396

File tree

8 files changed

+933
-873
lines changed

8 files changed

+933
-873
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ jobs:
6969
- ember-lts-5.4
7070
- ember-lts-5.8
7171
- ember-lts-5.12
72-
- ember-lts-5.12-with-fa5
7372
- ember-lts-6.4
73+
- ember-lts-6.4-with-fa5
74+
- ember-lts-6.4-with-fa6
7475
- ember-release
7576
- ember-beta
7677
- ember-canary

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ Hey there! We're glad you're here...
5151

5252
### Upgrading Font Awesome?
5353

54-
If you've used Font Awesome in the past (version 5 or older) there are some
54+
If you've used Font Awesome in the past (version 6 or older) there are some
5555
things that you should learn before you dive in.
5656

57-
> https://docs.fontawesome.com/web/setup/upgrade
57+
> v6: https://docs.fontawesome.com/upgrade/whats-changed
58+
>
59+
> Older: https://docs.fontawesome.com/upgrade/upgrade-from-older-versions
5860
5961
### Get started
6062

ember-fontawesome/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
7070
},
7171
"dependencies": {
72-
"@embroider/addon-shim": "^1.10.0"
72+
"@embroider/addon-shim": "^1.10.0",
73+
"@embroider/macros": "^1.10.0"
7374
},
7475
"devDependencies": {
7576
"@babel/core": "^7.28.0",
@@ -79,7 +80,7 @@
7980
"@ember/library-tsconfig": "^1.1.3",
8081
"@embroider/addon-dev": "^7.1.1",
8182
"@eslint/js": "^9.32.0",
82-
"@fortawesome/fontawesome-svg-core": "^6.7.2",
83+
"@fortawesome/fontawesome-svg-core": "^7.0.0",
8384
"@glimmer/component": "^2.0.0",
8485
"@glint/core": "^1.5.2",
8586
"@glint/environment-ember-loose": "^1.5.2",
@@ -105,7 +106,7 @@
105106
"webpack": "^5.101.0"
106107
},
107108
"peerDependencies": {
108-
"@fortawesome/fontawesome-svg-core": "^6.6.0",
109+
"@fortawesome/fontawesome-svg-core": "^6.6.0 || ^7.0.0",
109110
"@glimmer/component": ">= 1.1.2"
110111
},
111112
"publishConfig": {

ember-fontawesome/src/components/fa-icon.gts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { htmlSafe, type SafeString } from '@ember/template';
2020
import { getOwner } from '@ember/application';
2121
import { get } from '@ember/helper';
22+
import { dependencySatisfies, macroCondition } from '@embroider/macros';
2223

2324
function objectWithKey(
2425
key: string,
@@ -48,6 +49,7 @@ interface FaIconSignature {
4849
pull?: PullProp;
4950
transform?: Transform | string;
5051
symbol?: FaSymbol;
52+
// Note: Title is only supported for FA 5 + 6... for FA 7+ pass title as aria-label https://docs.fontawesome.com/upgrade/whats-changed#simpler-accessibility
5153
title?: string;
5254
mask?: IconName | IconLookup | IconDefinition;
5355
};
@@ -99,6 +101,18 @@ export default class FaIconComponent extends Component<FaIconSignature> {
99101
}
100102

101103
get abstractIcon(): AbstractElement | null {
104+
if (
105+
macroCondition(
106+
dependencySatisfies('@fortawesome/fontawesome-svg-core', '>=7.0.0'),
107+
)
108+
) {
109+
if (this.args.title !== undefined) {
110+
throw new Error(
111+
'@title has no effect in Font Awesome 7+. If you want to keep this behavior, use aria-label instead. For more details, see: https://docs.fontawesome.com/upgrade/whats-changed#simpler-accessibility',
112+
);
113+
}
114+
}
115+
102116
const iconLookup = this.normalizeIconArgs(this.args.icon, this.args.prefix);
103117
if (!iconLookup) {
104118
console.warn(
@@ -118,6 +132,7 @@ export default class FaIconComponent extends Component<FaIconSignature> {
118132
this.args.mask ? this.normalizeIconArgs(this.args.mask) : null,
119133
);
120134
const symbol = this.args.symbol ?? false;
135+
// Title is only supported for FA 5 + 6... for FA 7+ pass title as aria-label https://docs.fontawesome.com/upgrade/whats-changed#simpler-accessibility
121136
const title = this.args.title ? `${this.args.title}` : null;
122137

123138
const o = Object.assign({}, classes, transform, mask, {
@@ -200,14 +215,10 @@ export default class FaIconComponent extends Component<FaIconSignature> {
200215

201216
if (parse.icon) {
202217
if (typeof prefix === 'string' && typeof icon === 'string') {
203-
// Issue https://github.com/FortAwesome/Font-Awesome/issues/20231
204-
// @ts-expect-error Argument of type '{ prefix: IconPrefix; iconName: IconName; }' is not assignable to parameter of type 'string'.
205218
return parse.icon({ prefix: prefix, iconName: icon });
206219
}
207220

208221
if (typeof icon === 'string') {
209-
// Issue https://github.com/FortAwesome/Font-Awesome/issues/20231
210-
// @ts-expect-error Argument of type '{ prefix: IconPrefix; iconName: IconName; }' is not assignable to parameter of type 'string'.
211222
return parse.icon({ prefix: defaultPrefix, iconName: icon });
212223
}
213224
}

0 commit comments

Comments
 (0)