Skip to content

Commit

Permalink
[css] support for keywords as css values
Browse files Browse the repository at this point in the history
e.g. {:background-color :red}
  • Loading branch information
ggeoffrey committed Aug 23, 2024
1 parent abd55dc commit ab4fc2a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/hyperfiddle/electric_css3.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
(set-property [this key value]))

(defn to-str [x] ((if (keyword? x) name str) x))
(defn css-compatible-value [x] (if (keyword? x) (name x) x))

#?(:cljs
(extend-protocol StyleRule
Expand All @@ -87,7 +88,8 @@
(set-property [^js this key value] (set-property (.-style this) key value))
js/CSSStyleDeclaration
(set-property [^js this key value]
(let [key (to-str key)]
(let [key (to-str key)
value (css-compatible-value value)]
(if (str/starts-with? key "--") ; CSS variable
(.setProperty this key value)
(when-some [property (goog.style/getVendorJsStyleName_ js/document.body key)] ; normalize property names
Expand Down

0 comments on commit ab4fc2a

Please sign in to comment.