Переглянути джерело

enhance: lazy loading tippy content

Tienson Qin 4 роки тому
батько
коміт
4de27fe906
1 змінених файлів з 19 додано та 8 видалено
  1. 19 8
      src/main/frontend/ui.cljs

+ 19 - 8
src/main/frontend/ui.cljs

@@ -585,11 +585,22 @@
                 (assoc :selected selected))
                 (assoc :selected selected))
       label])])
       label])])
 
 
-(rum/defc tippy
-  [opts child]
-  (Tippy (merge {:arrow true
-                 :sticky true
-                 :theme (:ui/theme @state/state)
-                 :disabled (not (state/enable-tooltip?))
-                 :unmountHTMLWhenHide true} opts)
-         child))
+(rum/defcs tippy < rum/static
+  (rum/local false ::mounted?)
+  [state opts child]
+  (let [*mounted? (::mounted? state)
+        mounted? @*mounted?]
+    (Tippy (->
+           (merge {:arrow true
+                   :sticky true
+                   :theme (:ui/theme @state/state)
+                   :disabled (not (state/enable-tooltip?))
+                   :unmountHTMLWhenHide true
+                   :open @*mounted?
+                   :onShow #(reset! *mounted? true)
+                   :onHide #(reset! *mounted? false)}
+                  opts)
+           (assoc :html (if mounted?
+                          (:html opts)
+                          [:div ""])))
+          child)))