From 1ed692230be9166c54e4a797dcab13251f994a2c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 23 May 2024 09:24:12 +0200 Subject: [PATCH] Abstract functionality --- .../main/ui/workspace/sidebar/options/menus/measures.cljs | 7 +++---- frontend/src/app/main/ui/workspace/tokens/core.cljs | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) 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 4a26f0f39..c74a688d8 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 @@ -295,7 +295,7 @@ (mf/use-fn (mf/deps ids change-radius border-radius-tokens) (fn [token] - (let [token-value (some-> token wtc/resolve-token-value)] + (let [token-value (wtc/maybe-resolve-token-value token)] (st/emit! (change-radius (fn [shape] (-> (dt/unapply-token-id shape (wtc/token-attributes :border-radius)) @@ -305,11 +305,10 @@ (mf/use-fn (mf/deps ids change-radius border-radius-tokens) (fn [value] - (let [token (when (map? value) value) - token-value (some-> token wtc/resolve-token-value)] + (let [token-value (wtc/maybe-resolve-token-value value)] (st/emit! (change-radius (fn [shape] - (-> (dt/maybe-apply-token-to-shape {:token token + (-> (dt/maybe-apply-token-to-shape {:token (when token-value value) :shape shape :attributes (wtc/token-attributes :border-radius)}) (ctsr/set-radius-1 (or token-value value))))))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 9f0405a62..0fe4707f7 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -37,6 +37,9 @@ int-or-double (throw (ex-info (str "Implement token value resolve for " value) token)))) +(defn maybe-resolve-token-value [{:keys [value] :as token}] + (when value (resolve-token-value token))) + (defn group-tokens-by-type "Groups tokens by their `:type` property." [tokens]