Dinachi

Link

A semantic anchor element with style variants and support for external links and framework router composition.

View Source

#Installation

npx @dinachi/cli@latest add link

#Usage

tsx
import { Link } from '@/components/ui/link'

#Examples

#Framework Router Composition

The render prop accepts a React element or a function, matching the Base UI render prop pattern. This produces a single element (one tab stop) with both link behavior and styled appearance.

#Element form

Pass a React element to replace the underlying <a> tag:

tsx
import { Link } from '@/components/ui/link'
import NextLink from 'next/link'
 
<Link render={<NextLink href="/about" />}>About</Link>
tsx
import { Link } from '@/components/ui/link'
import { Link as RouterLink } from 'react-router-dom'
 
<Link render={<RouterLink to="/about" />}>About</Link>

#Function form

Pass a function to receive the merged props and spread them yourself:

tsx
import { Link } from '@/components/ui/link'
import NextLink from 'next/link'
 
<Link render={(props) => <NextLink {...props} href="/about" />}>
  About
</Link>

Use linkVariants to apply link styles to other elements:

tsx
import { linkVariants } from '@/components/ui/link'
 
<a className={linkVariants({ variant: "muted" })}>Styled anchor</a>

#API Reference

PropTypeDefaultDescription
variant'default' | 'muted' | 'plain' | 'unstyled''default'The visual style variant of the link.
renderReactElement | (props, state) => ReactElementReplace the rendered <a> element with a different component (e.g., Next.js Link or React Router Link). Accepts an element or a render function.
externalbooleanfalseWhen true, adds target="_blank", rel="noopener noreferrer", and an external link icon.
hrefstringThe URL the link points to.
targetstring'_blank' when externalThe browsing context for the link. Defaults to "_blank" when external is true.
relstring'noopener noreferrer' when externalThe relationship of the linked URL. Defaults to "noopener noreferrer" when external is true.
classNamestringAdditional CSS classes to apply.
childrenReact.ReactNodeThe link content.