Link
Link is a text link whose chevron turns into an arrow on hover. With external it opens a new tab and shows an external link icon instead. Long labels truncate, like the invoice ID capped with max-w-48.
@dentil/linkOn this page
- Customer
- Ada Lovelace
- Invoice
- in_1QX4b2Lk9mT8pR7sVw3yZcDe
- Subscription
- Pro, monthly
- Receipt
- View on shadcn/ui(opens in a new tab)
components/demos/link-overview.tsx
'use client';
import NextLink from 'next/link';
import { Link } from '@/components/dentil/link/link';
export function LinkOverviewDemo() {
return (
<dl className="grid w-full max-w-sm grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-3 text-sm">
<dt className="text-muted-foreground">Customer</dt>
<dd className="min-w-0">
<Link href="/docs/link#usage" linkComponent={NextLink}>
Ada Lovelace
</Link>
</dd>
<dt className="text-muted-foreground">Invoice</dt>
<dd className="min-w-0">
<Link href="/docs/link#usage" linkComponent={NextLink} className="max-w-48" labelClassName="font-mono">
in_1QX4b2Lk9mT8pR7sVw3yZcDe
</Link>
</dd>
<dt className="text-muted-foreground">Subscription</dt>
<dd className="min-w-0">
<Link href="/docs/link#usage" linkComponent={NextLink} arrow={false}>
Pro, monthly
</Link>
</dd>
<dt className="text-muted-foreground">Receipt</dt>
<dd className="min-w-0">
<Link href="https://ui.shadcn.com" external>
View on shadcn/ui
</Link>
</dd>
</dl>
);
}Installation
pnpm dlx shadcn@latest add @dentil/linknpx shadcn@latest add @dentil/linkyarn dlx shadcn@latest add @dentil/linkbunx --bun shadcn@latest add @dentil/linkFiles land in components/dentil/link/. It uses no shadcn components, only lucide-react icons and your theme's primary colour.
Usage
The link inherits the surrounding font size. With no linkComponent it renders a plain <a>, which reloads the page on click.
import { Link } from '@/components/dentil/link/link';
<Link href="/customers/cus_123">View customer</Link>
<Link href="/invoices" arrow={false}>All invoices</Link>
<Link href="https://stripe.com/docs" external>Stripe docs</Link>Next.js
Pass next/link directly, or wrap it to set its own props.
import NextLink from 'next/link';
import { Link, type LinkComponentProps } from '@/components/dentil/link/link';
<Link href="/customers/cus_123" linkComponent={NextLink}>
View customer
</Link>
// To set next/link props such as prefetch, wrap it once:
const NoPrefetchLink = (props: LinkComponentProps) => <NextLink prefetch={false} {...props} />;React Router
Adapt its Link once, since it takes to instead of href.
import { Link as RouterLink } from 'react-router';
import { Link, type LinkComponentProps } from '@/components/dentil/link/link';
// React Router's Link takes `to`, so adapt it once:
const AppLink = ({ href, ...props }: LinkComponentProps) => <RouterLink to={href} {...props} />;
<Link href="/customers/cus_123" linkComponent={AppLink}>
View customer
</Link>API reference
Link
| Prop | Type | Default | Description |
|---|---|---|---|
| href | string | — | Where the link goes. Passed to linkComponent unchanged. |
| arrow | boolean | true | Shows a chevron after the label that turns into an arrow on hover and keyboard focus. Ignored when external is set. |
| external | boolean | false | Sets target="_blank" and rel="noopener noreferrer", and shows an external link icon with screen reader text saying it opens a new tab. Pass target or rel to override them. |
| linkComponent | ElementType<LinkComponentProps> | 'a' | Renders the anchor. Pass next/link directly, or adapt a router link that takes to. |
| labelClassName | string | — | Merged onto the label. The label truncates with an ellipsis when the link is narrower than it. |
| className | string | — | Merged onto the anchor. |
| …props | Omit<ComponentProps<'a'>, 'href'> | — | Other anchor props, such as onClick, title and aria-* attributes, go to linkComponent. |