Link

A link to another page or place.

Usage

Code
import { Link } from '@leverui/components';
Code
<Link href="...">Click here</Link>

Renders an <a>. For a link to another site, set target and rel. Write link text that makes sense on its own.

Examples

Variants

Use the variant prop to change the appearance of the Link component

Within Text

Use Link within a text to create a hyperlink

Visit the Lever UI website

External

Add an external link icon to the Link component

Guides

Routing Library

Pass the router's link to asChild and spread getProps() onto it to keep the Link styles and attributes.

Code
import { Link } from '@leverui/components';
import { A } from '@solidjs/router';

function Demo() {
  return (
    <Link
      asChild={(getProps) => (
        <A {...getProps()} href="/about">
          Click here
        </A>
      )}
    />
  );
}

Set aria-current="page" on the current page's link.

Code
<Link href="/home" aria-current="page" class="nav-link">
  Home
</Link>
Code
.nav-link[aria-current='page'] {
  color: var(--leverui-colors-blue-500);
  font-weight: bold;
}

Solid Router's A sets aria-current="page" on the link whose href matches the current route, so a routed link only needs the class.

Code
import { Link } from '@leverui/components';
import { A } from '@solidjs/router';
import type { JSX } from '@solidjs/web';

function NavLink(props: { href: string; children: JSX.Element }) {
  return (
    <Link
      class="nav-link"
      asChild={(getProps) => (
        <A {...getProps()} href={props.href}>
          {props.children}
        </A>
      )}
    />
  );
}

Props

PropDefaultTypeDescription
colorPalettegray'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'Color palette.
variantplain'underline' | 'plain'Link style.
asaNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the link's props.
unstyled—booleanTurn off the Lever UI styles.

LinkPropsProvider sets default props for the links inside it. The defaults can be reactive. A prop on a link wins.

The provider's children can be a function. It runs once for each link with no content of its own and returns that link's label. Each link keeps its own ref and asChild function.

For a clickable card, use LinkBox and LinkOverlay. See Link Overlay.

Customize with CSS

Import @leverui/components/styles.css once, before your own CSS. Classes: .leverui-link, .leverui-linkbox, and .leverui-linkbox__overlay. Style one link with class and style. CSS object props, general style props, and custom recipes are not part of the public API.

Other links in a LinkBox, and abbreviations with a title, sit above the overlay and stay clickable. Use one overlay per box.