A platform for community discussion. Free, open, simple.
UX: Improve layout of install theme modal (#39808)
Penar Musaraj493f44018cff
diff --git a/app/assets/stylesheets/admin/customize-install-theme.scss b/app/assets/stylesheets/admin/customize-install-theme.scssindex 9a0f7549a33..e9c40d71b25 100644--- a/app/assets/stylesheets/admin/customize-install-theme.scss+++ b/app/assets/stylesheets/admin/customize-install-theme.scss@@ -1,5 +1,13 @@@use "lib/viewport";+.d-modal.-large.admin-install-theme-modal {+ @include viewport.from(sm) {+ .d-modal__container {+ max-width: min(1100px, 90vw);+ }+ }+}+.install-theme {display: flex;@@ -82,24 +90,38 @@}.popular-theme-items {- height: 65vh;+ height: 70vh;overflow: auto;padding-right: 20px;+ display: grid;+ grid-template-columns: repeat(2, minmax(0, 2fr));+ gap: 1em;++ @include viewport.until(sm) {+ display: block;+ }}.popular-theme-item {- border-bottom: 1px solid var(--content-border-color);- padding: 8px 0;display: flex;+ flex-direction: column;align-items: center;+ max-height: 22rem;+ border: 1px solid var(--content-border-color);+ border-radius: 4px;+ padding: 0.75em;+ overflow: hidden;@include viewport.until(sm) {- flex-direction: column;- align-items: initial;+ margin-bottom: 0.75em;}.popular-theme-name {flex: 1;+ width: 100%;+ margin: 0.75em 0;+ min-height: 0;+ overflow: auto;.popular-theme-type {font-weight: normal;@@ -120,15 +142,18 @@.popular-theme-description {font-size: var(--font-down-1);- padding-right: 20px;+ margin-top: 0.35em;}}.popular-theme-buttons {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 0.75em;+ width: 100%;+@include viewport.until(sm) {- display: flex;- justify-content: space-between;- align-items: center;margin-top: 0.25em;}@@ -140,14 +165,28 @@}> a {- display: block;font-size: var(--font-down-2);- margin-top: 5px;text-align: center;}}}+.popular-theme-screenshot {+ width: 100%;+ aspect-ratio: 16 / 9;+ overflow: hidden;+ border: 1px solid var(--primary-low);+ border-radius: 3px;+ background: var(--primary-very-low);++ img {+ display: block;+ width: 100%;+ height: 100%;+ object-fit: cover;+ }+}+.install-theme-warning {margin-bottom: 10px;}diff --git a/app/assets/stylesheets/common/components/theme-card.scss b/app/assets/stylesheets/common/components/theme-card.scssindex 00c72144188..15cccc0973c 100644--- a/app/assets/stylesheets/common/components/theme-card.scss+++ b/app/assets/stylesheets/common/components/theme-card.scss@@ -178,6 +178,21 @@margin-top: auto;}+ &__install-more-icon {+ height: 160px;+ display: flex;+ align-items: center;+ justify-content: center;+ border-bottom: 1px solid var(--content-border-color);+ background: var(--primary-very-low);+ color: var(--primary-medium);++ .d-icon {+ width: 3rem;+ height: 3rem;+ }+ }+&__button.--set-default {position: absolute;top: 4px;@@ -268,6 +283,10 @@}}+.admin-config-area-card.theme-card.--install-more {+ border-style: dashed;+}+.admin-config-area-card.theme-install-card {.theme-install-card__external-links {svg {diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 3f8d912b4ca..ad6f3e43daf 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -7657,6 +7657,8 @@ en:beginners_guide_title: "Beginner’s guide to using Discourse Themes"developers_guide_title: "Developer’s guide to Discourse Themes"browse_themes: "Browse community themes"+ install_more_themes: "Install more themes"+ install_more_themes_description: "Browse popular community themes or install one from a file or git repository."customize_desc: "Customize:"title: "Themes"description: "Themes are expansive customizations that change multiple elements of the style of your forum design, and often also include additional front-end features."@@ -7763,6 +7765,7 @@ en:public_key: "Grant the following public key access to the repo:"install: "Install"installed: "Installed"+ screenshot: "%{name} screenshot"install_popular: "Popular"install_upload: "From your device"install_git_repo: "From a git repository"diff --git a/frontend/discourse/admin/components/admin-config-areas/themes.gjs b/frontend/discourse/admin/components/admin-config-areas/themes.gjsindex 0ca80a429a6..38791631e87 100644--- a/frontend/discourse/admin/components/admin-config-areas/themes.gjs+++ b/frontend/discourse/admin/components/admin-config-areas/themes.gjs@@ -107,6 +107,6 @@ export default class AdminConfigAreasThemes extends Component {</PluginOutlet></:actions></DPageSubheader>- <ThemesGrid @themes={{@themes}} />+ <ThemesGrid @themes={{@themes}} @openInstallModal={{this.installModal}} /></template>}diff --git a/frontend/discourse/admin/components/modal/install-theme.gjs b/frontend/discourse/admin/components/modal/install-theme.gjsindex 88925bf416e..bb76ce2af93 100644--- a/frontend/discourse/admin/components/modal/install-theme.gjs+++ b/frontend/discourse/admin/components/modal/install-theme.gjs@@ -284,7 +284,7 @@ export default class InstallThemeModal extends Component {<template><DModal@bodyClass="install-theme"- class="admin-install-theme-modal"+ class="admin-install-theme-modal -large"@title={{i18n "admin.customize.theme.install"}}@closeModal={{@closeModal}}>@@ -323,6 +323,19 @@ export default class InstallThemeModal extends Component {<div class="popular-theme-items">{{#each this.themes as |theme|}}<div class="popular-theme-item" data-name={{theme.name}}>+ {{#if theme.screenshot_url}}+ <div class="popular-theme-screenshot">+ <img+ alt={{i18n+ "admin.customize.theme.screenshot"+ name=theme.name+ }}+ loading="lazy"+ src={{theme.screenshot_url}}+ />+ </div>+ {{/if}}+<div class="popular-theme-name"><ahref={{theme.meta_url}}@@ -347,7 +360,7 @@ export default class InstallThemeModal extends Component {<span>{{i18n "admin.customize.theme.installed"}}</span>{{else}}<DButton- class="btn-default btn-small"+ class="btn-primary"@label="admin.customize.theme.install"@disabled={{this.installDisabled}}@icon="upload"diff --git a/frontend/discourse/admin/components/themes-grid.gjs b/frontend/discourse/admin/components/themes-grid.gjsindex 36175e05161..3c98b09b3b1 100644--- a/frontend/discourse/admin/components/themes-grid.gjs+++ b/frontend/discourse/admin/components/themes-grid.gjs@@ -2,7 +2,9 @@ import Component from "@glimmer/component";import { cached } from "@glimmer/tracking";import AdminConfigAreaCard from "discourse/admin/components/admin-config-area-card";import AdminFilterControls from "discourse/admin/components/admin-filter-controls";+import DButton from "discourse/components/d-button";import PluginOutlet from "discourse/components/plugin-outlet";+import icon from "discourse/helpers/d-icon";import lazyHash from "discourse/helpers/lazy-hash";import { i18n } from "discourse-i18n";import ThemesGridCard from "./themes-grid-card";@@ -35,6 +37,14 @@ export default class ThemesGrid extends Component {return i18n("admin.customize.theme.search_placeholder");}+ get showInstallMoreThemesCard() {+ if (this.args.themes.length !== 2) {+ return false;+ }++ return this.args.themes.every((theme) => theme.system);+ }+get dropdownOptions() {return [{@@ -64,6 +74,33 @@ export default class ThemesGrid extends Component {{{#each themes as |theme|}}<ThemesGridCard @theme={{theme}} @allThemes={{@themes}} />{{/each}}+ {{#if this.showInstallMoreThemesCard}}+ <AdminConfigAreaCard class="theme-card --install-more">+ <:content>+ <div class="theme-card__install-more-icon">+ {{icon "plus"}}+ </div>+ <div class="theme-card__content">+ <h3 class="theme-card__title">+ {{i18n "admin.customize.theme.install_more_themes"}}+ </h3>+ <p class="theme-card__description">+ {{i18n+ "admin.customize.theme.install_more_themes_description"+ }}+ </p>+ </div>+ <div class="theme-card__footer">+ <DButton+ class="btn-primary theme-card__install-button"+ @label="admin.config_areas.themes_and_components.themes.install"+ @icon="upload"+ @action={{@openInstallModal}}+ />+ </div>+ </:content>+ </AdminConfigAreaCard>+ {{/if}}<PluginOutlet@name="admin-themes-grid-additional-cards"@outletArgs={{lazyHashdiff --git a/frontend/discourse/app/lib/popular-themes.js b/frontend/discourse/app/lib/popular-themes.jsindex d3779b32e87..2b8591e6eb0 100644--- a/frontend/discourse/app/lib/popular-themes.js+++ b/frontend/discourse/app/lib/popular-themes.js@@ -4,6 +4,8 @@ export const POPULAR_THEMES = [value: "https://github.com/discourse/graceful",preview:"https://discourse.theme-creator.io/theme/Discourse/graceful-theme",+ screenshot_url:+ "https://github.com/discourse/graceful/blob/main/screenshots/light.png?raw=true",description: "A light and graceful theme for Discourse.",meta_url: "https://meta.discourse.org/t/graceful-theme/93040",},@@ -12,6 +14,8 @@ export const POPULAR_THEMES = [value: "https://github.com/discourse/material-design-stock-theme",preview:"https://discourse.theme-creator.io/theme/Discourse/material-design-theme",+ screenshot_url:+ "https://github.com/discourse/material-design-stock-theme/blob/main/screenshots/light.png?raw=true",description:"Inspired by Material Design, this theme comes with several color palettes.",meta_url: "https://meta.discourse.org/t/material-design-theme/47142",@@ -20,6 +24,8 @@ export const POPULAR_THEMES = [name: "Mint",value: "https://github.com/discourse/discourse-mint-theme",preview: "https://discourse.theme-creator.io/theme/Discourse/mint-theme",+ screenshot_url:+ "https://github.com/discourse/discourse-mint-theme/blob/main/screenshots/light.webp?raw=true",description:"A minty colored theme with featured homepage categories and a search banner.",meta_url: "https://meta.discourse.org/t/mint-theme/202822",@@ -29,6 +35,8 @@ export const POPULAR_THEMES = [value: "https://github.com/discourse/discourse-simple-theme",preview:"https://discourse.theme-creator.io/theme/Discourse/sams-simple-theme",+ screenshot_url:+ "https://github.com/discourse/discourse-simple-theme/blob/main/screenshots/light.png?raw=true",description:"Simplified front page design with classic colors and typography.",meta_url: "https://meta.discourse.org/t/sams-simple-theme/23552",diff --git a/frontend/discourse/tests/acceptance/admin-install-theme-modal-test.js b/frontend/discourse/tests/acceptance/admin-install-theme-modal-test.jsindex 1bd4b0280bf..a1cd4e0b9bd 100644--- a/frontend/discourse/tests/acceptance/admin-install-theme-modal-test.js+++ b/frontend/discourse/tests/acceptance/admin-install-theme-modal-test.js@@ -172,11 +172,20 @@ acceptance("Admin - Themes - Install modal", function (needs) {assert.dom('.popular-theme-item[data-name="Graceful"] .popular-theme-buttons').hasText(i18n("admin.customize.theme.installed"));+ assert+ .dom('.popular-theme-item[data-name="Graceful"] img')+ .hasAttribute(+ "alt",+ i18n("admin.customize.theme.screenshot", { name: "Graceful" })+ );assert.dom('.popular-theme-item[data-name="Mint"] .popular-theme-buttons button').exists("install button is shown for not installed themes");+ assert+ .dom('.popular-theme-item[data-name="Mint"] .popular-theme-screenshot')+ .doesNotHaveAttribute("href", "screenshot is not linked");});});diff --git a/spec/system/admin_customize_themes_default_grid_spec.rb b/spec/system/admin_customize_themes_default_grid_spec.rbnew file mode 100644index 00000000000..9a00033f20b--- /dev/null+++ b/spec/system/admin_customize_themes_default_grid_spec.rb@@ -0,0 +1,24 @@+# frozen_string_literal: true++describe "Admin Customize Themes default grid" do+ fab!(:admin)+ fab!(:foundation_theme) { Theme.foundation_theme }+ fab!(:horizon_theme) { Theme.horizon_theme }++ let(:config_area) { PageObjects::Pages::AdminCustomizeThemesConfigArea.new }++ before { sign_in(admin) }++ it "shows an install themes CTA when only the default themes are installed" do+ config_area.visit++ expect(config_area).to have_themes(["Foundation", "Horizon", "Install more themes"])+ expect(config_area).to have_theme_cards(count: 3)+ expect(config_area).to have_install_more_themes_card++ install_modal = config_area.click_install_more_themes++ expect(install_modal).to be_open+ expect(install_modal.popular_options.first).to have_text("Graceful")+ end+enddiff --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 bddd2dec3bd..e8062c1456b 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@@ -62,6 +62,24 @@ module PageObjectsexpect(all(".theme-card__title").map(&:text)).to eq(names)end+ def has_theme_cards?(count:)+ has_css?(".themes-cards-container > .admin-config-area-card", count: count)+ end++ def has_install_more_themes_card?+ has_css?(+ ".theme-card.--install-more",+ text: I18n.t("admin_js.admin.customize.theme.install_more_themes"),+ )+ end++ def click_install_more_themes+ find(".theme-card.--install-more").click_button(+ I18n.t("admin_js.admin.config_areas.themes_and_components.themes.install"),+ )+ PageObjects::Modals::InstallTheme.new+ end+def has_no_theme?(name)has_no_css?(".theme-card.#{name.parameterize}")end