No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Using a custom icon font (Fontello, Flaticons, etc)

    Show & Tell
    custom font icon
    3
    4
    944
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      terrybradshaw last edited by

      (I’m writing this while 1.0 is in beta, however, neither the current docs for 0.17+ nor 1.0+ appear to support custom font sets.)

      Using Fontello, for example:

      • Select the Fontello icons you want, then in Settings, use a unique CSS prefix (for example, abc-), then name and download your font package as a ZIP.
      • Create a new folder inside /quasar/node_modules/quasar-extras for your custom font
      • Inside the new folder, copy the base CSS file from the ZIP download
      • Also inside the new folder, copy the font folder from the ZIP, including the folder contents
        • Note: Fontello’s CSS puts the CSS in its own subfolder, whereas we have put the CSS in the base folder, which is required by Quasar (because of css-loader module). This means we will need to slightly edit the CSS file so the path for the font files start with ./font instead of ../font Keep in mind if you add new icons and re-download the ZIP, you’ll have to re-edit the new CSS file
      • In the quasar-extras folder, copy the ionicons.js file, rename it for your custom font, and edit the file so it points to your new CSS file
      • In quasar.conf.js , add your font in the extras section
      • Final step - however, this edit is likely to be overwritten any time you upgrade Quasar, so it will likely have to be repeated later. Check your custom fonts any time you upgrade. Edit the file /quasar/node_modules/quasar-framework/src/components/icon/QIcon.js. Line 18 (on 0.17+) includes the code || icon.startsWith('icon-'). Copy this and paste it right after itself, except change icon- to the custom prefix you set in Fontello. So now the line contains || icon.startsWith('icon-') || icon.startsWith('abc-')
        • Basically, you are telling Quasar not to mess with the class of the icon, not to assume it is part of a different icon set.

      Now, you should be able to use <q-icon> tags or icon="" attributes inside Quasar components with your own font icons!

      Because you have to edit the source code of QIcon.js, this is hacky and not stable. If I could make a request/recommendation, I would like to see the ability to define a list of icon prefixes which Quasar would know not to change (currently, an unrecognized or unprefixed icon name is assumed to be from the Material Icon set). Something like { custom: ['abc-' , 'myicons-' , 'app-'] } in the extras section of quasar.conf.js.

      1 Reply Last reply Reply Quote 0
      • nothingismagick
        nothingismagick last edited by

        tl;dr; Please don’t do this!

        @terrybradshaw - this is not just “hacky and not stable”, it is really bad practice and definitely NOT something that the core team recommends. Tampering with quasar breaks the contract of the code - and I am already having a stomach ache because I am sure someone will try the things you just suggested, it will break and then they’ll be visiting the quasar discord with their “problem”.

        What are the “right” ways to do this?

        • Make a PR with your custom icon font and share your work with the community.
        • Make a webpack loader (probably too complex)
        • Create a custom “app-extension” (how-to forthcoming)
        1 Reply Last reply Reply Quote 1
        • T
          terrybradshaw last edited by

          Sorry for the late response. Quasar is a great project and I certainly don’t mean to violate the wishes of the core project team. But, as far as I can tell, there is no supported way to use a font created with Fontello, and the project I’m working on needed some icons that weren’t part of the supported sets.

          I did suggest a fix for future development (defining custom font prefixes in quasar.conf.js), but given that we are presently right between 0.17 and 1.0 beta I am not comfortable creating a PR because I don’t want to break backwards compatibility, nor do I want to introduce new features during a beta/RC phase. Or when the app-extension docs are available, I can look into that.

          1 Reply Last reply Reply Quote 0
          • D
            dteurope last edited by

            @terrybradshaw: Did you opened a PR or Feature Request for this issue? It would be awesome to get custom fonts into Quasar. We are at version 1.2.6 now. 🙂

            1 Reply Last reply Reply Quote 0
            • First post
              Last post