Add minor optimization to token-pill component

This commit is contained in:
Andrey Antukh 2025-02-05 18:12:14 +01:00
parent 05a459ea19
commit f0e5196659

View file

@ -9,6 +9,7 @@
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.main.style :as stl]) [app.main.style :as stl])
(:require (:require
[app.common.data :as d]
[app.common.files.helpers :as cfh] [app.common.files.helpers :as cfh]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.ui.components.color-bullet :refer [color-bullet]] [app.main.ui.components.color-bullet :refer [color-bullet]]
@ -157,15 +158,11 @@
shape-ids (into #{} xf:map-id selected-shapes)] shape-ids (into #{} xf:map-id selected-shapes)]
(wtt/shapes-applied-all? ids-by-attributes shape-ids attributes))) (wtt/shapes-applied-all? ids-by-attributes shape-ids attributes)))
(mf/defc token-pill* (mf/defc token-pill*
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo]}
[{:keys [on-click token on-context-menu selected-shapes active-theme-tokens]}] [{:keys [on-click token on-context-menu selected-shapes active-theme-tokens]}]
(let [{:keys [name value errors]} token (let [{:keys [name value errors]} token
token
(or (get active-theme-tokens (:name token)) token)
has-selected? (pos? (count selected-shapes)) has-selected? (pos? (count selected-shapes))
is-reference? (wtt/is-reference? token) is-reference? (wtt/is-reference? token)
contains-path? (str/includes? name ".") contains-path? (str/includes? name ".")
@ -175,12 +172,12 @@
full-applied? full-applied?
(if has-selected? (if has-selected?
(applied-all-attributes? token selected-shapes (or all-attributes attributes)) (applied-all-attributes? token selected-shapes (d/nilv all-attributes attributes))
true) true)
applied? applied?
(if has-selected? (if has-selected?
(wtt/shapes-token-applied? token selected-shapes (or all-attributes attributes)) (wtt/shapes-token-applied? token selected-shapes (d/nilv all-attributes attributes))
false) false)
half-applied? half-applied?
@ -196,11 +193,16 @@
(not (contains-reference-value? value active-theme-tokens))) (not (contains-reference-value? value active-theme-tokens)))
no-valid-value (seq errors) no-valid-value (seq errors)
errors? (or ref-not-in-active-set
errors?
(or ref-not-in-active-set
no-valid-value) no-valid-value)
color (when (wtt/color-token? token) color
(wtt/resolved-token-bullet-color token)) (when (wtt/color-token? token)
(let [theme-token (get active-theme-tokens (:name token))]
(or (wtt/resolved-token-bullet-color theme-token)
(wtt/resolved-token-bullet-color token))))
on-click on-click
(mf/use-fn (mf/use-fn