From 93cc8214fa7fa23fb5bc089977c701db1e761a4d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 11:05:39 +0200 Subject: [PATCH] Fix border-radius and sizing panels --- common/src/app/common/types/tokens_lib.cljc | 7 +++++++ .../sidebar/options/menus/measures.cljs | 16 +++++++++------- .../src/app/main/ui/workspace/tokens/core.cljs | 7 +++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 6fd65030b..53b47f7bf 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -132,6 +132,13 @@ token)) +(defn group-by-type [tokens] + (let [tokens' (if (or (map? tokens) + (d/ordered-map? tokens)) + (vals tokens) + tokens)] + (group-by :type tokens'))) + (defn filter-by-type [token-type tokens] (let [token-type? #(= token-type (:type %))] (cond diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index c5df4dc6c..1aed9f173 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -32,7 +32,8 @@ [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] [clojure.set :refer [rename-keys union]] - [rumext.v2 :as mf])) + [rumext.v2 :as mf] + [app.common.types.tokens-lib :as ctob])) (def measure-attrs [:proportion-lock @@ -101,28 +102,29 @@ selection-parents-ref (mf/use-memo (mf/deps ids) #(refs/parents-by-ids ids)) selection-parents (mf/deref selection-parents-ref) - tokens (-> (mf/deref refs/workspace-active-theme-sets-tokens) - (sd/use-resolved-tokens)) - tokens-by-type (mf/use-memo (mf/deps tokens) #(wtc/group-tokens-by-type-OLD tokens)) + tokens (sd/use-active-theme-sets-tokens) + tokens-by-type (mf/use-memo + (mf/deps tokens) + #(ctob/group-by-type tokens)) border-radius-tokens (:border-radius tokens-by-type) border-radius-options (mf/use-memo (mf/deps shape border-radius-tokens) - #(wtc/tokens-name-map->select-options-OLD + #(wtc/tokens->select-options {:shape shape :tokens border-radius-tokens :attributes (wtty/token-attributes :border-radius)})) sizing-tokens (:sizing tokens-by-type) width-options (mf/use-memo (mf/deps shape sizing-tokens) - #(wtc/tokens-name-map->select-options-OLD + #(wtc/tokens->select-options {:shape shape :tokens sizing-tokens :attributes (wtty/token-attributes :sizing) :selected-attributes #{:width}})) height-options (mf/use-memo (mf/deps shape sizing-tokens) - #(wtc/tokens-name-map->select-options-OLD + #(wtc/tokens->select-options {:shape shape :tokens sizing-tokens :attributes (wtty/token-attributes :sizing) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 9a0779a17..b511f5c4b 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -43,6 +43,13 @@ (cond-> (assoc item :label name) (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true)))))) +(defn tokens->select-options [{:keys [shape tokens attributes selected-attributes]}] + (map + (fn [{:keys [name] :as item}] + (cond-> (assoc item :label name) + (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))) + tokens)) + (defn tokens-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}] (map (fn [[_k {:keys [name] :as item}]]