Skip to content

Commit

Permalink
Fix incorrect CSS rules nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
ggeoffrey committed Sep 4, 2024
1 parent 7858fcb commit da30cb3
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/hyperfiddle/electric_css3.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,9 @@
(str/replace-first selectorB "&" "")
(str " " selectorB))))))

(def scope "")

(defn scoped [scope selector]
(if-not (empty? scope)
(concat-selectors (str "." scope) selector)
selector))

(defmacro rule [selector & declarations]
(let [[selector declarations] (if (map? selector) ["&" (cons selector declarations)] [selector declarations])]
`(binding [selector (scoped scope (concat-selectors selector ~selector))]
`(binding [selector (concat-selectors selector ~selector)]
~@(map #(rule* `hyperfiddle.electric-dom3/node `selector %) (filter map? declarations))
~@(remove map? declarations))))

Expand Down Expand Up @@ -187,11 +180,14 @@
`(binding [hyperfiddle.electric-dom3/node (e/input (identity stylesheet<))]
~@body))

(defn scoped-class [] (munge (gensym "class_")))

(defmacro scoped-style [& body]
`(binding [hyperfiddle.electric-dom3/node (e/input (identity stylesheet<))
scope (str (munge (gensym "class_")))]
~@body
scope))
`(let [scope# (scoped-class)] ; TODO revisit if unique class should be generated at runtime or compile time
(binding [hyperfiddle.electric-dom3/node (e/input (identity stylesheet<))
selector (str "." scope#)]
~@body
scope#)))

(defn grid-template
"Convenient way to build a string compatible with CSS grid-template rule.
Expand Down

0 comments on commit da30cb3

Please sign in to comment.