-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.tsx
More file actions
31 lines (27 loc) · 892 Bytes
/
link.tsx
File metadata and controls
31 lines (27 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { ArrowUpRightIcon } from 'lucide-react'
import * as React from 'react'
import type { z } from 'zod/v4'
import type { LinkProps, LinkVariantEnum } from '../types'
import { cn } from '../utils'
const linkVariantClasses: Record<z.infer<typeof LinkVariantEnum>, string> = {
ghost: '',
primary: 'text-blue-500 hover:underline underline-offset-2'
}
const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(
({ href, children, target, variant = 'primary', className }, ref) => {
return (
<a
ref={ref}
href={href}
target={target}
rel={target === '_blank' ? 'noopener noreferrer' : undefined}
className={cn('inline-flex items-center', variant && linkVariantClasses[variant], className)}
>
{children}
{target === '_blank' && variant !== 'ghost' && <ArrowUpRightIcon className="size-4" />}
</a>
)
}
)
Link.displayName = 'Link'
export { Link }