-
Notifications
You must be signed in to change notification settings - Fork 272
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
Get viewBox for SVG tag #32
Comments
@elado I can preserve |
@kisenka I don't think that helps. Seems like I currently solved this with another weird loader I created as a local module: module.exports = function (source) {
this.cacheable()
var m = source.match(/<svg[\s\S]+?viewBox="(.+?)"[\s\S]+?>/)
return `module.exports = ${JSON.stringify(m ? m[1] : null)}`
} and in my <svg viewBox={require(`!svg-viewbox-loader!path/to/icon.svg`)} ...>
<use xlinkHref={require(`path/to/icon.svg`)} />
</svg> |
@elado I think that conceptually it must be something like this: <svg viewBox={require(`path/to/icon.svg`).viewBox} ...>
<use xlinkHref={require(`path/to/icon.svg`).xlinkHref} />
</svg> Such loader API will be convenient what you think? |
I think it'll be a great addition to this loader. It can output an object if some param in the loader query is present (for backwards compatibility) |
If you have an es6 version, you can output the xlinkHref as default and the viewBox in a separate export. Automatic backwards compatibility. |
I think https://github.com/kisenka/svg-sprite-loader/blob/master/lib/svg-document.js needs to implement a getViewbox which gets it from cheerio either directly or via width/height, and then this gets passed to |
+1 |
1 similar comment
+1 |
Published my workaround - https://github.com/elado/svg-viewbox-loader |
Hey guys [email protected] with new runtime module is on the way, please read about it here #91 and take part in discussion/voting. |
Now it's possible to get viewBox of the symbol, see new version readme. |
It seems (and I might be wrong) that SVG requires either specific
width
andheight
orviewBox
and a single dimension to scale properly and preserve ratio.Here's a a demo with code that's similar to what this loader generates:
http://codepen.io/elado/pen/GZdJZG?editors=1100
If no dimension or viewBox supplied, SVG defaults to 300x150 which is a browser default.
In the demo, the ones without the
viewBox
and onlyheight
get the 300px width.Even though
viewBox
is defined on the<symbol>
, the<svg><use ...>
that will contain it won't grab it.Is there a way to somehow import the
viewBox
to the SVG, or another workaround?The text was updated successfully, but these errors were encountered: