Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Resolve components inside set #25

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading