41 lines
2.0 KiB
Clojure
41 lines
2.0 KiB
Clojure
(ns com.fulcrologic.rad.rendering.semantic-ui.controls.action-button
|
|
(:require
|
|
[com.fulcrologic.rad.report :as report]
|
|
[com.fulcrologic.rad.options-util :refer [?!]]
|
|
[com.fulcrologic.fulcro.data-fetch :as df]
|
|
[com.fulcrologic.rad.control :as control]
|
|
#?(:cljs [com.fulcrologic.fulcro.dom :as dom]
|
|
:clj [com.fulcrologic.fulcro.dom-server :as dom])
|
|
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]
|
|
#?@(:cljs [[ch.lyrion.carbon.button.ui-button :refer [ui-button]]])))
|
|
|
|
(defsc ActionButton [_ {:keys [instance control-key]}]
|
|
{:shouldComponentUpdate (fn [_ _ _] true)}
|
|
#?(:cljs
|
|
(let [controls (control/component-controls instance)
|
|
props (comp/props instance)
|
|
{:keys [label icon class action disabled? visible?] :as control} (get controls control-key)]
|
|
(when control
|
|
(let [label (?! label instance)
|
|
class (?! class instance)
|
|
loading? (df/loading? (get-in props [df/marker-table (comp/get-ident instance)]))
|
|
disabled? (or loading? (?! disabled? instance))
|
|
visible? (or (nil? visible?) (?! visible? instance))]
|
|
(when visible?
|
|
(ui-button
|
|
{:id (str control-key)
|
|
:className (when loading? "bx--skeleton")
|
|
:disabled (boolean disabled?)
|
|
:onClick (fn [] (when action (action instance control-key)))}
|
|
(when icon (dom/i {:className (str icon " icon")}))
|
|
(when label label))
|
|
#_(dom/button :.bx--btn.bx--btn--sm.bx--skeleton
|
|
{:key (str control-key)
|
|
:classes [(when class class)]
|
|
:disabled (boolean disabled?)
|
|
:onClick (fn [] (when action (action instance control-key)))}
|
|
(when icon (dom/i {:className (str icon " icon")}))
|
|
(when label label))))))))
|
|
|
|
(def render-control (comp/factory ActionButton {:keyfn :control-key}))
|