I want to add a conditional !important string to a definition without having to duplicate the lines… The closest I’ve come so far is this:
fontSize(size, isImportant = false)
importantString=""
if isImportant
importantString = !important
font-size unit(size, 'px') importantString
font-size unit(size / 10, 'rem') importantString
which doesn’t work because importantString="" actually inserts "", and removing the assignment actually prints importantString if it isn’t defined.
The best way would be something like:
font-size unit(size, 'px') if isImportant !important
But I guess that’s not possible.
Answering your question — you can just use
unquote()around the quotes forimportantString, so it would output to nothing if there is noimportant.That would look like this:
However! if you’d ask me, I’d recommend to make something different — make a transparent mixin for
font-sizelike this:That mixin could be used transparently as you could use the generic
font-size. Even more, there are two ways to use it:You can use
remunit there, that would be translated to pixels in a fallback, or use unitless number, that would be translated as you wanted it to be in your question. And the importance would be preserved and you’d even have a way to declare how much pixels are there in oneremusing$rem_ratiovariable.Enjoy!