Skip to content

Commit c895d39

Browse files
committed
feat: allow similar images with diff bg color, coexist with custom images
1 parent 1f042ea commit c895d39

4 files changed

Lines changed: 84 additions & 45 deletions

File tree

packages/common-config/src/components/HandbookSection/index.tsx

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import styles from "./styles.module.css";
22
import 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+
416
export interface Handbook {
517
title: string;
618
image: string;
719
href: string;
8-
bgImage: string;
20+
background: HandbookBackground;
921
}
1022

1123
export 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+
1772
export 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}>

packages/common-config/src/components/HandbookSection/styles.module.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ a.handbooksCard:hover {
138138
position: relative;
139139
}
140140

141+
.colorOverlay {
142+
position: absolute;
143+
top: 0;
144+
left: 0;
145+
width: 100%;
146+
height: 100%;
147+
mix-blend-mode: hue;
148+
z-index: 0;
149+
pointer-events: none;
150+
}
151+
141152
@media (max-width: 1100px) {
142153
.handbooksSection {
143154
padding-left: 1rem;
-196 KB
Binary file not shown.

sites/wonderland/src/pages/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,20 @@ const wonderlandHandbooks: Handbook[] = [
5353
{
5454
title: "Optimism handbook",
5555
image: "/img/optimism-handbook.svg",
56-
href: "/docs/handbook/overview",
57-
bgImage: "/common/img/red-card-bg.png",
56+
href: "/optimism",
57+
background: {
58+
bgType: "other",
59+
bgImage: "/common/img/red-card-bg.png",
60+
},
5861
},
5962
// {
6063
// title: "Aztec handbook",
6164
// image: "/img/aztec-handbook.svg",
62-
// href: "https://docs.aztec.network/aztec-handbook/overview",
63-
// bgImage: "/common/img/violet-card-bg.png",
65+
// href: "/aztec",
66+
// background: {
67+
// bgType: "wonderland",
68+
// color: "#625CBFD1",
69+
// },
6470
// },
6571
];
6672

0 commit comments

Comments
 (0)