mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 09:48:28 +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]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def sets-menu-ref
|
||||
(def ^:private ref:tokens-sets-context-menu
|
||||
(l/derived :token-set-context-menu refs/workspace-local))
|
||||
|
||||
(defn- prevent-default
|
||||
|
@ -26,44 +26,46 @@
|
|||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event))
|
||||
|
||||
(mf/defc menu-entry
|
||||
{::mf/props :obj}
|
||||
(mf/defc menu-entry*
|
||||
[{:keys [title value on-click]}]
|
||||
[:li {:class (stl/css :context-menu-item)
|
||||
:data-value value
|
||||
:on-click on-click}
|
||||
[:span {:class (stl/css :title)} title]])
|
||||
|
||||
(mf/defc menu
|
||||
[{:keys [group? path]}]
|
||||
(mf/defc menu*
|
||||
[{:keys [is-group path]}]
|
||||
(let [{:keys [on-create on-edit]} (sets-context/use-context)
|
||||
|
||||
create-set-at-path
|
||||
(mf/use-fn
|
||||
(mf/deps path)
|
||||
(mf/deps path on-create)
|
||||
#(on-create path))
|
||||
|
||||
edit-name
|
||||
(mf/use-fn
|
||||
(mf/deps group?)
|
||||
(mf/deps is-group on-edit)
|
||||
(fn []
|
||||
(let [path (if group?
|
||||
(let [path (if is-group
|
||||
(sets-context/set-group-path->id path)
|
||||
(sets-context/set-path->id path))]
|
||||
(on-edit path))))
|
||||
|
||||
delete-set
|
||||
(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)}
|
||||
(when group?
|
||||
[:& 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.delete") :on-click delete-set}]]))
|
||||
(when is-group
|
||||
[:> 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.delete") :on-click delete-set}]]))
|
||||
|
||||
(mf/defc sets-context-menu*
|
||||
[]
|
||||
(let [{:keys [position is-group path]}
|
||||
(mf/deref sets-menu-ref)
|
||||
(mf/deref ref:tokens-sets-context-menu)
|
||||
|
||||
position-top
|
||||
(+ (dm/get-prop position :y) 5)
|
||||
|
@ -82,5 +84,4 @@
|
|||
:style {:top position-top
|
||||
:left position-left}
|
||||
:on-context-menu prevent-default}
|
||||
[:& menu {:group? is-group
|
||||
:path path}]]]))
|
||||
[:> menu* {:is-group is-group :path path}]]]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue