1
-
2
1
import clsx from 'clsx' ;
3
2
import Link from '@docusaurus/Link' ;
4
3
import styles from './card.module.scss' ;
@@ -10,13 +9,16 @@ export function CardIcon ({
10
9
name,
11
10
color = '#000' ,
12
11
className,
12
+ isDarkTheme = false ,
13
13
...rest
14
14
} ) {
15
+ const iconColor = isDarkTheme ? color : color ;
16
+
15
17
return (
16
18
< div className = { styles [ 'card-category-icon-container' ] } >
17
19
< Icon
18
20
name = { name }
19
- color = { color }
21
+ color = { iconColor }
20
22
/>
21
23
</ div >
22
24
)
@@ -30,7 +32,6 @@ export function CardTitle({
30
32
...rest
31
33
} ) {
32
34
const TitleElement = ( as || 'h3' ) ;
33
-
34
35
return (
35
36
< TitleElement
36
37
className = { clsx (
@@ -55,7 +56,6 @@ export function CardDescription({
55
56
...rest
56
57
} ) {
57
58
const DescriptionElement = ( as || 'div' ) ;
58
-
59
59
return (
60
60
< DescriptionElement
61
61
className = { clsx (
@@ -84,13 +84,15 @@ export function CardImgBg({
84
84
85
85
export function CardImg ( {
86
86
className,
87
+ isDarkTheme = false ,
87
88
...rest
88
89
} ) {
89
90
return (
90
91
< img
91
92
className = { clsx (
92
93
styles [ 'card__img' ] ,
93
94
className ,
95
+ isDarkTheme ? styles [ 'card__img--dark' ] : ''
94
96
) }
95
97
{ ...rest }
96
98
/>
@@ -104,8 +106,11 @@ export function CardCta({
104
106
color = '#000' ,
105
107
withArrow,
106
108
asPlainContent = false ,
109
+ isDarkTheme = false ,
107
110
...rest
108
111
} ) {
112
+ const ctaColor = isDarkTheme ? ( color === '#000' ? '#FFFFFF' : color ) : color ;
113
+
109
114
const contentJSX = (
110
115
< >
111
116
{ text }
@@ -116,13 +121,13 @@ export function CardCta({
116
121
) }
117
122
</ >
118
123
) ;
119
-
124
+
120
125
if ( asPlainContent ) {
121
126
return (
122
127
< div
123
- className = { className }
128
+ className = { clsx ( className , isDarkTheme ? styles [ 'card-cta--dark' ] : '' ) }
124
129
style = { {
125
- color : color ,
130
+ color : ctaColor ,
126
131
paddingTop : '15px' ,
127
132
paddingBottom : '50px' ,
128
133
} }
@@ -132,13 +137,13 @@ export function CardCta({
132
137
</ div >
133
138
) ;
134
139
}
135
-
140
+
136
141
return (
137
142
< Link
138
- className = { className }
143
+ className = { clsx ( className , isDarkTheme ? styles [ 'card-cta--dark' ] : '' ) }
139
144
to = { to }
140
145
style = { {
141
- color : color ,
146
+ color : ctaColor ,
142
147
paddingTop : '15px' ,
143
148
paddingBottom : '50px' ,
144
149
} }
@@ -157,24 +162,42 @@ export function Card({
157
162
isContentDelimited,
158
163
to,
159
164
variant,
165
+ isDarkTheme = false ,
160
166
...rest
161
167
} ) {
162
168
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
+
165
188
return (
166
189
< CardElement
167
- { ...( ! href ? { } : { href, target : '_blank' } ) }
168
- { ...( ! to ? { } : { to } ) }
190
+ { ...linkProps }
169
191
className = { clsx (
170
192
styles . card ,
171
193
( isCallToAction && styles [ 'card--cta' ] ) ,
172
194
( isContentDelimited && styles [ 'card--content-delimited' ] ) ,
173
195
( variant && styles [ `card--${ variant } ` ] ) ,
174
196
className ,
175
- categoryType ? `category-${ categoryType } ` : ''
197
+ categoryType ? `category-${ categoryType } ` : '' ,
198
+ isDarkTheme ? styles [ 'card--dark' ] : ''
176
199
) }
177
200
{ ...rest }
178
201
/>
179
202
) ;
180
- }
203
+ }
0 commit comments