mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
⚡ Refactor the rest fot token sets context menu components
This commit is contained in:
parent
1fb48a1e8a
commit
b228438127
1 changed files with 17 additions and 16 deletions
|
@ -18,7 +18,7 @@
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(def sets-menu-ref
|
(def ^:private ref:tokens-sets-context-menu
|
||||||
(l/derived :token-set-context-menu refs/workspace-local))
|
(l/derived :token-set-context-menu refs/workspace-local))
|
||||||
|
|
||||||
(defn- prevent-default
|
(defn- prevent-default
|
||||||
|
@ -26,44 +26,46 @@
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(dom/stop-propagation event))
|
(dom/stop-propagation event))
|
||||||
|
|
||||||
(mf/defc menu-entry
|
(mf/defc menu-entry*
|
||||||
{::mf/props :obj}
|
|
||||||
[{:keys [title value on-click]}]
|
[{:keys [title value on-click]}]
|
||||||
[:li {:class (stl/css :context-menu-item)
|
[:li {:class (stl/css :context-menu-item)
|
||||||
:data-value value
|
:data-value value
|
||||||
:on-click on-click}
|
:on-click on-click}
|
||||||
[:span {:class (stl/css :title)} title]])
|
[:span {:class (stl/css :title)} title]])
|
||||||
|
|
||||||
(mf/defc menu
|
(mf/defc menu*
|
||||||
[{:keys [group? path]}]
|
[{:keys [is-group path]}]
|
||||||
(let [{:keys [on-create on-edit]} (sets-context/use-context)
|
(let [{:keys [on-create on-edit]} (sets-context/use-context)
|
||||||
|
|
||||||
create-set-at-path
|
create-set-at-path
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps path)
|
(mf/deps path on-create)
|
||||||
#(on-create path))
|
#(on-create path))
|
||||||
|
|
||||||
edit-name
|
edit-name
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps group?)
|
(mf/deps is-group on-edit)
|
||||||
(fn []
|
(fn []
|
||||||
(let [path (if group?
|
(let [path (if is-group
|
||||||
(sets-context/set-group-path->id path)
|
(sets-context/set-group-path->id path)
|
||||||
(sets-context/set-path->id path))]
|
(sets-context/set-path->id path))]
|
||||||
(on-edit path))))
|
(on-edit path))))
|
||||||
|
|
||||||
delete-set
|
delete-set
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
#(st/emit! (wdt/delete-token-set-path group? path)))]
|
(mf/deps is-group path)
|
||||||
|
#(st/emit! (wdt/delete-token-set-path is-group path)))]
|
||||||
|
|
||||||
[:ul {:class (stl/css :context-list)}
|
[:ul {:class (stl/css :context-list)}
|
||||||
(when group?
|
(when is-group
|
||||||
[:& menu-entry {:title (tr "workspace.token.add-set-to-group") :on-click create-set-at-path}])
|
[:> menu-entry* {:title (tr "workspace.token.add-set-to-group") :on-click create-set-at-path}])
|
||||||
[:& menu-entry {:title (tr "labels.rename") :on-click edit-name}]
|
[:> menu-entry* {:title (tr "labels.rename") :on-click edit-name}]
|
||||||
[:& menu-entry {:title (tr "labels.delete") :on-click delete-set}]]))
|
[:> menu-entry* {:title (tr "labels.delete") :on-click delete-set}]]))
|
||||||
|
|
||||||
(mf/defc sets-context-menu*
|
(mf/defc sets-context-menu*
|
||||||
[]
|
[]
|
||||||
(let [{:keys [position is-group path]}
|
(let [{:keys [position is-group path]}
|
||||||
(mf/deref sets-menu-ref)
|
(mf/deref ref:tokens-sets-context-menu)
|
||||||
|
|
||||||
position-top
|
position-top
|
||||||
(+ (dm/get-prop position :y) 5)
|
(+ (dm/get-prop position :y) 5)
|
||||||
|
@ -82,5 +84,4 @@
|
||||||
:style {:top position-top
|
:style {:top position-top
|
||||||
:left position-left}
|
:left position-left}
|
||||||
:on-context-menu prevent-default}
|
:on-context-menu prevent-default}
|
||||||
[:& menu {:group? is-group
|
[:> menu* {:is-group is-group :path path}]]]))
|
||||||
:path path}]]]))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue