-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved
DarkModeToggle
component showing currently active preference
- Loading branch information
1 parent
f3250eb
commit 2a58e8f
Showing
5 changed files
with
27 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<TertiaryButton @size="small" {{on "click" (fn this.setPreference "system")}}>System</TertiaryButton> | ||
<TertiaryButton @size="small" {{on "click" (fn this.setPreference "dark")}}>Dark</TertiaryButton> | ||
<TertiaryButton @size="small" {{on "click" (fn this.setPreference "light")}}>Light</TertiaryButton> | ||
<TertiaryButton @size="small" {{on "click" (fn this.setPreference null)}}>Unset</TertiaryButton> | ||
{{#each this.possiblePreferences as |preference|}} | ||
{{#if (eq this.darkMode.localStoragePreference preference)}} | ||
<PrimaryButton @size="small" class="capitalize" {{on "click" (fn this.setPreference preference)}}>{{or preference "unset"}}</PrimaryButton> | ||
{{else}} | ||
<TertiaryButton @size="small" class="capitalize" {{on "click" (fn this.setPreference preference)}}>{{or preference "unset"}}</TertiaryButton> | ||
{{/if}} | ||
{{/each}} | ||
|
||
{{yield}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
import Controller from '@ember/controller'; | ||
import { service } from '@ember/service'; | ||
import type LocalStorageService from 'codecrafters-frontend/services/local-storage'; | ||
import { LOCAL_STORAGE_KEY, type LocalStoragePreference } from 'codecrafters-frontend/services/dark-mode'; | ||
import { tracked } from 'tracked-built-ins'; | ||
import { action } from '@ember/object'; | ||
import DarkModeService from 'codecrafters-frontend/services/dark-mode'; | ||
|
||
export default class DemoDarkModeToggleController extends Controller { | ||
@service declare localStorage: LocalStorageService; | ||
|
||
@tracked currentLocalStoragePreference?: LocalStoragePreference; | ||
|
||
@action loadDarkModePreference() { | ||
this.currentLocalStoragePreference = this.localStorage.getItem(LOCAL_STORAGE_KEY) as LocalStoragePreference; | ||
} | ||
@service declare darkMode: DarkModeService; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters