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 Component from "@ember/component";
import { scrollTop } from "discourse/mixins/scroll-top"; import { scrollTop } from "discourse/mixins/scroll-top";
// Can add a body class from within a component, also will scroll to the top automatically. // Can add a body class from within a component, also will scroll to the top automatically.
export default Component.extend({ export default Component.extend({
tagName: "section", tagName: null,
pageClass: null,
bodyClass: null,
scrollTop: true,
didInsertElement() { didInsertElement() {
this._super(...arguments); this._super(...arguments);
const pageClass = this.pageClass; if (this.pageClass) {
if (pageClass) { document.body.classList.add(`${this.pageClass}-page`);
$("body").addClass(`${pageClass}-page`);
} }
const bodyClass = this.bodyClass; if (this.bodyClass) {
if (bodyClass) { document.body.classList.add(this.bodyClass);
$("body").addClass(bodyClass);
} }
if (this.scrollTop === "false") { 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; return;
} }
@ -27,14 +38,13 @@ export default Component.extend({
willDestroyElement() { willDestroyElement() {
this._super(...arguments); this._super(...arguments);
const pageClass = this.pageClass;
if (pageClass) { if (this.pageClass) {
$("body").removeClass(`${pageClass}-page`); document.body.classList.remove(`${this.pageClass}-page`);
} }
const bodyClass = this.bodyClass; if (this.bodyClass) {
if (bodyClass) { document.body.classList.remove(this.bodyClass);
$("body").removeClass(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 {{d-navigation
filterMode=filterMode filterMode=filterMode
canCreateTopic=canCreateTopic 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"> <nav role="navigation">
{{#mobile-nav class="activity-nav" desktopClass="action-list activity-list nav-stacked"}} {{#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}} {{#d-navigation-item route="userActivity.index"}}{{i18n "user.filters.all"}}{{/d-navigation-item}}