Skip to content

Commit 775e620

Browse files
authored
Merge pull request #25 from lambdaisland/ox/resolve-components-as-selectors-inside-a-set
🐛 Resolve components inside set
2 parents c44ff75 + 2d09657 commit 775e620

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Unreleased
2+
3+
## Added
4+
5+
## Fixed
6+
7+
- Fix component resolution inside a set (in a rule of another component) (see tests for example)
8+
9+
## Changed
10+
111
# 1.11.101 (2023-09-13 / 213279d)
212

313
## Fixed
@@ -78,4 +88,4 @@
7888

7989
## Added
8090

81-
- Initial implementation
91+
- Initial implementation

src/lambdaisland/ornament.cljc

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,21 @@
603603
~(walk/postwalk
604604
(fn [o]
605605
(if (vector? o)
606-
(into [(if (and (symbol? (first o))
607-
(contains? @registry (qualify-sym &env (first o))))
608-
`(str "." (get-in @registry ['~(qualify-sym &env (first o)) :classname]))
609-
(first o))]
610-
(mapcat (fn [s]
611-
(if (and (symbol? s)
612-
(contains? @registry (qualify-sym &env s)))
613-
(get-in @registry [(qualify-sym &env s) :rules])
614-
[s])))
615-
(next o))
606+
(let [component->selector
607+
(fn [s]
608+
(if (and (symbol? s)
609+
(contains? @registry (qualify-sym &env s)))
610+
`(str "." (get-in @registry ['~(qualify-sym &env s) :classname]))
611+
s))]
612+
(into [(if (set? (first o))
613+
(into #{} (map component->selector (first o)))
614+
(component->selector (first o)))]
615+
(mapcat (fn [s]
616+
(if (and (symbol? s)
617+
(contains? @registry (qualify-sym &env s)))
618+
(get-in @registry [(qualify-sym &env s) :rules])
619+
[s])))
620+
(next o)))
616621
o))
617622
(vec
618623
(mapcat (fn [s]

test/lambdaisland/ornament_test.cljc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,31 @@
422422

423423
(reset! o/registry reg))))
424424

425+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426+
;; Component resolution
427+
428+
(o/defstyled child-1 :div
429+
:bg-red-100
430+
([]
431+
[:p "hello"]))
432+
433+
(o/defstyled child-2 :div
434+
:bg-blue-100
435+
([]
436+
[:p "world"]))
437+
438+
(o/defstyled parent-set :div
439+
[#{child-1 child-2} :bg-green-700]
440+
([]
441+
[:<>
442+
[child-1]
443+
[child-2]]))
444+
445+
#?(:clj
446+
(deftest component-resolution-inside-set
447+
(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))}"
448+
(o/css parent-set)))))
449+
425450
(comment
426451
(require 'kaocha.repl)
427452
(kaocha.repl/run)

0 commit comments

Comments
 (0)