mirror of
https://github.com/penpot/penpot.git
synced 2025-05-01 21:06:21 +02:00
Fix theme select
This commit is contained in:
parent
9c97b31d28
commit
2104fc04df
3 changed files with 51 additions and 35 deletions
|
@ -16,14 +16,6 @@
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
#?(:clj [app.common.fressian :as fres])))
|
#?(:clj [app.common.fressian :as fres])))
|
||||||
|
|
||||||
;; === Constants
|
|
||||||
|
|
||||||
(def hidden-token-theme-group
|
|
||||||
"")
|
|
||||||
|
|
||||||
(def hidden-token-theme-name
|
|
||||||
"__PENPOT__HIDDEN__TOKEN__THEME__")
|
|
||||||
|
|
||||||
;; === Groups handling
|
;; === Groups handling
|
||||||
|
|
||||||
(def schema:groupable-item
|
(def schema:groupable-item
|
||||||
|
@ -263,6 +255,18 @@
|
||||||
(defn token-theme-path [group name]
|
(defn token-theme-path [group name]
|
||||||
(join-path [group name] theme-separator))
|
(join-path [group name] theme-separator))
|
||||||
|
|
||||||
|
(defn split-token-theme-path [path]
|
||||||
|
(split-path path theme-separator))
|
||||||
|
|
||||||
|
(def hidden-token-theme-group
|
||||||
|
"")
|
||||||
|
|
||||||
|
(def hidden-token-theme-name
|
||||||
|
"__PENPOT__HIDDEN__TOKEN__THEME__")
|
||||||
|
|
||||||
|
(def hidden-token-theme-path
|
||||||
|
(token-theme-path hidden-token-theme-group hidden-token-theme-name))
|
||||||
|
|
||||||
(defprotocol ITokenTheme
|
(defprotocol ITokenTheme
|
||||||
(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")
|
||||||
(theme-path [_] "get `token-theme-path` from theme")
|
(theme-path [_] "get `token-theme-path` from theme")
|
||||||
|
|
|
@ -462,6 +462,15 @@
|
||||||
(def workspace-token-theme-tree
|
(def workspace-token-theme-tree
|
||||||
(l/derived #(or (some-> % ctob/get-theme-tree) []) tokens-lib))
|
(l/derived #(or (some-> % ctob/get-theme-tree) []) tokens-lib))
|
||||||
|
|
||||||
|
(def workspace-token-theme-tree-no-hidden
|
||||||
|
(l/derived (fn [lib]
|
||||||
|
(or
|
||||||
|
(some-> lib
|
||||||
|
(ctob/delete-theme ctob/hidden-token-theme-group ctob/hidden-token-theme-name)
|
||||||
|
(ctob/get-theme-tree))
|
||||||
|
[]))
|
||||||
|
tokens-lib))
|
||||||
|
|
||||||
(def workspace-token-themes
|
(def workspace-token-themes
|
||||||
(l/derived #(or (some-> % ctob/get-themes) []) tokens-lib))
|
(l/derived #(or (some-> % ctob/get-themes) []) tokens-lib))
|
||||||
|
|
||||||
|
@ -477,6 +486,9 @@
|
||||||
(def workspace-active-theme-paths
|
(def workspace-active-theme-paths
|
||||||
(l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib))
|
(l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib))
|
||||||
|
|
||||||
|
(def workspace-active-theme-paths-no-hidden
|
||||||
|
(l/derived #(disj % ctob/hidden-token-theme-path) workspace-active-theme-paths))
|
||||||
|
|
||||||
(def workspace-active-set-names
|
(def workspace-active-set-names
|
||||||
(l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib))
|
(l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib))
|
||||||
|
|
||||||
|
|
|
@ -17,15 +17,16 @@
|
||||||
[app.main.ui.components.dropdown :refer [dropdown]]
|
[app.main.ui.components.dropdown :refer [dropdown]]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]
|
||||||
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
(mf/defc themes-list
|
(mf/defc themes-list
|
||||||
[{:keys [themes active-theme-ids on-close grouped?]}]
|
[{:keys [themes active-theme-paths on-close grouped?]}]
|
||||||
(when (seq themes)
|
(when (seq themes)
|
||||||
[:ul
|
[:ul
|
||||||
(for [[_ {:keys [group name] :as theme}] themes
|
(for [[_ {:keys [group name] :as theme}] themes
|
||||||
:let [theme-id (ctob/theme-path theme)
|
:let [theme-id (ctob/theme-path theme)
|
||||||
selected? (get active-theme-ids theme-id)]]
|
selected? (get active-theme-paths theme-id)]]
|
||||||
[:li {:key theme-id
|
[:li {:key theme-id
|
||||||
:class (stl/css-case
|
:class (stl/css-case
|
||||||
:checked-element true
|
:checked-element true
|
||||||
|
@ -39,37 +40,34 @@
|
||||||
[:span {:class (stl/css :check-icon)} i/tick]])]))
|
[:span {:class (stl/css :check-icon)} i/tick]])]))
|
||||||
|
|
||||||
(mf/defc theme-options
|
(mf/defc theme-options
|
||||||
[{:keys [on-close]}]
|
[{:keys [active-theme-paths themes on-close]}]
|
||||||
(let [active-theme-ids (dm/fixme (mf/deref refs/workspace-active-theme-paths))
|
[:ul
|
||||||
theme-groups (mf/deref refs/workspace-token-theme-tree)]
|
(for [[group themes] themes]
|
||||||
[:ul
|
[:li {:key group}
|
||||||
(for [[group themes] theme-groups]
|
(when (seq group)
|
||||||
[:li {:key group}
|
[:span {:class (stl/css :group)} group])
|
||||||
(when (seq group)
|
[:& themes-list {:themes themes
|
||||||
[:span {:class (stl/css :group)} group])
|
:active-theme-paths active-theme-paths
|
||||||
[:& themes-list {:themes themes
|
:on-close on-close
|
||||||
:active-theme-ids active-theme-ids
|
:grouped? true}]])
|
||||||
:on-close on-close
|
[:li {:class (stl/css-case :checked-element true
|
||||||
:grouped? true}]])
|
:checked-element-button true)
|
||||||
[:li {:class (stl/css-case :checked-element true
|
:on-click #(modal/show! :tokens/themes {})}
|
||||||
:checked-element-button true)
|
[:span "Edit themes"]
|
||||||
:on-click #(modal/show! :tokens/themes {})}
|
[:span {:class (stl/css :icon)} i/arrow]]])
|
||||||
[:span "Edit themes"]
|
|
||||||
[:span {:class (stl/css :icon)} i/arrow]]]))
|
|
||||||
|
|
||||||
(mf/defc theme-select
|
(mf/defc theme-select
|
||||||
[{:keys []}]
|
[{:keys []}]
|
||||||
(let [;; Store
|
(let [;; Store
|
||||||
temp-theme-id (dm/legacy (mf/deref refs/workspace-temp-theme-id))
|
active-theme-paths (mf/deref refs/workspace-active-theme-paths-no-hidden)
|
||||||
active-theme-ids (dm/legacy (-> (mf/deref refs/workspace-active-theme-paths)
|
active-themes-count (count active-theme-paths)
|
||||||
(disj temp-theme-id)))
|
themes (mf/deref refs/workspace-token-theme-tree-no-hidden)
|
||||||
active-themes-count (count active-theme-ids)
|
|
||||||
themes (mf/deref refs/workspace-token-theme-tree)
|
|
||||||
|
|
||||||
;; Data
|
;; Data
|
||||||
current-label (cond
|
current-label (cond
|
||||||
(> active-themes-count 1) (str active-themes-count " themes active")
|
(> active-themes-count 1) (str active-themes-count " themes active")
|
||||||
;; (pos? active-themes-count) (get-in themes [(first active-theme-ids) :name])
|
(= active-themes-count 1) (some-> (first active-theme-paths)
|
||||||
|
(str/replace "/" " / "))
|
||||||
:else "No theme active")
|
:else "No theme active")
|
||||||
|
|
||||||
;; State
|
;; State
|
||||||
|
@ -90,4 +88,6 @@
|
||||||
[:& dropdown {:show is-open? :on-close on-close-dropdown}
|
[:& dropdown {:show is-open? :on-close on-close-dropdown}
|
||||||
[:div {:ref dropdown-element*
|
[:div {:ref dropdown-element*
|
||||||
:class (stl/css :custom-select-dropdown)}
|
:class (stl/css :custom-select-dropdown)}
|
||||||
[:& theme-options {:on-close on-close-dropdown}]]]]))
|
[:& theme-options {:active-theme-paths active-theme-paths
|
||||||
|
:themes themes
|
||||||
|
:on-close on-close-dropdown}]]]]))
|
||||||
|
|
Loading…
Add table
Reference in a new issue