Skip to content

Commit 44b1b90

Browse files
committed
chore(docs): refactor marquee logo into own component
1 parent 90d3376 commit 44b1b90

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed
Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import { useEffect, useState } from "react"
2-
import { motion } from "framer-motion"
2+
import { Logo } from "./logo"
33
import manifest from "@/data/manifest.json"
44

5+
let render = 0
6+
57
const clamp = (min: number, num: number, max: number) =>
68
Math.min(Math.max(num, min), max)
79

8-
const logoSize = 96 // px
9-
10-
function randomFloat(min: number, max: number): number {
11-
const randomValue = Math.random() * (max - min) + min
12-
return Number(randomValue.toFixed(2))
13-
}
14-
1510
function changeScale() {
1611
if (typeof window !== "undefined") {
1712
const width = window.innerWidth
@@ -41,41 +36,19 @@ export const LogosMarquee = () => {
4136
return () => window.removeEventListener("resize", handleEvent)
4237
}, [])
4338

39+
render += 1
40+
console.log("render", render)
41+
4442
return (
4543
<div className="absolute top-0 left-0 w-full h-full opacity-30 pointer-events-none">
46-
{Object.entries(manifest.providersOAuth)
47-
.sort(() => Math.random() - 0.5)
48-
.filter((_, i) => i < logoCount!)
49-
.map(([id, name]) => (
50-
<motion.div
51-
initial={{ x: `${randomFloat(-10, 80)}vw` }}
52-
animate={{ x: "100vw" }}
53-
transition={{
54-
delay: randomFloat(-10, 2),
55-
duration: randomFloat(40, 70),
56-
ease: "linear",
57-
repeat: Infinity,
58-
repeatType: "loop",
59-
}}
60-
style={{
61-
width: (scale ?? 60) * randomFloat(0.8, 1.2),
62-
}}
63-
key={`company-${id}`}
64-
>
65-
<motion.img
66-
src={`/img/providers/${id}.svg`}
67-
className="opacity-40 animate-orbit grayscale dark:invert"
68-
style={{
69-
// @ts-expect-error
70-
"--duration": randomFloat(20, 30),
71-
"--radius": randomFloat(10, 20),
72-
}}
73-
width={logoSize}
74-
height={logoSize}
75-
alt={`${name} logo`}
76-
/>
77-
</motion.div>
78-
))}
44+
{Object.entries(manifest.providersOAuth)
45+
.sort(() => Math.random() - 0.5)
46+
.filter((_, i) => i < logoCount!)
47+
.map(([id, name]) => (
48+
<Logo providerId={id} name={name} scale={scale} key={id}
49+
/>
50+
)
51+
)}
7952
</div>
8053
)
8154
}

docs/components/LogosMarquee/logo.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { motion } from "framer-motion"
2+
3+
const logoSizePx = 96
4+
5+
function randomFloat(min: number, max: number): number {
6+
const randomValue = Math.random() * (max - min) + min
7+
return Number(randomValue.toFixed(2))
8+
}
9+
10+
export const Logo = ({ providerId: id, name, scale }) => {
11+
return (
12+
<motion.div
13+
initial={{ x: `${randomFloat(-40, 40)}vw` }}
14+
animate={{ x: "100vw" }}
15+
transition={{
16+
delay: randomFloat(-10, 10),
17+
duration: randomFloat(40, 80),
18+
ease: "linear",
19+
repeat: Infinity,
20+
repeatType: "loop",
21+
}}
22+
style={{
23+
width: (scale ?? 60) * randomFloat(0.8, 1.2),
24+
}}
25+
>
26+
<motion.img
27+
src={`/img/providers/${id}.svg`}
28+
className="opacity-40 animate-orbit grayscale dark:invert"
29+
style={{
30+
// @ts-expect-error
31+
"--duration": randomFloat(20, 30),
32+
"--radius": randomFloat(10, 20),
33+
}}
34+
width={logoSizePx}
35+
height={logoSizePx}
36+
alt={`${name} logo`}
37+
/>
38+
</motion.div>
39+
)
40+
}

0 commit comments

Comments
 (0)