Skip to content

Commit 1daffb1

Browse files
committed
[checkbox] Fix top-level prop assignment
1 parent a5f080a commit 1daffb1

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

src/re_com/checkbox.cljs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
(when include-args-desc?
3636
(vec
3737
(concat
38-
[{:name :model :required true :type "boolean | r/atom" :validate-fn #(or (boolean? %) (satisfies? IAtom %)) :description "holds state of the checkbox when it is called"}
38+
[{:name :model :required true :type "boolean | r/atom" :validate-fn #(or (nil? %) (some? %) (satisfies? IAtom %)) :description "holds state of the checkbox when it is called"}
3939
{:name :on-change :required true :type "boolean -> nil" :validate-fn fn? :description "called when the checkbox is clicked. Passed the new value of the checkbox"}
40-
{:name :disabled? :required false :default false :type "boolean | r/atom" :validate-fn #(or (boolean? %) (satisfies? IAtom %)) :description "if true, user interaction is disabled"}
40+
{:name :disabled? :required false :default false :type "boolean | r/atom" :validate-fn #(or (nil? %) (some? %) (satisfies? IAtom %)) :description "if true, user interaction is disabled"}
4141
{:name :label-class :required false :type "string" :validate-fn string? :description "CSS class names (applies to the label)"}
4242
{:name :label-style :required false :type "CSS style map" :validate-fn css-style? :description "CSS style map (applies to the label)"}
4343
args/class
@@ -54,7 +54,7 @@
5454
"Displays a single checkbox with optional label"
5555
[& {:keys [pre-theme theme]}]
5656
(let [theme (theme/comp pre-theme theme)]
57-
(fn [& {:keys [model on-change disabled? label-class label-style]
57+
(fn [& {:keys [model on-change disabled? label-class label-style class style attr]
5858
:as props}]
5959
(or
6060
(validate-args-macro checkbox-args-desc props)
@@ -64,31 +64,34 @@
6464
label-provided? (part/get-part part-structure props ::label)
6565
callback-fn #(when (and on-change (not disabled?))
6666
(on-change (not model)))
67-
re-com {:state {:model model
68-
:disabled? disabled?
69-
:label-class label-class
70-
:label-style label-style
67+
re-com {:state {:model model
68+
:disabled? disabled?
69+
:label-class label-class
70+
:label-style label-style
7171
:label-provided? label-provided?}}]
7272
(part ::wrapper
7373
{:impl h-box
74-
:post-props (-> (select-keys props [:class :style :attr])
75-
(debug/instrument props))
74+
:post-props (debug/instrument {} props)
7675
:theme theme
7776
:props {:re-com re-com
7877
:children
79-
[(part ::input
80-
{:theme theme
81-
:props {:re-com re-com
82-
:tag :input}
83-
:post-props {:attr {:type :checkbox
84-
:disabled disabled?
85-
:checked (boolean model)
86-
:on-change (handler-fn (callback-fn))}}})
78+
[(part ::input
79+
{:theme theme
80+
:props {:re-com re-com
81+
:tag :input}
82+
:post-props {:class class
83+
:style style
84+
:attr (merge
85+
{:type :checkbox
86+
:disabled disabled?
87+
:checked (boolean model)
88+
:on-change (handler-fn (callback-fn))}
89+
attr)}})
8790

88-
(when label-provided?
89-
(part ::label
90-
{:theme theme
91-
:props {:re-com re-com}
92-
:post-props (cond-> {:on-click (handler-fn (callback-fn))}
93-
label-class (tu/class label-class)
94-
label-style (tu/style label-style))}))]}}))))))
91+
(when label-provided?
92+
(part ::label
93+
{:theme theme
94+
:props {:re-com re-com}
95+
:post-props (cond-> {:on-click (handler-fn (callback-fn))}
96+
label-class (tu/class label-class)
97+
label-style (tu/style label-style))}))]}}))))))

0 commit comments

Comments
 (0)