demo.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. """Welcome to Reflex! This file outlines the steps to create a basic app."""
  2. from typing import Callable
  3. import reflex as rx
  4. from .pages import chatapp_page, datatable_page, forms_page, graphing_page, home_page
  5. from .sidebar import sidebar
  6. from .state import State
  7. from .styles import *
  8. meta = [
  9. {
  10. "name": "viewport",
  11. "content": "width=device-width, shrink-to-fit=no, initial-scale=1",
  12. },
  13. ]
  14. def template(main_content: Callable[[], rx.Component]) -> rx.Component:
  15. """The template for each page of the app.
  16. Args:
  17. main_content (Callable[[], rx.Component]): The main content of the page.
  18. Returns:
  19. rx.Component: The template for each page of the app.
  20. """
  21. menu_button = rx.chakra.box(
  22. rx.chakra.menu(
  23. rx.chakra.menu_button(
  24. rx.chakra.icon(
  25. tag="hamburger",
  26. size="4em",
  27. color=text_color,
  28. ),
  29. ),
  30. rx.chakra.menu_list(
  31. rx.chakra.menu_item(rx.chakra.link("Home", href="/", width="100%")),
  32. rx.chakra.menu_divider(),
  33. rx.chakra.menu_item(
  34. rx.chakra.link(
  35. "About", href="https://github.com/reflex-dev", width="100%"
  36. )
  37. ),
  38. rx.chakra.menu_item(
  39. rx.chakra.link(
  40. "Contact", href="mailto:founders@reflex.dev", width="100%"
  41. )
  42. ),
  43. ),
  44. ),
  45. position="fixed",
  46. right="1.5em",
  47. top="1.5em",
  48. z_index="500",
  49. )
  50. return rx.chakra.hstack(
  51. sidebar(),
  52. main_content(),
  53. rx.chakra.spacer(),
  54. menu_button,
  55. align_items="flex-start",
  56. transition="left 0.5s, width 0.5s",
  57. position="relative",
  58. left=rx.cond(State.sidebar_displayed, "0px", f"-{sidebar_width}"),
  59. )
  60. @rx.page("/", meta=meta)
  61. @template
  62. def home() -> rx.Component:
  63. """Home page.
  64. Returns:
  65. rx.Component: The home page.
  66. """
  67. return home_page()
  68. @rx.page("/forms", meta=meta)
  69. @template
  70. def forms() -> rx.Component:
  71. """Forms page.
  72. Returns:
  73. rx.Component: The settings page.
  74. """
  75. return forms_page()
  76. @rx.page("/graphing", meta=meta)
  77. @template
  78. def graphing() -> rx.Component:
  79. """Graphing page.
  80. Returns:
  81. rx.Component: The graphing page.
  82. """
  83. return graphing_page()
  84. @rx.page("/datatable", meta=meta)
  85. @template
  86. def datatable() -> rx.Component:
  87. """Data Table page.
  88. Returns:
  89. rx.Component: The chatapp page.
  90. """
  91. return datatable_page()
  92. @rx.page("/chatapp", meta=meta)
  93. @template
  94. def chatapp() -> rx.Component:
  95. """Chatapp page.
  96. Returns:
  97. rx.Component: The chatapp page.
  98. """
  99. return chatapp_page()
  100. # Create the app.
  101. app = rx.App(style=base_style)