Card count uses an “Auto” toggle alongside a discrete range slider. When auto mode is on, the slider is disabled and the card stack auto-fits to the available viewport height.
from cjm_fasthtml_card_stack.core.config import CardStackConfig, _reset_prefix_counterfrom cjm_fasthtml_card_stack.core.html_ids import CardStackHtmlIds_reset_prefix_counter()config = CardStackConfig(prefix="test")ids = CardStackHtmlIds(prefix="test")# Test auto mode (default)section = _render_card_count_section(config, ids)html = to_xml(section)assert'id="test-card-count-slider"'in htmlassert'id="test-card-count-auto-toggle"'in htmlassert'disabled="disabled"'in html # slider disabled in auto modeassert'checked'in html # toggle checked in auto modeassert'Auto'in htmlassert'Cards'in html# Tick labels for default options (1, 3, 5, 7, 9)for v in (1, 3, 5, 7, 9):assertf'>{v}<'in htmlprint("Card count section auto mode tests passed!")# Test manual modesection_manual = _render_card_count_section(config, ids, current_count=5, is_auto_mode=False)html_manual = to_xml(section_manual)assert'disabled="disabled"'notin html_manual # slider enabledassert'value="5"'in html_manual # current count reflectedprint("Card count section manual mode tests passed!")
def render_settings_trigger( modal_id:str, # ID of the settings modal dialog to open icon_size:int=4, # lucide icon size)->functools.partial(<function ft_hx at 0x7f130d21f920>, 'button'): # ghost button with sliders-horizontal icon
Render a settings icon button that opens the card stack settings modal.
def render_card_stack_settings_modal( config:CardStackConfig, # card stack configuration ids:CardStackHtmlIds, # HTML IDs for this instance current_count:int=1, # currently selected card count is_auto_mode:bool=True, # whether auto-adjust mode is active card_width:int=80, # current card width in rem show_scale:bool=False, # whether to include the scale slider card_scale:int=100, # current scale percentage (if show_scale=True) title:str='Display Settings', # modal title text)->tuple: # (modal_dialog, trigger_button)
Render a modal-based card stack settings panel.
Returns two components: - modal_dialog: The Dialog element (place anywhere in page) - trigger_button: Small settings icon button (place in toolbar)