Skip to content

Commit 6a37786

Browse files
committed
Auto merge of #4367 - Turbo87:body-class, r=Turbo87
Replace `ember-set-body-class` addon We can achieve the same thing with data attributes, with a bit less code :)
2 parents 0409e47 + 1ecf28e commit 6a37786

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

app/helpers/set-theme.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { helper } from '@ember/component/helper';
2+
3+
export default helper(function ([theme]) {
4+
if (window.document) {
5+
if (theme) {
6+
window.document.documentElement.dataset.theme = theme;
7+
} else {
8+
delete window.document.documentElement.dataset.theme;
9+
}
10+
}
11+
});

app/styles/application.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
--placeholder-bg2: hsl(213, 16%, 75%);
3030
}
3131

32-
:global(.new-design) {
32+
:root[data-theme="new-design"] {
3333
--header-bg-color: var(--violet800);
3434
--main-bg: white;
3535
--footer-bg-color: var(--grey900);

app/templates/application.hbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<HeadLayout />
22

33
{{page-title "crates.io: Rust Package Registry" separator=' - ' prepend=true}}
4+
{{set-theme (if this.design.useNewDesign "new-design")}}
45

56
<ProgressBar/>
67
<NotificationContainer @position="top-right"/>
@@ -19,7 +20,4 @@
1920
<button type="button" local-class="toggle-design-button" {{on "click" this.design.toggle}}>
2021
Toggle Design
2122
</button>
22-
{{/if}}
23-
{{#if this.design.useNewDesign}}
24-
{{set-body-class "new-design"}}
2523
{{/if}}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"ember-qunit": "5.1.5",
102102
"ember-resolver": "8.0.3",
103103
"ember-router-scroll": "4.1.2",
104-
"ember-set-body-class": "1.0.2",
105104
"ember-source": "3.28.8",
106105
"ember-svg-jar": "2.3.3",
107106
"ember-template-lint": "3.15.0",

tests/helpers/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ export function setupApplicationTest(hooks, options) {
1010
upstreamSetupApplicationTest(hooks, options);
1111
setupMirage(hooks);
1212
setupSentryMock(hooks);
13-
setupAppTestBodyClass(hooks);
13+
setupAppTestDataAttr(hooks);
1414
}
1515

16-
function setupAppTestBodyClass(hooks) {
17-
const ID = 'app-test';
18-
16+
function setupAppTestDataAttr(hooks) {
1917
hooks.beforeEach(function () {
20-
this.bodyClass = this.owner.lookup('service:body-class');
21-
this.bodyClass.register(ID, ['app-test']);
18+
document.documentElement.dataset.appTest = '';
2219
});
2320

2421
hooks.afterEach(function () {
25-
this.bodyClass.deregister(ID);
22+
delete document.documentElement.dataset.appTest;
2623
});
2724
}

vendor/qunit.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
body.app-test .ember-application {
1+
[data-app-test] .ember-application {
22
background-color: var(--header-bg-color);
33
}

yarn.lock

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6970,13 +6970,6 @@ ember-router-scroll@4.1.2:
69706970
ember-cli-babel "^7.26.6"
69716971
ember-compatibility-helpers "^1.2.5"
69726972

6973-
ember-set-body-class@1.0.2:
6974-
version "1.0.2"
6975-
resolved "https://registry.yarnpkg.com/ember-set-body-class/-/ember-set-body-class-1.0.2.tgz#a970933f00e57ece6b6a88b96daf22f2374c3c34"
6976-
integrity sha512-SEsTwFp9SHTg4LgebhkUuLgYWg1VZD7I1QcrV2sTY583wu216OThoSs5szvS/KgSc1xD1Z22TFvOb848t2hGfw==
6977-
dependencies:
6978-
ember-cli-babel "^7.22.1"
6979-
69806973
ember-source-channel-url@^3.0.0:
69816974
version "3.0.0"
69826975
resolved "https://registry.yarnpkg.com/ember-source-channel-url/-/ember-source-channel-url-3.0.0.tgz#bcd5be72c63fa0b8c390b3121783b462063e2a1b"

0 commit comments

Comments
 (0)