Mercurial > libervia-web
diff libervia/web/pages/_browser/components.py @ 1619:a2cd4222c702
browser: Updates for new design:
This patch add code to handle the new design for chat.
New bridge method are used to invite users to MUC or get list of occupants.
A new modules is used for components, with a first one for collapsible cards.
rel 457
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 12 Apr 2025 00:21:45 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libervia/web/pages/_browser/components.py Sat Apr 12 00:21:45 2025 +0200 @@ -0,0 +1,31 @@ +from browser import document + +def init_collapsible_cards(parent_elt=None) -> None: + """Initialize cards which can be collapsed.""" + parent = parent_elt or document + cards = parent.select('.collapsible-card') + + for card in cards: + header = card.select_one('.collapsible-header') + content = card.select_one('.collapsible-content') + + content.style.maxHeight = 'none' + natural_height = content.scrollHeight + content.dataset.natural_height = natural_height + + header.bind('click', lambda ev: _toggle_card(ev)) + +def _toggle_card(event): + """Collapse/expand the card.""" + header = event.currentTarget + card = header.closest('.collapsible-card') + content = card.select_one('.collapsible-content') + + if content.style.maxHeight == '0px': + # Expand + content.style.maxHeight = f"{content.dataset.natural_height}px" + header.classList.remove('collapsed') + else: + # Collapse + content.style.maxHeight = '0px' + header.classList.add('collapsed')