From 8dccb28d54558892591e00dc94b02c252f74e30b Mon Sep 17 00:00:00 2001 From: Dimitri Anoudis Date: Thu, 7 Nov 2024 11:33:06 +0000 Subject: [PATCH 1/8] (dark-light-mode): It adds Dark and Light mode for Brand Logo --- javascripts/discourse/components/brand-header-contents.gjs | 6 +++++- settings.yaml | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/javascripts/discourse/components/brand-header-contents.gjs b/javascripts/discourse/components/brand-header-contents.gjs index 14cb1d5..283011f 100644 --- a/javascripts/discourse/components/brand-header-contents.gjs +++ b/javascripts/discourse/components/brand-header-contents.gjs @@ -14,10 +14,14 @@ export default class BrandHeaderContents extends Component { const mobileLogoUrl = settings.mobile_logo_url || ""; const showMobileLogo = mobileView && mobileLogoUrl.length > 0; const logoUrl = settings.logo_url || ""; + const logoDarkUrl = settings.logo_dark_url || ""; + const logoLightUrl = settings.logo_light_url || ""; const title = settings.brand_name; + const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; + const selectedLogoUrl = isDarkMode ? logoDarkUrl : logoLightUrl; return { - url: showMobileLogo ? mobileLogoUrl : logoUrl, + url: showMobileLogo ? mobileLogoUrl : selectedLogoUrl || logoUrl, // Fallback to logoUrl if no light/dark URL set title, }; } diff --git a/settings.yaml b/settings.yaml index 51a1824..05cde6e 100644 --- a/settings.yaml +++ b/settings.yaml @@ -4,6 +4,10 @@ website_url: default: "" logo_url: default: "" +logo_dark_url: + default: "" +logo_light_url: + default: "" mobile_logo_url: default: "" From e3204742f431463a0ebe02214f306f9531e4158a Mon Sep 17 00:00:00 2001 From: Dimitri Anoudis Date: Wed, 13 Nov 2024 10:09:28 +0000 Subject: [PATCH 2/8] (dark-light-mode): It makes use of the category logo --- .../components/brand-header-contents.gjs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/javascripts/discourse/components/brand-header-contents.gjs b/javascripts/discourse/components/brand-header-contents.gjs index 283011f..c6356a9 100644 --- a/javascripts/discourse/components/brand-header-contents.gjs +++ b/javascripts/discourse/components/brand-header-contents.gjs @@ -1,5 +1,6 @@ import Component from "@glimmer/component"; import { service } from "@ember/service"; +import LightDarkImg from "discourse/components/light-dark-img"; import dIcon from "discourse-common/helpers/d-icon"; export default class BrandHeaderContents extends Component { @@ -15,13 +16,12 @@ export default class BrandHeaderContents extends Component { const showMobileLogo = mobileView && mobileLogoUrl.length > 0; const logoUrl = settings.logo_url || ""; const logoDarkUrl = settings.logo_dark_url || ""; - const logoLightUrl = settings.logo_light_url || ""; const title = settings.brand_name; - const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; - const selectedLogoUrl = isDarkMode ? logoDarkUrl : logoLightUrl; return { - url: showMobileLogo ? mobileLogoUrl : selectedLogoUrl || logoUrl, // Fallback to logoUrl if no light/dark URL set + mobileUrl: showMobileLogo ? mobileLogoUrl : null, + lightUrl: logoUrl, + darkUrl: logoDarkUrl || logoUrl, title, }; } @@ -37,17 +37,21 @@ export default class BrandHeaderContents extends Component {