Breadcrumb

A trail of links that shows where the current page sits in the site.

Usage

Code
import { Breadcrumb } from '@leverui/components';
Code
<Breadcrumb.Root>
  <Breadcrumb.List>
    <Breadcrumb.Item>
      <Breadcrumb.Link />
    </Breadcrumb.Item>
    <Breadcrumb.Separator />
  </Breadcrumb.List>
</Breadcrumb.Root>

For one component that sets up the parts, see the snippet below.

Examples

Sizes

Use the size prop to change the size of the breadcrumb component

Variants

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

With Separator

Use the Breadcrumb.Separator component to add a custom separator

Icon

Add a custom icon to the breadcrumb by rendering it within Breadcrumb.Link

Menu

Wrap the Breadcrumb.Link inside the MenuTrigger to ensure it works correctly within the menu component

Ellipsis

Render the Breadcrumb.Ellipsis component to show an ellipsis after a breadcrumb item

Routing Library

Pass a render function to asChild and spread getProps() onto the router's link to keep the breadcrumb styles.

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

function Example() {
  return (
    <Breadcrumb.Root>
      <Breadcrumb.List>
        <Breadcrumb.Item>
          <Breadcrumb.Link
            asChild={(getProps) => (
              <A {...getProps()} href="/docs">
                Docs
              </A>
            )}
          />
        </Breadcrumb.Item>
        <Breadcrumb.Separator />
      </Breadcrumb.List>
    </Breadcrumb.Root>
  );
}

Closed Component

One component that takes a list of items instead of parts.

Code
import { For, Show, omit } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Breadcrumb, type BreadcrumbRootProps } from '@leverui/components';

export type ClosedBreadcrumbProps = BreadcrumbRootProps & {
  separator?: JSX.Element;
  separatorGap?: string | undefined;
  items: readonly { title: JSX.Element; url?: string }[];
};

export function ClosedBreadcrumb(props: ClosedBreadcrumbProps) {
  const root = omit(props, 'separator', 'separatorGap', 'items');

  return (
    <Breadcrumb.Root {...root}>
      <Breadcrumb.List style={{ gap: props.separatorGap }}>
        <For each={props.items}>
          {(item, index) => (
            <Show
              when={index() < props.items.length - 1}
              fallback={
                <Breadcrumb.Item>
                  <Breadcrumb.CurrentLink>{item.title}</Breadcrumb.CurrentLink>
                </Breadcrumb.Item>
              }
            >
              <Breadcrumb.Item>
                <Breadcrumb.Link href={item.url}>{item.title}</Breadcrumb.Link>
              </Breadcrumb.Item>
              <Breadcrumb.Separator>{props.separator}</Breadcrumb.Separator>
            </Show>
          )}
        </For>
      </Breadcrumb.List>
    </Breadcrumb.Root>
  );
}

Props

Root

PropDefaultTypeDescription
colorPalettegraystringColor palette. Built-in or your own.
variantplain'underline' | 'plain'Breadcrumb style. Responsive.
sizemd'sm' | 'md' | 'lg'Breadcrumb size. Responsive.
asnavNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the breadcrumb's props.
unstyledfalsebooleanTurn off the Lever UI styles.

Use one CurrentLink for the current page. It adds aria-current="page". If the page has more than one navigation landmark, give the root its own label. Separator is decorative, so keep it out of the link names.

Customize with CSS

Classes: .leverui-breadcrumb__root, __list, __item, __link, __currentLink, __separator, __ellipsis. The root also sets data-size, data-variant, and data-leverui-color-palette.

Code
.site-trail .leverui-breadcrumb__link {
  color: var(--leverui-colors-blue-fg);
}

Explorer

Click a part name to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts