Skip to content

Commit acaf974

Browse files
committed
📚 (Docs): Improve colorMode displaying
1 parent 04dc2b3 commit acaf974

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

documentation/docusaurus.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ const config = {
6565
contextualSearch: true,
6666
},
6767
colorMode: {
68-
respectPrefersColorScheme: true,
68+
defaultMode: 'dark',
69+
disableSwitch: false,
70+
respectPrefersColorScheme: false,
6971
},
7072
navbar: {
7173
title: 'React Native Boilerplate',

documentation/src/components/Quickstart.tsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,17 @@ export default function Quickstart() {
4545
</div>
4646
</div>
4747

48-
{colorMode === 'dark'
49-
? (
50-
<img
51-
className="pointer-events-none hidden sm:block w-full md:w-[80%] 2xl:w-[85%] lg:w-2/3 mr-0 translate-x-[32%] md:translate-x-[20%] lg:translate-x-[15%] 2xl:translate-x-[28%] -translate-y-1/3 md:-translate-y-1/3 lg:-translate-y-1/2"
52-
src="./img/phone-dark.png"
53-
alt="phone"
54-
/>
55-
)
56-
: (
57-
<img
58-
className="pointer-events-none hidden sm:block w-full md:w-[80%] 2xl:w-[85%] lg:w-2/3 mr-0 translate-x-[32%] md:translate-x-[20%] lg:translate-x-[15%] 2xl:translate-x-[28%] -translate-y-1/3 md:-translate-y-1/3 lg:-translate-y-1/2"
59-
src="./img/phone.png"
60-
alt="phone"
61-
/>
62-
)}
48+
<img
49+
className="pointer-events-none hidden sm:block w-full md:w-[80%] 2xl:w-[85%] lg:w-2/3 mr-0 translate-x-[32%] md:translate-x-[20%] lg:translate-x-[15%] 2xl:translate-x-[28%] -translate-y-1/3 md:-translate-y-1/3 lg:-translate-y-1/2"
50+
src="./img/phone-dark.png"
51+
alt="phone"
52+
/>
53+
54+
<img
55+
className="dark:hidden pointer-events-none hidden sm:block w-full md:w-[80%] 2xl:w-[85%] lg:w-2/3 mr-0 translate-x-[32%] md:translate-x-[20%] lg:translate-x-[15%] 2xl:translate-x-[28%] -translate-y-1/3 md:-translate-y-1/3 lg:-translate-y-1/2"
56+
src="./img/phone.png"
57+
alt="phone"
58+
/>
6359
</div>
6460
</div>
6561
</section>

documentation/src/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function Home(): JSX.Element {
7777
<svg className="bottom-0 w-full sm:-mt-20 fill-red-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320">
7878
<path fill="current" fillOpacity="1" d="M0,320L60,272C120,224,240,128,360,128C480,128,600,224,720,234.7C840,245,960,171,1080,122.7C1200,75,1320,53,1380,42.7L1440,32L1440,320L1380,320C1320,320,1200,320,1080,320C960,320,840,320,720,320C600,320,480,320,360,320C240,320,120,320,60,320L0,320Z" />
7979
</svg>
80-
<Quickstart />
80+
<Quickstart />
8181
<svg className="pointer-events-none absolute bottom-0 sm:bottom-[169px] sm:bottom-[99px] lg:bottom-[269px] w-full sm:-mt-20 fill-neutral-100 dark:fill-neutral-900" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320">
8282
<path fill="current" fillOpacity="1" d="M0,288L48,272C96,256,192,224,288,197.3C384,171,480,149,576,165.3C672,181,768,235,864,250.7C960,267,1056,245,1152,250.7C1248,256,1344,288,1392,304L1440,320L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z" />
8383
</svg>

documentation/src/theme/Navbar/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ import { useColorMode } from '@docusaurus/theme-common';
66
export default function NavbarWrapper(props) {
77
const { colorMode } = useColorMode();
88

9+
useEffect(() => {
10+
const element = document.querySelector('html');
11+
12+
const observer = new MutationObserver((mutations) => {
13+
mutations.forEach((mutation) => {
14+
if (mutation.type === 'attributes') {
15+
const html = document.documentElement;
16+
const needOverride = colorMode === 'dark' && !html.classList.contains('dark');
17+
if (needOverride) {
18+
html.classList.add('dark');
19+
}
20+
}
21+
});
22+
});
23+
24+
observer.observe(element, {
25+
attributes: true,
26+
});
27+
28+
return () => {
29+
observer.disconnect();
30+
};
31+
});
32+
933
useEffect(() => {
1034
const html = document.documentElement;
1135
if (colorMode === 'dark') {

0 commit comments

Comments
 (0)