|
| 1 | +import param |
1 | 2 | from panel.chat.feed import ChatFeed as _PnChatFeed |
| 3 | +from panel.config import config |
2 | 4 | from panel.layout import Column |
3 | 5 |
|
4 | 6 | from ..layout import Card, Feed |
| 7 | +from ..theme import MaterialDesign |
5 | 8 | from .message import ChatMessage |
6 | 9 | from .step import ChatStep |
7 | 10 |
|
| 11 | +CARD_SX = {".MuiCollapse-vertical > .MuiCardContent-root": {"p": 0, "pb": 0}} |
| 12 | + |
8 | 13 |
|
9 | 14 | class ChatFeed(_PnChatFeed): |
10 | 15 | """ |
@@ -32,14 +37,37 @@ class ChatFeed(_PnChatFeed): |
32 | 37 | >>> chat_feed = ChatFeed(callback=say_welcome, header="Welcome Feed") |
33 | 38 | >>> chat_feed.send("Hello World!", user="New User", avatar="😊") |
34 | 39 | """ |
| 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 | + |
35 | 55 | _card_type = Card |
36 | 56 | _feed_type = Feed |
37 | 57 | _message_type = ChatMessage |
38 | 58 | _step_type = ChatStep |
39 | 59 |
|
40 | 60 | 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 |
41 | 65 | 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 | + ) |
43 | 71 |
|
44 | 72 | def _build_steps_layout(self, step, layout_params, default_layout): |
45 | 73 | layout_params = layout_params or {} |
|
0 commit comments