-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
239 additions
and
85 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
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,26 +1,46 @@ | ||
import { computed } from "#imports" | ||
import { computed, useUiStore } from "#imports" | ||
|
||
import { useFeatureFlagStore } from "~/stores/feature-flag" | ||
|
||
export const DARK_MODE_CLASS = "dark-mode" | ||
export const LIGHT_MODE_CLASS = "light-mode" | ||
|
||
/** | ||
* TODO: Replace with the user's actual dark mode preference. | ||
* Dark mode detection will be based on user preference, | ||
* overwritten by the "force_dark_mode" feature flag. | ||
* Determines the dark mode setting based on user preference or feature flag. | ||
* | ||
* When dark mode toggling is disabled, the site is in "light mode" unless | ||
* the `force_dark_mode` feature flag is on. | ||
* | ||
* When the "dark_mode_ui_toggle" flag is enabled, the site will respect | ||
* the user system preference by default. | ||
* | ||
*/ | ||
export function useDarkMode() { | ||
const uiStore = useUiStore() | ||
const featureFlagStore = useFeatureFlagStore() | ||
|
||
const isDarkMode = computed(() => featureFlagStore.isOn("force_dark_mode")) | ||
const cssClass = computed(() => | ||
isDarkMode.value ? DARK_MODE_CLASS : LIGHT_MODE_CLASS | ||
const darkModeToggleable = computed(() => | ||
featureFlagStore.isOn("dark_mode_ui_toggle") | ||
) | ||
const forceDarkMode = computed(() => featureFlagStore.isOn("force_dark_mode")) | ||
|
||
const colorMode = computed(() => { | ||
if (darkModeToggleable.value && !forceDarkMode.value) { | ||
return uiStore.colorMode | ||
} | ||
return forceDarkMode.value ? "dark" : "light" | ||
}) | ||
|
||
const cssClass = computed(() => { | ||
return { | ||
light: LIGHT_MODE_CLASS, | ||
dark: DARK_MODE_CLASS, | ||
system: "", | ||
}[colorMode.value] | ||
}) | ||
|
||
return { | ||
isDarkMode, | ||
/** The CSS class representing the current color mode. */ | ||
colorMode, | ||
cssClass, | ||
} | ||
} |
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
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
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
Oops, something went wrong.