Did anyone find an easy way to add an inline SVG t...
# javascript
m
Did anyone find an easy way to add an inline SVG to Kotlin React?
t
As string?
a
b
Is This easy enough?
a
It's not react πŸ€·β€β™‚οΈ
b
Had that in React as well
The concept is the same
m
No, I do need an SVG element.
b
Well webpack only loads a svg url for you. You can use it as you want from there
Or do you mean declaring svg in kotlin with no backing .svg file?
m
So how do I get the SVG file into the SVG tag? The SVG tag seems to have no useful functions in Kotlin React
b
Can't you just use img tag and pass svg url into src?
a
There is answer to that in SO question I've posted earlier
πŸ‘† 1
m
@Big Chungus No, you can't apply CSS to SVGs in an IMG
b
Ah, good point. Then add your attrs/child tags as customs. Kotlunx.html allows for arbitrary dom trees
m
@altavir Yeah, I'm afraid I have to manually convert every single SVG into Kotlin, element by element and attribute by attribute πŸ˜”
b
Shouldn't be too hard writing your own kotlinx.html extensions for most common attrs or children to tidy things up a bit
m
Maybe we need .ktx files at some point like jsx/tsx 😁
b
Not sure how that'd help?
m
You can just paste SVG markup into Kotlin code and it works just fine πŸ€”
b
Ah, you mean webpack jsx plugin for kotlin
Yeah, I see it being useful for migrations
m
It's useful for putting any markup into your project that's not supposed to be changed a lot anyway. Like SVGs, embeds or whatever.
So you don't have to convert it to Kotlin
And can also copy it out of the Kotlin project again and even put it in an SVG file
b
Could probably be achieved with kotlin compiler plugin or annotation processors
It's a matter of parsing html and generating kreact code
m
AP won't work. Compiler plugin probably neither. Afaik compiler plugins are not allowed to add new syntax. Maybe disguised as a multi-line string, but I'd consider that a workaround
b
Then some separate tool to parse ktx and generate kt files
The main problem is how to keep kt interop in kts itself
m
That would need additional IDE and tooling support and a lot of work
b
Noone is saying it's supposed to be easy πŸ˜€
πŸ˜„ 1
For MVP just being able to drop HTML snippets in ktx file and have kreact components generated would be useful enough. Then you don't need any more tooling, just register ktx files as html files in intellij
m
I think in that case an IDE plugin would make more sense
Like pasted Java code is automatically converted to Kotlin
πŸ‘ 1
b
Agreed. Now we only need to find someone that knows how to write IDEA plugins πŸ˜€
c
You can update SVG if you load it as an object instead of img. However it seems on Mobile Safari those changes don't always take effect.
m
I didn't know that object is still a thing πŸ˜… But good idea. I'd have to check browser support first.
l
The folks at #data2viz made a kotlinx.html converter that takes html code (including svg I assume) while you paste it in Kotlin code, and paste it as kotlinx.html code. Like when pasting Java code. Does it work for you @Marc Knaup?
πŸŽ‰ 1
139 Views