Display tokens contextual menu in body through portal

This commit is contained in:
Xavier Julian 2025-03-05 09:56:01 +01:00 committed by Xaviju
parent 5c53de8e76
commit 9da6c50cbe
4 changed files with 23 additions and 17 deletions

View file

@ -6,10 +6,11 @@
(ns app.main.ui.components.portal (ns app.main.ui.components.portal
(:require (:require
[app.util.dom :as dom]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
(mf/defc portal-on-document* (mf/defc portal-on-document*
[{:keys [children]}] [{:keys [children]}]
(mf/portal (mf/portal
(mf/html [:* children]) (mf/html [:* children])
(.-body js/document))) (dom/get-body)))

View file

@ -86,4 +86,4 @@
(when-let [modal (mf/deref ref:modal)] (when-let [modal (mf/deref ref:modal)]
(mf/portal (mf/portal
(mf/html [:> modal-wrapper* {:data modal :key (dm/str (:id modal))}]) (mf/html [:> modal-wrapper* {:data modal :key (dm/str (:id modal))}])
(.-body js/document)))) (dom/get-body))))

View file

@ -446,17 +446,22 @@
(mf/set-ref-val! dropdown-direction-change* (inc (mf/ref-val dropdown-direction-change*))))))) (mf/set-ref-val! dropdown-direction-change* (inc (mf/ref-val dropdown-direction-change*)))))))
;; FIXME: perf optimization ;; FIXME: perf optimization
[:& dropdown {:show is-open?
:on-close #(st/emit! (dt/assign-token-context-menu nil))} (when is-open?
[:div {:class (stl/css :token-context-menu) (mf/portal
:data-testid "tokens-context-menu-for-token" (mf/html
:ref dropdown-ref [:& dropdown {:show is-open?
:data-direction dropdown-direction :on-close #(st/emit! (dt/assign-token-context-menu nil))}
:style {:--bottom (if (= dropdown-direction "up") [:div {:class (stl/css :token-context-menu)
"40px" :data-testid "tokens-context-menu-for-token"
"unset") :ref dropdown-ref
:--top (dm/str top "px") :data-direction dropdown-direction
:left (dm/str left "px")} :style {:--bottom (if (= dropdown-direction "up")
:on-context-menu prevent-default} "40px"
(when mdata "unset")
[:& token-context-menu-tree (assoc mdata :width @width :direction dropdown-direction)])]])) :--top (dm/str top "px")
:left (dm/str left "px")}
:on-context-menu prevent-default}
(when mdata
[:& token-context-menu-tree (assoc mdata :width @width :direction dropdown-direction)])]])
(dom/get-body)))))

View file

@ -139,4 +139,4 @@
[:& theme-options {:active-theme-paths active-theme-paths [:& theme-options {:active-theme-paths active-theme-paths
:themes themes :themes themes
:on-close on-close-dropdown}]]]) :on-close on-close-dropdown}]]])
(.-body js/document)))])) (dom/get-body)))]))