Skip to content

Commit f2c905c

Browse files
committed
refactored theme switching logic to connect the HDS switcher with the Boundary switcher
1 parent 68c97da commit f2c905c

File tree

4 files changed

+25
-32
lines changed

4 files changed

+25
-32
lines changed

ui/admin/app/controllers/application.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { paramValueFinder } from 'admin/utils/param-value-finder';
1414
const THEMES = [
1515
{
1616
label: 'system',
17-
value: 'system-default-theme',
17+
value: 'system',
1818
},
1919
{
2020
label: 'light',
@@ -91,6 +91,20 @@ export default class ApplicationController extends Controller {
9191
rootEl.classList.remove('rose-theme-dark');
9292
rootEl.classList.remove('rose-theme-light');
9393
}
94+
95+
// set the HDS theme too
96+
this.hdsTheming.setTheme({
97+
theme,
98+
onSetTheme: ({ currentTheme, currentMode }) => {
99+
// eslint-disable-next-line no-console
100+
console.log(
101+
`BOUNDARY SWITCHER - onSetTheme invoked`,
102+
theme,
103+
currentTheme,
104+
currentMode,
105+
);
106+
},
107+
});
94108
}
95109

96110
/**
@@ -131,12 +145,8 @@ export default class ApplicationController extends Controller {
131145
@action
132146
onSetTheme({ currentTheme, currentMode }) {
133147
// eslint-disable-next-line no-console
134-
console.log(`onSetTheme invoked`, currentTheme, currentMode);
135-
}
136-
137-
@action
138-
removeTheming() {
139-
this.hdsTheming.setTheme({ theme: undefined });
148+
console.log(`HDS SWITCHER - onSetTheme invoked`, currentTheme, currentMode);
149+
this.toggleTheme(currentTheme);
140150
}
141151

142152
/**

ui/admin/app/templates/application.hbs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,11 @@
161161
<AF.Link @href={{(doc-url)}}>{{t 'titles.documentation'}}</AF.Link>
162162
<AF.LegalLinks />
163163
<AF.ExtraAfter>
164-
{{! template-lint-disable no-inline-styles }}
165-
<Hds::ButtonSet style='gap: 4px; align-items: center'>
166-
<Hds::ThemeSwitcher
167-
@toggleSize='small'
168-
@hasDefaultOption={{true}}
169-
@onSetTheme={{this.onSetTheme}}
170-
/>
171-
<Hds::Button
172-
@color='secondary'
173-
@size='small'
174-
@icon='trash'
175-
@isIconOnly={{true}}
176-
@text='Remove theme'
177-
{{on 'click' this.removeTheming}}
178-
/>
179-
</Hds::ButtonSet>
164+
<Hds::ThemeSwitcher
165+
@toggleSize='small'
166+
@hasDefaultOption={{true}}
167+
@onSetTheme={{this.onSetTheme}}
168+
/>
180169
</AF.ExtraAfter>
181170
</Hds::AppFooter>
182171
</Frame.Footer>

ui/admin/tests/acceptance/authentication-test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,7 @@ module('Acceptance | authentication', function (hooks) {
384384
// toggle system default
385385
await click(commonSelectors.TOGGLE_THEME_DEFAULT);
386386

387-
assert.strictEqual(
388-
currentSession().get('data.theme'),
389-
'system-default-theme',
390-
);
387+
assert.strictEqual(currentSession().get('data.theme'), 'system');
391388
assert.notOk(getRootElement().classList.contains('rose-theme-light'));
392389
assert.notOk(getRootElement().classList.contains('rose-theme-dark'));
393390

@@ -401,10 +398,7 @@ module('Acceptance | authentication', function (hooks) {
401398
// toggle system default
402399
await click(commonSelectors.TOGGLE_THEME_DEFAULT);
403400

404-
assert.strictEqual(
405-
currentSession().get('data.theme'),
406-
'system-default-theme',
407-
);
401+
assert.strictEqual(currentSession().get('data.theme'), 'system');
408402
assert.notOk(getRootElement().classList.contains('rose-theme-light'));
409403
assert.notOk(getRootElement().classList.contains('rose-theme-dark'));
410404
});

ui/admin/tests/helpers/selectors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const SIDEBAR_SCOPE_DROPDOWN =
5353
export const SIDEBAR_SCOPE_LINK = (url) =>
5454
`[data-test-side-nav-scope-dropdown] a[href="${url}"]`;
5555
export const TOGGLE_THEME_DEFAULT =
56-
'[data-test-side-nav-user-dropdown] [value=system-default-theme]';
56+
'[data-test-side-nav-user-dropdown] [value=system]';
5757
export const TOGGLE_THEME_LIGHT =
5858
'[data-test-side-nav-user-dropdown] [value=light]';
5959
export const TOGGLE_THEME_DARK =

0 commit comments

Comments
 (0)