From 3d99c2a5eb544edf3de1003d238fa70db2089287 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 6 Nov 2024 15:43:20 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20setting=20stroke-color=20vi?= =?UTF-8?q?a=20context-menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/app/common/types/token.cljc | 3 ++- .../src/app/main/ui/workspace/tokens/changes.cljs | 13 ++++++++++--- .../app/main/ui/workspace/tokens/context_menu.cljs | 4 +++- .../app/main/ui/workspace/tokens/token_types.cljs | 2 +- .../src/app/main/ui/workspace/tokens/update.cljs | 3 ++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index 2e21c2dad..933f0da61 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -74,7 +74,8 @@ (sm/register! ::color [:map - [:color {:optional true} token-name-ref]]) + [:fill {:optional true} token-name-ref] + [:stroke-color {:optional true} token-name-ref]]) (def color-keys (schema-keys ::color)) diff --git a/frontend/src/app/main/ui/workspace/tokens/changes.cljs b/frontend/src/app/main/ui/workspace/tokens/changes.cljs index 5be2d4e73..477f705f1 100644 --- a/frontend/src/app/main/ui/workspace/tokens/changes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/changes.cljs @@ -128,13 +128,20 @@ {:reg-objects? true :attrs [:strokes]})) -(defn update-color - [value shape-ids] +(defn update-color [f value shape-ids] (let [color (some->> value (tinycolor/valid-color) (tinycolor/->hex) (str "#"))] - (wdc/change-fill shape-ids {:color color} 0))) + (f shape-ids {:color color} 0))) + +(defn update-fill + [value shape-ids] + (update-color wdc/change-fill value shape-ids)) + +(defn update-stroke-color + [value shape-ids] + (update-color wdc/change-stroke value shape-ids)) (defn update-shape-dimensions [value shape-ids attributes] (ptk/reify ::update-shape-dimensions 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 bedd6c56f..b8ec3af16 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -10,7 +10,6 @@ [app.common.data :as d] [app.main.data.modal :as modal] [app.main.data.tokens :as dt] - [app.main.data.workspace.shape-layout :as dwsl] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.components.dropdown :refer [dropdown]] @@ -185,6 +184,9 @@ :r3 "Bottom Right"} :on-update-shape-all wtch/update-shape-radius-all :on-update-shape wtch/update-shape-radius-single-corner}) + :color (fn [context-data] + [(generic-attribute-actions #{:fill} "Fill" (assoc context-data :on-update-shape wtch/update-fill)) + (generic-attribute-actions #{:stroke-color} "Stroke" (assoc context-data :on-update-shape wtch/update-stroke-color))]) :spacing spacing-attribute-actions :sizing sizing-attribute-actions :rotation (partial generic-attribute-actions #{:rotation} "Rotation") diff --git a/frontend/src/app/main/ui/workspace/tokens/token_types.cljs b/frontend/src/app/main/ui/workspace/tokens/token_types.cljs index ce4c5cbf3..b8247a288 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token_types.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token_types.cljs @@ -24,7 +24,7 @@ :color {:title "Color" :attributes ctt/color-keys - :on-update-shape wtch/update-color + :on-update-shape wtch/update-fill :modal {:key :tokens/color :fields [{:label "Color" :key :color}]}} diff --git a/frontend/src/app/main/ui/workspace/tokens/update.cljs b/frontend/src/app/main/ui/workspace/tokens/update.cljs index d0c6dbec6..bc85bea83 100644 --- a/frontend/src/app/main/ui/workspace/tokens/update.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/update.cljs @@ -19,7 +19,8 @@ (def attributes->shape-update {#{:rx :ry} (fn [v ids _] (wtch/update-shape-radius-all v ids)) #{:r1 :r2 :r3 :r4} wtch/update-shape-radius-single-corner - ctt/color-keys wtch/update-color + #{:fill} wtch/update-fill + #{:stroke-color} wtch/update-stroke-color ctt/stroke-width-keys wtch/update-stroke-width ctt/sizing-keys wtch/update-shape-dimensions ctt/opacity-keys wtch/update-opacity