Better syntax and multiplexing
yisibl opened this issue ยท 18 comments
We can define a @svg
name
@svg 1px-border {
width: 100%;
height: 1px;
rect {
fill: #c8c7cc;
x: 0;
y: 0;
w: 100%;
height: 0.5;
}
}
@svg others { }
Use svg()
:
.bar {
background-image: svg(1px-border);
}
.baz {
border-image: svg(1px-border) 2 stretch;
}
Output:
.bar {
background-image: url('data:image/svg+xml;charset=utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="1"><rect fill="#c8c7cc" x="0" y="0" width="100%" height="0.5"/></svg>');
}
.baz {
border-image: url('data:image/svg+xml;charset=utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="1"><rect fill="#c8c7cc" x="0" y="0" width="100%" height="0.5"/></svg>') 2 stretch;
}
We can use in different properties. Not only in background-image
.
This is like Sass @function
@function svg() {
@return ...;
}
mixin?
O~ It's function
.
I think this is a great idea.
@tabatkins What do you think?
I had the @svg idea some time ago, and it's one of the motivating examples for custom at-rules. I strongly agree with the suggested changes here. In particular, the original proposal assuming that an svg would always and only be the sole background image in an element is not very useful; it shuts down a lot of other great usages, like multiple backgrounds, list bullets, and reusing the same SVG in several rules.
The only thing I don't like about this suggested syntax is the intermingling of properties and qualified rules; that's grammatically ambiguous, and wouldn't fly in normal CSS. I suggest making the nested elements with further at-rules, like @rect
.
Other than that, thumbs up, this matches my intent well and has a better syntax (expressing all attributes as properties, so you don't have to distinguish between presentation attributes and normal CSS properties) than I was coming up with.
Thanks, @tabatkins and @yisibl . The next release will follow these parameters. One thing that @yisibl and I chatted about was how the current version acts like an echo, whereas the next version should work more like @counter-style
. Which leaves me with these questions:
- @svg generate a keyword like
@counter-style
does, or should the name only be reference-able in ansvg()
function as this issue suggests? - If the new version uses an
svg()
function, should that function accept additional parameters to controlfill
, etc?
@tabatkins Thank you very much for your reply.
About 2, you meaning like this? https://github.com/pascalduez/SassySVG#api
svg-update($svg, circle, (fill: white));
@svg generate a keyword like @counter-style does, or should the name only be reference-able in an svg() function as this issue suggests?
Better to have a dedicated function. @counter-style was trying to "explain" counter styles, and so it merged in with other counter styles. In hindsight, that was a bit troublesome and possibly should have worked differently, but in any case it's limited to a single very locked-down property. Images aren't like that, they need to be namespaced properly.
If the new version uses an svg() function, should that function accept additional parameters to control fill, etc?
That seems hard to do in a generic way. However, it would be great to align with the proposal draft I sent out yesterday for SVG Parameters - let the svg() function accept param() functions like url() does. If you're only passing "real" values (or var() values that PostCSS can recognize and handle), you can just do a rewrite as you generate the SVG.
Is anyone working on this? Is there anything I can do to help with this issue?
I am working on it this weekend, yes.
@jonathantneal amazing! Happy to test / help out. Really want to use this feature in a project I'm working on.
@jonathantneal ๐
WooOO! ๐ ๐
The new syntax is live! Thank you, everyone.
WooOO! ๐ฏ