0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 22:22:43 -05:00

Allow setting stroke-color via context-menu

This commit is contained in:
Florian Schroedl 2024-11-06 15:43:20 +01:00
parent b3b8121d60
commit 3d99c2a5eb
5 changed files with 18 additions and 7 deletions

View file

@ -74,7 +74,8 @@
(sm/register! ::color (sm/register! ::color
[:map [: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)) (def color-keys (schema-keys ::color))

View file

@ -128,13 +128,20 @@
{:reg-objects? true {:reg-objects? true
:attrs [:strokes]})) :attrs [:strokes]}))
(defn update-color (defn update-color [f value shape-ids]
[value shape-ids]
(let [color (some->> value (let [color (some->> value
(tinycolor/valid-color) (tinycolor/valid-color)
(tinycolor/->hex) (tinycolor/->hex)
(str "#"))] (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] (defn update-shape-dimensions [value shape-ids attributes]
(ptk/reify ::update-shape-dimensions (ptk/reify ::update-shape-dimensions

View file

@ -10,7 +10,6 @@
[app.common.data :as d] [app.common.data :as d]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.tokens :as dt] [app.main.data.tokens :as dt]
[app.main.data.workspace.shape-layout :as dwsl]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.dropdown :refer [dropdown]] [app.main.ui.components.dropdown :refer [dropdown]]
@ -185,6 +184,9 @@
:r3 "Bottom Right"} :r3 "Bottom Right"}
:on-update-shape-all wtch/update-shape-radius-all :on-update-shape-all wtch/update-shape-radius-all
:on-update-shape wtch/update-shape-radius-single-corner}) :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 :spacing spacing-attribute-actions
:sizing sizing-attribute-actions :sizing sizing-attribute-actions
:rotation (partial generic-attribute-actions #{:rotation} "Rotation") :rotation (partial generic-attribute-actions #{:rotation} "Rotation")

View file

@ -24,7 +24,7 @@
:color :color
{:title "Color" {:title "Color"
:attributes ctt/color-keys :attributes ctt/color-keys
:on-update-shape wtch/update-color :on-update-shape wtch/update-fill
:modal {:key :tokens/color :modal {:key :tokens/color
:fields [{:label "Color" :key :color}]}} :fields [{:label "Color" :key :color}]}}

View file

@ -19,7 +19,8 @@
(def attributes->shape-update (def attributes->shape-update
{#{:rx :ry} (fn [v ids _] (wtch/update-shape-radius-all v ids)) {#{:rx :ry} (fn [v ids _] (wtch/update-shape-radius-all v ids))
#{:r1 :r2 :r3 :r4} wtch/update-shape-radius-single-corner #{: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/stroke-width-keys wtch/update-stroke-width
ctt/sizing-keys wtch/update-shape-dimensions ctt/sizing-keys wtch/update-shape-dimensions
ctt/opacity-keys wtch/update-opacity ctt/opacity-keys wtch/update-opacity