Skip to content

Commit 05bfbe9

Browse files
committed
Add dynamic SVG rendering based on color mode
1 parent 265b98a commit 05bfbe9

File tree

2 files changed

+239
-6
lines changed

2 files changed

+239
-6
lines changed

src/components/HomepageFeatures/index.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {ReactNode} from 'react';
2+
import {useColorMode} from '@docusaurus/theme-common';
23
import clsx from 'clsx';
34
import Heading from '@theme/Heading';
45
import styles from './styles.module.css';
@@ -21,7 +22,7 @@ const FeatureList: FeatureItem[] = [
2122
},
2223
{
2324
title: 'Compatibility',
24-
Svg: require('@site/static/img/SupportedPlatforms.svg').default,
25+
Svg: null, // Dynamically set based on color mode
2526
description: (
2627
<>
2728
Support for all popular platforms such as Paper, Velocity, Fabric, Sponge, and (Neo)Forge (via Sponge)
@@ -30,7 +31,7 @@ const FeatureList: FeatureItem[] = [
3031
},
3132
{
3233
title: 'Join the modern era',
33-
Svg: "null",//require('@site/static/img/undraw_docusaurus_tree.svg').default,
34+
Svg: null,
3435
description: (
3536
<>
3637
MiniPlaceholders is always up to date to support the latest features of Minecraft
@@ -40,15 +41,23 @@ const FeatureList: FeatureItem[] = [
4041
},
4142
];
4243

43-
function Feature({title, Svg, description}: FeatureItem) {
44+
function Feature(props: FeatureItem) {
45+
const {colorMode} = useColorMode();
46+
let SvgToRender = props.Svg;
47+
if (props.title === 'Compatibility') {
48+
SvgToRender = colorMode === 'dark'
49+
? require('@site/static/img/SupportedPlatforms.svg').default
50+
: require('@site/static/img/SupportedPlatformsLight.svg').default;
51+
}
52+
4453
return (
4554
<div className={clsx('col col--4')}>
4655
<div className="text--center">
47-
<Svg className={styles.featureSvg} role="img" />
56+
{SvgToRender && <SvgToRender className={styles.featureSvg} role="img" />}
4857
</div>
4958
<div className="text--center padding-horiz--md">
50-
<Heading as="h3">{title}</Heading>
51-
<p>{description}</p>
59+
<Heading as="h3">{props.title}</Heading>
60+
<p>{props.description}</p>
5261
</div>
5362
</div>
5463
);

0 commit comments

Comments
 (0)