I just added a new page toolbar button, using an SVG from Bootstrap Icons. It looks nice but I’d really like to get it to go light or dark gray depending on hover, like the other toolbar icons. Is there something I need to do to the SVG to make this happen? To the button widget?
Have you tried to mimic, say, $:/core/ui/Buttons/new-tiddler to replicate the implementation? I would assume that if you did so, you would end up with the same behavior… although perhaps you’d also have to add the class tc-image-button to the SVG, as in $:/core/images/new-button.
The crux here is that SVG images come in two forms:
Ordinary SVG images that are embedded in HTML with the img tag. They are “replaced content” in HTML terms, which means that the display of the image is not affected by styles set in the containing document
Inline SVG images are fragments of SVG embedded directly in HTML, with no img tag needed. The advantage of inline SVGs is that they are affected by document styles
There’s not much documentation on the web about inline SVGs. This blogpost covers some of the details.
In general, there is no reliable way to automatically convert an ordinary SVG image into an inline SVG image because there are many features that can be used in SVG images that can’t be represented in an inline SVG (for example, filters, custom fill patterns or any feature that requires use of an id attribute).
The process I use is as follows, but these steps don’t capture the trickiest part, which is understanding which SVG features cannot be used in this context.
Prepare the image in a vector editor, using only the colour #000 (ie black)
I think you forgot to convert lines to outlines, so they can be filled. IMO that’s the part most users don’t understand, that all TW icons are outline based, so they can be filled.
<svg xmlns="http://www.w3.org/2000/svg" width="210" height="297">
<path d="M181.103 4.734a66.257 2.753-19.797 2.621-44.094 [... big pile of numbers snipped for brevity... it's just one path, that's all it is.. ] 88-2.076-5.101-2.136a3.204 3.204 0 0 0-.353-.01z" />
</svg>
I snipped the fill style out of it, and a stroke-width style.
I’m not sure what’s left to simplify…unless there’s something about that path that’s not cricket. (I could paste the whole path if that’s helpful)
That’s right. Using the SVG type causes tiddlers to be displayed with the HTML <img> tag. With inline SVGs we need the SVG elements to be transcluded directly.