-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Proposal] SVG icon #2494
Comments
I also require custom svg in many cases Quasar offers the Eg. |
Nowadays its pretty simple to create your own symbol font (like font awesome). You can always use https://icomoon.io (for example) to create a symbol set that you can reference in your quasar just like any of the material icons. |
Henrique if this is true i’d love to try it out and write some guide on this for the quasar docs. For the time being can you point me in the direction to start doing this? Any blog post or guide you can recommend? |
I beautiful solution would be to allow to pass a path to the svg icon in the assets folder. <q-btn icon="~/svg/myCustomIcon.svg" /> What do you think? |
I think solution to use SVG icon may be like this:
As I can see, this solution allow to use SVG inline or by link ( |
@HenriqueSPin |
It's really a simple and straight forward process. All you have to do is start a new project in IcoMoon App (https://icomoon.io/app/), upload your own SVGs or use icons from the free IcoMoon catalog to compose your very own set. After this, you only have to export by click in "generate font". In the next screen you can customize the name of your glyphs (CSS class names) and download it. Now, in your project, unzip the folder into your fonts/assets folder and import the file into your stylus/css main (may be another css/styl file, like fonts.styl, as long as it is imported somewhere in your project). Now you are able to use the names of your glyphs as a icon. Jus like this PLUS: The files exported by IconMoon contains a .json with all your glyphs and sets that you can import anytime in the IcoMoon App and add/remove/edit glyphs or sets to the font. |
I like using SVG because it so much featured than font. In SVG you can have mapping and gradient, css transformations... I achieve using some SVG icons in quasar components by doing like that : /* CSS File */
.icon-svg:before{
content : url("path/to/file.svg");
} <!-- in template.vue -->
<q-btn @click="clikc" icon="icon-svg" /> But I can't influence currentColor in such case. I mean if I wan't to themify my app I have too supply all needed SVG coloured files and to do some tricky template tests. With the |
I've found this tricky way : <q-btn @click="home" >
<q-icon v-html="$options.filters.svg('home')" ></q-icon>
</q-btn> Vue.filter("svg", function (code, options) {
options=Object.assign({
width : 20,
height : 26,
"class" : "svg-icon"
}, options );
return `<svg viewBox="0 0 65 65" height="${options.height}px" width="${options.height}px" class="${options.class}"><use xlink:href="#svg-icon-${code}" /></svg>`;
}); With this method I can adapt my svg icon through CSS properties. |
@amfine-soft-scheminel - that is really freaking clever. |
I would love to use svg icons in all places (like For this to work, QIcon must be modified. Would you accept a PR on a working solution ? |
I just wanted to bump this thread since it's 2019 and V1 is released. Anywhere in Quasar I can use Eg. when the name passed in |
I have a very ugly override on QIcon, for quasar 0.17. It lets me use things as I had to update the webpack config also so an SVG file could be integrated (in // ...
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
module.exports = function (ctx) {
return {
//...
build: {
//...
chainWebpack (chain) {
// Remove icon path from Quasar's svg loader
chain.module.rule('images')
.exclude
.add(/src\/icons\/.*\.svg$/)
.end()
chain.module.rule('svg-sprite')
.test(/src\/icons\/.*\.svg$/)
.use('svg-sprite')
.loader('svg-sprite-loader')
.options({
extract: true,
spriteFilename: './dist/icons.svg',
})
chain.module.rule('svg-sprite')
.test(/src\/icons\/.*\.svg$/)
.use('svgo')
.loader('svgo-loader')
.options({
plugins: [
{
removeUselessStrokeAndFill: {
fill: true,
stroke: true,
},
},
],
})
chain.plugin('svg-sprite')
.use(SpriteLoaderPlugin, [{plainSprite: true}])
// Override QIcon
chain.plugin('override-q-icon')
.use(webpack.NormalModuleReplacementPlugin, [
/QIcon\.js$/,
(resource) => {
resource.request = path.resolve(__dirname, './src/override/QIcon.js')
}
])
},
//... I'll have to make it work for v1, but without answer from the quasar team, I'll probably do another ugly workaround in my corner. |
That is a bit ugly, I agree - there should be a way to do this natively without having to patch together an SVG loader. |
Actually having the SVG loader does seems normal to me. IMO, what's ugly here is overriding QIcon. |
Will be available in beta.12. QIcon <q-icon name="img:https://cdn.quasar-framework.org/logo/svg/quasar-logo.svg" />
<q-btn icon="img:https://cdn.quasar-framework.org/logo/svg/quasar-logo.svg" ... />
<q-icon name="img:statics/my/path/to/some.svg" /> This is not restricted to SVG only. You can use whatever image type you want (png, jpg, ...): <q-icon name="img:statics/bla/bla/my.png" />
<q-btn icon="img:statics/bla/bla/my.jpg" ... />
<q-input clearable clear-icon="img:statics/bla/bla/my.gif" ... /> |
Woooow this is soooo great. I have like three pre-v1 apps with hoops and loops to do this. Now it all works out of the box!!! 😍 Thank you so much for your time and effort. |
Is it possible to add it also for "q-expansion-item" and "q-tab" ? I'm just using it :) thanks you :D |
@scwall It will be available for ALL components that have icon-related props. So this also includes QExpansionItem and QTab. |
Perfect! |
Nice, but I suppose it won't be possible to use SVG sprites, with a <svg>
<use xlink:href="..."></use>
</svg> |
@drasill As per MDN docs,
|
@rstoenescu Could quasar add support for something like https://github.com/iconfu/svg-inject/ natively inside all components that utilize icons? For example, there's a Instead, would be cool to have
|
@iMakedonsky I'm using my own "MyIcon" wrapper in most projects that use If Quasar could natively support the possibility to inline SVGs any place it uses an However, maybe in this closed thread your suggestion might get lost. Maybe you could open a new feature request issue and link this thread? |
@rstoenescu |
RFC to watch: #6027 |
Hi!
Is it possible to support SVG icon (with
svg
tag) instead of icon font?For example, FontAwesome offer svg files for each icon, so if I use only several item of collection it would be optimal to place only needed icon inline in page template.
Thanks!
The text was updated successfully, but these errors were encountered: