Fork me on GitHub
#shadow-cljs
<
2023-07-29
>
J16:07:55

Hi! It possible to use the css macro like this:

(defmacro defstyles [name & rules]
  (-> (apply hash-map rules)
      (update-vals (fn [rule] (css rule))))

thheller17:07:34

I assume you mean the shadow-css macro? then the answer is no

thheller17:07:06

what would be the intent there? don't quite understand what this would be supposed to do

J07:07:42

No problem. Just a convenient macro instead of:

(def styles
  {:foo/container (css {:color "red" :width "600px"})
   :baz/container (css {...})
Do this:
(defstyles styles
  :foo/container {:color "red" :width "600px"}
  :baz/container {...})

thheller07:07:48

well, you could do that with the macro. the issue is that the build tooling only currently detects (css ...) forms

thheller07:07:16

so you'd need to write your own to also recognize defstyles

thheller07:07:08

I do want to make that extensible at some point, just didn't spend any time thinking about it so far

thheller07:07:31

and you'd need to write the macro properly of course 😛

thheller07:07:25

(defmacro defstyles [name & rules]
  (-> (apply hash-map rules)
      (update-vals (fn [rule] `(shadow.css/css ~rule))))

thheller07:07:41

might be enough from the code side, but as I said the build side is the challenge

thheller07:07:50

but your syntax kinda falls apart if you want to use aliases

thheller07:07:09

(defstyles styles
  :foo/container :px-4 :flex
  :baz/container {...})

thheller07:07:29

doesn't work, so you'd need to introduce a vector or something

J07:07:16

Thanks for the detailed answer.