Animations, kinda :D

This commit is contained in:
Timothy Pidashev
2024-03-11 23:56:08 -07:00
parent e7f70b4c02
commit ec1a5103c3
6 changed files with 78 additions and 22 deletions

View File

@@ -6,32 +6,27 @@ def navbar():
rx.center(
rx.flex(
rx.link(
rx.text("About", color=color["white"]),
href="http://about.timmypidashev.localhost"
rx.text("About", color=color["white"]), href="/about"
)
),
rx.flex(
rx.link(
rx.text("Projects", color=color["white"]),
href="http://projects.timmypidashev.localhost"
rx.text("Projects", color=color["white"]), href="/projects"
)
),
rx.flex(
rx.link(
rx.text("Resume", color=color["white"]),
href="http://resume.timmypidashev.localhost"
rx.text("Resume", color=color["white"]), href="/resume"
)
),
rx.flex(
rx.link(
rx.text("Blog", color=color["white"]),
href="http://blog.timmypidashev.localhost"
rx.text("Blog", color=color["white"]), href="/blog"
)
),
rx.flex(
rx.link(
rx.text("Shop", color=color["white"]),
href="http://shop.timmypidashev.localhost"
rx.text("Shop", color=color["white"]), href="shop"
)
),
spacing="7",

View File

@@ -0,0 +1 @@
from .motion import *

View File

@@ -0,0 +1,44 @@
"""Reflex custom component Motion."""
import reflex as rx
from typing import Any, Dict, List, Optional, Set, Union
class Motion(rx.Component):
"""Motion component."""
# The React library to wrap.
library = "framer-motion"
# The React component tag.
tag = "motion.div"
# The initial state of the component.
initial: rx.Var[Dict[str, Union[float, str]]]
# The animate state of the component.
animate: rx.Var[Dict[str, Union[float, str]]]
# The transition
transition: rx.Var[Dict[str, Union[float, str]]]
# What the component does when it's hovered.
while_hover: rx.Var[Dict[str, Union[float, str]]]
# What the component does when it's tapped.
while_tap: rx.Var[Dict[str, Union[float, str]]]
# What the component does when it's in view.
while_in_view: rx.Var[Dict[str, Union[float, str]]]
# What the component does when its focused.
while_focus: rx.Var[Dict[str, Union[float, str]]]
# What the component does when it's out of view.
viewport: rx.Var[Union[str, List[str]]]
def _get_custom_code(self) -> str:
return """
import { useIsPresent } from "framer-motion";
"""
motion = Motion.create

View File

@@ -1,15 +1,24 @@
import reflex as rx
from web.templates import webpage
from web.motion import motion
# TODO: Add a go back here link
@webpage(path="/404", title="Page Not Found")
def page404():
return rx.center(
rx.vstack(
rx.heading("Whoops, this page doesn't exist...", size="9"),
rx.spacer(),
return rx.box(
rx.center(
rx.vstack(
motion(
rx.heading(
"Whoops, this page doesn't exist...", size="9"
),
initial={"opacity": 0, "y": -50}, # Initial state: transparent and above the screen
animate={"opacity": 1, "y": 0, "transition": {"duration": 0.5, "ease": "easeInOut"}}, # Animate opacity to 1 and move down into view
while_hover={"scale": 1.1}, # Enlarge on hover
)
),
height="100vh",
width="100%",
),
height="100vh",
width="100%",
)

View File

@@ -1,6 +1,7 @@
from typing import Callable
import reflex as rx
from web.route import Route
from web.motion import motion
def webpage(path: str, title: str = "Timothy Pidashev", props=None) -> Callable:
"""This template wraps the webpage with the navbar and footer.
@@ -39,12 +40,18 @@ def webpage(path: str, title: str = "Timothy Pidashev", props=None) -> Callable:
from web.components.navbar import navbar
from web.components.footer import footer
# Wrap the component in the template.
# Declare the entire page content
return rx.box(
navbar(),
contents(*children, **props),
footer(),
**props,
motion(
rx.box(
navbar(),
contents(*children, **props),
footer(),
**props
),
initial={"opacity": 0, "y": -50}, # Initial state: transparent and above the screen
animate={"opacity": 1, "y": 0, "transition": {"duration": 0.5, "ease": "easeInOut"}}, # Animate opacity to 1 and move down into view
)
)
return Route(