From 30b9dc62c63eec23fb422a4d18656cc7614e599a Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Tue, 18 Feb 2025 20:59:48 -0500 Subject: [PATCH] refactor(link-box): use `asChild strategy for `LinkBox` component --- src/components/Contributors.tsx | 1 - src/components/ui/avatar.tsx | 35 +++++++++++++++------------------ src/components/ui/link-box.tsx | 12 ++++------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/components/Contributors.tsx b/src/components/Contributors.tsx index b8212a4dddb..c9796afcc82 100644 --- a/src/components/Contributors.tsx +++ b/src/components/Contributors.tsx @@ -34,7 +34,6 @@ const Contributors = () => { {contributorsList.map((contributor) => ( diff --git a/src/components/ui/avatar.tsx b/src/components/ui/avatar.tsx index 663200f5b0a..f8513a8b77d 100644 --- a/src/components/ui/avatar.tsx +++ b/src/components/ui/avatar.tsx @@ -151,25 +151,22 @@ const Avatar = React.forwardRef< const _ref = ref as React.ForwardedRef return ( - - - {label} - - - - {fallbackInitials} - + +
+ + {label} + + + + {fallbackInitials} + +
) } diff --git a/src/components/ui/link-box.tsx b/src/components/ui/link-box.tsx index 4a1c184e2a2..aa0ea9828b1 100644 --- a/src/components/ui/link-box.tsx +++ b/src/components/ui/link-box.tsx @@ -1,19 +1,15 @@ -import { - type BaseHTMLAttributes, - type ElementRef, - type ElementType, - forwardRef, -} from "react" +import { type BaseHTMLAttributes, type ElementRef, forwardRef } from "react" import { Slot } from "@radix-ui/react-slot" import { cn } from "@/lib/utils/cn" type LinkBoxElement = ElementRef<"div"> -type LinkBoxProps = BaseHTMLAttributes & { as?: ElementType } +type LinkBoxProps = BaseHTMLAttributes & { asChild?: boolean } const LinkBox = forwardRef( - ({ as: Comp = "div", className, ...props }, ref) => { + ({ asChild, className, ...props }, ref) => { + const Comp = asChild ? Slot : "div" return ( )