mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 11:24:59 +08:00
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:
parent
97623f5351
commit
eb7f0ec766
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user