|
35 | 35 | (when include-args-desc? |
36 | 36 | (vec |
37 | 37 | (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"} |
39 | 39 | {: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"} |
41 | 41 | {:name :label-class :required false :type "string" :validate-fn string? :description "CSS class names (applies to the label)"} |
42 | 42 | {:name :label-style :required false :type "CSS style map" :validate-fn css-style? :description "CSS style map (applies to the label)"} |
43 | 43 | args/class |
|
54 | 54 | "Displays a single checkbox with optional label" |
55 | 55 | [& {:keys [pre-theme theme]}] |
56 | 56 | (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] |
58 | 58 | :as props}] |
59 | 59 | (or |
60 | 60 | (validate-args-macro checkbox-args-desc props) |
|
64 | 64 | label-provided? (part/get-part part-structure props ::label) |
65 | 65 | callback-fn #(when (and on-change (not disabled?)) |
66 | 66 | (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 |
71 | 71 | :label-provided? label-provided?}}] |
72 | 72 | (part ::wrapper |
73 | 73 | {:impl h-box |
74 | | - :post-props (-> (select-keys props [:class :style :attr]) |
75 | | - (debug/instrument props)) |
| 74 | + :post-props (debug/instrument {} props) |
76 | 75 | :theme theme |
77 | 76 | :props {:re-com re-com |
78 | 77 | :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)}}) |
87 | 90 |
|
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