Skip to content

Commit af9acd3

Browse files
committed
Support returning a render function from defstyled
As seen with reagent form-2 components.
1 parent 3e58eea commit af9acd3

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Unreleased
22

3-
## Added
4-
53
## Fixed
64

7-
## Changed
5+
- Support using `defstyled` components as reagent form-2 components
86

97
# 0.9.87 (2023-04-15 / dac82f4)
108

@@ -74,4 +72,4 @@
7472

7573
## Added
7674

77-
- Initial implementation
75+
- Initial implementation

src/lambdaisland/ornament.cljc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,11 @@
420420
attributes passed in via the `::attrs` property."
421421
[tag css-class args component]
422422
(if component
423-
(expand-hiccup-tag-simple tag css-class (apply component args) (::attrs (first args)))
423+
(let [result (apply component args)]
424+
(if (fn? result)
425+
(fn [& args]
426+
(expand-hiccup-tag-simple tag css-class (apply result args) (::attrs (first args))))
427+
(expand-hiccup-tag-simple tag css-class result (::attrs (first args)))))
424428
(expand-hiccup-tag-simple tag css-class (seq args) nil)))
425429

426430
(defn styled

test/lambdaisland/ornament_test.cljc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@
131131
:color "#cff9cf"
132132
:text-decoration "underline"})
133133

134+
(o/defstyled form-2 :div
135+
([a]
136+
(fn [b]
137+
[:<> "hello"])))
138+
139+
134140
#?(:clj
135141
(deftest css-test
136142
(is (= ".ot__simple{color:#fff}"
@@ -248,6 +254,8 @@
248254
[:a] [:a] [:a] [:a] [:a] [:a] [:a] [:a] [:a] [:a] [:a]
249255
[:a] [:a] [:a] [:a]]
250256
"<span class=\"ot__simple\"><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a></span>"
257+
[(form-2 7) {::o/attrs {:data-a 11}}]
258+
"<div data-a=\"11\" class=\"ot-form-2\">hello</div>"
251259

252260
))
253261

0 commit comments

Comments
 (0)