mirror of
https://github.com/penpot/penpot.git
synced 2025-08-01 09:18:21 +02:00
Activating initial sets by adding them to the token theme
This commit is contained in:
parent
5825fa656b
commit
f1f2767e2a
2 changed files with 24 additions and 6 deletions
|
@ -273,6 +273,7 @@
|
||||||
(def hidden-token-theme-path
|
(def hidden-token-theme-path
|
||||||
(token-theme-path hidden-token-theme-group hidden-token-theme-name))
|
(token-theme-path hidden-token-theme-group hidden-token-theme-name))
|
||||||
|
|
||||||
|
|
||||||
(defprotocol ITokenTheme
|
(defprotocol ITokenTheme
|
||||||
(set-sets [_ set-names] "set the active token sets")
|
(set-sets [_ set-names] "set the active token sets")
|
||||||
(toggle-set [_ set-name] "togle a set used / not used in the theme")
|
(toggle-set [_ set-name] "togle a set used / not used in the theme")
|
||||||
|
@ -347,6 +348,12 @@
|
||||||
|
|
||||||
token-theme))
|
token-theme))
|
||||||
|
|
||||||
|
(defn make-hidden-token-theme
|
||||||
|
[& {:keys [] :as params}]
|
||||||
|
(make-token-theme (assoc params
|
||||||
|
:group hidden-token-theme-group
|
||||||
|
:name hidden-token-theme-name)))
|
||||||
|
|
||||||
;; === TokenThemes (collection)
|
;; === TokenThemes (collection)
|
||||||
|
|
||||||
(defprotocol ITokenThemes
|
(defprotocol ITokenThemes
|
||||||
|
|
|
@ -182,10 +182,7 @@
|
||||||
active-token-set-names (ctob/get-active-themes-set-names tokens-lib)
|
active-token-set-names (ctob/get-active-themes-set-names tokens-lib)
|
||||||
theme (-> (or (some-> prev-theme
|
theme (-> (or (some-> prev-theme
|
||||||
(ctob/set-sets active-token-set-names))
|
(ctob/set-sets active-token-set-names))
|
||||||
(ctob/make-token-theme
|
(ctob/make-hidden-token-theme :sets active-token-set-names))
|
||||||
:group ctob/hidden-token-theme-group
|
|
||||||
:name ctob/hidden-token-theme-name
|
|
||||||
:sets active-token-set-names))
|
|
||||||
(ctob/toggle-set token-set-name))
|
(ctob/toggle-set token-set-name))
|
||||||
prev-active-token-themes (ctob/get-active-theme-paths tokens-lib)
|
prev-active-token-themes (ctob/get-active-theme-paths tokens-lib)
|
||||||
changes (-> (pcb/empty-changes it)
|
changes (-> (pcb/empty-changes it)
|
||||||
|
@ -218,8 +215,22 @@
|
||||||
token-set-name (or (:name token-set) "Global")
|
token-set-name (or (:name token-set) "Global")
|
||||||
changes (if (not token-set)
|
changes (if (not token-set)
|
||||||
;; No set created add a global set
|
;; No set created add a global set
|
||||||
(->> (ctob/make-token-set :name token-set-name :tokens {(:name token) token})
|
(let [tokens-lib (get-tokens-lib state)
|
||||||
(pcb/add-token-set (pcb/empty-changes)))
|
token-set (ctob/make-token-set :name token-set-name :tokens {(:name token) token})
|
||||||
|
hidden-theme (ctob/make-hidden-token-theme :sets [token-set-name])
|
||||||
|
active-theme-paths (some-> tokens-lib ctob/get-active-theme-paths)
|
||||||
|
add-to-hidden-theme? (= active-theme-paths #{ctob/hidden-token-theme-path})
|
||||||
|
base-changes (pcb/add-token-set (pcb/empty-changes) token-set)]
|
||||||
|
(cond
|
||||||
|
(not tokens-lib) (-> base-changes
|
||||||
|
(pcb/add-token-theme hidden-theme)
|
||||||
|
(pcb/update-active-token-themes #{ctob/hidden-token-theme-path} #{}))
|
||||||
|
|
||||||
|
add-to-hidden-theme? (let [prev-hidden-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name)]
|
||||||
|
(-> base-changes
|
||||||
|
(pcb/update-token-theme (ctob/toggle-set prev-hidden-theme ctob/hidden-token-theme-path) prev-hidden-theme)))
|
||||||
|
|
||||||
|
:else base-changes))
|
||||||
;; Either update or add token to existing set
|
;; Either update or add token to existing set
|
||||||
(if-let [prev-token (ctob/get-token token-set (or prev-token-name (:name token)))]
|
(if-let [prev-token (ctob/get-token token-set (or prev-token-name (:name token)))]
|
||||||
(pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token)
|
(pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue