Skip to content

Commit f475a88

Browse files
author
kk
committed
[theme] Try describing the components which a part descends "from"
1 parent 8621cd7 commit f475a88

File tree

4 files changed

+59
-45
lines changed

4 files changed

+59
-45
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: 41 additions & 40 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,54 +183,54 @@
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
189190
:alert-class alert-class
190191
:alert-style alert-style}}]
191192
(part ::al/wrapper
192-
{:impl box
193+
{:impl box
194+
:theme theme
195+
:post-props (debug/instrument {} props)
196+
:props
197+
{:re-com re-com
198+
:child
199+
(part ::al/body
200+
{:impl border
193201
:theme theme
194-
:post-props (debug/instrument {} props)
202+
:post-props (-> props
203+
(select-keys [:class :style :attr])
204+
(assoc :border border-style
205+
:padding padding))
195206
:props
196207
{:re-com re-com
197208
:child
198-
(part ::al/body
199-
{:impl border
200-
:theme theme
201-
:post-props (-> props
202-
(select-keys [:class :style :attr])
203-
(assoc :border border-style
204-
:padding padding))
205-
:props
206-
{:re-com re-com
207-
:child
208-
(part ::al/scroller
209-
{:impl scroller
210-
:theme theme
211-
:post-props {:style (when max-height {:max-height max-height})}
212-
:props {:re-com re-com
209+
(part ::al/scroller
210+
{:impl scroller
211+
:theme theme
212+
:post-props {:style (when max-height {:max-height max-height})}
213+
:props {:re-com re-com
213214
:child
214215
(part ::al/v-box
215-
{:impl v-box
216-
:theme theme
217-
:props
218-
{:re-com re-com
219-
:children
220-
(for [alert alerts]
221-
(let [{:keys [id alert-type heading body padding closeable?]} alert]
222-
(part ::al/alert-box
223-
{:impl alert-box
224-
:theme theme
225-
:key id
226-
:post-props {:class alert-class
227-
:style alert-style}
228-
:props
229-
{:id id
230-
:alert-type alert-type
231-
:heading heading
232-
:body body
233-
:padding padding
234-
:closeable? closeable?
235-
:on-close on-close}})))}})}})}})}}))))
216+
{:impl v-box
217+
:theme theme
218+
:props
219+
{:re-com re-com
220+
:children
221+
(for [alert alerts]
222+
(let [{:keys [id alert-type heading body padding closeable?]} alert]
223+
(part ::al/alert-box
224+
{:impl alert-box
225+
:theme theme
226+
:key id
227+
:post-props {:class alert-class
228+
:style alert-style}
229+
:props
230+
{:id id
231+
:alert-type alert-type
232+
:heading heading
233+
:body body
234+
:padding padding
235+
:closeable? closeable?
236+
:on-close on-close}})))}})}})}})}}))))

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)