DEV: refactors d-section (#15245)

- go tagless
- properly declares properties
- deprecates "false" in favour of false
- drops jquery
This commit is contained in:
Joffrey JAFFEUX 2021-12-09 13:47:47 +01:00 committed by GitHub
parent 76dff7fd9e
commit 5d44adb9b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 15 deletions

View File

@ -1,24 +1,35 @@
import deprecated from "discourse-common/lib/deprecated";
import Component from "@ember/component";
import { scrollTop } from "discourse/mixins/scroll-top";
// Can add a body class from within a component, also will scroll to the top automatically.
export default Component.extend({
tagName: "section",
tagName: null,
pageClass: null,
bodyClass: null,
scrollTop: true,
didInsertElement() {
this._super(...arguments);
const pageClass = this.pageClass;
if (pageClass) {
$("body").addClass(`${pageClass}-page`);
if (this.pageClass) {
document.body.classList.add(`${this.pageClass}-page`);
}
const bodyClass = this.bodyClass;
if (bodyClass) {
$("body").addClass(bodyClass);
if (this.bodyClass) {
document.body.classList.add(this.bodyClass);
}
if (this.scrollTop === "false") {
deprecated("Uses boolean instead of string for scrollTop.", {
since: "2.8.0.beta9",
dropFrom: "2.9.0.beta1",
});
return;
}
if (!this.scrollTop) {
return;
}
@ -27,14 +38,13 @@ export default Component.extend({
willDestroyElement() {
this._super(...arguments);
const pageClass = this.pageClass;
if (pageClass) {
$("body").removeClass(`${pageClass}-page`);
if (this.pageClass) {
document.body.classList.remove(`${this.pageClass}-page`);
}
const bodyClass = this.bodyClass;
if (bodyClass) {
$("body").removeClass(bodyClass);
if (this.bodyClass) {
document.body.classList.remove(this.bodyClass);
}
},
});

View File

@ -0,0 +1 @@
<section>{{yield}}</section>

View File

@ -1,4 +1,4 @@
{{#d-section bodyClass="navigation-topics" class="navigation-container" scrollTop="false"}}
{{#d-section bodyClass="navigation-topics" class="navigation-container" scrollTop=false}}
{{d-navigation
filterMode=filterMode
canCreateTopic=canCreateTopic

View File

@ -1,4 +1,4 @@
{{#d-section pageClass="user-activity" class="user-secondary-navigation" scrollTop="false"}}
{{#d-section pageClass="user-activity" class="user-secondary-navigation" scrollTop=false}}
<nav role="navigation">
{{#mobile-nav class="activity-nav" desktopClass="action-list activity-list nav-stacked"}}
{{#d-navigation-item route="userActivity.index"}}{{i18n "user.filters.all"}}{{/d-navigation-item}}