Skip to content

A platform for community discussion. Free, open, simple.

UX: Polish the theme picker modal (#40414)

Keegan George3cd6cbcb0647
diff --git a/app/assets/stylesheets/common/components/admin-onboarding-banner.scss b/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
index 0e0fffd07fe..576160bb56c 100644
--- a/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
+++ b/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
@@ -206,14 +206,32 @@
border-radius: var(--d-border-radius);
overflow: hidden;
background: var(--secondary);
+ cursor: pointer;
+ transition: border-color 0.15s ease;
- &.--active {
+ &:hover {
+ border-color: var(--primary-low-mid);
+ }
+
+ &.--selected {
border-color: var(--tertiary);
+ box-shadow: 0 0 0 1px var(--tertiary);
}
}
- &__card > .btn {
- margin: var(--space-3) var(--space-4) var(--space-4);
+ .theme-card-preview__image-wrapper {
+ height: 220px;
+ }
+
+ .theme-card-preview__image {
+ image-rendering: -webkit-optimize-contrast;
+ image-rendering: crisp-edges;
+ }
+
+ &__footer {
+ display: flex;
+ justify-content: center;
+ margin-top: var(--space-4);
}
&__enabled-badge {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 6cb9a2f3f77..190b88e24ec 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -522,9 +522,9 @@ en:
description: "Choose a starting theme for your community"
action: "Select theme"
modal_title: "Choose a theme"
- use_theme: "Use this theme"
- enabled: "Enabled"
- theme_set: "%{theme} is now your default theme"
+ use_theme: "Use selected theme"
+ enabled: "Selected"
+ applying_theme: "Applying theme..."
browse_all: "Manage themes"
show_light_screenshot: "Show light screenshot"
show_dark_screenshot: "Show dark screenshot"
diff --git a/frontend/discourse/app/components/admin-onboarding/modal/theme-picker.gjs b/frontend/discourse/app/components/admin-onboarding/modal/theme-picker.gjs
index 00cd9657973..8b429a4a8b2 100644
--- a/frontend/discourse/app/components/admin-onboarding/modal/theme-picker.gjs
+++ b/frontend/discourse/app/components/admin-onboarding/modal/theme-picker.gjs
@@ -1,8 +1,8 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { fn } from "@ember/helper";
+import { on } from "@ember/modifier";
import { action } from "@ember/object";
-import { service } from "@ember/service";
import PluginOutlet from "discourse/components/plugin-outlet";
import ThemeCardPreview from "discourse/components/theme-card-preview";
import { ajax } from "discourse/lib/ajax";
@@ -13,42 +13,35 @@ import {
HORIZON_THEME_ID,
setLocalTheme,
} from "discourse/lib/theme-selector";
+import { eq } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
import DModal from "discourse/ui-kit/d-modal";
import dIcon from "discourse/ui-kit/helpers/d-icon";
-import dLoadingSpinner from "discourse/ui-kit/helpers/d-loading-spinner";
import { i18n } from "discourse-i18n";
const ALLOWED_THEME_IDS = [FOUNDATION_THEME_ID, HORIZON_THEME_ID];
const ThemeCard = <template>
- <div class="theme-picker-modal__card {{if @theme.default '--active'}}">
- {{#if @theme.default}}
+ <div
+ class="theme-picker-modal__card {{if @isSelected '--selected'}}"
+ {{on "click" (fn @onSelect @theme)}}
+ role="button"
+ >
+ {{#if @isSelected}}
<span class="theme-picker-modal__enabled-badge">
{{dIcon "check"}}
{{i18n "admin_onboarding_banner.select_theme.enabled"}}
</span>
{{/if}}
- <ThemeCardPreview @theme={{@theme}}>
- <:footer>
- <DButton
- @action={{fn @onSelect @theme}}
- @translatedLabel={{i18n
- "admin_onboarding_banner.select_theme.use_theme"
- }}
- class="btn-primary"
- />
- </:footer>
- </ThemeCardPreview>
+ <ThemeCardPreview @theme={{@theme}} />
</div>
</template>;
export default class ThemePickerModal extends Component {
- @service toasts;
-
@tracked themes = [];
@tracked loading = true;
@tracked saving = false;
+ @tracked selectedTheme = null;
constructor() {
super(...arguments);
@@ -61,6 +54,7 @@ export default class ThemePickerModal extends Component {
this.themes = result.themes.filter((theme) =>
ALLOWED_THEME_IDS.includes(theme.id)
);
+ this.selectedTheme = this.themes.find((t) => t.default) || null;
} catch (error) {
popupAjaxError(error);
} finally {
@@ -68,57 +62,83 @@ export default class ThemePickerModal extends Component {
}
}
+ get applyDisabled() {
+ return !this.selectedTheme || this.saving;
+ }
+
@action
- async selectTheme(theme) {
- if (this.saving) {
+ selectTheme(theme) {
+ this.selectedTheme = theme;
+ }
+
+ @action
+ async applyTheme() {
+ if (this.applyDisabled) {
+ return;
+ }
+
+ if (this.selectedTheme.default) {
+ await this.args.model?.onThemeSelected?.();
+ this.args.closeModal();
return;
}
this.saving = true;
try {
- await ajax(`/admin/themes/${theme.id}.json`, {
+ await ajax(`/admin/themes/${this.selectedTheme.id}.json`, {
type: "PUT",
data: { theme: { default: true } },
});
setLocalTheme([], 0);
- this.toasts.success({
- data: {
- message: i18n("admin_onboarding_banner.select_theme.theme_set", {
- theme: theme.name,
- }),
- },
- });
-
await this.args.model?.onThemeSelected?.();
- this.args.closeModal();
window.location.reload();
} catch (error) {
- popupAjaxError(error);
- } finally {
this.saving = false;
+ popupAjaxError(error);
}
}
<template>
<DModal
- class="theme-picker-modal"
+ class="theme-picker-modal --large"
@title={{i18n "admin_onboarding_banner.select_theme.modal_title"}}
@closeModal={{@closeModal}}
>
<:body>
{{#if this.loading}}
<div class="theme-picker-modal__loading">
- {{dLoadingSpinner}}
+ <div class="spinner"></div>
</div>
{{else}}
<div class="theme-picker-modal__themes">
{{#each this.themes as |theme|}}
- <ThemeCard @theme={{theme}} @onSelect={{this.selectTheme}} />
+ <ThemeCard
+ @theme={{theme}}
+ @isSelected={{if
+ this.selectedTheme
+ (eq this.selectedTheme.id theme.id)
+ false
+ }}
+ @onSelect={{this.selectTheme}}
+ />
{{/each}}
</div>
+ <div class="theme-picker-modal__footer">
+ <DButton
+ @action={{this.applyTheme}}
+ @translatedLabel={{if
+ this.saving
+ (i18n "admin_onboarding_banner.select_theme.applying_theme")
+ (i18n "admin_onboarding_banner.select_theme.use_theme")
+ }}
+ @disabled={{this.applyDisabled}}
+ @isLoading={{this.saving}}
+ class="btn-primary"
+ />
+ </div>
<PluginOutlet @name="theme-picker-modal-below-themes">
<p class="theme-picker-modal__browse-all">
<a href={{getURL "/admin/config/customize/themes"}}>
diff --git a/spec/system/page_objects/modals/admin_onboarding_theme_picker.rb b/spec/system/page_objects/modals/admin_onboarding_theme_picker.rb
index 1eeab461d44..023a9b2ee2c 100644
--- a/spec/system/page_objects/modals/admin_onboarding_theme_picker.rb
+++ b/spec/system/page_objects/modals/admin_onboarding_theme_picker.rb
@@ -16,11 +16,12 @@ module PageObjects
end
def first_selectable_theme_name
- find("#{CARD_SELECTOR}:not(.--active) #{NAME_SELECTOR}", match: :first).text
+ find("#{CARD_SELECTOR}:not(.--selected) #{NAME_SELECTOR}", match: :first).text
end
def select_theme(name)
- find(CARD_SELECTOR, text: name).find(".btn-primary").click
+ find(CARD_SELECTOR, text: name).click
+ find(".theme-picker-modal__footer .btn-primary").click
end
def select_first_selectable_theme