TextLink
A standalone text link with a clear navigation affordance.
Default
Show code
Example.astroAstro
---
import TextLink from '@dhekode/ui/primitives/TextLink.tsx';
---
<TextLink href="/decoderen/button/">View Button</TextLink>Arrow
Show code
Example.astroAstro
---
import TextLink from '@dhekode/ui/primitives/TextLink.tsx';
---
<TextLink href="/decoderen/button/" arrow>View Button</TextLink>New tab
Show code
Example.astroAstro
---
import TextLink from '@dhekode/ui/primitives/TextLink.tsx';
---
<TextLink href="https://docs.astro.build/" external>Astro documentation</TextLink>Dark surface
Show code
Example.astroAstro
---
import TextLink from '@dhekode/ui/primitives/TextLink.tsx';
---
<div data-surface="brand"><TextLink href="/decoderen/button/" arrow>View Button</TextLink></div>API reference
hrefType:
stringDefault:
requiredNavigation destination.
arrowType:
booleanDefault:
falseAdds the existing forward chevron.
externalType:
booleanDefault:
falseOpens a new tab with a visible-to-assistive-technology notice and safe rel attributes.
classNameType:
string | undefinedDefault:
unsetAdds classes to the React component root, after its own utilities. React components take className, not class.
Slots: Default: descriptive link text.
Use for standalone text actions; ordinary prose can use a native anchor. The control retains the shared touch target. Other anchor attributes pass through, so a router link can wrap it.
Original component source
packages/ui/src/primitives/TextLink.tsxAstro
import type { ComponentProps, ReactNode } from 'react';
import Icon from '@dhekode/icons/Icon.tsx';
import { classNames } from '@dhekode/utils/class-names';
interface TextLinkOptions {
href: string;
/** Appends a chevron that opens into an arrow on hover. Use for forward navigation only. */
arrow?: boolean | undefined;
/** Opens in a new tab, safely, and says so to assistive technology. */
external?: boolean | undefined;
className?: string | undefined;
children: ReactNode;
}
/** `style` is left out: the hash-based CSP blocks inline styles (AGENTS.md section 5). */
export type TextLinkProps = TextLinkOptions &
Omit<ComponentProps<'a'>, keyof TextLinkOptions | 'style'>;
/**
* An inline or standalone text link with a 44px touch target. Other attributes pass through to
* the anchor, so a router can wrap it (its click handler, ref and active state).
*/
export default function TextLink({
href,
arrow = false,
external = false,
className,
children,
...native
}: TextLinkProps) {
// A new tab, asked for either way, always gets the safe rel and the spoken note.
const newTab = external || native.target === '_blank';
return (
<a
{...native}
className={classNames(
'dk-text-link inline-flex min-h-(--dk-layout-touch-target) w-fit max-w-full items-center gap-xs font-medium text-surface-accent no-underline transition-colors duration-(--dk-motion-duration-quick) hover:text-surface-link-hover',
arrow && 'dk-learn',
className,
)}
href={href}
target={newTab ? '_blank' : native.target}
rel={newTab ? 'noopener noreferrer' : native.rel}
>
<span className="min-w-0 underline decoration-(length:--dk-border-width-hairline) underline-offset-(--dk-layout-underline-offset) wrap-anywhere">
{children}
{newTab && <span className="sr-only"> (opens in a new tab)</span>}
</span>
{arrow && <Icon name="chevron-learn" className="dk-learn__chevron" />}
</a>
);
}Best practices
- Use descriptive destinations and announce new-tab behavior.