0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-20 05:34:23 -05:00

Add context menu item for set groups

This commit is contained in:
Florian Schroedl 2024-12-03 11:13:51 +01:00
parent d34c88b6e4
commit 53229c03d6
2 changed files with 22 additions and 0 deletions

View file

@ -215,6 +215,10 @@
(defn split-token-set-path [path]
(split-path path set-separator))
(defn get-token-set-final-name [path]
(-> (split-token-set-path path)
(last)))
(defn set-name->prefixed-full-path [name-str]
(-> (split-token-set-path name-str)
(set-full-path->set-prefixed-full-path)))
@ -223,6 +227,11 @@
(let [path (get-path token-set set-separator)]
(set-full-path->set-prefixed-full-path path)))
(defn get-prefixed-token-set-final-prefix [prefixed-path-str]
(some-> (get-token-set-final-name prefixed-path-str)
(split-set-str-path-prefix)
(first)))
(defn set-name-string->prefixed-set-path-string [name-str]
(-> (set-name->prefixed-full-path name-str)
(join-set-path)))
@ -235,6 +244,16 @@
path-part)))
(join-set-path)))
(defn prefixed-set-path-final-group?
"Predicate if the given prefixed path string ends with a group."
[prefixed-path-str]
(= (get-prefixed-token-set-final-prefix prefixed-path-str) set-group-prefix))
(defn prefixed-set-path-final-set?
"Predicate if the given prefixed path string ends with a set."
[prefixed-path-str]
(= (get-prefixed-token-set-final-prefix prefixed-path-str) set-prefix))
(defn tokens-tree
"Convert tokens into a nested tree with their `:name` as the path.
Optionally use `update-token-fn` option to transform the token."

View file

@ -7,6 +7,7 @@
(ns app.main.ui.workspace.tokens.sets-context-menu
(:require-macros [app.main.style :as stl])
(:require
[app.common.types.tokens-lib :as ctob]
[app.main.data.tokens :as wdt]
[app.main.refs :as refs]
[app.main.store :as st]
@ -40,6 +41,8 @@
edit-name (mf/use-fn #(on-edit prefixed-set-path))
delete-set (mf/use-fn #(st/emit! (wdt/delete-token-set-path prefixed-set-path)))]
[:ul {:class (stl/css :context-list)}
(when (ctob/prefixed-set-path-final-group? prefixed-set-path)
[:& menu-entry {:title "Add set to this group" :on-click js/console.log}])
[:& menu-entry {:title (tr "labels.rename") :on-click edit-name}]
[:& menu-entry {:title (tr "labels.delete") :on-click delete-set}]]))