A link allows a user to navigate to a page inside or outside the application.
Here's the <Link /> component in action.
| ID | FIRST NAME | LAST NAME | PHONE | |
|---|---|---|---|---|
| 0 | Rodrigo | Jordeson | rjordesonrr@nbcnews.com | 596-412-7883 |
| 1 | Jessamyn | Espinazo | jespinazo0@chicagotribune.com | 162-166-0977 |
| 2 | Isac | Tooher | itooher1@psu.edu | 655-567-3619 |
| 3 | Tabbatha | Proschke | tproschke2@weibo.com | 327-612-4850 |
| 4 | Ninetta | Mabb | nmabb3@canalblog.com | 971-296-0911 |
| 5 | Danni | Wallentin | dwallentin4@comcast.net | 983-297-0506 |
| 6 | Neely | Purkins | npurkins5@mediafire.com | 379-119-4237 |
| 7 | Jessika | Kinkaid | jkinkaid6@eventbrite.com | 771-888-6284 |
| 8 | Julianna | Swindall | jswindall7@aol.com | 252-614-0486 |
| 9 | Corrinne | Geeve | cgeeve8@wisc.edu | 450-872-8646 |
import { NavLink, type NavLinkProps } from '@remix-run/react'import { type ElementRef, forwardRef, useRef, type MutableRefObject, type RefCallback } from 'react'import { useLink, mergeProps, type AriaLinkOptions, useHover, useFocusRing } from 'react-aria'import { cn } from '#app/utils/tailwind-merge.ts'
export interface LinkProps extends AriaLinkOptions, Omit<NavLinkProps, 'download' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'to'> { to?: NavLinkProps['to'] variant?: 'default' | 'typographical' | 'unstyled' | 'button' | 'ghost' buttonVariant?: 'primary' | 'secondary' | 'danger' | 'ghost' size?: 'sm' | 'md' | 'lg'}
const Link = forwardRef<ElementRef<typeof NavLink>, LinkProps>(({ to = '/', variant = 'default', buttonVariant = 'primary', size, children, className, ...props }, ref) => { const privateRef = useRef(null) const { linkProps, isPressed } = useLink(props, privateRef) const { hoverProps, isHovered } = useHover(props) const { focusProps, isFocused, isFocusVisible } = useFocusRing() const mergedProps = mergeProps(props, linkProps, hoverProps, focusProps) return ( <NavLink ref={mergeRefs(privateRef, ref)} to={to} className={cn('link', variant, variant === 'button' ? buttonVariant : null, size, className)} {...mergedProps} data-focused={isFocused || undefined} data-hovered={isHovered || undefined} data-pressed={isPressed || undefined} data-focus-visible={isFocusVisible || undefined} data-current={!!props['aria-current'] || undefined} data-disabled={props.isDisabled || undefined} > {children} </NavLink> )})Link.displayName = 'Link'
type MutableRefList<T> = Array<RefCallback<T> | MutableRefObject<T> | undefined | null>
export function mergeRefs<T>(...refs: MutableRefList<T>): RefCallback<T> { return (val: T) => { setRef(val, ...refs) }}export function setRef<T>(val: T, ...refs: MutableRefList<T>): void { refs.forEach(ref => { if (typeof ref === 'function') { ref(val) } else if (ref != null) { ref.current = val } })}
export { Link }