Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
1618:5d9889f14012 | 1619:a2cd4222c702 |
---|---|
1 from browser import document | |
2 | |
3 def init_collapsible_cards(parent_elt=None) -> None: | |
4 """Initialize cards which can be collapsed.""" | |
5 parent = parent_elt or document | |
6 cards = parent.select('.collapsible-card') | |
7 | |
8 for card in cards: | |
9 header = card.select_one('.collapsible-header') | |
10 content = card.select_one('.collapsible-content') | |
11 | |
12 content.style.maxHeight = 'none' | |
13 natural_height = content.scrollHeight | |
14 content.dataset.natural_height = natural_height | |
15 | |
16 header.bind('click', lambda ev: _toggle_card(ev)) | |
17 | |
18 def _toggle_card(event): | |
19 """Collapse/expand the card.""" | |
20 header = event.currentTarget | |
21 card = header.closest('.collapsible-card') | |
22 content = card.select_one('.collapsible-content') | |
23 | |
24 if content.style.maxHeight == '0px': | |
25 # Expand | |
26 content.style.maxHeight = f"{content.dataset.natural_height}px" | |
27 header.classList.remove('collapsed') | |
28 else: | |
29 # Collapse | |
30 content.style.maxHeight = '0px' | |
31 header.classList.add('collapsed') |