Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadcn Migrate: Leaderboard.tsx #14807

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 16 additions & 63 deletions src/components/Leaderboard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { useTranslation } from "next-i18next"
import {
Box,
Flex,
LinkBox,
LinkOverlay,
List,
ListItem,
useColorModeValue,
VisuallyHidden,
} from "@chakra-ui/react"
import { VisuallyHidden } from "@radix-ui/react-visually-hidden"

import Emoji from "@/components/Emoji"
import { BaseLink } from "@/components/Link"

import { GITHUB_URL } from "@/lib/constants"

import { Avatar } from "./ui/avatar"
import { Flex } from "./ui/flex"
import { LinkBox } from "./ui/link-box"
import { LinkOverlay } from "./ui/link-box"
import { List, ListItem } from "./ui/list"

import { useRtlFlip } from "@/hooks/useRtlFlip"

Expand All @@ -31,29 +25,12 @@ type LeaderboardProps = {
}

const Leaderboard = ({ content, limit = 100 }: LeaderboardProps) => {
const { flipForRtl } = useRtlFlip()
const colorModeStyles = useColorModeValue(
{
listBoxShadow: "tableBox.light",
linkBoxShadow: "tableItemBox.light",
scoreColor: "blackAlpha.700",
},
{
listBoxShadow: "tableBox.dark",
linkBoxShadow: "tableItemBox.dark",
scoreColor: "whiteAlpha.600",
}
)

const { twFlipForRtl } = useRtlFlip()
const { t } = useTranslation("page-bug-bounty")

return (
<List
bgColor="background.base"
boxShadow={colorModeStyles.listBoxShadow}
w="100%"
mb={8}
ms={0}
className="mb-8 ms-0 w-full list-none bg-background shadow-table-box"
aria-label={t("page-upgrades-bug-bounty-leaderboard-list")}
>
{content
Expand All @@ -73,26 +50,12 @@ const Leaderboard = ({ content, limit = 100 }: LeaderboardProps) => {
}

return (
<ListItem key={username} mb={0}>
<ListItem className="mb-0" key={username}>
<LinkBox
className="mb-1 flex w-full items-center justify-between p-4 shadow-table-item-box hover:rounded-lg hover:bg-background-highlight hover:no-underline hover:shadow-primary"
key={idx}
display="flex"
justifyContent="space-between"
alignItems="center"
boxShadow={colorModeStyles.linkBoxShadow}
mb={0.25}
p={4}
w="100%"
_hover={{
textDecor: "none",
borderRadius: 0.5,
boxShadow: "0 0 1px var(--eth-colors-primary-base)",
background: "tableBackgroundHover",
}}
>
<Box me={4} opacity="0.4">
{idx + 1}
</Box>
<div className="me-4 opacity-40">{idx + 1}</div>
<Avatar
src={avatarImg}
name={avatarAlt}
Expand All @@ -101,13 +64,10 @@ const Leaderboard = ({ content, limit = 100 }: LeaderboardProps) => {
// `size-10` is not part of a "size" variant
className="me-4 size-10"
/>
<Flex flex="1 1 75%" direction="column" me={8}>
<Flex className="me-8 flex-1 basis-3/4 flex-col">
<LinkOverlay
as={BaseLink}
className="text-body no-underline"
href={hasGitHub ? `${GITHUB_URL}${username}` : "#"}
textDecor="none"
color="text"
hideArrow
>
<VisuallyHidden>{`In place number ${
idx + 1
Expand All @@ -118,20 +78,13 @@ const Leaderboard = ({ content, limit = 100 }: LeaderboardProps) => {
)}
</LinkOverlay>

<Box fontSize="sm" color={colorModeStyles.scoreColor}>
<div className="text-sm text-body-medium">
{score} {t("page-upgrades-bug-bounty-leaderboard-points")}
</Box>
</div>
</Flex>
{emoji && <Emoji className="me-8 text-2xl" text={emoji} />}
<Box
as="span"
_after={{
content: '"↗"',
ms: 0.5,
me: 1.5,
transform: flipForRtl,
display: "inline-block",
}}
<span
className={`after:me-1.5 after:ms-0.5 after:content-['↗'] after:${twFlipForRtl} after:inline-block`}
/>
</LinkBox>
</ListItem>
Expand Down