Skip to content

Commit a248d97

Browse files
committed
Implement dark mode for images
1 parent a68d561 commit a248d97

File tree

10 files changed

+71
-44
lines changed

10 files changed

+71
-44
lines changed

β€Ži18n/en/docusaurus-plugin-content-docs/current/get-started/tutorial.mdxβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ sidebar_position: 2
33
---
44

55
import { ReactCompareSlider, ReactCompareSliderImage, ReactCompareSliderHandle } from "react-compare-slider";
6+
import { ThemedCompareSliderImage } from "@site/src/shared/ui";
67

78
# Tutorial
89

910
Let's look at the principles of Feature-Sliced Design by building a simple web notes app. We will start theoretical, so don't worry if you don't know the stack. Here's how the app looks like, nice and simple, only for mobile:
1011

11-
{/* TODO: dark mode */}
12-
13-
![Notes application screens](/img/tutorial/overview.jpg)
12+
![Notes application screens](/img/tutorial/overview-light.jpg#light-mode-only)
13+
![Notes application screens](/img/tutorial/overview-dark.jpg#dark-mode-only)
1414

1515
## Decomposing the user interface
1616

@@ -55,8 +55,8 @@ Useful questions to ask yourself when determining whether an element is an entit
5555

5656
<ReactCompareSlider
5757
handle={<ReactCompareSliderHandle buttonStyle={{WebkitBackdropFilter: undefined, backdropFilter: undefined, backgroundColor: 'white', boxShadow: undefined, color: '#444'}} linesStyle={{opacity: 0.5}}/>}
58-
itemOne={<ReactCompareSliderImage src="/img/tutorial/overview.jpg" alt="Screens, unannotated" />}
59-
itemTwo={<ReactCompareSliderImage src="/img/tutorial/annotated-entities-features.jpg" alt="Screens, annotated with entities and features" />}
58+
itemOne={<ThemedCompareSliderImage srcLight="/img/tutorial/overview-light.jpg" srcDark="/img/tutorial/overview-dark.jpg" alt="Screens, unannotated" />}
59+
itemTwo={<ThemedCompareSliderImage srcLight="/img/tutorial/annotated-entities-features-light.jpg" srcDark="/img/tutorial/annotated-entities-features-dark.jpg" alt="Screens, annotated with entities and features" />}
6060
position={100}
6161
/>
6262

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@docusaurus/plugin-content-docs": "2.1.0",
3131
"@docusaurus/plugin-ideal-image": "2.1.0",
3232
"@docusaurus/preset-classic": "2.1.0",
33+
"@docusaurus/theme-common": "2.1.0",
3334
"@fontsource/overpass": "^4.5.4",
3435
"@fontsource/ubuntu": "^4.5.4",
3536
"@mdx-js/react": "^1.6.22",

β€Žpnpm-lock.yamlβ€Ž

Lines changed: 24 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žsrc/app/doc-item.scssβ€Ž

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ html {
2828
}
2929
}
3030

31+
:root[data-theme=dark] [src$="#light-mode-only"] {
32+
display: none
33+
}
34+
35+
:root[data-theme=light] [src$="#dark-mode-only"] {
36+
display: none
37+
}
38+
39+
@media(prefers-color-scheme: dark) {
40+
:root[data-theme=auto] [src$="#light-mode-only"] {
41+
display:none
42+
}
43+
}
44+
45+
@media(prefers-color-scheme: light) {
46+
:root[data-theme=auto] [src$="#dark-mode-only"] {
47+
display:none
48+
}
49+
}
50+
3151
iframe {
3252
width: 100%;
3353
height: 700px;

β€Žsrc/shared/ui/index.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
export * from "./card";
33
export * from "./section";
44
export * from "./table";
5+
export { ThemedCompareSliderImage } from "./themed-compare-slider-image";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { ReactCompareSliderImage, ReactCompareSliderImageProps } from "react-compare-slider";
3+
import { useColorMode } from "@docusaurus/theme-common";
4+
5+
interface ThemedCompareSliderImageProps extends Omit<ReactCompareSliderImageProps, "src"> {
6+
srcLight: string;
7+
srcDark: string;
8+
}
9+
10+
export const ThemedCompareSliderImage = ({
11+
srcDark,
12+
srcLight,
13+
...restProps
14+
}: ThemedCompareSliderImageProps) => {
15+
const { colorMode } = useColorMode();
16+
17+
return (
18+
<ReactCompareSliderImage src={colorMode === "dark" ? srcDark : srcLight} {...restProps} />
19+
);
20+
};
412 KB
Loading
222 KB
Loading

0 commit comments

Comments
Β (0)