Skip to content
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

Hotfix color mode #13915

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/@chakra-ui/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import semanticTokens from "./semanticTokens"

const config: ThemeConfig = {
cssVarPrefix: "eth",
initialColorMode: "system",
initialColorMode: "light",
/**
* Disable Chakra's system color subscription, as it works differently from
* `next-themes` and causes a desync with it.
Expand Down
18 changes: 3 additions & 15 deletions src/components/Nav/useNav.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from "react"
import { useTranslation } from "next-i18next"
import { useTheme } from "next-themes"
import {
Expand Down Expand Up @@ -29,7 +28,7 @@ import type { NavSections } from "./types"

export const useNav = () => {
const { t } = useTranslation("common")
const { setTheme, resolvedTheme, systemTheme } = useTheme()
const { setTheme, resolvedTheme } = useTheme()
const { setColorMode } = useColorMode()

const linkSections: NavSections = {
Expand Down Expand Up @@ -462,23 +461,12 @@ export const useNav = () => {
},
}

// Listen for changes to systemTheme and update theme accordingly
// Important if the user has not engaged the color mode toggle yet, and
// toggles system color preferences
useEffect(() => {
setTheme("system")
setColorMode(systemTheme)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [systemTheme])

const toggleColorMode = () => {
// resolvedTheme: "light" | "dark" = Current resolved color mode from useTheme
const targetTheme = resolvedTheme === "dark" ? "light" : "dark"
// If target theme matches the users system pref, set ls theme to "system"
const lsTheme = targetTheme === systemTheme ? "system" : targetTheme

setTheme(lsTheme)
setTheme(targetTheme)
setColorMode(targetTheme)

trackCustomEvent({
eventCategory: "nav bar",
eventAction: "click",
Expand Down
6 changes: 3 additions & 3 deletions src/components/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const ThemeProvider = ({ children }: Pick<ThemeProviderProps, "children">) => {
const theme = useMemo(() => merge(customTheme, { direction }), [direction])
return (
<NextThemesProvider
attribute="class"
defaultTheme="system"
enableSystem
attribute="data-theme"
defaultTheme="light"
enableSystem={false}
disableTransitionOnChange
storageKey={COLOR_MODE_STORAGE_KEY}
>
Expand Down
4 changes: 2 additions & 2 deletions src/styles/docsearch.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

.DocSearch-Button-Container svg {
@apply size-3.5 group-hover:rotate-12 transition-transform duration-500 group-hover:transition-transform group-hover:duration-500;
@apply size-3.5 transition-transform duration-500 group-hover:rotate-12 group-hover:transition-transform group-hover:duration-500;
}

.DocSearch-Search-Icon,
Expand Down Expand Up @@ -39,7 +39,7 @@
--docsearch-hit-height: fit-content;
}

.dark {
[data-theme="dark"] {
--docsearch-modal-background: theme(backgroundColor.background.DEFAULT);
--docsearch-highlight-color: theme(colors.primary.hover);
}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
--search-background: var(--background);
}

.dark {
[data-theme="dark"] {
/* Semantic Colors: Dark mode */
/* ! Deprecating primary-light */
--primary-light: hsla(var(--orange-100));
Expand Down
2 changes: 1 addition & 1 deletion src/styles/semantic-tokens.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
}

/* Dark mode token declarations */
.dark {
[data-theme="dark"] {
--body: var(--gray-100);
--body-medium: var(--gray-400);
--body-light: var(--gray-600);
Expand Down
Loading