sidebar.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import reflex as rx
  2. from ...webui import styles
  3. from ...webui.state import State
  4. def sidebar_chat(chat: str) -> rx.Component:
  5. """A sidebar chat item.
  6. Args:
  7. chat: The chat item.
  8. Returns:
  9. The sidebar chat item.
  10. """
  11. return rx.chakra.hstack(
  12. rx.chakra.box(
  13. chat,
  14. on_click=lambda: State.set_chat(chat),
  15. style=styles.sidebar_style,
  16. color=styles.icon_color,
  17. flex="1",
  18. ),
  19. rx.chakra.box(
  20. rx.chakra.icon(
  21. tag="delete",
  22. style=styles.icon_style,
  23. on_click=State.delete_chat,
  24. ),
  25. style=styles.sidebar_style,
  26. ),
  27. color=styles.text_light_color,
  28. cursor="pointer",
  29. )
  30. def sidebar() -> rx.Component:
  31. """The sidebar component.
  32. Returns:
  33. The sidebar component.
  34. """
  35. return rx.chakra.drawer(
  36. rx.chakra.drawer_overlay(
  37. rx.chakra.drawer_content(
  38. rx.chakra.drawer_header(
  39. rx.chakra.hstack(
  40. rx.chakra.text("Chats"),
  41. rx.chakra.icon(
  42. tag="close",
  43. on_click=State.toggle_drawer,
  44. style=styles.icon_style,
  45. ),
  46. )
  47. ),
  48. rx.chakra.drawer_body(
  49. rx.chakra.vstack(
  50. rx.foreach(State.chat_titles, lambda chat: sidebar_chat(chat)),
  51. align_items="stretch",
  52. )
  53. ),
  54. ),
  55. ),
  56. placement="left",
  57. is_open=State.drawer_open,
  58. )