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

Add separate gap

This commit is contained in:
Florian Schroedl 2024-07-22 18:23:12 +02:00
parent c00023319a
commit 2411eeb644

View file

@ -253,14 +253,16 @@
{:padding {:p1 "Top" {:padding {:p1 "Top"
:p2 "Right" :p2 "Right"
:p3 "Bottom" :p3 "Bottom"
:p4 "Left"}}) :p4 "Left"}
:gap {:column-gap "Column Gap"
:row-gap "Row Gap"}})
(defn spacing-attribute-actions [{:keys [token-id selected-shapes] :as _props}] (defn spacing-attribute-actions [{:keys [token-id selected-shapes] :as _props}]
(let [token {:id token-id} (let [token {:id token-id}
padding-attrs (:padding spacing) padding-attrs (:padding spacing)
all-padding-attrs (into #{} (keys padding-attrs)) all-padding-attrs (into #{} (keys padding-attrs))
{:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes all-padding-attrs) {:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes all-padding-attrs)
single-attributes (->> padding-attrs single-padding (->> padding-attrs
(map (fn [[attr title]] (map (fn [[attr title]]
(let [selected? (selected-pred attr)] (let [selected? (selected-pred attr)]
{:title title {:title title
@ -274,8 +276,36 @@
selected? (wtc/unapply-token props) selected? (wtc/unapply-token props)
:else (-> (assoc props :on-update-shape wtc/update-shape-radius-single-corner) :else (-> (assoc props :on-update-shape wtc/update-shape-radius-single-corner)
(wtc/apply-token)))] (wtc/apply-token)))]
(st/emit! event))})))) (st/emit! event))})))
all-attribute (let [props {:attributes all-padding-attrs (into))
all-padding (let [props {:attributes all-padding-attrs
:token token
:shape-ids shape-ids}]
{:title "All"
:selected? all-selected?
:action #(if all-selected?
(st/emit! (wtc/unapply-token props))
(st/emit! (wtc/apply-token (assoc props :on-update-shape wtc/update-shape-radius-all))))})
gap-attrs (:gap spacing)
all-gap-attrs (into #{} (keys gap-attrs))
{:keys [all-selected? selected-pred shape-ids]} (attribute-actions token selected-shapes all-gap-attrs)
single-gap (->> gap-attrs
(map (fn [[attr title]]
(let [selected? (selected-pred attr)]
{:title title
:selected? (and (not all-selected?) selected?)
:action #(let [props {:attributes #{attr}
:token token
:shape-ids shape-ids}
event (cond
all-selected? (-> (assoc props :attributes-to-remove #{:r1 :r2 :r3 :r4 :rx :ry})
(wtc/apply-token))
selected? (wtc/unapply-token props)
:else (-> (assoc props :on-update-shape wtc/update-shape-radius-single-corner)
(wtc/apply-token)))]
(st/emit! event))})))
(into))
all-gap (let [props {:attributes all-gap-attrs
:token token :token token
:shape-ids shape-ids}] :shape-ids shape-ids}]
{:title "All" {:title "All"
@ -283,7 +313,11 @@
:action #(if all-selected? :action #(if all-selected?
(st/emit! (wtc/unapply-token props)) (st/emit! (wtc/unapply-token props))
(st/emit! (wtc/apply-token (assoc props :on-update-shape wtc/update-shape-radius-all))))})] (st/emit! (wtc/apply-token (assoc props :on-update-shape wtc/update-shape-radius-all))))})]
(concat [all-attribute] single-attributes))) (concat [all-padding]
single-padding
[:separator]
[all-gap]
single-gap)))
(comment (comment
(comment (comment