-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"use client"; | ||
|
||
import discoverableSvg from "@/assets/guild-badges/discoverable.svg"; | ||
import partnerSvg from "@/assets/guild-badges/partner.svg"; | ||
import verifiedSvg from "@/assets/guild-badges/verified.svg"; | ||
import { ImageWithFallback } from "@/components/ImageWithFallback.tsx"; | ||
import { type Snowflake, guildIcon } from "@/utils/discord-cdn.ts"; | ||
import { formatToNearestOrderOfMagnitude } from "@/utils/format-to-nearest-order-of-magnitude.ts"; | ||
import AutoScroll from "embla-carousel-auto-scroll"; | ||
import useEmblaCarousel from "embla-carousel-react"; | ||
import Image from "next/image"; | ||
|
||
export function FeaturedGuilds({ guilds, startDelay = 0 }: FeaturedGuildsProps) { | ||
const [emblaRef] = useEmblaCarousel({ loop: true, dragFree: true }, [AutoScroll({ speed: 0.75, startDelay })]); | ||
|
||
return ( | ||
<div className="overflow-hidden relative" ref={emblaRef}> | ||
<div className="flex"> | ||
{guilds.map((guild) => ( | ||
<div | ||
className="basis-full sm:basis-1/2 lg:basis-1/3 xl:basis-1/4 shrink-0 min-w-0 mr-4" | ||
key={`featured-${guild.id}`} | ||
> | ||
<FeaturedGuild key={guild.id} {...guild} /> | ||
</div> | ||
))} | ||
</div> | ||
|
||
<div className="absolute left-0 inset-y-0 right-[90%] bg-gradient-to-l from-transparent to-background" /> | ||
<div className="absolute right-0 inset-y-0 left-[90%] bg-gradient-to-r from-transparent to-background" /> | ||
</div> | ||
); | ||
} | ||
|
||
function FeaturedGuild({ id, icon, name, memberCount, partner, verified }: FeaturedGuild) { | ||
const iconSrc = verified ? verifiedSvg : partner ? partnerSvg : discoverableSvg; | ||
const alt = verified ? "Verified guild badge" : partner ? "Partner guild badge" : "Discoverable guild badge"; | ||
|
||
return ( | ||
<div className="flex items-center gap-4 md:gap-6 bg-darker px-3 py-2 border border-white/25 rounded-lg select-none"> | ||
<ImageWithFallback | ||
alt={`${name}'s icon`} | ||
className="rounded-full size-14 md:size-16 no-drag" | ||
height={64} | ||
src={guildIcon(id, icon, { format: "webp", size: 64 })} | ||
priority | ||
width={64} | ||
/> | ||
|
||
<div className="flex flex-col"> | ||
<p className="flex items-center gap-2 text-xl md:text-2xl font-bold text-ellipsis" title={name}> | ||
<Image src={iconSrc} alt={alt} width={20} height={20} className="size-5 rounded-full no-drag" /> | ||
{name} | ||
</p> | ||
<p className="text-md md:text-lg text-white/50"> | ||
{formatToNearestOrderOfMagnitude(memberCount).toLocaleString("en")} members | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
interface FeaturedGuildsProps { | ||
readonly guilds: readonly FeaturedGuild[]; | ||
readonly startDelay?: number; | ||
} | ||
|
||
export interface FeaturedGuild { | ||
id: Snowflake; | ||
name: string; | ||
icon: string | null; | ||
memberCount: number; | ||
verified: boolean; | ||
partner: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters