From 3826afb76b06c0cfff86a66d61f3f0f58e3ca6ee Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 5 Aug 2024 11:18:19 +0200 Subject: [PATCH 1/4] Fix applying stroke --- frontend/src/app/main/ui/workspace/tokens/changes.cljs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/changes.cljs b/frontend/src/app/main/ui/workspace/tokens/changes.cljs index 3ba521c39..63026b44a 100644 --- a/frontend/src/app/main/ui/workspace/tokens/changes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/changes.cljs @@ -116,9 +116,12 @@ (defn update-stroke-width [value shape-ids] - (dch/update-shapes shape-ids (fn [shape] - (when (seq (:strokes shape)) - (assoc-in shape [:strokes 0 :stroke-width] value))))) + (dch/update-shapes shape-ids + (fn [shape] + (when (seq (:strokes shape)) + (assoc-in shape [:strokes 0 :stroke-width] value))) + {:reg-objects? true + :attrs [:strokes]})) (defn update-shape-dimensions [value shape-ids attributes] (ptk/reify ::update-shape-dimensions From 2a97749d23a55ba731d8200acc061b672bf89e22 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 5 Aug 2024 11:42:36 +0200 Subject: [PATCH 2/4] Add shape property passing --- .../test/token_tests/logic/token_actions_test.cljs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 1b6565d00..7d419eeb8 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -14,12 +14,12 @@ (t/use-fixtures :each {:before thp/reset-idmap!}) -(defn- setup-file - [] +(defn setup-file + [& {:keys [rect-1 rect-2 rect-3]}] (-> (cthf/sample-file :file-1 :page-label :page-1) - (ctho/add-rect :rect-1 {}) - (ctho/add-rect :rect-2 {}) - (ctho/add-rect :rect-3 {}) + (ctho/add-rect :rect-1 rect-1) + (ctho/add-rect :rect-2 rect-2) + (ctho/add-rect :rect-3 rect-3) (toht/add-token :token-1 {:value "12" :name "borderRadius.sm" :type :border-radius}) From c9d1fe44e9f89da1d80035f6491d14f75356d160 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 5 Aug 2024 11:43:46 +0200 Subject: [PATCH 3/4] Add stroke-width test --- .../token_tests/logic/token_actions_test.cljs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 7d419eeb8..d58d85e01 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -212,6 +212,39 @@ (t/is (= (:rotation (:applied-tokens rect-1')) (:id token-target'))) (t/is (= (:rotation rect-1') 120))))))))) +(t/deftest test-apply-stroke-width + (t/testing "applies stroke-width token and updates the shapes with stroke" + (t/async + done + (let [file (-> (setup-file {:rect-1 {:strokes [{:stroke-alignment :inner, + :stroke-style :solid, + :stroke-color "#000000", + :stroke-opacity 1, + :stroke-width 5}]}}) + (toht/add-token :token-target {:value "10" + :name "stroke-width.sm" + :type :stroke-width})) + store (ths/setup-store file) + rect-with-stroke (cths/get-shape file :rect-1) + rect-without-stroke (cths/get-shape file :rect-2) + events [(wtch/apply-token {:shape-ids [(:id rect-with-stroke) (:id rect-without-stroke)] + :attributes #{:stroke-width} + :token (toht/get-token file :token-target) + :on-update-shape wtch/update-stroke-width})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' :token-target) + rect-with-stroke' (cths/get-shape file' :rect-1) + rect-without-stroke' (cths/get-shape file' :rect-2)] + (t/testing "token got applied to rect with stroke and shape stroke got updated" + (t/is (= (:stroke-width (:applied-tokens rect-with-stroke')) (:id token-target'))) + (t/is (= (get-in rect-with-stroke' [:strokes 0 :stroke-width]) 10))) + (t/testing "token got applied to rect without stroke but shape didnt get updated" + (t/is (= (:stroke-width (:applied-tokens rect-without-stroke')) (:id token-target'))) + (t/is (empty? (:strokes rect-without-stroke'))))))))))) + (t/deftest test-toggle-token-none (t/testing "should apply token to all selected items, where no item has the token applied" (t/async From fe9bb69c756f3ab5568125c9c77cd66ba473e44e Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 5 Aug 2024 11:45:32 +0200 Subject: [PATCH 4/4] Update CHANGELOG --- frontend/src/app/main/ui/workspace/tokens/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/app/main/ui/workspace/tokens/CHANGELOG.md b/frontend/src/app/main/ui/workspace/tokens/CHANGELOG.md index 7347888c4..57e68b109 100644 --- a/frontend/src/app/main/ui/workspace/tokens/CHANGELOG.md +++ b/frontend/src/app/main/ui/workspace/tokens/CHANGELOG.md @@ -18,6 +18,12 @@ If possible add video here from PR as well ## Changes +### 2024-08-05 - Fix stroke witdth applying breaking app + +[Link to PR](https://github.com/orgs/tokens-studio/projects/69/views/11?pane=issue&itemId=73072870) + +`:stroke-width` token applying wont update for shapes without a stroke. + ### 2024-07-25 - UX Improvements for the context menu [Link to PR](https://github.com/tokens-studio/tokens-studio-for-penpot/pull/224)