Skip to content

Commit 4d4a84b

Browse files
authored
Add support for dark mode to new homepage cards (#2442)
* Update docusaurus.config.js for production launch * Add support for both color modes * Remove border in dark mode * Add screenshot for CMS dark mode * Fix non external link Previously cards opened the pages in a new tab * Update homepage images
1 parent 52d4229 commit 4d4a84b

File tree

8 files changed

+161
-133
lines changed

8 files changed

+161
-133
lines changed

docusaurus/docusaurus.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const darkCodeTheme = themes.dracula;
1010
const config = {
1111
title: 'Strapi 5 Documentation',
1212
tagline: 'Design APIs fast, manage content easily.',
13-
url: 'https://docs-next.strapi.io',
13+
url: 'https://docs.strapi.io',
1414
baseUrl: '/',
1515
onBrokenLinks: 'throw', // replace with 'throw' to stop building if broken links
1616
onBrokenMarkdownLinks: 'throw',
@@ -128,7 +128,7 @@ const config = {
128128
docs: {
129129
routeBasePath: '/',
130130
sidebarPath: require.resolve('./sidebars.js'),
131-
editUrl: 'https://github.com/strapi/documentation/edit/next/docusaurus', // TODO change back to next then main for production releases admonitions: {
131+
editUrl: 'https://github.com/strapi/documentation/edit/main/docusaurus',
132132
admonitions: {
133133
keywords: [
134134
// Admonitions defaults
@@ -194,8 +194,8 @@ const config = {
194194
hideOnScroll: false,
195195
logo: {
196196
alt: 'Strapi Documentation Logo',
197-
src: 'img/logo-beta.png',
198-
srcDark: 'img/logo-beta-dark.png',
197+
src: 'img/logo.png',
198+
srcDark: 'img/logo-dark.png',
199199
},
200200
items: [
201201
{

docusaurus/src/components/Card/Card.jsx

+39-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import clsx from 'clsx';
32
import Link from '@docusaurus/Link';
43
import styles from './card.module.scss';
@@ -10,13 +9,16 @@ export function CardIcon ({
109
name,
1110
color = '#000',
1211
className,
12+
isDarkTheme = false,
1313
...rest
1414
}) {
15+
const iconColor = isDarkTheme ? color : color;
16+
1517
return (
1618
<div className={styles['card-category-icon-container']}>
1719
<Icon
1820
name={name}
19-
color={color}
21+
color={iconColor}
2022
/>
2123
</div>
2224
)
@@ -30,7 +32,6 @@ export function CardTitle({
3032
...rest
3133
}) {
3234
const TitleElement = (as || 'h3');
33-
3435
return (
3536
<TitleElement
3637
className={clsx(
@@ -55,7 +56,6 @@ export function CardDescription({
5556
...rest
5657
}) {
5758
const DescriptionElement = (as || 'div');
58-
5959
return (
6060
<DescriptionElement
6161
className={clsx(
@@ -84,13 +84,15 @@ export function CardImgBg({
8484

8585
export function CardImg({
8686
className,
87+
isDarkTheme = false,
8788
...rest
8889
}) {
8990
return (
9091
<img
9192
className={clsx(
9293
styles['card__img'],
9394
className,
95+
isDarkTheme ? styles['card__img--dark'] : ''
9496
)}
9597
{...rest}
9698
/>
@@ -104,8 +106,11 @@ export function CardCta({
104106
color = '#000',
105107
withArrow,
106108
asPlainContent = false,
109+
isDarkTheme = false,
107110
...rest
108111
}) {
112+
const ctaColor = isDarkTheme ? (color === '#000' ? '#FFFFFF' : color) : color;
113+
109114
const contentJSX = (
110115
<>
111116
{text}
@@ -116,13 +121,13 @@ export function CardCta({
116121
)}
117122
</>
118123
);
119-
124+
120125
if (asPlainContent) {
121126
return (
122127
<div
123-
className={className}
128+
className={clsx(className, isDarkTheme ? styles['card-cta--dark'] : '')}
124129
style={{
125-
color: color,
130+
color: ctaColor,
126131
paddingTop: '15px',
127132
paddingBottom: '50px',
128133
}}
@@ -132,13 +137,13 @@ export function CardCta({
132137
</div>
133138
);
134139
}
135-
140+
136141
return (
137142
<Link
138-
className={className}
143+
className={clsx(className, isDarkTheme ? styles['card-cta--dark'] : '')}
139144
to={to}
140145
style={{
141-
color: color,
146+
color: ctaColor,
142147
paddingTop: '15px',
143148
paddingBottom: '50px',
144149
}}
@@ -157,24 +162,42 @@ export function Card({
157162
isContentDelimited,
158163
to,
159164
variant,
165+
isDarkTheme = false,
160166
...rest
161167
}) {
162168
const isCallToAction = !!(href || to || asCallToAction);
163-
const CardElement = (to ? Link : (href ? 'a' : 'div'));
164-
169+
170+
let CardElement;
171+
let linkProps = {};
172+
173+
if (to) {
174+
CardElement = Link;
175+
linkProps = { to };
176+
} else if (href) {
177+
if (href.startsWith('/')) {
178+
CardElement = Link;
179+
linkProps = { to: href };
180+
} else {
181+
CardElement = 'a';
182+
linkProps = { href, target: '_blank' };
183+
}
184+
} else {
185+
CardElement = 'div';
186+
}
187+
165188
return (
166189
<CardElement
167-
{...(!href ? {} : { href, target: '_blank' })}
168-
{...(!to ? {} : { to })}
190+
{...linkProps}
169191
className={clsx(
170192
styles.card,
171193
(isCallToAction && styles['card--cta']),
172194
(isContentDelimited && styles['card--content-delimited']),
173195
(variant && styles[`card--${variant}`]),
174196
className,
175-
categoryType ? `category-${categoryType}` : ''
197+
categoryType ? `category-${categoryType}` : '',
198+
isDarkTheme ? styles['card--dark'] : ''
176199
)}
177200
{...rest}
178201
/>
179202
);
180-
}
203+
}

docusaurus/src/components/Card/card.module.scss

+4
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,8 @@
240240
}
241241
}
242242
}
243+
244+
[class*="card__img"] {
245+
border: none !important;
246+
}
243247
}

0 commit comments

Comments
 (0)