1
+ import React , { useEffect , useState } from 'react' ;
2
+ import { useColorMode } from '@docusaurus/theme-common' ;
3
+ import Link from '@docusaurus/Link' ;
4
+ import styles from './InfoCard.module.css'
5
+ import useBaseUrl from '@docusaurus/useBaseUrl' ;
6
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
7
+
8
+ export type InfoCardProps = {
9
+ title : string ; // 标题,中文
10
+ title_en ?: string ; // 标题,英文
11
+ logo ?: string ; // logo, xx.xx -> xx.dark.xx for night mode
12
+ subtitle ?: string ;
13
+ subtitle_en ?: string ;
14
+ description ?: string ;
15
+ description_en ?: string ;
16
+ link : string ; // Link
17
+ } ;
18
+
19
+ export const InfoCard : React . FC < InfoCardProps > = ( { title, title_en, logo, subtitle, subtitle_en, description, description_en, link } ) => {
20
+ const [ dark , setDark ] = useState ( false ) ;
21
+ const { colorMode } = useColorMode ( ) ;
22
+ useEffect ( ( ) => {
23
+ setDark ( colorMode === 'dark' ) ;
24
+ } , [ [ ] ] )
25
+ const [ name , ext ] = logo . split ( / \. (? = [ ^ . ] + $ ) / ) ;
26
+ const {
27
+ i18n : { currentLocale } ,
28
+ } = useDocusaurusContext ( ) ;
29
+ const isEn = currentLocale === 'en' ;
30
+
31
+ return (
32
+ < div className = { styles . card } onClick = { ( ) => window . open ( link , '_blank' ) } >
33
+ < div style = { { display : 'flex' , alignItems : 'center' , gap : '10px' } } >
34
+ { logo &&
35
+ dark ?
36
+ < img src = { useBaseUrl ( `${ name } .dark.${ ext } ` ) } alt = { title } style = { { width : 40 , height : 40 , borderRadius : '50%' } } onError = { ( e ) => ( e . currentTarget . src = useBaseUrl ( logo ) ) } />
37
+ :
38
+ < img src = { useBaseUrl ( logo ) } alt = { title } style = { { width : 40 , height : 40 , borderRadius : '50%' } } />
39
+ }
40
+ < div >
41
+ < h3 style = { { margin : 0 , fontSize : '1.1em' } } >
42
+ < Link to = { link } className = { styles . title } style = { { textDecoration : 'none' , color : 'inherit' } } >
43
+ { isEn ? ( title_en != null ? title_en : title ) : title }
44
+ </ Link >
45
+ </ h3 >
46
+ < p className = { styles . subTitle } style = { { margin : 0 } } >
47
+ { isEn ? ( subtitle_en != null ? subtitle_en : subtitle ) : subtitle }
48
+ </ p >
49
+ </ div >
50
+ </ div >
51
+ < p style = { { margin : '10px 0 0' , fontSize : '0.85em' , color : dark ? '#aaa' : '#555' } } >
52
+ { isEn ? ( description_en != null ? description_en : description ) : description }
53
+ </ p >
54
+ </ div >
55
+ ) ;
56
+ } ;
57
+
58
+
59
+ const InfoCardList : React . FC < { items : InfoCardProps [ ] } > = ( { items } ) => {
60
+ return (
61
+ < div style = { { display : 'grid' , gap : '16px' } } >
62
+ { items . map ( ( item , index ) => (
63
+ < InfoCard key = { index } { ...item } />
64
+ ) ) }
65
+ </ div >
66
+ ) ;
67
+ } ;
68
+
69
+ export default InfoCardList ;
0 commit comments