Skip to content

Commit

Permalink
improve(ui): optimize functional components to rum functional component
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Mar 21, 2023
1 parent 97a501a commit 9b6b5a6
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/main/frontend/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@
(if (not @collapsed?) (content) nil)
content)]]))

(defn admonition
(rum/defc admonition
[type content]
(let [type (name type)]
(when-let [icon (case (string/lower-case type)
Expand Down Expand Up @@ -925,14 +925,14 @@
[:div {:key "tippy"} ""])))
(rum/fragment {:key "tippy-children"} child))))

(defn slider
(rum/defc slider
[default-value {:keys [min max on-change]}]
[:input.cursor-pointer
{:type "range"
:value (int default-value)
:min min
:max max
:style {:width "100%"}
{:type "range"
:value (int default-value)
:min min
:max max
:style {:width "100%"}
:on-change #(let [value (util/evalue %)]
(on-change value))}])

Expand All @@ -949,18 +949,18 @@
(def get-adapt-icon-class
(memoize (fn [klass] (r/adapt-class klass))))

(defn icon
(rum/defc icon
([name] (icon name nil))
([name {:keys [extension? font? class] :as opts}]
(when-not (string/blank? name)
(let [^js jsTablerIcons (gobj/get js/window "tablerIcons")]
(if (or extension? font? (not jsTablerIcons))
[:span.ui__icon (merge {:class
(util/format
(str "%s-" name
(when (:class opts)
(str " " (string/trim (:class opts)))))
(if extension? "tie tie" "ti ti"))}
(str "%s-" name
(when (:class opts)
(str " " (string/trim (:class opts)))))
(if extension? "tie tie" "ti ti"))}
(dissoc opts :class :extension? :font?))]

;; tabler svg react
Expand All @@ -970,7 +970,7 @@
{:class (str "ls-icon-" name " " class)}
(f (merge {:size 18} (r/map-keys->camel-case (dissoc opts :class))))])))))))

(defn button
(rum/defc button
[text & {:keys [background href class intent on-click small? large? title icon icon-props disabled?]
:or {small? false large? false}
:as option}]
Expand All @@ -981,15 +981,15 @@
klass (if disabled? (str klass "disabled:opacity-75") klass)]
[:button.ui__button
(merge
{:type "button"
:title title
:disabled disabled?
:class (str (util/hiccup->class klass) " " class)}
(dissoc option :background :class :small? :large?)
(when href
{:on-click (fn []
(util/open-url href)
(when (fn? on-click) (on-click)))}))
{:type "button"
:title title
:disabled disabled?
:class (str (util/hiccup->class klass) " " class)}
(dissoc option :background :class :small? :large?)
(when href
{:on-click (fn []
(util/open-url href)
(when (fn? on-click) (on-click)))}))
(when icon (frontend.ui/icon icon (merge icon-props {:class (when-not (empty? text) "mr-1")})))
text]))

Expand Down

0 comments on commit 9b6b5a6

Please sign in to comment.