mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 14:12:36 -05:00
Use resolved tokens from style-dictionary
This commit is contained in:
parent
9261c53aff
commit
5c2891b247
4 changed files with 34 additions and 17 deletions
|
@ -34,10 +34,12 @@
|
||||||
[token shapes token-attributes]
|
[token shapes token-attributes]
|
||||||
(some #(token-applied? token % token-attributes) shapes))
|
(some #(token-applied? token % token-attributes) shapes))
|
||||||
|
|
||||||
(defn resolve-token-value [{:keys [value] :as token}]
|
(defn resolve-token-value [{:keys [value resolved-value] :as token}]
|
||||||
(if-let [int-or-double (d/parse-double value)]
|
(or
|
||||||
int-or-double
|
resolved-value
|
||||||
(throw (ex-info (str "Implement token value resolve for " value) token))))
|
(if-let [int-or-double (d/parse-double value)]
|
||||||
|
int-or-double
|
||||||
|
(throw (ex-info (str "Implement token value resolve for " value) token)))))
|
||||||
|
|
||||||
(defn maybe-resolve-token-value [{:keys [value] :as token}]
|
(defn maybe-resolve-token-value [{:keys [value] :as token}]
|
||||||
(when value (resolve-token-value token)))
|
(when value (resolve-token-value token)))
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
||||||
[app.main.ui.workspace.tokens.core :as wtc]
|
[app.main.ui.workspace.tokens.core :as wtc]
|
||||||
|
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
[rumext.v2 :as mf]
|
[rumext.v2 :as mf]
|
||||||
[shadow.resource]))
|
[shadow.resource]))
|
||||||
|
@ -26,16 +28,21 @@
|
||||||
(mf/defc token-pill
|
(mf/defc token-pill
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
[{:keys [on-click token highlighted? on-context-menu]}]
|
[{:keys [on-click token highlighted? on-context-menu]}]
|
||||||
(let [{:keys [name value]} token
|
(js/console.log "token" token)
|
||||||
resolved-value (try
|
(let [{:keys [name value resolved-value errors]} token
|
||||||
(wtc/resolve-token-value token)
|
errors? (seq errors)]
|
||||||
(catch js/Error _ nil))]
|
[:button {:class (stl/css-case :token-pill true
|
||||||
[:div {:class (stl/css-case :token-pill true
|
:token-pill-highlighted highlighted?
|
||||||
:token-pill-highlighted highlighted?
|
:token-pill-invalid errors?)
|
||||||
#_#_:token-pill-invalid (not resolved-value))
|
:title (cond
|
||||||
:title (str (if resolved-value "Token value: " "Invalid token value: ") value)
|
errors? (sd/humanize-errors token)
|
||||||
:on-click on-click
|
:else (->> [(str "Token: " name)
|
||||||
:on-context-menu on-context-menu}
|
(str "Original value: " value)
|
||||||
|
(str "Resolved value: " resolved-value)]
|
||||||
|
(str/join "\n")))
|
||||||
|
:on-click on-click
|
||||||
|
:on-context-menu on-context-menu
|
||||||
|
:disabled errors?}
|
||||||
name]))
|
name]))
|
||||||
|
|
||||||
(mf/defc token-section-icon
|
(mf/defc token-section-icon
|
||||||
|
@ -138,7 +145,8 @@
|
||||||
selected (mf/deref refs/selected-shapes)
|
selected (mf/deref refs/selected-shapes)
|
||||||
selected-shapes (into [] (keep (d/getf objects)) selected)
|
selected-shapes (into [] (keep (d/getf objects)) selected)
|
||||||
|
|
||||||
tokens (mf/deref refs/workspace-tokens)
|
tokens (-> (mf/deref refs/workspace-tokens)
|
||||||
|
(sd/use-resolved-tokens))
|
||||||
token-groups (mf/with-memo [tokens]
|
token-groups (mf/with-memo [tokens]
|
||||||
(sorted-token-groups tokens))]
|
(sorted-token-groups tokens))]
|
||||||
[:article
|
[:article
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
&.token-pill-invalid {
|
&.token-pill-invalid {
|
||||||
|
background-color: var(--button-secondary-background-color-rest);
|
||||||
color: var(--status-color-error-500);
|
color: var(--status-color-error-500);
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
["style-dictionary$default" :as sd]
|
["style-dictionary$default" :as sd]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[rumext.v2 :as mf]
|
[rumext.v2 :as mf]
|
||||||
[shadow.resource]))
|
[shadow.resource]))
|
||||||
|
@ -71,8 +72,13 @@
|
||||||
(js/console.log "Resolved tokens" resolved-tokens))
|
(js/console.log "Resolved tokens" resolved-tokens))
|
||||||
resolved-tokens))))))
|
resolved-tokens))))))
|
||||||
|
|
||||||
(def errors
|
(defn humanize-errors [{:keys [errors value] :as _token}]
|
||||||
{:style-dictionary/missing-reference {:user/message "Could not resolve reference token with the name: %s"}})
|
(->> (map (fn [err]
|
||||||
|
(case err
|
||||||
|
:style-dictionary/missing-reference (str "Could not resolve reference token with the name: " value)
|
||||||
|
nil))
|
||||||
|
errors)
|
||||||
|
(str/join "\n")))
|
||||||
|
|
||||||
(defn tokens-name-map [tokens]
|
(defn tokens-name-map [tokens]
|
||||||
(->> tokens
|
(->> tokens
|
||||||
|
|
Loading…
Add table
Reference in a new issue