1-
21import clsx from 'clsx' ;
32import Link from '@docusaurus/Link' ;
43import 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
8585export 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+ }
0 commit comments