-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consume more tokens from arches theme, add dark mode toggle #91
Open
jacobtylerwalls
wants to merge
13
commits into
main
Choose a base branch
from
jtw/consume-tokens
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7e3bbaf
Consume more tokens from arches theme
jacobtylerwalls f811b9b
Add dark mode toggle
jacobtylerwalls cfc70dc
Add aria-label on dark mode toggle
jacobtylerwalls 9149cdf
Consume custom toast styling from core
jacobtylerwalls ec29833
Consume fontFamily token
jacobtylerwalls ad89307
Avoid arrow function
jacobtylerwalls 81daf62
Un-tokenize some styles
jacobtylerwalls 2979f72
Ignore constants.ts from coverage
jacobtylerwalls b5aaa35
Revert "Ignore constants.ts from coverage"
jacobtylerwalls 7ba76f7
PR feedback
jacobtylerwalls 8b764d5
Merge branch 'main' into jtw/consume-tokens
jacobtylerwalls abdb414
Adjust action template
jacobtylerwalls 822246c
Respect the initial value of isDarkModeEnabled
jacobtylerwalls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
45 changes: 45 additions & 0 deletions
45
arches_lingo/src/arches_lingo/components/header/DarkModeToggle.vue
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script setup lang="ts"> | ||
import { onMounted, ref } from "vue"; | ||
import { useGettext } from "vue3-gettext"; | ||
|
||
import ToggleButton from "primevue/togglebutton"; | ||
|
||
import { DEFAULT_THEME } from "@/arches/themes/default.ts"; | ||
|
||
const { $gettext } = useGettext(); | ||
|
||
const isDarkModeEnabled = ref( | ||
window.matchMedia && | ||
window.matchMedia("(prefers-color-scheme: dark)").matches, | ||
); | ||
|
||
function toggleDarkMode() { | ||
chrabyrd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const element = document.querySelector("html"); | ||
// Remove the leading dot from the selector to get class name. | ||
element!.classList.toggle( | ||
DEFAULT_THEME.theme.options.darkModeSelector.substring(1), | ||
); | ||
isDarkModeEnabled.value = !isDarkModeEnabled.value; | ||
} | ||
|
||
onMounted(() => { | ||
if (isDarkModeEnabled.value) { | ||
toggleDarkMode(); | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<ToggleButton | ||
jacobtylerwalls marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:model-value="isDarkModeEnabled" | ||
:on-label="$gettext('Dark')" | ||
:off-label="$gettext('Light')" | ||
off-icon="pi pi-sun" | ||
on-icon="pi pi-moon" | ||
:pt="{ | ||
root: { ariaLabel: $gettext('Toggle dark mode') }, | ||
label: { style: { display: 'none' } }, | ||
}" | ||
@click="toggleDarkMode" | ||
/> | ||
</template> |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDarkModeEnabled
works! (🎉 ). However, regardless of if its value, the theme when the page is loaded is always light. I was able to solve this locally viaHowever, this may not be the right solution. There's further complexity to add that may nullify that pattern. Namely, I can set the toggle to
dark
, see the change, refresh the page, and it's automatically set back tolight
. My guess is that either cookies or localstorage need to be leveraged to persist this through page refreshes.If we wanted to get really fancy we could add a column to the
User
model to support preferred theme, but that's probably overkill at this point. And we'd still need something on the browser to persist for anonymous user so /shrug that's not an entirely baked idea.If this component is changed to read from cookies/localstorage on mount, it'd be more readable to change the toggle method to accept an arg so it can be explicitly set the mode. This will also support adding other themes later. However I'm not married to this pattern, YAGNI and whatnot /shrug. Regardless, reading from cookies/localstorage nullifies the simple code laid out above.
But this reveals another titchy thing: we're handling all of theming in this component. If I have a cookie ( or bit of localstorage ) saved that says I prefer dark mode, I'd expect the application to handle this regardless of the presence or absence of the header / DarkModeToggle. Like in reports and whatnot. It could be argued that the ability to switch themes should be handled in this component of course, but the ability to query a preferred theme and apply it should be handled at a deeper level.
Perhaps even in core since it's touching the
<html>
element, but I don't feel strongly about that yet.