UX: Styling changes to global banner (#16191)

This commit is contained in:
Penar Musaraj 2022-03-15 16:19:55 +01:00 committed by GitHub
parent dec68d780c
commit 593f3e5dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 46 deletions

View File

@ -1,15 +1,18 @@
import Component from "@ember/component"; import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { action } from "@ember/object";
export default Component.extend({ export default Component.extend({
hide: false, hide: false,
@discourseComputed("banner.html") @discourseComputed("banner.html")
content(bannerHtml) { content(bannerHtml) {
const $div = $("<div>"); const newDiv = document.createElement("div");
$div.append(bannerHtml); newDiv.innerHTML = bannerHtml;
$div.find("[id^='heading--']").removeAttr("id"); newDiv.querySelectorAll("[id^='heading--']").forEach((el) => {
return $div.html(); el.removeAttribute("id");
});
return newDiv.innerHTML;
}, },
@discourseComputed("user.dismissed_banner_key", "banner.key", "hide") @discourseComputed("user.dismissed_banner_key", "banner.key", "hide")
@ -27,17 +30,16 @@ export default Component.extend({
return !hide && bannerKey && dismissedBannerKey !== bannerKey; return !hide && bannerKey && dismissedBannerKey !== bannerKey;
}, },
actions: { @action
dismiss() { dismiss() {
if (this.user) { if (this.user) {
this.user.dismissBanner(this.get("banner.key")); this.user.dismissBanner(this.get("banner.key"));
} else { } else {
this.set("hide", true); this.set("hide", true);
this.keyValueStore.set({ this.keyValueStore.set({
key: "dismissed_banner_key", key: "dismissed_banner_key",
value: this.get("banner.key"), value: this.get("banner.key"),
}); });
} }
},
}, },
}); });

View File

@ -1,12 +1,20 @@
{{#if visible}} {{#if visible}}
<div class="row"> <div class="row">
<div id="banner" class={{overlay}}> <div id="banner" class={{overlay}}>
{{d-button icon="times" action=(action "dismiss") class="btn btn-flat close" title="banner.close"}} <div class="floated-buttons">
{{#if currentUser.staff}}
<a href={{banner.url}} class="btn btn-flat edit-banner">
{{d-icon "pencil-alt"}}
{{#unless site.mobileView}}
{{html-safe (i18n "banner.edit")}}
{{/unless}}
</a>
{{/if}}
{{d-button icon="times" action=(action "dismiss") class="btn btn-flat close" title="banner.close"}}
</div>
<div id="banner-content"> <div id="banner-content">
{{html-safe content}} {{html-safe content}}
{{#if currentUser.staff}}
<p><a href={{banner.url}}>{{html-safe (i18n "banner.edit")}}</a></p>
{{/if}}
</div> </div>
</div> </div>
</div> </div>

View File

@ -3,29 +3,37 @@
// -------------------------------------------------- // --------------------------------------------------
#banner { #banner {
padding: 0.5em 1em; padding: 1em;
background: var(--tertiary-low); background: var(--tertiary-low);
color: var(--primary); color: var(--primary);
z-index: z("base") + 1; z-index: z("base") + 1;
margin-bottom: 1em; margin-bottom: 1em;
max-height: 250px; max-height: 20vh;
overflow: auto; overflow: auto;
&.overlay { .floated-buttons {
position: fixed;
}
.close {
color: var(--primary-low-mid);
padding-left: 5px;
float: right; float: right;
.d-icon { display: flex;
color: var(--primary-medium);
}
}
.meta { > .btn {
display: none; padding-top: 0em;
padding-bottom: 0em;
color: var(--primary-high);
.d-icon {
color: var(--primary-medium);
}
&:hover {
color: var(--primary);
.d-icon {
color: var(--primary-high);
}
}
}
.desktop-view & .btn.close {
margin-left: 0.25em;
}
} }
} }
@ -33,4 +41,12 @@
hr { hr {
border-color: var(--primary-medium); border-color: var(--primary-medium);
} }
> p:first-child {
margin-top: 0;
}
> p:last-of-type {
margin-bottom: 0;
}
} }

View File

@ -1,4 +1,3 @@
@import "banner";
@import "topic-footer-mobile-dropdown"; @import "topic-footer-mobile-dropdown";
@import "user-card"; @import "user-card";
@import "user-stream-item"; @import "user-stream-item";

View File

@ -1,8 +0,0 @@
// --------------------------------------------------
// Banner
// --------------------------------------------------
#banner {
max-height: 180px;
height: 20vh;
}

View File

@ -411,8 +411,8 @@ en:
switch_from_anon: "Exit Anonymous Mode" switch_from_anon: "Exit Anonymous Mode"
banner: banner:
close: "Dismiss this banner." close: "Dismiss this banner"
edit: "Edit this banner >>" edit: "Edit"
pwa: pwa:
install_banner: "Do you want to <a href>install %{title} on this device?</a>" install_banner: "Do you want to <a href>install %{title} on this device?</a>"