diff --git a/CHANGELOG.md b/CHANGELOG.md index 16bf040..00a9500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# Unreleased + +## Added + +## Fixed + +- Fix component resolution inside a set (in a rule of another component) (see tests for example) + +## Changed + # 1.11.101 (2023-09-13 / 213279d) ## Fixed @@ -78,4 +88,4 @@ ## Added -- Initial implementation \ No newline at end of file +- Initial implementation diff --git a/src/lambdaisland/ornament.cljc b/src/lambdaisland/ornament.cljc index d1d6848..10d665e 100644 --- a/src/lambdaisland/ornament.cljc +++ b/src/lambdaisland/ornament.cljc @@ -603,16 +603,21 @@ ~(walk/postwalk (fn [o] (if (vector? o) - (into [(if (and (symbol? (first o)) - (contains? @registry (qualify-sym &env (first o)))) - `(str "." (get-in @registry ['~(qualify-sym &env (first o)) :classname])) - (first o))] - (mapcat (fn [s] - (if (and (symbol? s) - (contains? @registry (qualify-sym &env s))) - (get-in @registry [(qualify-sym &env s) :rules]) - [s]))) - (next o)) + (let [component->selector + (fn [s] + (if (and (symbol? s) + (contains? @registry (qualify-sym &env s))) + `(str "." (get-in @registry ['~(qualify-sym &env s) :classname])) + s))] + (into [(if (set? (first o)) + (into #{} (map component->selector (first o))) + (component->selector (first o)))] + (mapcat (fn [s] + (if (and (symbol? s) + (contains? @registry (qualify-sym &env s))) + (get-in @registry [(qualify-sym &env s) :rules]) + [s]))) + (next o))) o)) (vec (mapcat (fn [s] diff --git a/test/lambdaisland/ornament_test.cljc b/test/lambdaisland/ornament_test.cljc index 3800365..8e2b04f 100644 --- a/test/lambdaisland/ornament_test.cljc +++ b/test/lambdaisland/ornament_test.cljc @@ -422,6 +422,31 @@ (reset! o/registry reg)))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Component resolution + +(o/defstyled child-1 :div + :bg-red-100 + ([] + [:p "hello"])) + +(o/defstyled child-2 :div + :bg-blue-100 + ([] + [:p "world"])) + +(o/defstyled parent-set :div + [#{child-1 child-2} :bg-green-700] + ([] + [:<> + [child-1] + [child-2]])) + +#?(:clj + (deftest component-resolution-inside-set + (is (= ".ot__parent_set .ot__child_2,.ot__parent_set .ot__child_1{--gi-bg-opacity:1;background-color:rgba(21,128,61,var(--gi-bg-opacity))}" + (o/css parent-set))))) + (comment (require 'kaocha.repl) (kaocha.repl/run)