index.tsx58 lines · main
| 1 | 'use client' |
| 2 | |
| 3 | import { ChevronRight } from 'lucide-react' |
| 4 | import Link from 'next/link' |
| 5 | import { cn } from 'ui' |
| 6 | |
| 7 | interface Props { |
| 8 | label: string |
| 9 | url?: string |
| 10 | className?: string |
| 11 | counter?: number |
| 12 | hasChevron?: boolean |
| 13 | chevronAnimation?: 'translate' | 'fadeIn' |
| 14 | target?: '_blank' | '_self' |
| 15 | } |
| 16 | |
| 17 | export function TextLink({ |
| 18 | url = '', |
| 19 | label, |
| 20 | className, |
| 21 | counter, |
| 22 | hasChevron = true, |
| 23 | chevronAnimation = 'translate', |
| 24 | target = '_self', |
| 25 | ...props |
| 26 | }: Props) { |
| 27 | return ( |
| 28 | <Link |
| 29 | href={url} |
| 30 | className={cn( |
| 31 | 'group/text-link text-foreground-light hover:text-foreground mt-3 block cursor-pointer text-sm focus-visible:ring-2 focus-visible:outline-hidden focus-visible:rounded-xs focus-visible:ring-foreground-lighter focus-visible:text-foreground', |
| 32 | className |
| 33 | )} |
| 34 | target={target} |
| 35 | {...props} |
| 36 | > |
| 37 | <div className="group flex items-center gap-1"> |
| 38 | <span className="sr-only">{`${label} about ${url}`}</span> |
| 39 | <span>{label}</span> |
| 40 | {counter && ( |
| 41 | <span className="text-xs flex items-center justify-center text-foreground-lighter group-hover/text-link:text-foreground"> |
| 42 | ({counter}) |
| 43 | </span> |
| 44 | )} |
| 45 | {hasChevron && ( |
| 46 | <div |
| 47 | className={cn( |
| 48 | 'transition-all group-hover:ml-0.5', |
| 49 | chevronAnimation === 'fadeIn' && 'opacity-0 group-hover:opacity-100' |
| 50 | )} |
| 51 | > |
| 52 | <ChevronRight size={14} strokeWidth={2} /> |
| 53 | </div> |
| 54 | )} |
| 55 | </div> |
| 56 | </Link> |
| 57 | ) |
| 58 | } |