mirror of
https://github.com/penpot/penpot.git
synced 2025-02-01 11:59:17 -05:00
Abstract API
This commit is contained in:
parent
e181065bda
commit
2dd994799c
2 changed files with 15 additions and 9 deletions
|
@ -99,15 +99,15 @@
|
||||||
selection-parents (mf/deref selection-parents-ref)
|
selection-parents (mf/deref selection-parents-ref)
|
||||||
|
|
||||||
tokens (mf/deref refs/workspace-tokens)
|
tokens (mf/deref refs/workspace-tokens)
|
||||||
border-radius-tokens (mf/use-memo
|
tokens-by-type (mf/use-memo (mf/deps tokens) #(wtc/group-tokens-by-type tokens))
|
||||||
(mf/deps tokens)
|
|
||||||
#(wtc/tokens-name-map-for-type :border-radius tokens))
|
border-radius-tokens (:border-radius tokens-by-type)
|
||||||
border-radius-options (mf/use-memo
|
border-radius-options (mf/use-memo
|
||||||
(mf/deps shape border-radius-tokens)
|
(mf/deps shape border-radius-tokens)
|
||||||
#(map (fn [[_k {:keys [name] :as item}]]
|
#(wtc/tokens-name-map->select-options
|
||||||
(cond-> (assoc item :label name)
|
{:shape shape
|
||||||
(wtc/token-applied? item shape (wtc/token-attributes :border-radius)) (assoc :selected? true)))
|
:tokens border-radius-tokens
|
||||||
border-radius-tokens))
|
:attributes (wtc/token-attributes :border-radius)}))
|
||||||
|
|
||||||
flex-child? (->> selection-parents (some ctl/flex-layout?))
|
flex-child? (->> selection-parents (some ctl/flex-layout?))
|
||||||
absolute? (ctl/item-absolute? shape)
|
absolute? (ctl/item-absolute? shape)
|
||||||
|
@ -296,7 +296,7 @@
|
||||||
|
|
||||||
on-border-radius-token-unapply
|
on-border-radius-token-unapply
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps ids change-radius border-radius-tokens)
|
(mf/deps ids change-radius)
|
||||||
(fn [token]
|
(fn [token]
|
||||||
(let [token-value (wtc/maybe-resolve-token-value token)]
|
(let [token-value (wtc/maybe-resolve-token-value token)]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
|
@ -306,7 +306,7 @@
|
||||||
|
|
||||||
on-radius-1-change
|
on-radius-1-change
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps ids change-radius border-radius-tokens)
|
(mf/deps ids change-radius)
|
||||||
(fn [value]
|
(fn [value]
|
||||||
(let [token-value (wtc/maybe-resolve-token-value value)]
|
(let [token-value (wtc/maybe-resolve-token-value value)]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
|
|
|
@ -63,6 +63,12 @@
|
||||||
(get token-type [])
|
(get token-type [])
|
||||||
(tokens-name-map)))
|
(tokens-name-map)))
|
||||||
|
|
||||||
|
(defn tokens-name-map->select-options [{:keys [shape tokens attributes]}]
|
||||||
|
(->> (tokens-name-map tokens)
|
||||||
|
(map (fn [[_k {:keys [name] :as item}]]
|
||||||
|
(cond-> (assoc item :label name)
|
||||||
|
(token-applied? item shape attributes) (assoc :selected? true))))))
|
||||||
|
|
||||||
;; Update functions ------------------------------------------------------------
|
;; Update functions ------------------------------------------------------------
|
||||||
|
|
||||||
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]
|
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]
|
||||||
|
|
Loading…
Add table
Reference in a new issue