Skip to content

Commit

Permalink
feat: add Breadcrumbs component
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Feb 17, 2025
1 parent d128b3b commit 576a593
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/components/breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
For,
Show,
splitProps,
type ComponentProps,
type JSXElement,
type ParentComponent,
} from 'solid-js';
import { IconChevronRight, IconDots } from '@tabler/icons-solidjs';
Expand Down Expand Up @@ -111,3 +114,54 @@ export const BreadcrumbEllipsis: ParentComponent<
</span>
);
};

export type BreadcrumbEntry = {
/**
* Content to display (string or JSX).
**/
content: JSXElement;

/**
* Href for navigation.
**/
href: string;
};

export interface BreadcrumbsProps {
/**
* Array of items to display in the breadcrumb.
**/
entries: BreadcrumbEntry[];
}

export function Breadcrumbs(props: BreadcrumbsProps) {
return (
<Breadcrumb>
<BreadcrumbList>
<For each={props.entries}>
{(entry, index) => (
<>
<BreadcrumbItem>
<BreadcrumbLink
href={entry.href}
onClick={e => {
// Skip navigation if the current entry is the last one.
if (index() === props.entries.length - 1) {
e.preventDefault();
}
}}
>
{entry.content}
</BreadcrumbLink>
</BreadcrumbItem>

<Show when={index() !== props.entries.length - 1}>
<BreadcrumbSeparator />
</Show>
</>
)}
</For>
</BreadcrumbList>
</Breadcrumb>
);
}

0 comments on commit 576a593

Please sign in to comment.