Files
integreat/src/cljs/auto_ap/views/components.cljs

35 lines
1.1 KiB
Clojure

(ns auto-ap.views.components
(:require [reagent.core :as r]
[clojure.string :as str]))
(defn checkbox [{:keys [on-change
value
label]
:as props}]
(into [:label.checkbox
[:input (-> props
(assoc
:type "checkbox"
:on-change (fn []
(on-change (not value)))
:checked value)
(dissoc :value))]
" " label
]
(r/children (r/current-component))))
(defn select-field [{:keys [options allow-nil? class] :as props}]
[:div.select {:class class}
[:select (-> props
(dissoc :allow-nil? :class :options)
(update :value (fn [v]
(if (str/blank? v)
""
v))))
[:<>
(when allow-nil?
[:option {:value nil}])
(for [[k v] options]
^{:key k} [:option {:value k} v])]]])