Skip to content

Commit 02ba983

Browse files
authored
fix: dynamic theme logo (#50)
1 parent 074fc60 commit 02ba983

File tree

5 files changed

+16
-42
lines changed

5 files changed

+16
-42
lines changed

docs/offlegacy.org/src/components/demo-playground.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
import { highlight, Pre, type HighlightedCode } from "codehike/code";
44
import { DemoButton } from "./demo-button";
5-
import { useTheme } from "nextra-theme-docs";
6-
import { useSystemDarkMode } from "../logo/useSystemDarkMode";
7-
import { useEffect, useState } from "react";
5+
import { Link, useTheme } from "nextra-theme-docs";
6+
import { useLayoutEffect, useState } from "react";
87
import { motion } from "motion/react";
98
import { Toaster } from "sonner";
109

@@ -31,13 +30,11 @@ function App() {
3130
}`;
3231

3332
export function DemoCode() {
34-
const { theme } = useTheme();
35-
const isSystemDarkMode = useSystemDarkMode();
36-
const resolvedTheme = theme === "system" ? (isSystemDarkMode ? "dark" : "light") : theme;
33+
const { resolvedTheme } = useTheme();
3734
const codeTheme = resolvedTheme === "dark" ? "github-dark" : "github-light";
3835
const [highlighted, setHighlighted] = useState<HighlightedCode | null>(null);
3936

40-
useEffect(() => {
37+
useLayoutEffect(() => {
4138
highlight(
4239
{
4340
value: code,
@@ -66,7 +63,9 @@ export function DemoCode() {
6663
<div className="relative overflow-hidden rounded-xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-gray-900">
6764
<div className="flex items-center justify-between border-b border-gray-200 bg-gray-50 px-4 py-3 dark:border-gray-700 dark:bg-gray-800/50">
6865
<div className="flex items-center space-x-2">
69-
<span className="ml-2 text-sm font-medium text-gray-600 dark:text-gray-400">example-basic.tsx</span>
66+
<Link href="/docs/basic-example" className="ml-2 text-sm font-medium text-gray-600 dark:text-gray-400">
67+
example-basic.tsx
68+
</Link>
7069
</div>
7170
</div>
7271
<div className="relative overflow-x-auto p-6">

docs/offlegacy.org/src/components/home-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default async function HomePage({
4646
<InstallCopyButton />
4747
</div>
4848
</div>
49-
<div className="min-h-[572.75px]">
49+
<div className="min-h-[572.75px] w-full max-w-[723px]">
5050
<DemoCode />
5151
</div>
5252
</div>

docs/offlegacy.org/src/content/en/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import HomePage from "@/components/home-page";
77
<HomePage
88
description="Comprehensive solution for event tracking in React applications"
99
startedText="Get Started"
10-
featureSectionTitle="Event tracking paradigm presented by Event Tracker"
10+
featureSectionTitle="Focus on 'what' to track, not 'how' to track it!"
1111
featureSectionContents={[
1212
{
1313
title: "Declarative API",

docs/offlegacy.org/src/logo/index.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import Image from "next/image";
44
import { useTheme } from "nextra-theme-docs";
5-
6-
import { useSystemDarkMode } from "./useSystemDarkMode";
5+
import { useLayoutEffect, useState } from "react";
76

87
interface LogoProps {
98
size?: number;
@@ -13,12 +12,12 @@ const DARK_LOGO_PATH = "/img/dark-logo.png";
1312
const LIGHT_LOGO_PATH = "/img/light-logo.png";
1413

1514
export const Logo = ({ size = 30 }: LogoProps) => {
16-
const isSystemDarkMode = useSystemDarkMode();
17-
const { theme } = useTheme();
15+
const { resolvedTheme } = useTheme();
16+
const [src, setSrc] = useState(LIGHT_LOGO_PATH);
1817

19-
const isDarkMode = theme === "system" ? isSystemDarkMode : theme === "dark";
18+
useLayoutEffect(() => {
19+
setSrc(resolvedTheme === "dark" ? DARK_LOGO_PATH : LIGHT_LOGO_PATH);
20+
}, [resolvedTheme]);
2021

21-
return (
22-
<Image src={isDarkMode ? DARK_LOGO_PATH : LIGHT_LOGO_PATH} alt="event-tracker logo" width={size} height={size} />
23-
);
22+
return <Image src={src} alt="event-tracker logo" width={size} height={size} />;
2423
};

docs/offlegacy.org/src/logo/useSystemDarkMode.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)