mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:42:53 +08:00
Add site setting to pick dark mode color scheme (#10390)
Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
parent
b86198198f
commit
9c9aa21726
17
app/models/color_scheme_setting.rb
Normal file
17
app/models/color_scheme_setting.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ColorSchemeSetting < EnumSiteSetting
|
||||
|
||||
def self.valid_value?(val)
|
||||
val == -1 || ColorScheme.find_by_id(val)
|
||||
end
|
||||
|
||||
def self.values
|
||||
values = [{ name: I18n.t("site_settings.dark_mode_none"), value: -1 }]
|
||||
ColorScheme.all.map do |c|
|
||||
values << { name: c.name, value: c.id }
|
||||
end
|
||||
values
|
||||
end
|
||||
|
||||
end
|
|
@ -1834,6 +1834,8 @@ en:
|
|||
desktop_category_page_style: "Visual style for the /categories page."
|
||||
category_colors: "A list of hexadecimal color values allowed for categories."
|
||||
category_style: "Visual style for category badges."
|
||||
default_dark_mode_color_scheme_id: "The color scheme used when in dark mode."
|
||||
dark_mode_none: "None"
|
||||
|
||||
max_image_size_kb: "The maximum image upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well. Images larger than this and smaller than client_max_body_size will be resized to fit on upload."
|
||||
max_attachment_size_kb: "The maximum attachment files upload size in kB. This must be configured in nginx (client_max_body_size) / apache or proxy as well."
|
||||
|
|
|
@ -247,7 +247,8 @@ basic:
|
|||
hidden: true
|
||||
default_dark_mode_color_scheme_id:
|
||||
default: -1
|
||||
hidden: true
|
||||
type: enum
|
||||
enum: "ColorSchemeSetting"
|
||||
client: true
|
||||
relative_date_duration:
|
||||
client: true
|
||||
|
|
|
@ -364,8 +364,10 @@ describe ApplicationHelper do
|
|||
expect(cs_stylesheets.scan("stylesheets/color_definitions").size).to eq(2)
|
||||
end
|
||||
|
||||
it 'fails gracefully when the dark color scheme ID is set but missing' do
|
||||
SiteSetting.default_dark_mode_color_scheme_id = -5
|
||||
it 'handles a missing dark color scheme gracefully' do
|
||||
scheme = ColorScheme.create!(name: "pyramid")
|
||||
SiteSetting.default_dark_mode_color_scheme_id = scheme.id
|
||||
scheme.destroy!
|
||||
cs_stylesheets = helper.discourse_color_scheme_stylesheets
|
||||
|
||||
expect(cs_stylesheets).to include("stylesheets/color_definitions")
|
||||
|
|
Loading…
Reference in New Issue
Block a user