Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added base template + improve templating code #1937

Merged
merged 13 commits into from
Oct 16, 2023
Binary file added reflex/.templates/apps/base/assets/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions reflex/.templates/apps/base/assets/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions reflex/.templates/apps/base/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions reflex/.templates/apps/base/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions reflex/.templates/apps/base/assets/paneleft.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions reflex/.templates/apps/base/code/__init__ .py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Base template for Reflex."""
Alek99 marked this conversation as resolved.
Show resolved Hide resolved
86 changes: 86 additions & 0 deletions reflex/.templates/apps/base/code/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""Welcome to Reflex! This file outlines the steps to create a basic app."""
from typing import Callable

import reflex as rx

from .pages import dashboard_page, home_page, settings_page
from .sidebar import sidebar
from .styles import *


def template(main_content: Callable[[], rx.Component]) -> rx.Component:
"""The template for each page of the app.

Args:
main_content (Callable[[], rx.Component]): The main content of the page.

Returns:
rx.Component: The template for each page of the app.
"""
menu_button = rx.box(
rx.menu(
rx.menu_button(
rx.icon(
tag="hamburger",
size="4em",
color=text_color,
),
),
rx.menu_list(
rx.menu_item(rx.link("Home", href="/", width="100%")),
rx.menu_divider(),
rx.menu_item(rx.link("About", href="https://github.com/reflex-dev", width="100%")),
rx.menu_item(rx.link("Contact", href="mailto:founders@=reflex.dev", width="100%")),
),
),
position="fixed",
right="1.5em",
top="1.5em",
z_index="500",
)

return rx.hstack(
sidebar(),
main_content(),
rx.spacer(),
menu_button,
align_items="flex-start",
)


@rx.page("/")
@template
def home() -> rx.Component:
"""Home page.

Returns:
rx.Component: The home page.
"""
return home_page()


@rx.page("/settings")
@template
def settings() -> rx.Component:
"""Settings page.

Returns:
rx.Component: The settings page.
"""
return settings_page()


@rx.page("/dashboard")
@template
def dashboard() -> rx.Component:
"""Dashboard page.

Returns:
rx.Component: The dashboard page.
"""
return dashboard_page()


# Add state and page to the app.
app = rx.App(style=base_style)
app.compile()
4 changes: 4 additions & 0 deletions reflex/.templates/apps/base/code/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""The pages of the app."""
from .dashboard import dashboard_page
from .home import home_page
from .settings import settings_page
28 changes: 28 additions & 0 deletions reflex/.templates/apps/base/code/pages/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""The dashboard page for the template."""
import reflex as rx

from ..styles import *


def dashboard_page() -> rx.Component:
"""The UI for the dashboard page.

Returns:
rx.Component: The UI for the dashboard page.
"""
return rx.box(
rx.vstack(
rx.heading(
"Dashboard",
size="3em",
),
rx.text(
"Welcome to Reflex!",
),
rx.text(
"You can use this template to get started with Reflex.",
),
style=template_content_style,
),
style=template_page_style,
)
28 changes: 28 additions & 0 deletions reflex/.templates/apps/base/code/pages/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""The home page of the app."""
import reflex as rx

from ..styles import *


def home_page() -> rx.Component:
"""The UI for the home page.

Returns:
rx.Component: The UI for the home page.
"""
return rx.box(
rx.vstack(
rx.heading(
"Home",
size="3em",
),
rx.text(
"Welcome to Reflex!",
),
rx.text(
"You can use this template to get started with Reflex.",
),
style=template_content_style,
),
style=template_page_style,
)
28 changes: 28 additions & 0 deletions reflex/.templates/apps/base/code/pages/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""The settings page for the template."""
import reflex as rx

from ..styles import *


def settings_page() -> rx.Component:
"""The UI for the settings page.

Returns:
rx.Component: The UI for the settings page.
"""
return rx.box(
rx.vstack(
rx.heading(
"Settings",
size="3em",
),
rx.text(
"Welcome to Reflex!",
),
rx.text(
"You can use this template to get started with Reflex.",
),
style=template_content_style,
),
style=template_page_style,
)
Loading
Loading