mirror of
https://github.com/penpot/penpot.git
synced 2025-01-06 14:50:20 -05:00
Apply tokens directly to shape
This commit is contained in:
parent
cdca00a986
commit
c60c5ac34f
3 changed files with 19 additions and 10 deletions
|
@ -55,19 +55,23 @@
|
|||
(->> (map (fn [attr] [attr token-id]) attributes)
|
||||
(into {})))
|
||||
|
||||
(defn apply-token-id [{:keys [shape token-id attributes]}]
|
||||
(defn apply-token-id-to-attributes [{:keys [shape token-id attributes]}]
|
||||
(let [token (token-from-attributes token-id attributes)]
|
||||
(toggle-or-apply-token shape token)))
|
||||
|
||||
(defn apply-token-to-shape [{:keys [shape _token-id _attributes] :as props}]
|
||||
(let [applied-tokens (apply-token-id-to-attributes props)]
|
||||
(update shape :applied-tokens #(merge % applied-tokens))))
|
||||
|
||||
(defn update-token-from-attributes
|
||||
[{:keys [token-id shape-id attributes]}]
|
||||
(ptk/reify ::update-token-from-attributes
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [shape (get-shape-from-state shape-id state)
|
||||
applied-tokens (apply-token-id {:shape shape
|
||||
:token-id token-id
|
||||
:attributes attributes})]
|
||||
applied-tokens (apply-token-id-to-attributes {:shape shape
|
||||
:token-id token-id
|
||||
:attributes attributes})]
|
||||
(rx/of (update-shape shape-id {:applied-tokens applied-tokens}))))))
|
||||
|
||||
(defn add-token
|
||||
|
|
|
@ -262,7 +262,7 @@
|
|||
(update-fn shape)
|
||||
shape))
|
||||
{:reg-objects? true
|
||||
:attrs [:rx :ry :r1 :r2 :r3 :r4]})))
|
||||
:attrs [:rx :ry :r1 :r2 :r3 :r4 :applied-tokens]})))
|
||||
|
||||
on-switch-to-radius-1
|
||||
(mf/use-fn
|
||||
|
@ -293,12 +293,14 @@
|
|||
(fn [value]
|
||||
(let [token (when (symbol? value)
|
||||
(get border-radius-tokens (str value)))
|
||||
token-value (wtc/resolve-token-value token)]
|
||||
token-value (some-> token wtc/resolve-token-value)]
|
||||
(st/emit!
|
||||
(dt/update-token-from-attributes {:token-id (:id token)
|
||||
:shape-id (first ids)
|
||||
:attributes (get-in wtc/token-types [:border-radius :attributes])})
|
||||
(change-radius #(ctsr/set-radius-1 % (or token-value value)))))))
|
||||
(change-radius (fn [shape]
|
||||
(cond-> shape
|
||||
token-value (#(dt/apply-token-to-shape {:token-id (:id token)
|
||||
:shape %
|
||||
:attributes (wtc/token-attributes :border-radius)}))
|
||||
:always (ctsr/set-radius-1 (or token-value value)))))))))
|
||||
|
||||
on-radius-multi-change
|
||||
(mf/use-fn
|
||||
|
|
|
@ -188,3 +188,6 @@
|
|||
{:label "Paragraph Indent" :key :paragraph-indent}
|
||||
{:label "Text Decoration" :key :text-decoration}
|
||||
{:label "Text Case" :key :text-case}]}}]))
|
||||
|
||||
(defn token-attributes [token-type]
|
||||
(get-in token-types [token-type :attributes]))
|
||||
|
|
Loading…
Reference in a new issue