Skip to content

Commit dab68ff

Browse files
committed
[theme] Try describing the components which a part descends "from"
1 parent 58e905d commit dab68ff

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

demo/re_demo/alert_list.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
[p "For demonstration purposes, a 'dotted' " [:code ":border-style"] " is set."]
6363
[alert-list
6464
:src (at)
65+
:re-com {:from [:re-demo/alert-list]}
6566
:alerts alerts
6667
:on-close #(reset! alerts (remove-id-item % @alerts))
6768
:max-height "300px"

src/re_com/alert.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(:require-macros
33
[re-com.core :refer [at]])
44
(:require
5+
[re-com :as-alias rc]
56
[re-com.args :as args]
67
re-com.alert-box.theme
78
re-com.alert-list.theme
@@ -67,7 +68,7 @@
6768
:as props}]
6869
(or
6970
(validate-args-macro alert-box-args-desc props)
70-
(let [part (partial part/part part-structure props)
71+
(let [part (partial part/part part-structure (part/descend props ::rc/alert-box))
7172
heading? (part/get-part part-structure props ::ab/heading)
7273
body? (part/get-part part-structure props ::ab/body)
7374
re-com {:state {:alert-type alert-type
@@ -182,7 +183,7 @@
182183
(validate-args-macro alert-list-args-desc props)
183184
(let [alerts (deref-or-value alerts)
184185
theme (theme/comp pre-theme theme)
185-
part (partial part/part alert-list-part-structure props)
186+
part (partial part/part alert-list-part-structure (part/descend props ::rc/alert-list))
186187
re-com {:state {:max-height max-height
187188
:padding padding
188189
:border-style border-style

src/re_com/alert_box/theme.cljs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@
3333
(tu/class props "rc-alert-heading"))
3434

3535
(defmethod bootstrap ::ab/heading-wrapper
36-
[props]
37-
(tu/class props "rc-alert-h4"))
36+
[{{:keys [from]} :re-com :as props}]
37+
(cond-> props
38+
:do (tu/class "rc-alert-h4")
39+
(and (contains? (set from) :re-com/alert-list)
40+
(contains? (set from) :re-demo/alert-list))
41+
(tu/attr {:title (str "This tooltip only appears on an alert-box "
42+
"which descends from an alert-list!")})))
3843

3944
(defmethod base ::ab/body-wrapper
4045
[props]

src/re_com/part.cljs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,17 @@
149149

150150
(def hiccup? vector?)
151151

152+
(defn descend [props k]
153+
(update-in props [:re-com :from]
154+
(fnil conj []) k))
155+
152156
(defn part
153-
([structure props k opts]
157+
([structure {{:keys [from]} :re-com :as props} k opts]
154158
(part (get-part structure props k)
155-
(assoc opts :part k)))
156-
([part-value {:keys [impl key theme post-props props]
159+
(cond-> opts
160+
:do (assoc :part k)
161+
from (assoc :from from))))
162+
([part-value {:keys [impl key theme post-props props from]
157163
part-id :part
158164
:or {impl default}}]
159165
(->
@@ -167,6 +173,7 @@
167173
props
168174
(cond-> {:part part-id}
169175
:do (merge props)
176+
from (assoc-in [:re-com :from] from)
170177
theme (theme component)
171178
part-map (tu/merge-props part-map)
172179
post-props (tu/merge-props post-props))]

0 commit comments

Comments
 (0)