Skip to content

Commit 2f7dcb6

Browse files
authored
docs: light mode dark mode (#8050)
* feat(docs): add ThemeScript component to root * feat(docs): enhance theme toggle functionality and styles - Added dark mode support in global CSS with new color variables. - Refactored ThemeScript component to improve theme preference handling. - Updated theme toggle components to accept class props for better styling. - Simplified theme toggle logic in ThemeToggle component. - Removed deprecated ThemeScript import from root component. - Cleaned up unused CSS styles related to theme toggle. * feat: enhance dark mode support and clean up theme toggle components - Added CSS rules for dark mode image filtering and temporary workarounds. - Updated theme toggle components to remove unused imports and streamline code. - Introduced light mode styles for ecosystem elements based on user preferences. * feat: improve dark mode styles and remove unused theme toggle components - Added dark mode styles for various components including code sandbox and API documentation. - Removed sun-and-moon theme toggle components and associated CSS to streamline the codebase. - Updated theme icon styles for better responsiveness and consistency. * fix: update SVG logos to use consistent fill color for dark mode * refactor: streamline theme handling and remove unused dark mode styles - Removed dark mode CSS rules from global styles and various components to simplify the codebase. - Updated theme toggle logic to improve responsiveness and ensure consistent theme application based on user preferences. - Enhanced theme script to handle theme attributes more robustly. * refactor: update SVG logos to use 'currentColor' for fill attribute - Changed the fill attribute in Discord, GitHub, and Twitter logo SVGs from a specific color to 'currentColor' for better adaptability in different themes. - Cleaned up unnecessary CSS rules in the API styles to enhance maintainability. * refactor: reorganize theme handling and remove deprecated theme script - Moved the ThemeScript import to the theme-toggle component for better structure. - Removed the obsolete theme-script file to clean up the codebase. - Updated the colorSchemeChangeListener import to reflect the new file structure. * refactor: enhance theme toggle component for better responsiveness - Updated the theme toggle button styles to improve layout and alignment. - Added conditional text display for theme preference on smaller screens. - Adjusted visibility of theme icons based on screen size for a cleaner UI. * refactor: extract theme loading logic into a separate module - Created a new load-theme.js file to encapsulate the theme loading logic. - Updated ThemeScript component to import and utilize the new loadThemeScript for improved code organization and maintainability. * refactor: remove IIFE from load-theme.js for cleaner code structure - Eliminated the immediately invoked function expression (IIFE) in load-theme.js to simplify the theme loading logic. - Improved readability and maintainability of the theme loading process.
1 parent ab51dea commit 2f7dcb6

File tree

15 files changed

+195
-205
lines changed

15 files changed

+195
-205
lines changed

packages/docs/src/components/header/header.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ import { TwitterLogo } from '../svgs/twitter-logo';
1818
import styles from './header.css?inline';
1919
import { GlobalStore } from '../../context';
2020
import {
21-
colorSchemeChangeListener,
2221
getColorPreference,
2322
setPreference,
2423
ThemeToggle,
24+
getEffectiveTheme,
2525
} from '../theme-toggle/theme-toggle';
2626
import { SearchIcon } from '../docsearch/icons/SearchIcon';
2727
import { getPkgManagerPreference } from '../package-manager-tabs';
28+
import { colorSchemeChangeListener } from '../theme-toggle/theme-script';
2829

2930
export const SearchButton = component$<PropsOf<'button'>>(({ ...props }) => {
3031
return (
@@ -49,10 +50,14 @@ export const Header = component$(() => {
4950

5051
useVisibleTask$(() => {
5152
globalStore.pkgManager = getPkgManagerPreference();
52-
globalStore.theme = getColorPreference();
53+
const pref = getColorPreference();
54+
globalStore.theme = getEffectiveTheme(pref);
5355
return colorSchemeChangeListener((isDark) => {
54-
globalStore.theme = isDark ? 'dark' : 'light';
55-
setPreference(globalStore.theme);
56+
const currentPref = getColorPreference();
57+
if (currentPref === 'auto') {
58+
globalStore.theme = isDark ? 'dark' : 'light';
59+
setPreference('auto');
60+
}
5661
});
5762
});
5863

packages/docs/src/components/router-head/router-head.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { component$ } from '@builder.io/qwik';
22
import { useDocumentHead, useLocation } from '@builder.io/qwik-city';
33
import { Social } from './social';
44
import { Vendor } from './vendor';
5-
import { ThemeScript } from './theme-script';
5+
import { ThemeScript } from '../theme-toggle/theme-script';
66

77
export const RouterHead = component$(() => {
88
const { url } = useLocation();

packages/docs/src/components/router-head/theme-script.tsx

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

packages/docs/src/components/svgs/discord-logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const DiscordLogo = ({ width, height }: DiscordLogoProps) => (
1313
viewBox="0 0 512 512"
1414
role="img"
1515
aria-label="Discord Logo"
16-
class="fill-[var(--text-color)]"
16+
fill="currentColor"
1717
>
1818
<path d="M464 66.52A50 50 0 00414.12 17L97.64 16A49.65 49.65 0 0048 65.52V392c0 27.3 22.28 48 49.64 48H368l-13-44 109 100zM324.65 329.81s-8.72-10.39-16-19.32C340.39 301.55 352.5 282 352.5 282a139 139 0 01-27.85 14.25 173.31 173.31 0 01-35.11 10.39 170.05 170.05 0 01-62.72-.24 184.45 184.45 0 01-35.59-10.4 141.46 141.46 0 01-17.68-8.21c-.73-.48-1.45-.72-2.18-1.21-.49-.24-.73-.48-1-.48-4.36-2.42-6.78-4.11-6.78-4.11s11.62 19.09 42.38 28.26c-7.27 9.18-16.23 19.81-16.23 19.81-53.51-1.69-73.85-36.47-73.85-36.47 0-77.06 34.87-139.62 34.87-139.62 34.87-25.85 67.8-25.12 67.8-25.12l2.42 2.9c-43.59 12.32-63.44 31.4-63.44 31.4s5.32-2.9 14.28-6.77c25.91-11.35 46.5-14.25 55-15.21a24 24 0 014.12-.49 205.62 205.62 0 0148.91-.48 201.62 201.62 0 0172.89 22.95s-19.13-18.15-60.3-30.45l3.39-3.86s33.17-.73 67.81 25.16c0 0 34.87 62.56 34.87 139.62 0-.28-20.35 34.5-73.86 36.19z" />
1919
<path d="M212.05 218c-13.8 0-24.7 11.84-24.7 26.57s11.14 26.57 24.7 26.57c13.8 0 24.7-11.83 24.7-26.57.25-14.76-10.9-26.57-24.7-26.57zM300.43 218c-13.8 0-24.7 11.84-24.7 26.57s11.14 26.57 24.7 26.57c13.81 0 24.7-11.83 24.7-26.57S314 218 300.43 218z" />

packages/docs/src/components/svgs/github-logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const GithubLogo = ({ width, height }: GithubLogoProps) => (
1010
height={height}
1111
role="img"
1212
aria-label="GitHub Logo"
13-
class="fill-[var(--text-color)]"
13+
fill="currentColor"
1414
>
1515
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />
1616
</svg>

packages/docs/src/components/svgs/twitter-logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const TwitterLogo = ({ width, height }: TwitterLogoProps) => (
1111
viewBox="0 0 512 512"
1212
role="img"
1313
aria-label="Twitter Logo"
14-
class="fill-[var(--text-color)]"
14+
fill="currentColor"
1515
>
1616
<path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z" />
1717
</svg>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { component$ } from '@builder.io/qwik';
2+
3+
interface BrillianceIconProps {
4+
class?: string;
5+
}
6+
7+
export const BrillianceIcon = component$<BrillianceIconProps>(({ class: className, ...props }) => {
8+
return (
9+
<svg
10+
xmlns="http://www.w3.org/2000/svg"
11+
fill="currentColor"
12+
class={className}
13+
viewBox="0 0 16 16"
14+
{...props}
15+
>
16+
<path d="M8 16A8 8 0 1 1 8 0a8 8 0 0 1 0 16M1 8a7 7 0 0 0 7 7 3.5 3.5 0 1 0 0-7 3.5 3.5 0 1 1 0-7 7 7 0 0 0-7 7" />
17+
</svg>
18+
);
19+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { component$ } from '@builder.io/qwik';
2+
3+
interface MoonIconProps {
4+
class?: string;
5+
}
6+
7+
export const MoonIcon = component$<MoonIconProps>(({ class: className, ...props }) => {
8+
return (
9+
<svg
10+
xmlns="http://www.w3.org/2000/svg"
11+
fill="none"
12+
viewBox="0 0 24 24"
13+
stroke-width="1.5"
14+
stroke="currentColor"
15+
class={className}
16+
{...props}
17+
>
18+
<path
19+
stroke-linecap="round"
20+
stroke-linejoin="round"
21+
d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"
22+
/>
23+
</svg>
24+
);
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { component$ } from '@builder.io/qwik';
2+
3+
interface SunIconProps {
4+
class?: string;
5+
}
6+
7+
export const SunIcon = component$<SunIconProps>(({ class: className, ...props }) => {
8+
return (
9+
<svg
10+
xmlns="http://www.w3.org/2000/svg"
11+
fill="none"
12+
viewBox="0 0 24 24"
13+
stroke-width="1.5"
14+
stroke="currentColor"
15+
class={className}
16+
{...props}
17+
>
18+
<path
19+
stroke-linecap="round"
20+
stroke-linejoin="round"
21+
d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"
22+
/>
23+
</svg>
24+
);
25+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
try {
2+
const getItem = localStorage.getItem('theme-preference');
3+
const el = document.firstElementChild;
4+
if (!el) {
5+
throw new Error('documentElement not found');
6+
}
7+
8+
if (getItem === 'light' || getItem === 'dark') {
9+
el.setAttribute('data-theme', getItem);
10+
} else {
11+
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
12+
el.setAttribute('data-theme', isDark ? 'dark' : 'light');
13+
}
14+
} catch (err) {
15+
console.error(err);
16+
}

0 commit comments

Comments
 (0)