Skip to content

Commit

Permalink
Docs: add example for headless components
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Jan 6, 2025
1 parent 0a5b08c commit 727b021
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions apps/docs/content/docs/headless/components/breadcrumb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ a page based on the given page tree.
it exports a `useBreadcrumb` hook:

```ts twoslash
/**
* @author hel
*/
declare const tree: any;
// ---cut---
import { usePathname } from 'next/navigation';
Expand All @@ -26,6 +23,51 @@ const items = useBreadcrumb(pathname, tree);
// ^?
```

### Example

A styled example.

```tsx
'use client';
import { usePathname } from 'next/navigation';
import { useBreadcrumb } from 'fumadocs-core/breadcrumb';
import type { PageTree } from 'fumadocs-core/server';
import { Fragment } from 'react';
import { ChevronRight } from 'lucide-react';
import Link from 'next/link';

export function Breadcrumb({ tree }: { tree: PageTree.Root }) {
const pathname = usePathname();
const items = useBreadcrumb(pathname, tree);

if (items.length === 0) return null;

return (
<div className="-mb-3 flex flex-row items-center gap-1 text-sm font-medium text-fd-muted-foreground">
{items.map((item, i) => (
<Fragment key={i}>
{i !== 0 && (
<ChevronRight className="size-4 shrink-0 rtl:rotate-180" />
)}
{item.url ? (
<Link
href={item.url}
className="truncate hover:text-fd-accent-foreground"
>
{item.name}
</Link>
) : (
<span className="truncate">{item.name}</span>
)}
</Fragment>
))}
</div>
);
}
```

You can use it by passing the page tree via `tree` in a server component.

### Breadcrumb Item

<AutoTypeTable path="./content/docs/headless/props.ts" name="BreadcrumbItem" />

0 comments on commit 727b021

Please sign in to comment.