mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Move to tokens ns, add test
This commit is contained in:
parent
cf07de3bcf
commit
5cef23267c
3 changed files with 16 additions and 17 deletions
|
@ -39,25 +39,9 @@
|
|||
(->> (vals tokens)
|
||||
(group-by :type)))
|
||||
|
||||
(defn tokens-name-map
|
||||
"Convert tokens into a map with their `:name` as the key.
|
||||
|
||||
E.g.: {\"sm\" {:token-type :border-radius :id #uuid \"000\" ...}}"
|
||||
[tokens]
|
||||
(->> (map (fn [{:keys [name] :as token}] [name token]) tokens)
|
||||
(into {})))
|
||||
|
||||
(defn tokens-name-map-for-type
|
||||
"Convert tokens with `token-type` into a map with their `:name` as the key.
|
||||
|
||||
E.g.: {\"sm\" {:token-type :border-radius :id #uuid \"000\" ...}}"
|
||||
[token-type tokens]
|
||||
(-> (group-tokens-by-type tokens)
|
||||
(get token-type [])
|
||||
(tokens-name-map)))
|
||||
|
||||
(defn tokens-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}]
|
||||
(->> (tokens-name-map tokens)
|
||||
(->> (wtt/token-names-map tokens)
|
||||
(map (fn [[_k {:keys [name] :as item}]]
|
||||
(cond-> (assoc item :label name)
|
||||
(wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))))))
|
||||
|
|
|
@ -35,6 +35,14 @@
|
|||
{:path (seq path)
|
||||
:selector selector}))
|
||||
|
||||
(defn token-names-map
|
||||
"Convert tokens into a map with their `:name` as the key.
|
||||
|
||||
E.g.: {\"sm\" {:token-type :border-radius :id #uuid \"000\" ...}}"
|
||||
[tokens]
|
||||
(->> (map (fn [{:keys [name] :as token}] [name token]) tokens)
|
||||
(into {})))
|
||||
|
||||
(defn token-names-tree
|
||||
"Convert tokens into a nested tree with their `:name` as the path."
|
||||
[tokens]
|
||||
|
|
|
@ -37,6 +37,13 @@
|
|||
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz")))
|
||||
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz...."))))
|
||||
|
||||
(t/deftest tokens-name-map-test
|
||||
(t/testing "creates a a names map from tokens"
|
||||
(t/is (= {"border-radius.sm" {:name "border-radius.sm", :value "10"}
|
||||
"border-radius.md" {:name "border-radius.md", :value "20"}}
|
||||
(wtt/token-names-map [{:name "border-radius.sm" :value "10"}
|
||||
{:name "border-radius.md" :value "20"}])))))
|
||||
|
||||
(t/deftest tokens-name-tree-test
|
||||
(t/is (= {"foo"
|
||||
{"bar"
|
||||
|
|
Loading…
Add table
Reference in a new issue