Skip to content

Commit b4f4ca8

Browse files
authored
Add dark_theme, sx and theme_config params to ChatFeed / ChatInterface (#635)
1 parent 55bc2ee commit b4f4ca8

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/panel_material_ui/chat/feed.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import param
12
from panel.chat.feed import ChatFeed as _PnChatFeed
3+
from panel.config import config
24
from panel.layout import Column
35

46
from ..layout import Card, Feed
7+
from ..theme import MaterialDesign
58
from .message import ChatMessage
69
from .step import ChatStep
710

11+
CARD_SX = {".MuiCollapse-vertical > .MuiCardContent-root": {"p": 0, "pb": 0}}
12+
813

914
class ChatFeed(_PnChatFeed):
1015
"""
@@ -32,14 +37,37 @@ class ChatFeed(_PnChatFeed):
3237
>>> chat_feed = ChatFeed(callback=say_welcome, header="Welcome Feed")
3338
>>> chat_feed.send("Hello World!", user="New User", avatar="😊")
3439
"""
40+
dark_theme = param.Boolean(doc="""
41+
Whether to use dark theme. If not specified, will default to Panel's
42+
global theme setting.""")
43+
44+
45+
theme_config = param.Dict(default=None, nested_refs=True, doc="""
46+
Options to configure the ThemeProvider.
47+
See https://mui.com/material-ui/customization/theme-overview/ for more information.""")
48+
49+
sx = param.Dict(default=None, doc="""
50+
A dictionary of CSS styles to apply to the component.
51+
The keys are the CSS class names and the values are the styles.
52+
The CSS class names are generated by the component and can be found
53+
in the component's documentation.""")
54+
3555
_card_type = Card
3656
_feed_type = Feed
3757
_message_type = ChatMessage
3858
_step_type = ChatStep
3959

4060
def __init__(self, *objects, **params):
61+
if 'dark_theme' not in params:
62+
params['dark_theme'] = config.theme == 'dark'
63+
if 'design' not in params:
64+
params['design'] = MaterialDesign
4165
super().__init__(*objects, **params)
42-
self._card.sx = {".MuiCollapse-vertical > .MuiCardContent-root": {"p": 0, "pb": 0}}
66+
self._card.param.update(
67+
dark_theme=self.param.dark_theme,
68+
sx=self.param.sx.rx.pipe(lambda v: dict(CARD_SX, **v) if v else CARD_SX),
69+
theme_config=self.param.theme_config,
70+
)
4371

4472
def _build_steps_layout(self, step, layout_params, default_layout):
4573
layout_params = layout_params or {}

0 commit comments

Comments
 (0)