From 370a5d9bb8afeff6822bcb3f812bf204a9d9b6c9 Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Mon, 27 May 2024 13:02:24 +0530 Subject: [PATCH] Add initial context menu token specific functionality --- .../ui/workspace/tokens/context_menu.cljs | 53 ++++++++++++------- .../app/main/ui/workspace/tokens/sidebar.cljs | 1 + 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index 5a69b066b..8e26a3f8e 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -27,25 +27,39 @@ (def tokens-menu-ref (l/derived :token-context-menu refs/workspace-local)) +(defn additional-actions [token-type token-id] + (case token-type + :border-radius [{:title "Top Left Corner" :action #(js/console.log "Top Left Corner")} + {:title "Bottom Left Corner" :action #(js/console.log "Bottom Left Corner")} + {:title "Top Right Corner" :action #(js/console.log "Top Right Corner")} + {:title "Bottom Right Corner" :action #(js/console.log "Bottom Right Corner")}] + [])) + +(defn generate-menu-entries [token-type-props token-id token-type] + (let [{:keys [modal]} token-type-props + default-actions [{:title "Delete Token" :action #(st/emit! (dt/delete-token token-id))} + {:title "Duplicate Token" :action #(st/emit! (dt/duplicate-token token-id))} + {:title "Edit Token" :action (fn [event] + (let [{:keys [key fields]} modal + token (dt/get-token-data-from-token-id token-id)] + (st/emit! dt/hide-token-context-menu) + (dom/stop-propagation event) + (modal/show! key {:x (.-clientX ^js event) + :y (.-clientY ^js event) + :position :right + :fields fields + :token token})))}] + specific-actions (additional-actions token-type token-id) + all-actions (concat default-actions specific-actions)] + (map (fn [{:keys [title action]}] + [:& menu-entry {:title title :on-click action}]) + all-actions))) + (mf/defc token-pill-context-menu - [{:keys [token-id token-type-props]}] - (let [{:keys [modal attributes title]} token-type-props - do-delete #(st/emit! (dt/delete-token token-id)) - do-duplicate #(st/emit! (dt/duplicate-token token-id)) - do-edit (fn [event] - (let [{:keys [key fields]} modal - token (dt/get-token-data-from-token-id token-id)] - (st/emit! dt/hide-token-context-menu) - (dom/stop-propagation event) - (modal/show! key {:x (.-clientX ^js event) - :y (.-clientY ^js event) - :position :right - :fields fields - :token token})))] - [:* - [:& menu-entry {:title "Delete Token" :on-click do-delete}] - [:& menu-entry {:title "Duplicate Token" :on-click do-duplicate}] - [:& menu-entry {:title "Edit Token" :on-click do-edit}]])) + [{:keys [token-id token-type-props token-type]}] + (let [menu-entries (generate-menu-entries token-type-props token-id token-type)] + (into [:*] menu-entries) + )) (mf/defc token-context-menu [] @@ -76,4 +90,5 @@ (when (= :token (:type mdata)) [:ul {:class (stl/css :context-list)} [:& token-pill-context-menu {:token-id (:token-id mdata) - :token-type-props (:token-type-props mdata)}]])]])) \ No newline at end of file + :token-type-props (:token-type-props mdata) + :token-type (:token-type mdata)}]])]])) \ No newline at end of file diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 64800f962..f0246b4a4 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -68,6 +68,7 @@ (st/emit! (dt/show-token-context-menu {:type :token :position (dom/get-client-position event) :token-type-props token-type-props + :token-type type :token-id (:id token)})))) on-toggle-open-click (mf/use-fn