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

fix: 🐛 Force dark mode on marketing pages #551

Merged
merged 1 commit into from
Apr 30, 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
16 changes: 2 additions & 14 deletions src/components/HomepageHero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,10 @@ import HeroDesktopBg from "@site/static/img/hero-desktop.svg";
import HeroMobileBg from "@site/static/img/hero-mobile.svg";
import styles from "./styles.module.scss";
import { useIsJapanese } from "@site/src/utils/isJapanese";
import { useColorMode } from "@docusaurus/theme-common";
import { useForcedDarkTheme } from "@site/src/utils/useForcedDarkTheme";
export default function HomepageHero(): JSX.Element {
const isJapanese = useIsJapanese();
const { setColorMode, colorMode } = useColorMode();

//quick fix for updating color mode on page load breaking after theme upgrade
React.useEffect(() => {
const originalTheme = colorMode;

// The second parameter exists, it's just not on the type :(
setColorMode("dark", { persist: false });

return () => {
setColorMode(originalTheme);
};
}, []);
useForcedDarkTheme();

return (
<header className={clsx("bg-11-o-clock text-white", styles.homepageHero)}>
Expand Down
3 changes: 3 additions & 0 deletions src/components/PageHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from "react";
import clsx from "clsx";
import styles from "./styles.module.scss";
import { useForcedDarkTheme } from "@site/src/utils/useForcedDarkTheme";

type PageHeaderProps = {
heading: string;
Expand All @@ -12,6 +13,8 @@ export default function PageHeader({
heading,
subheading,
}: PageHeaderProps): JSX.Element {
useForcedDarkTheme();

return (
<header className={clsx("bg-11-o-clock text-white", styles.pageHeader)}>
<div className="container">
Expand Down
17 changes: 17 additions & 0 deletions src/utils/useForcedDarkTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from "react";
import { useColorMode } from "@docusaurus/theme-common";

export function useForcedDarkTheme() {
const { setColorMode, colorMode } = useColorMode();
//quick fix for updating color mode on page load breaking after theme upgrade
React.useEffect(() => {
const originalTheme = colorMode;

// The second parameter exists, it's just not on the type :(
setColorMode("dark", { persist: false });

return () => {
setColorMode(originalTheme);
};
}, []);
}
Loading