reflex/reflex/constants/event.py
Masen Furer 67606561d3
[REF-668] Wrap MyApp with radix Theme component (#1867)
* partly add some radix-ui/themes based components

* add @radix-ui/themes integration to top-level app

* WiP: compile _app_wrap based on which component library is used

TODO: working color mode

* WiP get color mode working with agnostic provider

still not perfect, as the RadixColorModeProvider seems to trip hydration errors
when using color_mode_cond component, but for now, this provides a nice balance
between the two libraries and allows them to interoperate.

* WiP template _app.js instead of making a separate wrap file

* WiP: use next-themes for consistent darkmode switching

* strict pin chakra deps

* Move ChakraColorModeProvider to separate js file

* move nasty radix themes js code into js files

* remove chakra from default imports

* chakra fixup import to use .js extension

* Add radix theme typography and layout components

* do NOT special case the radix theme...

avoid templating json and applying it, avoid non-customizable logic

just add the radix Theme component as an app wrap if the user specifies it to
rx.App, and any other app-wrap theme-like component could _also_ be used
without having to change the code.

this also allows different themes for different sections of the app by simply
placing elements inside a different rdxt.theme wrapper.

* Theme uses "radius" not "borderRadius"

* move next-themes to main packages.json

this is always used, regardless of the component library

* test_app: test cases for app_wrap interface

* Finish wrapping Button, Switch, and TextField components

* docstring, comments, static fixups

* debounce: use alias or tag when passing child Element

Fix REF-830

* test_app: ruin my beautiful indentation

* py38 compatibility

* Add event triggers for switch and TextField

* Add type hints for radix theme components

* radix themes fixups from writing the tests

* Add integration test for radix themes components

* test_app: mock out package installation

we only need the compile result, we're not actually trying to install packages

* avoid incompatible version of @emotion/react

* test_radix_themes: include theme_panel component

* next-themes default scheme: "light"

until all of our components look good in dark mode, need to keep the default as
light mode regardless of the system setting.
2023-10-16 15:31:50 -07:00

87 lines
2.2 KiB
Python

"""Event-related constants."""
from enum import Enum
from types import SimpleNamespace
class Endpoint(Enum):
"""Endpoints for the reflex backend API."""
PING = "ping"
EVENT = "_event"
UPLOAD = "_upload"
def __str__(self) -> str:
"""Get the string representation of the endpoint.
Returns:
The path for the endpoint.
"""
return f"/{self.value}"
def get_url(self) -> str:
"""Get the URL for the endpoint.
Returns:
The full URL for the endpoint.
"""
# Import here to avoid circular imports.
from reflex.config import get_config
# Get the API URL from the config.
config = get_config()
url = "".join([config.api_url, str(self)])
# The event endpoint is a websocket.
if self == Endpoint.EVENT:
# Replace the protocol with ws.
url = url.replace("https://", "wss://").replace("http://", "ws://")
# Return the url.
return url
class SocketEvent(SimpleNamespace):
"""Socket events sent by the reflex backend API."""
PING = "ping"
EVENT = "event"
def __str__(self) -> str:
"""Get the string representation of the event name.
Returns:
The event name string.
"""
return str(self.value)
class EventTriggers(SimpleNamespace):
"""All trigger names used in Reflex."""
ON_FOCUS = "on_focus"
ON_BLUR = "on_blur"
ON_CANCEL = "on_cancel"
ON_CLICK = "on_click"
ON_CHANGE = "on_change"
ON_CHANGE_END = "on_change_end"
ON_CHANGE_START = "on_change_start"
ON_CHECKED_CHANGE = "on_checked_change"
ON_COMPLETE = "on_complete"
ON_CONTEXT_MENU = "on_context_menu"
ON_DOUBLE_CLICK = "on_double_click"
ON_DROP = "on_drop"
ON_EDIT = "on_edit"
ON_KEY_DOWN = "on_key_down"
ON_KEY_UP = "on_key_up"
ON_MOUSE_DOWN = "on_mouse_down"
ON_MOUSE_ENTER = "on_mouse_enter"
ON_MOUSE_LEAVE = "on_mouse_leave"
ON_MOUSE_MOVE = "on_mouse_move"
ON_MOUSE_OUT = "on_mouse_out"
ON_MOUSE_OVER = "on_mouse_over"
ON_MOUSE_UP = "on_mouse_up"
ON_SCROLL = "on_scroll"
ON_SUBMIT = "on_submit"
ON_MOUNT = "on_mount"
ON_UNMOUNT = "on_unmount"