0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-05 20:31:20 -05:00

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
(:require
[app.util.dom :as dom]
[rumext.v2 :as mf]))
(mf/defc portal-on-document*
[{:keys [children]}]
(mf/portal
(mf/html [:* children])
(.-body js/document)))
(dom/get-body)))

View file

@ -86,4 +86,4 @@
(when-let [modal (mf/deref ref:modal)]
(mf/portal
(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*)))))))
;; FIXME: perf optimization
[:& dropdown {:show is-open?
:on-close #(st/emit! (dt/assign-token-context-menu nil))}
[:div {:class (stl/css :token-context-menu)
:data-testid "tokens-context-menu-for-token"
:ref dropdown-ref
:data-direction dropdown-direction
:style {:--bottom (if (= dropdown-direction "up")
"40px"
"unset")
:--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)])]]))
(when is-open?
(mf/portal
(mf/html
[:& dropdown {:show is-open?
:on-close #(st/emit! (dt/assign-token-context-menu nil))}
[:div {:class (stl/css :token-context-menu)
:data-testid "tokens-context-menu-for-token"
:ref dropdown-ref
:data-direction dropdown-direction
:style {:--bottom (if (= dropdown-direction "up")
"40px"
"unset")
:--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
:themes themes
:on-close on-close-dropdown}]]])
(.-body js/document)))]))
(dom/get-body)))]))