-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why so explicit (the :icon="['far', 'coffee']" syntax)? #347
Comments
Isn't it For me it's working with |
@angelhdzmultimedia
See documentation I've created pull request #243 to allow us change the default, but unfortunately it gets closed. |
I'm a bit lost. Are you trying to use reactive :icon? Or you can just use a normal icon attribute with a string? |
I think what you need is mask: |
@angelhdzmultimedia Just read the documentation. I'm not the one that create this "ugly" syntax. I'm using pro license, so I can't just use I haven't tried your way My pull request was to allow us change the default. |
Also, you can made a custom component that wraps FontAwesomeIcon, then you can pass icon="fas fa-user-secret", and then you split that string inside your component, to an array, and pass that array to . |
FaIcon.vue: <template>
<FontAwesomeIcon :icon="_icon"></FontAwesomeIcon>
</template>
<script lang="ts">
export default {
name: 'FaIcon',
inheritAttrs: false,
customOptions: {},
}
</script>
<script setup lang="ts">
import { toRefs, useAttrs, ref } from 'vue'
const {icon} = useAttrs()
const _icon = ref(String(icon).split(' '))
</script>
<style>
</style> App.vue: <template>
<FaIcon icon="fas eye"></FaIcon>
</template>
<script setup lang="ts">
import FaIcon from './components/FaIcon.vue'
</script> You can use this solution while they add I read that version 6 releases this month... |
Sorry for the late reply. The import { library } from '@fortawesome/fontawesome-svg-core';
library.add(
require('@fortawesome/pro-solid-svg-icons/faUser').definition,
require('@fortawesome/pro-regular-svg-icons/faUser').definition
); If I have two different styles for the same icon, I need to use an "ugly" syntax, even if the icon is not reactive -- like most cases I intend to use. Like: Thus, my suggestion is to allow that instead of an I'm not the best person to do a PR with this change, but from what I've been investigating the change should occur in this file or deeper, in @fortawesome/fontawesome-svg-core. |
Hello, no worries for the delay. I finally understood your issue, and confirmed it. The documentation says explicitly that we can easily use This should be submitted as a BUG and not as a FEATURE REQUEST I think. |
@angelhdzmultimedia In fact, the <font-awesome-icon icon="fa-regular fa-file-chart-pie" /> The style is wrong (must be But regardless of the site's error (which would be nice to fix, in fact), the most important thing would be to make <font-awesome-icon icon="far file-chart-pie" /> And not like (the confusing...): <font-awesome-icon :icon="[ 'far', 'file-chart-pie' ]" /> |
Yeah. Completely agree. Don't know how they could miss something important like this. Not everyone want to pass the icons names dynamically... In the meantime, you can put those in a reactive object as part of the component's state: <button :style="styles.openDialogButton.style">
<font-awesome-icon :style="styles.openDialogButton.icon.style" :icon="styles.openDialogButton.icon.name" />
<span>{{ styles.openDialogButton.text }}</span>
</button>
const styles= reactive({
openDialogButton: {
icon: {
style: {
color: 'white'
},
name: [ 'far', 'file-chart-pie' ]
},
text: 'Open Chart',
style: {
background: 'primary'
}
}
}); Or even store it in a state management store like Pinia, instead of hardcoding everything. Wish you success and health! |
Being able to specify an icon using This component (vue-fontawesome) uses the new First up, @rentalhost can you tell me what version of @fortwesome/fontawesome-svg-core you are using? And have you added the icons you are trying to use to the library? |
@robmadole yes, that is my "devDependencies": {
"@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/vue-fontawesome": "^3.0.0-5",
// [...]
} I am using import { library } from '@fortawesome/fontawesome-svg-core';
library.add(
require('@fortawesome/pro-solid-svg-icons/faUser').definition,
require('@fortawesome/pro-regular-svg-icons/faUser').definition,
); As for the ability to use I've been looking at two pieces of code:
So what I can see is that the |
Ok, we'll need to get the Vue 3 version of this library updated to support v6. Thanks for the clarification. |
Just wanted to give an update: Using Vue 2.x you can add icons using the string format and/or the array format: Using Vue 3.x currently you can only add icons using the array syntax: Our next release will allow you to use either (or both) in our Vue 3.x package. |
Thank you for that update. And when is that next release expected to be available? |
@jasonlundien I'd like to be able to set the default icon style. Or even better if we can just write |
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 Array To get our official Vue 3.x component: |
@jasonlundien Is there a reason why we need to type the whole string |
We added the string format ( Currently, the other ways in which you can add icons using a shortened syntax would be: We do not have the |
I wanted to follow up by suggesting another option we have with setting the default style. In your So your
You could then call the "duotone" icons, in this example, by: You would still need to call the other icons (that are NOT the default style) by using either the
So we have a few options in which icons can be called . With that said, I am going to go ahead and close this issue "Why so explicit". |
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:
This syntax, when used, will throw an error:
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:
vue-fontawesome/src/components/FontAwesomeIcon.js
Lines 29 to 31 in 6cbcf0c
Something like:
The text was updated successfully, but these errors were encountered: