Skip to content

Commit ebcadae

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

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

ui/admin/app/controllers/application.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
const hdsTheme = theme === 'light' || theme === 'dark' ? theme : 'system';
97+
this.hdsTheming.setTheme({
98+
theme: hdsTheme,
99+
onSetTheme: ({ currentTheme, currentMode }) => {
100+
// eslint-disable-next-line no-console
101+
console.log(
102+
`BOUNDARY SWITCHER - onSetTheme invoked`,
103+
currentTheme,
104+
currentMode,
105+
);
106+
},
107+
});
94108
}
95109

96110
/**
@@ -131,12 +145,11 @@ 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+
const roseTheme =
150+
// note: we pass `null` here, because of the JSDOC definition above, but the selector in the sidenav dropdown passes `system-default-theme`
151+
currentTheme === 'light' || currentTheme === 'dark' ? currentTheme : null;
152+
this.toggleTheme(roseTheme);
140153
}
141154

142155
/**

ui/admin/app/templates/application.hbs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,10 @@
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+
@onSetTheme={{this.onSetTheme}}
167+
/>
180168
</AF.ExtraAfter>
181169
</Hds::AppFooter>
182170
</Frame.Footer>

0 commit comments

Comments
 (0)