Skip to content

Commit

Permalink
Merge pull request #25 from lambdaisland/ox/resolve-components-as-sel…
Browse files Browse the repository at this point in the history
…ectors-inside-a-set

🐛 Resolve components inside set
  • Loading branch information
plexus authored Sep 27, 2023
2 parents c44ff75 + 2d09657 commit 775e620
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -78,4 +88,4 @@

## Added

- Initial implementation
- Initial implementation
25 changes: 15 additions & 10 deletions src/lambdaisland/ornament.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 25 additions & 0 deletions test/lambdaisland/ornament_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 775e620

Please sign in to comment.