mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 06:57:55 +08:00
FIX: Ensure ColorScheme#resolve falls back to base for missing color (#20186)
When a CUSTOM_SCHEME is missing a color (e.g. 'Dracula' is missing a 'highlight' color), we need to fallback to `ColorScheme.base_colors`. This regressed in 66256c15bd81c633d4a363acd262766618573396
This commit is contained in:
parent
a86112fc25
commit
754d1b71aa
@ -448,10 +448,11 @@ class ColorScheme < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def resolved_colors
|
||||
from_base = base_colors.except("hover", "selected")
|
||||
from_base = ColorScheme.base_colors
|
||||
from_custom_scheme = base_colors
|
||||
from_db = colors.map { |c| [c.name, c.hex] }.to_h
|
||||
|
||||
resolved = from_base.merge(from_db)
|
||||
resolved = from_base.merge(from_custom_scheme).except("hover", "selected").merge(from_db)
|
||||
|
||||
# Equivalent to primary-100 in light mode, or primary-low in dark mode
|
||||
resolved["hover"] ||= ColorMath.dark_light_diff(
|
||||
|
@ -144,6 +144,21 @@ RSpec.describe ColorScheme do
|
||||
expect(resolved["secondary"]).to eq(ColorScheme.base_colors["secondary"])
|
||||
end
|
||||
|
||||
it "falls back to default scheme if base scheme does not have color" do
|
||||
custom_scheme_id = "BaseSchemeWithNoHighlightColor"
|
||||
ColorScheme::CUSTOM_SCHEMES[custom_scheme_id.to_sym] = { "secondary" => "123123" }
|
||||
|
||||
color_scheme = ColorScheme.new(base_scheme_id: custom_scheme_id)
|
||||
color_scheme.color_scheme_colors << ColorSchemeColor.new(name: "primary", hex: "121212")
|
||||
|
||||
resolved = color_scheme.resolved_colors
|
||||
expect(resolved["primary"]).to eq("121212") # From db
|
||||
expect(resolved["secondary"]).to eq("123123") # From custom scheme
|
||||
expect(resolved["tertiary"]).to eq("0088cc") # From `foundation/colors.scss`
|
||||
ensure
|
||||
ColorScheme::CUSTOM_SCHEMES.delete(custom_scheme_id)
|
||||
end
|
||||
|
||||
it "calculates 'hover' and 'selected' from existing db colors in dark mode" do
|
||||
color_scheme = ColorScheme.new
|
||||
color_scheme.color_scheme_colors << ColorSchemeColor.new(name: "primary", hex: "ddd")
|
||||
|
Loading…
x
Reference in New Issue
Block a user