Skip to content

Commit

Permalink
Fix support for complex defkeyframes in the latest garden version
Browse files Browse the repository at this point in the history
  • Loading branch information
dhleong committed Nov 1, 2024
1 parent cfa5241 commit f82b772
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/spade/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#?@(:clj [[garden.stylesheet]
[net.cgrand.macrovich :as macros]
[spade.runtime]])
[spade.util :refer [factory->name build-style-name]]))
[spade.util :refer [factory->name build-style-name
unpack-keyframes-nesting]]))

(defn- extract-key [style]
(:key (meta (first style))))
Expand Down Expand Up @@ -169,10 +170,16 @@
style params style-name-var)
info-map (cond->
`{:css (when ~name-var
(spade.runtime/compile-css
(garden.stylesheet/at-keyframes
~name-var
~(or base-style-var (vec style)))))
~(if base-style-var
`(spade.runtime/compile-css
(apply garden.stylesheet/at-keyframes
~name-var
(#'unpack-keyframes-nesting ~base-style-var)))
`(spade.runtime/compile-css
(garden.stylesheet/at-keyframes
~name-var
~@style))))
:style ~(str (vec style))
:name ~name-var}

key-var (assoc ::key key-var))]
Expand Down
15 changes: 15 additions & 0 deletions src/spade/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@

; easiest case: no key is necessary
:else base))

(defn unpack-keyframes-nesting
"In the latest versions of garden, using [:&] to return multiple
style rules from within a conditional or other structure like
`(let)` in an `(at-keyframes)` structure keeps that `&` in the
output CSS. This function 'unpacks' such structures so the compiled CSS is clean."
[style-rules]
(mapcat
(fn maybe-unpack-keyframes-nesting [style-rule]
(if (and (vector? style-rule)
(= :& (first style-rule)))
(next style-rule)
[style-rule]))
style-rules))

0 comments on commit f82b772

Please sign in to comment.