0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Activate themes via lib

This commit is contained in:
Florian Schroedl 2024-09-24 15:25:29 +02:00
parent 4c327f38ef
commit 844819a50c
6 changed files with 36 additions and 22 deletions

View file

@ -258,7 +258,7 @@
[:update-active-token-themes
[:map {:title "UpdateActiveTokenThemes"}
[:type [:= :update-active-token-themes]]
[:theme-ids [:set ::sm/uuid]]]]
[:theme-ids [:set :string]]]]
[:delete-temporary-token-theme
[:map {:title "DeleteTemporaryTokenThemeChange"}
@ -846,7 +846,10 @@
(defmethod process-change :update-active-token-themes
[data {:keys [theme-ids]}]
(ctotl/assoc-active-token-themes data theme-ids))
(-> data
(update :tokens-lib #(-> %
(ctob/ensure-tokens-lib)
(ctob/set-active-themes theme-ids)))))
(defmethod process-change :delete-temporary-token-theme
[data {:keys [id group name]}]

View file

@ -328,6 +328,7 @@
(get-theme-groups [_] "get a sequence of group names by order")
(get-active-theme-paths [_] "get the active theme paths")
(get-active-themes [_] "get an ordered sequence of active themes in the library")
(set-active-themes [_ active-themes] "set active themes in library")
(theme-active? [_ group name] "predicate if token theme is active")
(activate-theme [_ group name] "adds theme from the active-themes")
(deactivate-theme [_ group name] "removes theme from the active-themes")
@ -489,6 +490,12 @@
(get-theme [_ group name]
(dm/get-in themes [group name]))
(set-active-themes [_ active-themes]
(TokensLib. sets
set-groups
themes
active-themes))
(activate-theme [this group name]
(if-let [theme (get-theme this group name)]
(let [group-themes (->> (get themes group)

View file

@ -140,17 +140,19 @@
theme))
:else changes)))
(defn toggle-token-theme [token-theme-id]
(ptk/reify ::toggle-token-theme
(defn toggle-token-theme-active? [group name]
(ptk/reify ::toggle-token-theme-active?
ptk/WatchEvent
(watch [it state _]
(let [themes (wtts/get-active-theme-ids state)
new-themes (wtts/toggle-active-theme-id token-theme-id state)
changes (-> (pcb/empty-changes it)
(pcb/update-active-token-themes new-themes themes))]
(let [tokens-lib (get-tokens-lib state)
prev-active-token-themes (some-> tokens-lib
(ctob/get-active-theme-paths))
active-token-themes (some-> tokens-lib
(ctob/toggle-theme-active? group name)
(ctob/get-active-theme-paths))
changes (pcb/update-active-token-themes (pcb/empty-changes it) active-token-themes prev-active-token-themes)]
(rx/of
(dch/commit-changes changes)
(wtu/update-workspace-tokens))))))
(dch/commit-changes changes))))))
(defn delete-token-theme [token-theme-id]
(ptk/reify ::delete-token-theme

View file

@ -471,10 +471,10 @@
(def workspace-ordered-token-sets
(l/derived #(or (some-> % ctob/get-sets) []) tokens-lib))
(dm/legacy
(def workspace-active-theme-ids
(l/derived wtts/get-active-theme-ids st/state))
(def workspace-active-theme-paths
(l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib))
(dm/legacy
(def workspace-temp-theme-id
(l/derived wtts/get-temp-theme-id st/state))

View file

@ -7,6 +7,7 @@
(ns app.main.ui.workspace.tokens.modals.themes
(:require-macros [app.main.style :as stl])
(:require
[app.common.types.tokens-lib :as ctob]
[app.main.data.modal :as modal]
[app.main.data.tokens :as wdt]
[app.main.refs :as refs]
@ -55,7 +56,7 @@
(mf/defc themes-overview
[{:keys [set-state]}]
(let [active-theme-ids (mf/deref refs/workspace-active-theme-ids)
(let [active-theme-ids (mf/deref refs/workspace-active-theme-paths)
themes-groups (mf/deref refs/workspace-token-theme-tree)
on-edit-theme (fn [theme e]
(dom/prevent-default e)
@ -69,15 +70,15 @@
(when (seq group)
[:span {:class (stl/css :theme-group-label)} group])
[:ul {:class (stl/css :theme-group-rows-wrapper)}
(for [[_ {:keys [id name] :as theme}] themes
:let [selected? (some? (get active-theme-ids id))]]
(for [[_ {:keys [id group name] :as theme}] themes
:let [selected? (some? (get active-theme-ids (ctob/theme-path theme)))]]
[:li {:key (str "token-theme-" id)
:class (stl/css :theme-row)}
[:div {:class (stl/css :theme-row-left)}
[:div {:on-click (fn [e]
(dom/prevent-default e)
(dom/stop-propagation e)
(st/emit! (wdt/toggle-token-theme id)))}
(st/emit! (wdt/toggle-token-theme-active? group name)))}
[:& switch {:name (str "Theme" name)
:on-change (constantly nil)
:selected? selected?}]]

View file

@ -8,6 +8,7 @@
(:require-macros [app.main.style :as stl])
(:require
[app.common.data.macros :as dm]
[app.common.types.tokens-lib :as ctob]
[app.common.uuid :as uuid]
[app.main.data.modal :as modal]
[app.main.data.tokens :as wdt]
@ -22,8 +23,8 @@
[{:keys [themes active-theme-ids on-close grouped?]}]
(when (seq themes)
[:ul
(for [[_ {:keys [id name]}] themes
:let [selected? (get active-theme-ids id)]]
(for [[_ {:keys [id group name] :as theme}] themes
:let [selected? (get active-theme-ids (ctob/theme-path theme))]]
[:li {:key id
:class (stl/css-case
:checked-element true
@ -31,14 +32,14 @@
:is-selected selected?)
:on-click (fn [e]
(dom/stop-propagation e)
(st/emit! (wdt/toggle-token-theme id))
(st/emit! (wdt/toggle-token-theme-active? group name))
(on-close))}
[:span {:class (stl/css :label)} name]
[:span {:class (stl/css :check-icon)} i/tick]])]))
(mf/defc theme-options
[{:keys [on-close]}]
(let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-ids))
(let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-paths))
theme-groups (mf/deref refs/workspace-token-theme-tree)]
[:ul
(for [[group themes] theme-groups]
@ -59,7 +60,7 @@
[{:keys []}]
(let [;; Store
temp-theme-id (dm/legacy (mf/deref refs/workspace-temp-theme-id))
active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-ids)
active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-paths)
(disj temp-theme-id)))
active-themes-count (count active-theme-ids)
themes (mf/deref refs/workspace-token-theme-tree)