A platform for community discussion. Free, open, simple.
FEATURE: Toggle light/dark theme screenshots in theme cards (#37257)
Martin Brennan2891c983398c
diff --git a/app/assets/stylesheets/common/components/theme-card.scss b/app/assets/stylesheets/common/components/theme-card.scssindex 8c7658f730a..00c72144188 100644--- a/app/assets/stylesheets/common/components/theme-card.scss+++ b/app/assets/stylesheets/common/components/theme-card.scss@@ -91,11 +91,10 @@&__image-wrapper {width: 100%;height: 160px;- overflow-x: auto;- overflow-y: hidden;+ overflow: hidden;display: flex;align-items: center;- scroll-snap-type: x mandatory;+ position: relative;border-bottom: 1px solid var(--content-border-color);border-top-left-radius: var(--d-border-radius);border-top-right-radius: var(--d-border-radius);@@ -105,6 +104,10 @@top: 0;left: 0;}++ &:hover .theme-card__screenshot-toggle {+ opacity: 1;+ }}&__image {@@ -112,7 +115,14 @@flex-shrink: 0;object-fit: cover;object-position: top left;- scroll-snap-align: start;+ }++ &__screenshot-toggle {+ position: absolute;+ bottom: 0.5rem;+ right: 0.5rem;+ opacity: 0;+ transition: opacity 0.2s ease-in-out;}.ember-checkbox {diff --git a/frontend/discourse/admin/components/themes-grid-card.gjs b/frontend/discourse/admin/components/themes-grid-card.gjsindex 5f6b3bfb746..2bf2bc62db1 100644--- a/frontend/discourse/admin/components/themes-grid-card.gjs+++ b/frontend/discourse/admin/components/themes-grid-card.gjs@@ -11,7 +11,6 @@ import icon from "discourse/helpers/d-icon";import { popupAjaxError } from "discourse/lib/ajax-error";import { removeValueFromArray } from "discourse/lib/array-tools";import getURL from "discourse/lib/get-url";-import { and } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";import ThemesGridPlaceholder from "./themes-grid-placeholder";@@ -25,8 +24,11 @@ export default class ThemeCard extends Component {@service toasts;@service dialog;@service router;+ @service interfaceColor;+ @service session;@tracked isUpdating = false;+ @tracked showingDarkScreenshot = this.#shouldShowDarkByDefault();get themeCardClasses() {return [@@ -49,6 +51,31 @@ export default class ThemeCard extends Component {return this.args.theme.default || this.args.theme.system;}+ get currentScreenshotUrl() {+ return this.showingDarkScreenshot+ ? this.args.theme.screenshot_dark_url+ : this.args.theme.screenshot_light_url;+ }++ get screenshotToggleIcon() {+ return this.showingDarkScreenshot ? "sun" : "moon";+ }++ get hasBothScreenshots() {+ return (+ this.args.theme.screenshot_light_url &&+ this.args.theme.screenshot_dark_url+ );+ }++ #shouldShowDarkByDefault() {+ return (+ this.interfaceColor.colorModeIsDark ||+ window.matchMedia("(prefers-color-scheme: dark)").matches ||+ this.session.defaultColorSchemeIsDark+ );+ }+get editUrl() {return this.router.urlFor("adminCustomizeThemes.show",@@ -145,6 +172,11 @@ export default class ThemeCard extends Component {});}+ @action+ toggleScreenshot() {+ this.showingDarkScreenshot = !this.showingDarkScreenshot;+ }+@actiondestroyTheme() {return this.dialog.deleteConfirm({@@ -177,31 +209,23 @@ export default class ThemeCard extends Component {><:content><div class="theme-card__image-wrapper">- {{#if @theme.screenshot_light_url}}- <img- class="theme-card__image"- src={{@theme.screenshot_light_url}}- alt={{i18n- "admin.customize.theme.light_mode"- }}- />- {{/if}}- {{#if @theme.screenshot_dark_url}}+ {{#if this.currentScreenshotUrl}}<imgclass="theme-card__image"- src={{@theme.screenshot_dark_url}}- alt={{i18n- "admin.customize.theme.dark_mode"- }}+ src={{this.currentScreenshotUrl}}+ alt={{@theme.name}}/>- {{/if}}- {{#unless- (and @theme.screenshot_dark_url @theme.screenshot_light_url)- }}+ {{#if this.hasBothScreenshots}}+ <DButton+ @action={{this.toggleScreenshot}}+ @icon={{this.screenshotToggleIcon}}+ @preventFocus={{true}}+ class="btn-flat theme-card__screenshot-toggle"+ />+ {{/if}}+ {{else}}<ThemesGridPlaceholder @theme={{@theme}} />- {{/unless}}+ {{/if}}</div><div class="theme-card__content"><a class="theme-card__title" href={{this.editUrl}}>{{@theme.name}}</a>@@ -257,8 +281,7 @@ export default class ThemeCard extends Component {><:content><DropdownMenu as |dropdown|>- {{! TODO: Jordan- solutions for broken, disabled states }}+ {{! TODO: Jordan solutions for broken, disabled states }}<dropdown.item><DButton@action={{this.setDefault}}diff --git a/spec/system/admin_customize_themes_config_area_spec.rb b/spec/system/admin_customize_themes_config_area_spec.rbindex b7e2111281b..b8b5eb8b220 100644--- a/spec/system/admin_customize_themes_config_area_spec.rb+++ b/spec/system/admin_customize_themes_config_area_spec.rb@@ -99,4 +99,55 @@ describe "Admin Customize Themes Config Area Page", type: :system doI18n.t("admin_js.admin.config_areas.themes_and_components.themes.title"),)end++ describe "screenshot toggle" do+ fab!(:light_upload, :image_upload)+ fab!(:dark_upload, :image_upload)+ fab!(:theme_with_screenshots) do+ Fabricate(+ :theme,+ name: "Theme with screenshots",+ theme_fields: [+ ThemeField.new(+ target_id: Theme.targets[:common],+ name: "screenshot_light",+ type_id: ThemeField.types[:theme_screenshot_upload_var],+ upload_id: light_upload.id,+ value: "",+ ),+ ThemeField.new(+ target_id: Theme.targets[:common],+ name: "screenshot_dark",+ type_id: ThemeField.types[:theme_screenshot_upload_var],+ upload_id: dark_upload.id,+ value: "",+ ),+ ],+ )+ end++ it "allows toggling between light and dark screenshots" do+ config_area.visit++ light_src = config_area.screenshot_image(theme_with_screenshots)[:src]+ expect(light_src).to include(light_upload.url)++ expect(config_area).to have_screenshot_with_icon(theme_with_screenshots, "moon")++ config_area.click_screenshot_toggle(theme_with_screenshots)++ expect(config_area.screenshot_image(theme_with_screenshots)[:src]).to include(dark_upload.url)+ expect(config_area.screenshot_image(theme_with_screenshots)[:src]).not_to eq(light_src)++ expect(config_area).to have_screenshot_with_icon(theme_with_screenshots, "sun")++ config_area.click_screenshot_toggle(theme_with_screenshots)++ expect(config_area.screenshot_image(theme_with_screenshots)[:src]).to include(light_src)++ config_area.visit++ expect(config_area).to have_no_screenshot_toggle_button(theme)+ end+ endenddiff --git a/spec/system/page_objects/pages/admin_customize_themes_config_area.rb b/spec/system/page_objects/pages/admin_customize_themes_config_area.rbindex aa91be7be26..bddd2dec3bd 100644--- a/spec/system/page_objects/pages/admin_customize_themes_config_area.rb+++ b/spec/system/page_objects/pages/admin_customize_themes_config_area.rb@@ -78,6 +78,32 @@ module PageObjectsdef click_install_buttonPageObjects::Components::AdminCustomizeThemeInstallButton.new.clickend++ def screenshot_toggle_button(theme)+ find_theme_card(theme).find(".theme-card__screenshot-toggle")+ end++ def has_screenshot_toggle_button?(theme)+ find_theme_card(theme).has_css?(".theme-card__screenshot-toggle")+ end++ def has_no_screenshot_toggle_button?(theme)+ find_theme_card(theme).has_no_css?(".theme-card__screenshot-toggle")+ end++ def click_screenshot_toggle(theme)+ find_theme_card(theme).hover+ screenshot_toggle_button(theme).click+ end++ def screenshot_image(theme)+ find_theme_card(theme).find(".theme-card__image")+ end++ def has_screenshot_with_icon?(theme, icon_name)+ find_theme_card(theme).hover+ find_theme_card(theme).has_css?(".theme-card__screenshot-toggle .d-icon-#{icon_name}")+ endendendenddiff --git a/themes/foundation/screenshots/dark.png b/themes/foundation/screenshots/dark.pngindex 6d1531bc8b9..962f4a53ad8 100644Binary files a/themes/foundation/screenshots/dark.png and b/themes/foundation/screenshots/dark.png differdiff --git a/themes/foundation/screenshots/light.png b/themes/foundation/screenshots/light.pngindex 1e567e90020..2f415d946ab 100644Binary files a/themes/foundation/screenshots/light.png and b/themes/foundation/screenshots/light.png differ