Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font awesome icons in buefy

I'm trying to switch my project from bulma + jQuery to buefy. I load buefy, vue and font awesome from a cdn. ([email protected], [email protected], font awesome 5.2.0). The main problem I have with icons. My project uses font awesome icons. And default buefy iconPack is material design. It must support font awesome. I've tried to change the default icon pack, but that does nothing:

Vue.use(Buefy.default, {
    defaultIconPack: 'fas',
});

the same nothing:

Vue.use(Buefy, {
    defaultIconPack: 'fas',
});

So I need to point the iconpack explicitly for every icon.

The second problem is that even in this case buefy adds fa-lg that I don't need at all. For example for b-tab-item component

<b-tab-item label="Similarity" icon="search" icon-pack="fas"></b-tab-item>

It renders:

<i class="fas fa fa-search fa-lg"></i>

Is it possible to change this buefy behaviour?

like image 994
Роман Коптев Avatar asked Sep 24 '18 17:09

Роман Коптев


People also ask

How do I use icons in Font Awesome?

Font Awesome is designed to be used with inline elements. The <i> and <span> elements are widely used for icons. Also note that if you change the font-size or color of the icon's container, the icon changes.

Is buefy compatible with material design icons?

Buefy is compatible with both Material Design Icons , FontAwesome 4 and FontAwesome 5 but you can also add your custom icon pack. They adapt to most elements background automatically — but you can also override their colors. Using far or fad while having FontAwesome free tier might have missing icons.

What is Font Awesome?

Great for bold statements or small sizes. When a lighter touch is needed. Fits in with the latest super-light designs. Gives an illustrated feel or a pop of color. Not Sure Where to Start? Take a dive into the depths of Font Awesome with some popular searches. Font Awesome is the world's most popular icon set and toolkit.

Do I need to download or install Font Awesome?

Note: No downloading or installation is required! You place Font Awesome icons by using the prefix fa and the icon's name.


2 Answers

to anyone that may still struggle with this. my problems was solved by using this in my main.js:

import Buefy from 'buefy'
import 'buefy/dist/buefy.css'

import { library } from '@fortawesome/fontawesome-svg-core';
// internal icons
import { fas } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";

library.add(fas);
Vue.component('vue-fontawesome', FontAwesomeIcon);


Vue.use(Buefy, {
  defaultIconComponent: "vue-fontawesome",
  defaultIconPack: "fas",
  customIconPacks: {
    fas: {
      sizes: {
        default: "lg",
        "is-small": "1x",
        "is-medium": "2x",
        "is-large": "3x"
      },
      iconPrefix: ""
    }
  }
});

make sure to install all the dependencies using npm:

$ npm i --save @fortawesome/fontawesome-svg-core
$ npm i --save @fortawesome/free-solid-svg-icons
$ npm i --save @fortawesome/vue-fontawesome

then you can use it in your components as follows:

<b-icon
  pack="fas"
  icon="user"
  size="is-large"
  type="is-success"></b-icon>
like image 166
Moher Avatar answered Oct 06 '22 18:10

Moher


This is working code for me in buefy

in main.js

import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'

library.add(fas)
Vue.component('font-awesome-icon', FontAwesomeIcon)
Vue.use(Buefy, { defaultIconPack: 'fas' })

and in index.html

place in head tag

<link
      rel="stylesheet"
      href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
      integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/"
      crossorigin="anonymous"
    />

make sure first off you add the fortawesome npm package

like image 23
Amir Khadem Avatar answered Oct 06 '22 19:10

Amir Khadem