annotate libervia/web/pages/_browser/popup.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 f52b89365002
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1582
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
1 from browser import document, timer
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
2 from js_modules.tippy_js import tippy as tippy_ori
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
3 from javascript import pyobj2jsobj
1582
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
4
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
5 # FIXME: workaround for https://github.com/brython-dev/brython/issues/2542
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
6 def tippy(target, data):
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
7 return tippy_ori(target, pyobj2jsobj(data))
1582
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
8
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
9 def create_popup(
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
10 target,
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
11 content_elt,
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
12 focus_class="has-popup-focus",
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
13 focus_elt=None,
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
14 **kwargs
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
15 ):
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
16 """Create a popup and show a popup below a target
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
17
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
18 The popup is created and destroyed on each call, this can be used for dynamic content.
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
19 @param target: element where the popup will appear, or a selector
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
20 @param content_elt: HTML element to show in the popup
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
21 @param focus_class: class added to target element when popup is shown
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
22 @param focus_elt: element where focus_class is added. If None, target will be used.
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
23 @param kwargs: arguments used to override tippy options
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
24 """
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
25 if focus_elt is None:
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
26 focus_elt = target
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
27 def on_hide(__):
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
28 focus_elt.classList.remove(focus_class)
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
29 timer.set_timeout(tippy_instance.destroy, 0)
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
30 tippy_opts = {
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
31 "trigger": "click",
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
32 "content": content_elt,
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
33 "appendTo": document.body,
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
34 "placement": "bottom",
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
35 "interactive": True,
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
36 "trigger": "manual",
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
37 "theme": "light",
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
38 "onShow": lambda __: focus_elt.classList.add(focus_class),
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
39 "onHide": on_hide
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
40 }
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
41 tippy_opts.update(kwargs)
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
42
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
43 tippy_instance = tippy(
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
44 target,
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
45 tippy_opts
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
46 )
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
47 tippy_instance.show()
f52b89365002 browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff changeset
48 return tippy_instance