The site would be much better if it loaded a sample SVG by default so I don't have to hunt down the source for an SVG that I have lying around (or on the internet).
React is such a nice way to make SVGs generally. My team was building a microservices to generate our dynamic images, then had the realization: our frontend is React, and we can make these images client-side as inline SVGs (or server side if we need using the same code).
There's some browser compatibility issues we have to stay on top of, but overall it's been a blast.
I just started doing this for a project at work. It works amazingly well. I ended building a react designer to handle loading and creating new elements so that we can create images on the web versus converting an existing SVG from an illistrator file.
For anyone who looked at the repository linked from the Heroku app and was confused as to how this works (or indeed the extent of what it does), the actual transformation is being done server-side, using this: https://github.com/balajmarius/svg-to-jsx/blob/master/index.... (from the same author).
It seems useful if you have an SVG that has been produced in a vector graphics editor that you want in a JSX format to make pieces interactive using React.
hey lucideer, I think it's usefull when you had to work with SVG sprites + React.
Converts the attributes not supported in React (xlink:href, fill-rule, etc.) to valid React attributes and also in case you have inline styles (eg. style="margin-left:20px") this tool will generate a Javascript object from that style ({marginLeft: 20}), which is valid React inline style.
Also, I think it's super usefull in case you had to use an inline SVG exported from Sketch or AI
Super useful if you need to inline some SVG in a react app. I recently learned about the benefits of inline SVG thanks to front-end center and started using similar to OP's tool for that.
I have not yet tried this OP's tool, but I've been using something similar (http://svg-jsx.patmoody.com/) and I'm very happy with the utility. Next time I need to inline SVG in react I will use this one.
Slight aside: what are the performance impacts here? I've been wondering for a while whether JSX is a little dangerous in that it makes repeated, huge, nested calls to React.createElement() look like plaintext.
For example, I could easily just run element.innerHTML = "<svg...>" to add SVG content to my page. If the SVG isn't being dynamically updated, doesn't making JSX like this incur a large and unnecessary overhead?
Is `xmlns` actually required? We've pulled it out of all of our React svg's and everything seems to work fine. Does anyone know of any quirks this could be causing?
You have to escape some portions, like CSS, (otherwise { and } will be interpreted as JS expression interpolation) remove xml namespaces, `class` also needs to be renamed to `className`, among other tweaks.
brettlangdon|8 years ago
desdiv|8 years ago
balajmarius|8 years ago
unknown|8 years ago
[deleted]
mabbo|8 years ago
There's some browser compatibility issues we have to stay on top of, but overall it's been a blast.
Prefinem|8 years ago
bshimmin|8 years ago
namuol|8 years ago
paol|8 years ago
lucideer|8 years ago
Particularly given it's a lossy transformation, I can't think of any situation where I'd use this.
jowiar|8 years ago
kennethkl|8 years ago
oh, noticed `0.5` turn into `.5` and `black` turn into `#000`. not sure how that will make it more JSX compatible
balajmarius|8 years ago
Converts the attributes not supported in React (xlink:href, fill-rule, etc.) to valid React attributes and also in case you have inline styles (eg. style="margin-left:20px") this tool will generate a Javascript object from that style ({marginLeft: 20}), which is valid React inline style.
Also, I think it's super usefull in case you had to use an inline SVG exported from Sketch or AI
armandososa|8 years ago
amk_|8 years ago
https://facebook.github.io/react/docs/dom-elements.html#all-...
Anything else needs to be stripped out - mostly stuff like meta data with ":" in the tag.armandososa|8 years ago
untog|8 years ago
For example, I could easily just run element.innerHTML = "<svg...>" to add SVG content to my page. If the SVG isn't being dynamically updated, doesn't making JSX like this incur a large and unnecessary overhead?
Rexxar|8 years ago
awinograd|8 years ago
balajmarius|8 years ago
devrelm|8 years ago
tomgp|8 years ago
barbuza|8 years ago
tonetheman|8 years ago
TheCoreh|8 years ago