def render_progress_indicator( focused_index:int, # Currently focused item index (0-based) total_items:int, # Total number of items ids:CardStackHtmlIds, # HTML IDs for this card stack instance label:str='Item', # Label prefix (e.g., "Item", "Segment", "Card") oob:bool=False, # Whether to render as OOB swap)->Any: # Progress indicator component
Render position indicator showing current item in the collection.
# Test render_progress_indicatorfrom fasthtml.common import to_xmlids = CardStackHtmlIds(prefix="cs0")progress = render_progress_indicator(0, 20, ids)html = to_xml(progress)assert'id="cs0-progress"'in htmlassert"Item 1 of 20"in htmlprint("Basic progress test passed!")
Basic progress test passed!
# Test custom labelprogress = render_progress_indicator(4, 100, ids, label="Segment")html = to_xml(progress)assert"Segment 5 of 100"in htmlprint("Custom label test passed!")
Custom label test passed!
# Test OOB modeprogress = render_progress_indicator(9, 50, ids, oob=True)html = to_xml(progress)assert'hx-swap-oob="true"'in html# Non-OOB should not have the attributeprogress = render_progress_indicator(9, 50, ids, oob=False)html = to_xml(progress)assert'hx-swap-oob'notin htmlprint("OOB mode tests passed!")
OOB mode tests passed!
# Test number formatting with large valuesprogress = render_progress_indicator(999, 1500, ids)html = to_xml(progress)assert"Item 1,000 of 1,500"in htmlprint("Number formatting test passed!")