Skip to content

Commit 6530c66

Browse files
committed
Add graph decor around the website
1 parent ef645c0 commit 6530c66

File tree

7 files changed

+158
-5
lines changed

7 files changed

+158
-5
lines changed

Diff for: src/assets/images/brand/decor/git/graph-1.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { ForwardedRef, SVGProps, forwardRef } from "react";
44

55
const Graph1 = forwardRef(({ color = "#7C3AED", color1 = "#2563EB", ...props }: SVGProps<SVGSVGElement> & { color1?: string; }, ref: ForwardedRef<SVGSVGElement>) => (
66
<svg ref={ref} width="600" height="1900" viewBox="0 0 600 1900" fill="none" xmlns="http://www.w3.org/2000/svg" data-reset {...props}>
7-
<g clip-path="url(.clip0_115_309)">
7+
<g clipPath="url(.clip0_115_309)">
88
<path d="M479.208 500L433.246 454.038L200.973 686.311C185.406 679.35 168.155 675.48 150 675.48C80.9644 675.48 25 731.444 25 800.48C25 858.093 63.9768 906.603 117 921.078L117 1124.97L117 1125H117.033L430.395 1438.36L476.357 1392.4L182 1098.04V921.346C235.533 907.211 275 858.455 275 800.48C275 773.294 266.322 748.136 251.584 727.624L479.208 500Z" fill={color} />
99
<path d="M744.135 -127L790.097 -81.038L482 227.059V379.614C535.533 393.749 575 442.505 575 500.48C575 558.455 535.533 607.211 482 621.346V979.613C535.533 993.748 575 1042.5 575 1100.48C575 1158.46 535.533 1207.21 482 1221.35V1279.61C535.533 1293.75 575 1342.5 575 1400.48C575 1458.46 535.533 1507.21 482 1521.35V1672.94L790.097 1981.04L744.135 2027L417.133 1700H417V1521.08C363.977 1506.6 325 1458.1 325 1400.48C325 1342.86 363.977 1294.36 417 1279.88V1221.08C363.977 1206.6 325 1158.1 325 1100.48C325 1042.86 363.977 994.356 417 979.882V621.078C363.977 606.603 325 558.093 325 500.48C325 442.867 363.977 394.357 417 379.882V200H417.135L744.135 -127Z" fill={color1} />
1010
</g>

Diff for: src/assets/images/brand/decor/git/graph-2.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { SVGProps, forwardRef, ForwardedRef } from "react";
22

33
const Graph2 = forwardRef(({ color = "#DC2626", ...props }: SVGProps<SVGSVGElement>, ref: ForwardedRef<SVGSVGElement>) => (
44
<svg ref={ref} width="300" height="1600" viewBox="0 0 300 1600" fill="none" xmlns="http://www.w3.org/2000/svg" data-reset {...props}>
5-
<g clip-path="url(.clip0_115_276)">
5+
<g clipPath="url(.clip0_115_276)">
66
<path d="M444.135 -127L490.097 -81.038L182 227.059V379.614C235.533 393.749 275 442.505 275 500.48C275 558.455 235.533 607.211 182 621.346V679.614C235.533 693.749 275 742.505 275 800.48C275 858.455 235.533 907.211 182 921.346V1372.94L490.097 1681.04L444.135 1727L117.133 1400H117V921.078C63.9768 906.602 25 858.093 25 800.48C25 742.867 63.9768 694.358 117 679.882V621.078C63.9768 606.603 25 558.093 25 500.48C25 442.867 63.9768 394.357 117 379.882V200H117.135L444.135 -127Z" fill={color} />
77
</g>
88
<defs>

Diff for: src/assets/images/brand/decor/git/graph-3.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { SVGProps, forwardRef, ForwardedRef } from "react";
22

33
const Graph3 = forwardRef(({ color = "#F59E0B", ...props }: SVGProps<SVGSVGElement>, ref: ForwardedRef<SVGSVGElement>) => (
44
<svg ref={ref} width="300" height="2500" viewBox="0 0 300 2500" fill="none" xmlns="http://www.w3.org/2000/svg" data-reset {...props}>
5-
<g clip-path="url(.clip0_115_290)">
5+
<g clipPath="url(.clip0_115_290)">
66
<path d="M490.097 -81.038L444.135 -127L117.135 200H117V379.882C63.9768 394.357 25 442.867 25 500.48C25 558.093 63.9768 606.603 117 621.078V679.882C63.9768 694.358 25 742.867 25 800.48C25 858.093 63.9768 906.602 117 921.078V1279.88C63.9768 1294.36 25 1342.86 25 1400.48C25 1458.1 63.9768 1506.6 117 1521.08V1579.88C63.9768 1594.36 25 1642.86 25 1700.48C25 1758.1 63.9768 1806.6 117 1821.08V2300H117.133L444.135 2627L490.097 2581.04L182 2272.94V1821.35C235.533 1807.21 275 1758.46 275 1700.48C275 1642.5 235.533 1593.75 182 1579.61V1521.35C235.533 1507.21 275 1458.46 275 1400.48C275 1342.5 235.533 1293.75 182 1279.61V921.346C235.533 907.211 275 858.455 275 800.48C275 742.505 235.533 693.749 182 679.614V621.346C235.533 607.211 275 558.455 275 500.48C275 442.505 235.533 393.749 182 379.614V227.059L490.097 -81.038Z" fill={color} />
77
</g>
88
<defs>

Diff for: src/assets/images/brand/decor/git/graph-4.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { SVGProps, forwardRef, ForwardedRef } from "react";
22

33
const Graph4 = forwardRef(({ color = "#DC2626", color1 = "#A3E635", ...props }: SVGProps<SVGSVGElement> & { color1?: string; }, ref: ForwardedRef<SVGSVGElement>) => (
44
<svg ref={ref} width="300" height="2800" viewBox="0 0 300 2800" fill="none" xmlns="http://www.w3.org/2000/svg" data-reset {...props}>
5-
<g clip-path="url(.clip0_115_255)">
5+
<g clipPath="url(.clip0_115_255)">
66
<path d="M490.097 -81.038L444.135 -127L117.135 200H117V379.882C63.9768 394.357 25 442.867 25 500.48C25 558.093 63.9768 606.603 117 621.078V679.882C63.9768 694.358 25 742.867 25 800.48C25 858.093 63.9768 906.603 117 921.078V1100H117.133L444.135 1427L490.097 1381.04L182 1072.94V921.346C235.533 907.211 275 858.455 275 800.48C275 742.505 235.533 693.749 182 679.614V621.346C235.533 607.211 275 558.455 275 500.48C275 442.505 235.533 393.749 182 379.614V227.059L490.097 -81.038Z" fill={color} />
77
<path d="M490.097 1418.96L444.135 1373L117.133 1700H117V1879.88C63.9768 1894.36 25 1942.86 25 2000.48C25 2058.1 63.9768 2106.6 117 2121.08V2179.88C63.9768 2194.36 25 2242.86 25 2300.48C25 2358.1 63.9768 2406.6 117 2421.08V2600H117.133L444.135 2927L490.097 2881.04L182 2572.94V2421.35C235.533 2407.21 275 2358.46 275 2300.48C275 2242.5 235.533 2193.75 182 2179.61V2121.35C235.533 2107.21 275 2058.46 275 2000.48C275 1942.5 235.533 1893.75 182 1879.61V1727.06L490.097 1418.96Z" fill={color1} />
88
</g>

Diff for: src/components/layout/GraphDecor.tsx

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import Graph1 from "@/assets/images/brand/decor/git/graph-1";
2+
import Graph2 from "@/assets/images/brand/decor/git/graph-2";
3+
import Graph3 from "@/assets/images/brand/decor/git/graph-3";
4+
import Graph4 from "@/assets/images/brand/decor/git/graph-4";
5+
import useSSGSafe from "@/hooks/useSSGSafe";
6+
7+
import React, { useMemo, useRef } from "react";
8+
9+
export interface GraphDecorProps {
10+
11+
}
12+
13+
const colors = [
14+
"#DC2626",
15+
"#2563EB",
16+
"#7C3AED",
17+
"#A3E635",
18+
"#F59E0B"
19+
];
20+
21+
const makeColorBrush = () => {
22+
const notChosenColors = [...colors];
23+
24+
return () => {
25+
const colorPool = notChosenColors.length === 0 ? colors : notChosenColors;
26+
const chosenIndex = Math.floor(Math.random() * colorPool.length);
27+
const color = colorPool[chosenIndex];
28+
29+
if (notChosenColors.length !== 0) {
30+
notChosenColors.splice(chosenIndex, 1);
31+
}
32+
33+
return color;
34+
};
35+
};
36+
37+
const getSide = (perviousSides: boolean[]) => {
38+
if (perviousSides.length === 0) {
39+
const side = Math.random() > 0.5;
40+
perviousSides.unshift(side);
41+
return side;
42+
};
43+
44+
const samePreviousSides = perviousSides.every((value, i, arr) => i === 0 || value === arr[i - 1]);
45+
const side = samePreviousSides ? !perviousSides.at(0)! : Math.random() > 0.5;
46+
47+
perviousSides.unshift(side);
48+
perviousSides.length > 2 && perviousSides.pop();
49+
50+
return side;
51+
};
52+
53+
const decors = [
54+
{
55+
name: "1",
56+
widthMultiplier: 2,
57+
aspect: 1900 / 600,
58+
component: ({ makeColor, ...props }) => (
59+
<Graph1
60+
{...props}
61+
color={makeColor()}
62+
color1={makeColor()}
63+
/>
64+
)
65+
},
66+
{
67+
name: "2",
68+
widthMultiplier: 1,
69+
aspect: 1600 / 300,
70+
component: ({ makeColor, ...props }) => (
71+
<Graph2
72+
{...props}
73+
color={makeColor()}
74+
/>
75+
)
76+
},
77+
{
78+
name: "3",
79+
widthMultiplier: 1,
80+
aspect: 2500 / 300,
81+
component: ({ makeColor, ...props }) => (
82+
<Graph3
83+
{...props}
84+
color={makeColor()}
85+
/>
86+
)
87+
},
88+
{
89+
name: "4",
90+
widthMultiplier: 1,
91+
aspect: 2800 / 300,
92+
component: ({ makeColor, ...props }) => (
93+
<Graph4
94+
{...props}
95+
color={makeColor()}
96+
color1={makeColor()}
97+
/>
98+
)
99+
}
100+
] as {
101+
name: string;
102+
widthMultiplier: number;
103+
aspect: number;
104+
component: React.ComponentType<Omit<React.ComponentProps<"svg">, "ref"> & { makeColor: () => string; }>;
105+
}[];
106+
107+
const AMOUNT = 40;
108+
109+
const GraphDecor = ({ }: GraphDecorProps) => {
110+
const isSafe = useSSGSafe();
111+
112+
const renderedGraphs = useMemo(() => {
113+
if (!isSafe) return;
114+
115+
const controls = {
116+
currentLength: 60, // rem
117+
perviousSides: [] as boolean[] // last 2 sides
118+
};
119+
120+
return Array(AMOUNT).fill(true).map((_, i) => {
121+
const decor = decors[Math.floor(Math.random() * decors.length)];
122+
const side = getSide(controls.perviousSides);
123+
124+
const width = 10 * decor.widthMultiplier; // rem
125+
const height = width * decor.aspect;
126+
const padding = Math.random() * 40 + 20;
127+
const style = { "--width-mulitplier": decor.widthMultiplier, "--length": `${controls.currentLength}rem` } as React.CSSProperties;
128+
129+
controls.currentLength += (height + padding) * 1.5;
130+
131+
return (
132+
<decor.component
133+
key={i}
134+
makeColor={makeColorBrush()}
135+
style={style}
136+
className={`absolute opacity-10 w-[calc(var(--width)_*_var(--width-mulitplier))] top-[var(--length)] [--width:10rem] md:[--width:6rem] motion-safe:transition-all ${side ? "left-0 -scale-100" : "right-0"}`}
137+
/>
138+
);
139+
});
140+
}, [isSafe]);
141+
142+
return (
143+
<div className="absolute inset-0 overflow-hidden">
144+
{isSafe && <>
145+
{renderedGraphs}
146+
</>}
147+
</div>
148+
);
149+
};
150+
151+
export default React.memo(GraphDecor);

Diff for: src/pages/_app.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import BannerImage from "@/assets/images/brand/rocket-with-graph.svg";
1414

1515
import { makeOgMeta } from "@/lib/meta/opengraph";
1616
import makeSitemapMeta from "@/lib/meta/sitemap";
17+
import GraphDecor from "@/components/layout/GraphDecor";
1718

1819

1920
const pageTransition = {
@@ -79,6 +80,7 @@ export default function App({ Component, pageProps, router }: AppProps) {
7980
<KeywordsMeta />
8081
</Head>
8182
<GoogleAnalytics />
83+
<GraphDecor />
8284
<div className="flex flex-col font-sans">
8385
<Header />
8486
<AnimatePresence mode="wait" onExitComplete={onAnimFinished}>

Diff for: src/styles/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ body,
1010
}
1111

1212
html {
13-
@apply min-h-full bg-cr-fill text-cr-fill-contrast;
13+
@apply min-h-full bg-cr-fill text-cr-fill-contrast relative;
1414
}
1515

1616
svg[data-reset] {

0 commit comments

Comments
 (0)