Skip to content

Commit 96cbc79

Browse files
committed
docs(breadcrumbs): adjust a few wording
1 parent 6c5a2a5 commit 96cbc79

1 file changed

Lines changed: 38 additions & 36 deletions

File tree

  • packages/docs/src/app/breadcrumbs

packages/docs/src/app/breadcrumbs/page.mdx

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ The naive solutions all have problems:
2626

2727
## The Idea
2828

29-
With `foxact/breadcrumbs`, **you declare breadcrumbs the same way you declare your UI — as components, right where they belong.** Just like you write `<h1>Products</h1>` inside the Products layout, you write `<BreadcrumbItem title="Products" href="/products">` in the same place. Each breadcrumb segment is declared naturally alongside the UI it describes, and the full chain assembles itself automatically from the component tree. There's no separate config file to maintain, no global store to dispatch into.
29+
With `foxact/breadcrumbs`, **you declare breadcrumbs the same way you declare your UI — as components, right where they belong.** Just like you write `<h1>Products</h1>` inside the Products layout, you write `<BreadcrumbSegment title="Products" href="/products">` in the same place. Each breadcrumb segment is declared naturally alongside the UI it describes, and the full chain assembles itself automatically from the component tree. There's no separate config file to maintain, no global store to dispatch into.
3030

31-
Under the hood, each `BreadcrumbItem` uses React Context to accumulate the chain: it reads the parent chain, appends its own `{ title, href }`, and provides the extended chain to its children. This is just nested context providers — the same mechanism React already uses for tree-shaped data.
31+
Under the hood, each `BreadcrumbSegment` uses React Context to accumulate the chain: it reads the parent chain, appends its own `{ title, href }`, and provides the extended chain to its children. This is just nested context providers — the natural React tree hierarchy.
3232

33-
At the leaf (a page component), `BreadcrumbPage` reads the full accumulated chain and portals the rendered breadcrumb UI to a target element in the root layout via [Magic Portal](/magic-portal). No data flows "upward" — the chain is built top-down through context, and the UI is "teleported" to the global layout header via a React Portal.
33+
At the leaf (a page component), `BreadcrumbCurrent` reads the full accumulated chain and portals the rendered breadcrumb UI to a target element in the root layout via [Magic Portal](/magic-portal). No data flows "upward" — the chain is built top-down through context, and the UI is "teleported" back up to the global layout header via a React Portal.
3434

3535
The result:
3636

3737
- **Declarative** — breadcrumbs are declared as components in your UI tree, not configured elsewhere.
38-
- **Co-located**each layout/page knows about its own segment.
39-
- **Automatic collection** — nesting `BreadcrumbItem` components is all it takes; no boilerplate wiring.
38+
- **Co-located**your breadcrumb declarations live right at your UI.
39+
- **Automatic collection** — nesting `BreadcrumbSegment` components is all it takes; no boilerplate wiring.
4040
- **No extra renders** — no global state, no `useEffect` dispatches, no double-render workarounds.
4141

4242
import NextImage from 'next/image';
@@ -51,7 +51,7 @@ import FoxactBreadcrumbsImage from '../../images/foxact-breadcrumbs.png';
5151

5252
### Setup
5353

54-
Create the breadcrumb primitives in a shared file. `createBreadcrumbs` returns an array, so you can name the components however you like:
54+
Create the breadcrumb primitives in a shared file. `createBreadcrumbs` returns an array/tuple, so you can name the components and hooks however you like:
5555

5656
```tsx filename="src/breadcrumbs/index.tsx" copy
5757
'use client';
@@ -65,10 +65,10 @@ export const [
6565
BreadcrumbProvider,
6666
// Target — specify where the breadcrumb UI will "teleport" to, typically you render this in the root layout
6767
BreadcrumbTarget,
68-
// Item — one per intermediate layout/route segment, declares a breadcrumb segment
69-
BreadcrumbItem,
70-
// Page — the leaf that completes the chain and renders the breadcrumb UI
71-
BreadcrumbPage,
68+
// Segment — one per intermediate layout/route segment, declares a breadcrumb segment
69+
BreadcrumbSegment,
70+
// Current — the leaf that completes the chain and renders the breadcrumb UI
71+
BreadcrumbCurrent,
7272
// Hook — read the current breadcrumb chain from context
7373
useBreadcrumbs
7474
] = createBreadcrumbs(
@@ -107,31 +107,33 @@ export default function AppLayout({ children }: React.PropsWithChildren) {
107107

108108
### Intermediate Layouts / Route Segments
109109

110-
In each intermediate layout / route segment, wrap `children` with `BreadcrumbItem` to declare a breadcrumb segment:
110+
In each intermediate layout / route segment, wrap `children` with `BreadcrumbSegment` to declare a breadcrumb segment:
111111

112112
```tsx filename="src/layouts/products-layout.tsx" copy
113-
import { BreadcrumbItem } from '@/breadcrumbs';
113+
import { BreadcrumbSegment } from '@/breadcrumbs';
114114

115115
export default function ProductsLayout({ children }: React.PropsWithChildren) {
116116
return (
117-
<BreadcrumbItem title="Products" href="/products">
117+
<BreadcrumbSegment title="Products" href="/products">
118118
{children}
119-
</BreadcrumbItem>
119+
</BreadcrumbSegment>
120120
);
121121
}
122122
```
123123

124+
> Under the hood, `BreadcrumbSegment` is a React context provider that accumulates the breadcrumb chain. That's why you must provide subtree via `children`.
125+
124126
### Leaf Page
125127

126-
In the leaf page, use `BreadcrumbPage` to complete the chain and render the breadcrumb UI. Pass a **render function** as children to receive the full item array:
128+
In the leaf page, use `BreadcrumbCurrent` to complete the chain and render the breadcrumb UI. Pass a **render function** as children to receive the full item array:
127129

128130
```tsx filename="src/pages/product-detail.tsx" copy
129-
import { BreadcrumbPage } from '@/breadcrumbs';
131+
import { BreadcrumbCurrent } from '@/breadcrumbs';
130132

