question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why so explicit (the :icon="['far', 'coffee']" syntax)?

See original GitHub issue

I would like to suggest an improvement over the icon style (or understand why not). The way it currently works is very complicated (and ugly, visually).

The documentation explains some reasons why we can’t use some style with some syntaxes, but I believe the way below can solve the problem:

<font-awesome-icon icon="fas user" />

This syntax, when used, will throw an error:

- Could not find one or more icon(s) {prefix: 'fas', iconName: 'far user'} {}

If it’s for performance reasons (eg having to break the string into spaces, similar to using :icon="[ 'fas', 'user' ]"), I believe that the string break could only occur a moment before this error is thrown, as a fallback. Even so, if that’s really the case, breaking a string for space wouldn’t actually generate any kind of performance problem, I believe.

In my vision, some could be done at this part:

https://github.com/FortAwesome/vue-fontawesome/blob/6cbcf0c536396f7211edbcd6328931d85ec86873/src/components/FontAwesomeIcon.js#L29-L31

Something like:

  if (typeof icon === 'string') {
    const [ prefix, iconName ] = icon.split(/\s+/); 

    return iconName ? { prefix, iconName } : { prefix: 'fas', iconName: prefix }
  }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jasonlundiencommented, Jun 18, 2022

@christhofer

We added the string format ("fa-solid fa-user-secret") to the Vue 3 component mainly because our Vue 2 component allowed us to call icons that way, so seemed only natural and quite frankly not a huge fix.

Currently, the other ways in which you can add icons using a shortened syntax would be: <font-awesome-icon icon="fas fa-alien" size="5x"/> <font-awesome-icon :icon="['fas', 'alien']" size="3x"/>

We do not have the "fas user-secret" option at this time. Once the the Sharp family style has been released we can explore alternatives to calling the icons.

1reaction
jasonlundiencommented, Jun 17, 2022

Update:

We have released updated components for both Vue 2 and Vue 3. You can now use the array and/or the string format for either component.

String <font-awesome-icon icon="fa-solid fa-user-secret" />

Array <font-awesome-icon :icon="['fas', 'user-secret']" />

To get our official Vue 3.x component: $ npm i --save @fortawesome/vue-fontawesome@latest-3 ** the prerelease has been deprecated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue-fontawesome - JavaScript
Why so explicit (the :icon="['far', 'coffee']" syntax)? ... Explicit prefix (note the Vue bind shorthand because this uses an array).
Read more >
CoffeeScript, Why do I need the explicit return on a conditional
Show activity on this post. It's because CoffeeScript doesn't know, for sure, that the x if x == 0 || x == 1...
Read more >
CoffeeScript - Syntax - Tutorialspoint
In this chapter, let us check out the syntax of CoffeeScript. The syntax of CoffeeScript is more graceful when compared to the syntax...
Read more >
CoffeeScript
Transpilation. CoffeeScript 2 generates JavaScript that uses the latest, modern syntax. The runtime or browsers where you want your code to run might...
Read more >
The Little Book on CoffeeScript - The Bad Parts
First, let's talk about what things the language does solve. A JavaScript Subset. CoffeeScript's syntax only covers a subset of JavaScript's, the famous...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found