feat: 🎸 add initial color theme toggle UX

This commit is contained in:
Randall Morey committed 2020-11-04 13:51:37 -05:00
1 parent 5c1f79f98d
commit ef96369392
9 files changed
+98 -4

No files matched your search

+30
View File
@@ -26,6 +26,11 @@ export default class ApplicationRoute extends Route.extend(
// =methods
beforeModel() {
const theme = this.session.get('data.theme');
this.toggleTheme(theme);
}
/**
* After becoming authenticated, does nothing. This overrides the default
* behavior of the ApplicationRouteMixin, which is to redirect after auth.
@@ -115,4 +120,29 @@ export default class ApplicationRoute extends Route.extend(
}
}
/**
* Applies the specified color theme to the root ember element.
* @param {string} theme - "light", "dark", or nullish (system default)
*/
@action
toggleTheme(theme) {
const rootElementSelector = getOwner(this).rootElement;
const rootEl = getOwner(this).lookup('service:-document')
.querySelector(rootElementSelector);
this.session.set('data.theme', theme);
switch (theme) {
case 'light':
rootEl.classList.add('rose-theme-light');
rootEl.classList.remove('rose-theme-dark');
break;
case 'dark':
rootEl.classList.add('rose-theme-dark');
rootEl.classList.remove('rose-theme-light');
break;
default:
rootEl.classList.remove('rose-theme-dark');
rootEl.classList.remove('rose-theme-light');
}
}
}
+22
View File
@@ -23,11 +23,33 @@
{{t 'actions.change-password'}}
</dropdown.link>
<dropdown.separator />
<dropdown.button
{{on "click" (route-action "invalidateSession")}}
>
{{t 'actions.deauthenticate'}}
</dropdown.button>
<dropdown.separator />
<Rose::Form as |form|>
<form.radioGroup
@name="theme"
@selectedValue={{this.session.data.theme}}
@changed={{route-action "toggleTheme"}}
as |radioGroup|>
<dropdown.item>
<radioGroup.radio @label={{t "themes.system"}} />
</dropdown.item>
<dropdown.item>
<radioGroup.radio @label={{t "themes.light"}} @value="light" />
</dropdown.item>
<dropdown.item>
<radioGroup.radio @label={{t "themes.dark"}} @value="dark" />
</dropdown.item>
</form.radioGroup>
</Rose::Form>
</utilities.dropdown>
</header.utilities>