131133
export default function ProductDetailPage({ product }: { product: Product }) {
132134
return (
133135
<div>
134-
<BreadcrumbPage title={product.name}>
136+
<BreadcrumbCurrent title={product.name}>
135137
{(items) => (
136138
<ol>
137139
{items.map((item) => (
@@ -143,7 +145,7 @@ export default function ProductDetailPage({ product }: { product: Product }) {
143145
))}
144146
</ol>
145147
)}
146-
</BreadcrumbPage>
148+
</BreadcrumbCurrent>
147149

148150
<h1>{product.name}</h1>
149151
{/* ... */}
@@ -164,16 +166,16 @@ The items array for a product page nested under "Products" would look like:
164166
You can also render a custom React element instead of providing a callback function. And you can read the item array via the `useBreadcrumbs` hook:
165167

166168
```tsx filename="src/pages/product-detail.tsx" copy
167-
import { BreadcrumbPage } from '@/breadcrumbs';
169+
import { BreadcrumbCurrent } from '@/breadcrumbs';
168170
import { ProductBreadcrumb } from './product-breadcrumb';
169171

170172
export default function ProductDetailPage({ product }: { product: Product }) {
171173
return (
172174
<div>
173-
<BreadcrumbPage title={product.name}>
175+
<BreadcrumbCurrent title={product.name}>
174176
{/* Pass a React element instead of a function */}
175177
<ProductBreadcrumb />
176-
</BreadcrumbPage>
178+
</BreadcrumbCurrent>
177179

178180
<h1>{product.name}</h1>
179181
</div>
@@ -225,19 +227,19 @@ export default function RootLayout({ children }: React.PropsWithChildren) {
225227

226228
```tsx filename="src/app/products/layout.tsx" copy
227229
// layout for each route segment
228-
import { BreadcrumbItem } from '@/breadcrumbs';
230+
import { BreadcrumbSegment } from '@/breadcrumbs';
229231

230232
export default function ProductsLayout({ children }: React.PropsWithChildren) {
231233
return (
232-
<BreadcrumbItem title="Products" href="/products">
234+
<BreadcrumbSegment title="Products" href="/products">
233235
{children}
234-
</BreadcrumbItem>
236+
</BreadcrumbSegment>
235237
);
236238
}
237239
```
238240

239241
```tsx filename="src/app/products/[category]/layout.tsx" copy
240-
import { BreadcrumbItem } from '@/breadcrumbs';
242+
import { BreadcrumbSegment } from '@/breadcrumbs';
241243

242244
export default async function CategoryLayout({
243245
children,
@@ -246,15 +248,15 @@ export default async function CategoryLayout({
246248
const { category } = await params;
247249

248250
return (
249-
<BreadcrumbItem title={category} href={`/products/${category}`}>
251+
<BreadcrumbSegment title={category} href={`/products/${category}`}>
250252
{children}
251-
</BreadcrumbItem>
253+
</BreadcrumbSegment>
252254
);
253255
}
254256
```
255257

256258
```tsx filename="src/app/products/[category]/[id]/page.tsx" copy
257-
import { BreadcrumbPage } from '@/breadcrumbs';
259+
import { BreadcrumbCurrent } from '@/breadcrumbs';
258260
import { ProductBreadcrumb } from './product-breadcrumb';
259261

260262
export default async function ProductPage({ params }: { params: Promise<{ category: string, id: string }> }) {
@@ -263,9 +265,9 @@ export default async function ProductPage({ params }: { params: Promise<{ catego
263265

264266
return (
265267
<div>
266-
<BreadcrumbPage title={product.name}>
268+
<BreadcrumbCurrent title={product.name}>
267269
<ProductBreadcrumb />
268-
</BreadcrumbPage>
270+
</BreadcrumbCurrent>
269271
<h1>{product.name}</h1>
270272
</div>
271273
);
@@ -318,20 +320,20 @@ import type { ReactNode } from 'react';
318320
export const [
319321
BreadcrumbProvider,
320322
BreadcrumbTarget,
321-
BreadcrumbItem,
322-
BreadcrumbPage,
323+
BreadcrumbSegment,
324+
BreadcrumbCurrent,
323325
useBreadcrumbs
324326
] = createBreadcrumbs<{ icon?: ReactNode }>('MainNav');
325327
```
326328

327329
Then pass `meta` on each item and use it during rendering:
328330

329331
```tsx
330-
<BreadcrumbItem title="Products" href="/products" meta={{ icon: <ShopIcon /> }}>
332+
<BreadcrumbSegment title="Products" href="/products" meta={{ icon: <ShopIcon /> }}>
331333
{children}
332-
</BreadcrumbItem>
334+
</BreadcrumbSegment>
333335

334-
<BreadcrumbPage title={product.name} meta={{ icon: <ProductIcon /> }}>
336+
<BreadcrumbCurrent title={product.name} meta={{ icon: <ProductIcon /> }}>
335337
{(items) => (
336338
<ol>
337339
{items.map((item) => (
@@ -342,7 +344,7 @@ Then pass `meta` on each item and use it during rendering:
342344
))}
343345
</ol>
344346
)}
345-
</BreadcrumbPage>
347+
</BreadcrumbCurrent>
346348
```
347349

348350
## Server-Side Rendering

0 commit comments

Comments
 (0)