@k8ordo/ui

Anchor

A text link. An external link gets a new-tab icon.

Import

ts
import { Anchor } from '@k8ordo/ui';

Usage

tsx
<Anchor href="https://example.com" openInNewTab>
  External Link
</Anchor>

Opening in a new tab

tsx
<Anchor href="#">
  Same Tab Link
</Anchor>
<Anchor href="https://example.com" openInNewTab>
  New Tab Link
</Anchor>

Replacing the element

To swap in a framework link such as Next.js’s Link, pass renderAnchor. Spread the props it receives onto the replacement element, after taking out kind. It says whether the link is internal or external, and it is not an attribute.

tsx
// Swap in the Next.js Link
import Link from 'next/link';

<Anchor
  href="/about"
  renderAnchor={({ children, ...rest }) => (
    <Link {...rest}>{children}</Link>
  )}
>
  About
</Anchor>

Props

children
Type: ReactNode
Default: -
href
Type: T
Default: -
openInNewTab?
Type: boolean
Default: false
renderAnchor?
Type: (props: RenderAnchorProps<T>) => ReactNode
Default: defaultRenderAnchor
PropTypeDefault
childrenReactNode-
hrefT-
openInNewTab?booleanfalse
renderAnchor?(props: RenderAnchorProps<T>) => ReactNodedefaultRenderAnchor

Inherited attributes (except the ones set internally): AnchorHTMLAttributes<HTMLAnchorElement>

k8ordo

React libraries that use Baseline features without holding back.