DEV: Add home-logo-minimized transformer (#30832)

Similar to the `home-logo-href` and `home-logo-image-url` transformers,
this PR adds a new `home-logo-minimized` transformer to allow
plugins/themes to amend the default behavior of the header logo.

Internal topic: t/144688.
This commit is contained in:
Osama Sayegh 2025-01-17 03:38:42 +03:00 committed by GitHub
parent ff815384b1
commit d964fbc550
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import { hash } from "@ember/helper";
import { service } from "@ember/service";
import { and } from "truth-helpers";
import deprecatedOutletArgument from "discourse/helpers/deprecated-outlet-argument";
import { applyValueTransformer } from "discourse/lib/transformer";
import BootstrapModeNotice from "../bootstrap-mode-notice";
import PluginOutlet from "../plugin-outlet";
import HomeLogo from "./home-logo";
@ -24,6 +25,18 @@ export default class Contents extends Component {
return "bars";
}
get minimized() {
return applyValueTransformer(
"home-logo-minimized",
this.args.topicInfoVisible,
{
topicInfo: this.args.topicInfo,
sidebarEnabled: this.args.sidebarEnabled,
showSidebar: this.args.showSidebar,
}
);
}
<template>
<div class="contents">
<PluginOutlet
@ -55,7 +68,7 @@ export default class Contents extends Component {
<div class="home-logo-wrapper-outlet">
<PluginOutlet @name="home-logo-wrapper">
<HomeLogo @minimized={{@topicInfoVisible}} />
<HomeLogo @minimized={{this.minimized}} />
</PluginOutlet>
</div>

View File

@ -12,6 +12,7 @@ export const VALUE_TRANSFORMERS = Object.freeze([
"header-notifications-avatar-size",
"home-logo-href",
"home-logo-image-url",
"home-logo-minimized",
"invite-simple-mode-topic",
"latest-topic-list-item-class",
"mentions-class",

View File

@ -0,0 +1,24 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("home-logo-minimized transformer", function () {
test("can force minimize the logo", async function (assert) {
withPluginApi("1.34.0", (api) => {
api.registerValueTransformer("home-logo-minimized", () => true);
});
await visit("/");
assert.dom("#site-logo").hasClass("logo-small");
});
test("can force un-minimize the logo", async function (assert) {
withPluginApi("1.34.0", (api) => {
api.registerValueTransformer("home-logo-minimized", () => false);
});
await visit("/");
assert.dom("#site-logo").hasClass("logo-big");
});
});