Browse Source

fix: button doesn't support href attribute

Tienson Qin 2 years ago
parent
commit
eeeea39fa4
2 changed files with 24 additions and 24 deletions
  1. 10 5
      deps/shui/src/logseq/shui/button/v2.cljs
  2. 14 19
      src/main/frontend/components/settings.cljs

+ 10 - 5
deps/shui/src/logseq/shui/button/v2.cljs

@@ -18,13 +18,18 @@
         color-class (str "shui__button-color-" color-string)
         muted-class (when muted "shui__button-muted")
         size-class  (str "shui__button-size-" (name size))
-        tiled-class (when tiled "shui__button-tiled")]
+        tiled-class (when tiled "shui__button-tiled")
+        on-click (fn [e]
+                   (when href (set! (.-href js/window.location) href))
+                   (when on-click (on-click e)))]
     [:button.shui__button (merge
                            comp-opts
-                           {:class (str theme-class " " depth-class " " color-class " " size-class " " tiled-class " " muted-class " " class)
-                            :on-click (cond on-click on-click href #(js/window.open href "_blank"))
-                            :on-mouse-over #(when hover-theme (reset! *theme hover-theme))
-                            :on-mouse-out #(reset! *theme theme)})
+                           (cond->
+                            {:class (str theme-class " " depth-class " " color-class " " size-class " " tiled-class " " muted-class " " class)
+                             :on-mouse-over #(when hover-theme (reset! *theme hover-theme))
+                             :on-mouse-out #(reset! *theme theme)}
+                             on-click
+                             (assoc :on-click on-click)))
      (if-not tiled text
              (for [[index tile] (map-indexed vector (rest (string/split text #"")))]
                [:<>

+ 14 - 19
src/main/frontend/components/settings.cljs

@@ -169,47 +169,42 @@
      (if action action (shui/button {:text button-label
                                      :href href
                                      :on-click on-click}
-                                    (make-shui-context nil nil)))]
-     ; (if action action (ui/button
-     ;                      button-label
-     ;                      :class    "text-sm p-1"
-     ;                      :href     href
-     ;                      :on-click on-click))]
+                         (make-shui-context)))]
     (when-not (or (util/mobile?)
                   (mobile-util/native-platform?))
       [:div.text-sm.flex desc])]])
 
 (defn edit-config-edn []
   (row-with-button-action
-    {:left-label   (t :settings-page/custom-configuration)
-     :button-label (t :settings-page/edit-config-edn)
-     :href         (rfe/href :file {:path (config/get-repo-config-path)})
-     :on-click     #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))
-     :-for         "config_edn"}))
+   {:left-label   (t :settings-page/custom-configuration)
+    :button-label (t :settings-page/edit-config-edn)
+    :href         (rfe/href :file {:path (config/get-repo-config-path)})
+    :on-click     ui-handler/toggle-settings-modal!
+    :-for         "config_edn"}))
 
 (defn edit-global-config-edn []
   (row-with-button-action
     {:left-label   (t :settings-page/custom-global-configuration)
      :button-label (t :settings-page/edit-global-config-edn)
      :href         (rfe/href :file {:path (global-config-handler/global-config-path)})
-     :on-click     #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))
+     :on-click     ui-handler/toggle-settings-modal!
      :-for         "global_config_edn"}))
 
 (defn edit-custom-css []
   (row-with-button-action
-    {:left-label   (t :settings-page/custom-theme)
-     :button-label (t :settings-page/edit-custom-css)
-     :href         (rfe/href :file {:path (config/get-custom-css-path)})
-     :on-click     #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))
-     :-for         "customize_css"}))
+   {:left-label   (t :settings-page/custom-theme)
+    :button-label (t :settings-page/edit-custom-css)
+    :href         (rfe/href :file {:path (config/get-custom-css-path)})
+    :on-click     ui-handler/toggle-settings-modal!
+    :-for         "customize_css"}))
 
 (defn edit-export-css []
   (row-with-button-action
    {:left-label   (t :settings-page/export-theme)
     :button-label (t :settings-page/edit-export-css)
     :href         (rfe/href :file {:path (config/get-export-css-path)})
-    :on-click     #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))
-    :-for         "customize_css"}))
+    :on-click     ui-handler/toggle-settings-modal!
+    :-for         "export_css"}))
 
 (defn show-brackets-row [t show-brackets?]
   [:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start