11import styles from "./styles.module.css" ;
22import React , { ReactNode } from "react" ;
33
4+ type WonderlandBgTypeHandbook = {
5+ bgType : "wonderland" ;
6+ color : string ;
7+ } ;
8+
9+ type OtherBgTypeHandbook = {
10+ bgType : "other" ;
11+ bgImage : string ;
12+ } ;
13+
14+ type HandbookBackground = WonderlandBgTypeHandbook | OtherBgTypeHandbook ;
15+
416export interface Handbook {
517 title : string ;
618 image : string ;
719 href : string ;
8- bgImage : string ;
20+ background : HandbookBackground ;
921}
1022
1123export interface HandbookSectionProps {
@@ -14,6 +26,49 @@ export interface HandbookSectionProps {
1426 description : string ;
1527}
1628
29+ interface HandbookCardProps {
30+ handbook : Handbook ;
31+ isDefault ?: boolean ;
32+ }
33+
34+ function HandbookCard ( { handbook, isDefault = false } : HandbookCardProps ) {
35+ if ( isDefault ) {
36+ return (
37+ < div className = { styles . handbooksCardDefault } >
38+ < img
39+ src = "/img/default-handbook.svg"
40+ alt = ""
41+ className = { styles . handbooksCardIcon }
42+ />
43+ </ div >
44+ ) ;
45+ }
46+
47+ let cardStyle : React . CSSProperties = { } ;
48+ if ( handbook . background . bgType === "wonderland" ) {
49+ cardStyle . backgroundImage = "url(/common/img/red-card-bg.png)" ;
50+ } else if ( handbook . background . bgType === "other" ) {
51+ cardStyle . backgroundImage = `url(${ handbook . background . bgImage } )` ;
52+ }
53+
54+ return (
55+ < a
56+ href = { handbook . href }
57+ style = { cardStyle }
58+ target = "_blank"
59+ className = { styles . handbooksCard }
60+ >
61+ { handbook . background . bgType === "wonderland" && (
62+ < div
63+ className = { styles . colorOverlay }
64+ style = { { backgroundColor : handbook . background . color } }
65+ > </ div >
66+ ) }
67+ < img src = { handbook . image } alt = "" className = { styles . handbooksCardIcon } />
68+ </ a >
69+ ) ;
70+ }
71+
1772export default function HandbookSection ( {
1873 handbooks,
1974 title,
@@ -23,7 +78,7 @@ export default function HandbookSection({
2378 < section className = { styles . handbooksSection } >
2479 < img
2580 src = "/common/img/star-icon.svg"
26- alt = "Star illustration "
81+ alt = ""
2782 className = { styles . starMobile }
2883 />
2984 < div className = { styles . handbooksSeparator } >
@@ -35,48 +90,15 @@ export default function HandbookSection({
3590 < div className = { styles . handbooksCards } >
3691 { handbooks . length === 1 ? (
3792 < >
38- { /* First handbook card */ }
39- < a
40- key = { handbooks [ 0 ] . title }
41- href = { handbooks [ 0 ] . href }
42- style = { { backgroundImage : `url(${ handbooks [ 0 ] . bgImage } )` } }
43- target = "_blank"
44- className = { styles . handbooksCard }
45- >
46- < img
47- src = { handbooks [ 0 ] . image }
48- alt = ""
49- className = { styles . handbooksCardIcon }
50- />
51- </ a >
52-
93+ { /* First handbook card */ }
94+ < HandbookCard handbook = { handbooks [ 0 ] } />
5395 { /* Default handbook card (not a link) */ }
54- < div className = { styles . handbooksCardDefault } >
55- < img
56- src = "/img/default-handbook.svg"
57- alt = ""
58- className = { styles . handbooksCardIcon }
59- />
60- </ div >
96+ < HandbookCard handbook = { handbooks [ 0 ] } isDefault />
6197 </ >
6298 ) : (
63- handbooks . map ( ( handbook ) => {
64- return (
65- < a
66- key = { handbook . title }
67- href = { handbook . href }
68- style = { { backgroundImage : `url(${ handbook . bgImage } )` } }
69- target = "_blank"
70- className = { styles . handbooksCard }
71- >
72- < img
73- src = { handbook . image }
74- alt = ""
75- className = { styles . handbooksCardIcon }
76- />
77- </ a >
78- ) ;
79- } )
99+ handbooks . map ( ( handbook ) => (
100+ < HandbookCard key = { handbook . title } handbook = { handbook } />
101+ ) )
80102 ) }
81103 </ div >
82104 < div className = { styles . handbooksSeparator } >
0 commit comments