FIX: In components, fall back to default theme color variables (#12423)

Component SCSS compilation should use the current theme's SCSS color
variables as a fallback before using the default core colors.

This is mostly a backwards-compatibility fix, new themes and components
should use CSS custom properties, which offer better support for on-the-fly
color scheme changes (dark mode support, etc.).
This commit is contained in:
Penar Musaraj 2021-03-17 13:34:15 -04:00 committed by GitHub
parent 97623f5351
commit eb7f0ec766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -135,8 +135,11 @@ module Stylesheet
rescue
ColorScheme.base_colors
end
elsif (@theme_id && theme.color_scheme)
colors = theme.color_scheme.resolved_colors
else
colors = (@theme_id && theme.color_scheme) ? theme.color_scheme.resolved_colors : ColorScheme.base_colors
colors = Theme.find_by_id(SiteSetting.default_theme_id)&.color_scheme&.resolved_colors ||
ColorScheme.base_colors
end
colors.each do |n, hex|

View File

@ -415,6 +415,24 @@ describe Stylesheet::Manager do
expect { stylesheet.compile }.not_to raise_error
end
it "child theme SCSS includes the default theme's color scheme variables" do
SiteSetting.default_theme_id = theme.id
custom_scheme = ColorScheme.create_from_base(name: "Neutral", base_scheme_id: "Neutral")
ColorSchemeRevisor.revise(custom_scheme, colors: [{ name: "primary", hex: "CC0000" }])
theme.color_scheme_id = custom_scheme.id
theme.save!
scss = "body{ border: 2px solid $primary;}"
child.set_field(target: :common, name: "scss", value: scss)
child.save!
child_theme_manager = Stylesheet::Manager.new(:desktop_theme, child.id)
child_theme_manager.compile(force: true)
child_css = File.read(child_theme_manager.stylesheet_fullpath)
expect(child_css).to include("body{border:2px solid #c00}")
end
end
context 'encoded slugs' do