Breadcrumb Component Implementation Summary
Overview
Successfully implemented a Breadcrumb navigation component for djust following the established component patterns. The component provides hierarchical navigation showing the current page's location in the site structure.
Files Created
1. Component Implementation
File: /Users/tip/Dropbox/online_projects/ai/djust/python/djust/components/ui/breadcrumb_simple.py
- Type: Stateless Component (uses
_render_custom()method for loop-based rendering) - Size: 8,935 bytes
- Performance: ~1.55μs per render (Python fallback)
- Framework Support: Bootstrap 5, Tailwind CSS, Plain HTML
Key Features:
- List of breadcrumb items with labels and optional URLs
- Current/active item styling
- Separator support (default:
/, customizable) - Bootstrap 5 breadcrumb styles
- Optional home icon for first item
- Accessibility attributes (aria-label, aria-current)
2. Export Updates
File: /Users/tip/Dropbox/online_projects/ai/djust/python/djust/components/ui/__init__.py
Added Breadcrumb to:
- Import statement (line 18)
__all__export list (line 47)
3. Test Suite
File: /Users/tip/Dropbox/online_projects/ai/djust/test_breadcrumb_component.py
Comprehensive test suite with 8 test cases:
- ✅ Basic breadcrumb with multiple items
- ✅ Custom separator (>)
- ✅ Breadcrumb with home icon
- ✅ Single item breadcrumb (edge case)
- ✅ Empty breadcrumb (edge case)
- ✅ Long breadcrumb trail (6+ items)
- ✅ Different CSS frameworks (Bootstrap 5, Tailwind, Plain)
- ✅ Performance test (1000 renders)
Test Results: All 8 tests passed ✅
4. Examples
File: /Users/tip/Dropbox/online_projects/ai/djust/examples/breadcrumb_example.py
Seven real-world usage examples:
- Product page breadcrumb
- Breadcrumb with home icon
- Blog post breadcrumb
- Settings page breadcrumb
- Minimal breadcrumb (two items)
- Using in LiveView (code example)
- Dynamic breadcrumb from URL path
Component API
Basic Usage
from djust.components.ui import Breadcrumb
# Simple breadcrumb
breadcrumb = Breadcrumb(items=[
{'label': 'Home', 'url': '/'},
{'label': 'Products', 'url': '/products'},
{'label': 'Laptop', 'url': None}, # Current page (no link)
])
html = breadcrumb.render()
Parameters
- items (List[Dict]): List of breadcrumb items
label(str): Text to displayurl(str, optional): Link URL (omit for current page)
- separator (str, default='/'): Separator between items
- show_home (bool, default=False): Show home icon for first item
In Templates
<!-- Simple render -->
{{ breadcrumb.render|safe }}
<!-- Or just -->
{{ breadcrumb }}
In LiveView
from djust import LiveView
from djust.components.ui import Breadcrumb
class ProductDetailView(LiveView):
def mount(self, request, product_id):
self.breadcrumb = Breadcrumb(items=[
{'label': 'Home', 'url': '/'},
{'label': 'Products', 'url': '/products'},
{'label': self.product.name},
])
def get_context_data(self, **kwargs):
return {'breadcrumb': self.breadcrumb}
Implementation Details
Rendering Strategy
The component uses Python _render_custom() method because:
- Breadcrumbs require loops over items
- Rust template engine doesn't support
forloop.counter0reliably - Python f-string rendering is still fast (~1.55μs per render)
Framework-Specific Rendering
Bootstrap 5 (default):
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Current</li>
</ol>
</nav>
Tailwind CSS:
<nav class="flex" aria-label="Breadcrumb">
<ol class="inline-flex items-center space-x-1 md:space-x-3">
<li class="inline-flex items-center">
<a href="/" class="text-gray-700 hover:text-blue-600">Home</a>
</li>
<!-- SVG separators between items -->
</ol>
</nav>
Plain HTML:
<nav class="breadcrumb" aria-label="breadcrumb">
<ol>
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-separator">/</li>
<li class="breadcrumb-item breadcrumb-item-active">Current</li>
</ol>
</nav>
Performance
Benchmark Results (1000 renders):
- Total time: 1.55ms
- Average: 1.55μs per render
- Well within the target of <200μs for Python fallback
Performance compared to other components:
- Pure Rust: ~1μs (not yet implemented)
- Hybrid template: ~5-10μs (not applicable for loops)
- Python fallback: ~1.55μs ⭐ (excellent!)
Accessibility
The component includes proper accessibility attributes:
aria-label="breadcrumb"on nav elementaria-current="page"on active/current item- Semantic HTML with
<nav>and<ol>
Edge Cases Handled
- ✅ Empty breadcrumb (no items)
- ✅ Single item breadcrumb
- ✅ Long breadcrumb trails (6+ items)
- ✅ Items without URLs (current page)
- ✅ Custom separators
- ✅ Home icon variants
Future Enhancements
Potential Rust Implementation
- Could add pure Rust implementation for ~1μs rendering
- Would require Rust support for loops in component rendering
- Current Python performance is already excellent
Additional Features
- Truncation for very long breadcrumbs (ellipsis in middle)
- Click event handling (for SPA-style navigation)
- Breadcrumb schema markup (for SEO)
- Dropdown menus for intermediate levels
Testing
All tests pass successfully:
$ python test_breadcrumb_component.py
============================================================
BREADCRUMB COMPONENT TEST SUITE
============================================================
Test 1: Basic Breadcrumb ✅ PASSED
Test 2: Custom Separator (>) ✅ PASSED
Test 3: Breadcrumb with Home Icon ✅ PASSED
Test 4: Single Item Breadcrumb ✅ PASSED
Test 5: Empty Breadcrumb ✅ PASSED
Test 6: Long Breadcrumb Trail ✅ PASSED
Test 7: Different CSS Frameworks ✅ PASSED
Test 8: Performance Test ✅ PASSED
============================================================
✅ ALL TESTS PASSED!
============================================================
Conclusion
The Breadcrumb component has been successfully implemented following djust component patterns:
✅ Component created at python/djust/components/ui/breadcrumb_simple.py
✅ Exports updated in python/djust/components/ui/__init__.py
✅ Tests created and passing (8/8)
✅ Examples provided (7 real-world scenarios)
✅ Performance validated (1.55μs per render)
✅ Framework support (Bootstrap 5, Tailwind, Plain HTML)
✅ Accessibility (proper ARIA attributes)
The component is production-ready and can be used immediately in djust applications!