thheller / shadow-css

CSS-in-CLJ(S)
https://github.com/thheller/shadow-css
Eclipse Public License 1.0
108 stars 10 forks source link

Static CSS injection #19

Closed raystubbs closed 11 months ago

raystubbs commented 11 months ago

It'd be awesome if we could re-use aliases when generating custom CSS. Any chance of supporting a macro like: (css-rule "custom selector" ...all the things) -> generated static CSS rule. The use case I have is for styling ::slotted targets from the shadow dom.

I have something like this:

[:style
"
::slotted([slot=\"my-thing\"]) {
  ...the rules...
}
"]
[:slot {:name \"my-thing\"}]

It would be sweet to be able to do:

[:style (css-rule "::slotted([slot=\"my-thing\"])" :flex :bg-yellow ...etc)]
[:slot {:name "my-thing"}]

As it stands, there's no easy way to borrow shadow-css aliases for stuff like this. It seems like having a catch-all for edgy cases like this might be a good idea.

thheller commented 11 months ago

My take is that you just use CSS, and let the build process include it. :shadow.css/include exists for that.

As done here:

You can just tell it to include any CSS file from the classpath, so like this file is just prepended as is into the output.

I'm not totally against creating global styles by some other way, but so far this has solved any need I had.

[:slot {:name "my-thing" :class (css ["&::slotted" :flex :bg-yellow)}] should also be fine?

thheller commented 11 months ago

Also note that the general idea for shadow-css is that elements style themselves. not others. So selectors like this likely will get you in trouble and create conflicting nightmares shadow-css was designed to prevent in the first place.

raystubbs commented 11 months ago

Wow, that include ability is cool. Didn't know about it. Yes something like what you mention above actually does generate the right CSS. The shadow root I was attaching it to didn't seem to like it though, so I'd started to wonder if ::slotted couldn't be nested under another selector... turns out the problem was something else entirely.

Anyway thanks for all the work you do on these projects man, they're really cool.

raystubbs commented 11 months ago

What do you think about allowing something like Tailwind's @apply in included CSS? Seems like it might be interesting to consider, would allow the styling setup for aliases to be re-used in custom CSS.

thheller commented 11 months ago

Currently out of scope. I simply don't want to maintain a CSS parser or anything that processes CSS in any way. Generating it is my limit for now.