Breadcrumb Block
The Breadcrumb Component is a fully customizable and accessible navigation breadcrumb built with React and TypeScript. It provides a complete breadcrumb navigation interface with modern design patterns, flexible customization options, and support for custom navigation items.
π Installationβ
npm install @nodeblocks/frontend-breadcrumb-block@0.1.0
π Usageβ
import {Breadcrumbs} from '@nodeblocks/frontend-breadcrumb-block';
- Basic Usage
- Advanced Usage
function BasicBreadcrumb() {
return (
<Breadcrumbs>
<Breadcrumbs.BreadcrumbItem url="#home">
Home
</Breadcrumbs.BreadcrumbItem>
<Breadcrumbs.BreadcrumbChevron />
<Breadcrumbs.BreadcrumbItem url="#products">
Products
</Breadcrumbs.BreadcrumbItem>
</Breadcrumbs>
);
}
function AdvancedBreadcrumb() {
return (
<Breadcrumbs>
{({ defaultBlocks, defaultBlockOrder }) => ({
blocks: {
...defaultBlocks,
// π Home breadcrumb with props override
home: {
...defaultBlocks.breadcrumbItem,
props: {
...defaultBlocks.breadcrumbItem.props,
url: "#home",
children: "π Home",
style: { fontWeight: 'bold' }
},
},
// π± Products breadcrumb with custom styling
products: {
...defaultBlocks.breadcrumbItem,
props: {
...defaultBlocks.breadcrumbItem.props,
url: "#products",
children: "π± Products",
className: "custom-product-link"
},
},
// π Full block override with custom component
search: (
<span style={{
color: '#fff',
backgroundColor: '#007bff',
padding: '4px 8px',
borderRadius: '4px',
fontSize: '12px'
}}>
π Search Results
</span>
),
// π¨ Custom chevron override
breadcrumbChevron: (
<span style={{
margin: '0 8px',
color: '#ffd700',
fontWeight: 'bold'
}}>
β
</span>
),
// π Current page (no link)
currentPage: (
<span style={{
color: '#ccc',
fontStyle: 'italic'
}}>
Current Page
</span>
),
},
blockOrder: ['home', 'products', 'search', 'currentPage'],
})}
</Breadcrumbs>
);
}
π§ Props Referenceβ
Main Component Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | undefined | Additional CSS class name for styling the breadcrumb container |
children | BlocksOverride | undefined | Function to override default blocks or add custom breadcrumb items |
Note: The main component inherits all HTML nav element props.
Sub-Componentsβ
The Breadcrumb component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.
Breadcrumbs.BreadcrumbItemβ
| Prop | Type | Default | Description |
|---|---|---|---|
url | string | Required | The URL/href for the breadcrumb link |
children | ReactNode | Required | Content to display as the breadcrumb item text |
Note: This component inherits all HTML a element props.
Breadcrumbs.BreadcrumbChevronβ
This component accepts no props and renders a chevron separator.
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {Breadcrumbs} from '@nodeblocks/frontend-breadcrumb-block';
import {ComponentProps, ReactNode} from 'react';
// Main component interface
interface BreadcrumbProps extends Omit<ComponentProps<'nav'>, 'children'> {
children?: BlocksOverride<DefaultBlocks, CustomBlocks>;
className?: string;
}
// BreadcrumbItem interface
interface BreadcrumbItemProps extends Omit<ComponentProps<'a'>, 'children'> {
url: string;
children: ReactNode;
}
// Usage example with data structure
interface BreadcrumbItem {
key: string;
url: string;
label: string;
}
const breadcrumbItems: BreadcrumbItem[] = [
{ key: 'home', url: '#home', label: 'Home' },
{ key: 'products', url: '#products', label: 'Products' },
{ key: 'current', url: '#products/laptop', label: 'Laptop' },
];
// Example with anchor props
function AdvancedBreadcrumb() {
return (
<Breadcrumbs>
{breadcrumbItems.map((item, index) => (
<>
<Breadcrumbs.BreadcrumbItem key={item.key} url={item.url}>
{item.label}
</Breadcrumbs.BreadcrumbItem>
{index < breadcrumbItems.length - 1 && <Breadcrumbs.BreadcrumbChevron />}
</>
))}
</Breadcrumbs>
);
}
Built with β€οΈ using React, TypeScript, and modern web standards.