-
Notifications
You must be signed in to change notification settings - Fork 23
/
boolean_field.cljc
39 lines (37 loc) · 1.73 KB
/
boolean_field.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(ns com.fulcrologic.rad.rendering.semantic-ui.boolean-field
(:require
#?(:cljs
[com.fulcrologic.fulcro.dom :as dom :refer [div label input]]
:clj
[com.fulcrologic.fulcro.dom-server :as dom :refer [div label input]])
[com.fulcrologic.rad.attributes :as attr]
[com.fulcrologic.fulcro.components :as comp]
[clojure.string :as str]
[com.fulcrologic.rad.form :as form]
[com.fulcrologic.rad.options-util :refer [?!]]
[com.fulcrologic.rad.rendering.semantic-ui.form-options :as sufo]
[com.fulcrologic.fulcro.dom.events :as evt]))
(defn render-field [{::form/keys [form-instance] :as env} attribute]
(let [k (::attr/qualified-key attribute)
props (comp/props form-instance)
user-props (?! (form/field-style-config env attribute :input/props) env)
field-label (form/field-label env attribute)
visible? (form/field-visible? form-instance attribute)
read-only? (form/read-only? form-instance attribute)
omit-label? (form/omit-label? form-instance attribute)
top-class (sufo/top-class form-instance attribute)
value (get props k false)]
(when visible?
(div {:className (or top-class "ui field")
:key (str k)}
(div :.ui.checkbox
(input (merge
{:checked value
:type "checkbox"
:disabled (boolean read-only?)
:onChange (fn [evt]
(let [v (not value)]
(form/input-blur! env k v)
(form/input-changed! env k v)))}
user-props))
(when-not omit-label? (label field-label)))))))