adjust colors resolver to handle communities color (#17339)

This commit is contained in:
Jamie Caprani 2023-09-21 01:03:02 +02:00 committed by GitHub
parent 0ae1e9bc5a
commit e41fb03b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 10 deletions

View File

@ -272,17 +272,17 @@
([color suffix]
(custom-color color suffix nil))
([color suffix opacity]
(let [hex? (not (keyword? color))
color (if (hex-string? (get colors-map color))
(get colors-map color)
(get-in colors-map [color suffix]))]
(cond
(and opacity hex?) (alpha color (/ opacity 100))
opacity (alpha color (/ opacity 100))
hex? color
:else color))))))
(let [hex? (not (keyword? color))
resolved-color (cond hex? color
(hex-string? (get colors-map color)) (get colors-map color)
:else (get-in colors-map
[color suffix]))]
(if opacity
(alpha resolved-color (/ opacity 100))
resolved-color))))))
(defn custom-color-by-theme
"(custom-color-by-theme color suffix-light suffix-dark opacity-light opacity-dark)
color :primary/:purple/...
suffix-light 50/60
@ -290,6 +290,7 @@
opacity-light 0-100 (optional)
opacity-dark 0-100 (optional)
theme :light/:dark (optional)"
{:deprecated true :superseded-by "theme/colors"}
([color suffix-light suffix-dark]
(custom-color-by-theme color suffix-light suffix-dark nil nil (theme/get-theme)))
([color suffix-light suffix-dark opacity-light opacity-dark]

View File

@ -0,0 +1,27 @@
(ns quo2.foundations.colors-test
(:require [cljs.test :refer-macros [deftest testing is]]
[quo2.foundations.colors :as colors]))
(deftest custom-color-resolver-test
(testing "community color - resolves a hex string and ignores suffix of 50"
(is (= "#fff" (colors/custom-color "#fff" 50))))
(testing "community color - resolves a hex string and ignores suffix of 60"
(is (= "#fff" (colors/custom-color "#fff" 60))))
(testing "user/wallet/chat colors - resolves a keyword from the customization map with suffix 50"
(is (= (get-in colors/customization [:blue 50]) (colors/custom-color :blue 50))))
(testing "user/wallet/chat colors - resolves a keyword from the colors map with suffix 60"
(is (= (get-in colors/customization [:blue 60]) (colors/custom-color :blue 60))))
(testing "network colors - resolves a keyword with from the networks map which has no suffix"
(is (= (:ethereum colors/networks) (colors/custom-color :ethereum nil)))))
(deftest custom-color-resolver-with-opacity-test
(testing "community color with 10% opacity- resolves a hex string and ignores suffix of 50"
(is (= "rgba(255,15,NaN,0.1)" (colors/custom-color "#fff" 50 10))))
(testing "community color with 10% opacity- resolves a hex string and ignores suffix of 50"
(is (= "rgba(255,15,NaN,0.9)" (colors/custom-color "#fff" 50 90))))
(testing
"user/wallet/chat colors with 10% opacity - resolves a keyword from the colors map with suffix 50"
(is (= "rgba(42,74,245,0.1)" (colors/custom-color :blue 50 10))))
(testing
"network colors with 10% opacity - resolves a keyword with from the networks map which has no suffix"
(is (= "rgba(117,142,235,0.1)" (colors/custom-color :ethereum nil 10)))))

View File

@ -126,7 +126,7 @@
(defn change-shell-status-bar-style
[]
(rf/dispatch [:change-shell-status-bar-style
(if (or (quo.theme/get-theme)
(if (or (= :dark (quo.theme/get-theme))
(not (home-stack-open?)))
:light
:dark)]))