Skip to content

Commit

Permalink
Merge pull request #8 from reflex-dev/masenf/immutable-var-updates
Browse files Browse the repository at this point in the history
[REF-3591] Integrate changes from ImmutableVar project
  • Loading branch information
ElijahAhianyo authored Sep 5, 2024
2 parents 5a77d5b + 707d4db commit 5431572
Show file tree
Hide file tree
Showing 73 changed files with 3,091 additions and 5,120 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "reflex-chakra"
version = "0.5.10"
version = "0.6.0a1"
description = "reflex using chakra components"
authors = [
"Elijah Ahianyo <elijah@reflex.dev>"
Expand All @@ -10,7 +10,7 @@ packages = [{include = "reflex_chakra"}]

[tool.poetry.dependencies]
python = "^3.8"
reflex = ">=0.5.9"
reflex = ">=0.6.0a"


[build-system]
Expand Down
32 changes: 17 additions & 15 deletions reflex_chakra/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

from functools import lru_cache
from typing import List, Literal
import reflex as rx

from reflex.components.component import Component
from reflex.ivars.base import ImmutableVar
from reflex.utils.imports import ImportDict, ImportVar
from reflex.vars import Var

class ChakraComponent(rx.Component):

class ChakraComponent(Component):
"""A component that wraps a Chakra component."""

library: str = "@chakra-ui/react@2.6.1" # type: ignore
Expand All @@ -18,7 +22,7 @@ class ChakraComponent(rx.Component):

@staticmethod
@lru_cache(maxsize=None)
def _get_app_wrap_components() -> dict[tuple[int, str], rx.Component]:
def _get_app_wrap_components() -> dict[tuple[int, str], Component]:
return {
(60, "ChakraProvider"): chakra_provider,
}
Expand All @@ -33,14 +37,14 @@ def _get_style(self) -> dict:

@classmethod
@lru_cache(maxsize=None)
def _get_dependencies_imports(cls) -> rx.utils.imports.ImportDict:
def _get_dependencies_imports(cls) -> ImportDict:
"""Get the imports from lib_dependencies for installing.
Returns:
The dependencies imports of the component.
"""
return {
dep: [rx.ImportVar(tag=None, render=False)]
dep: [ImportVar(tag=None, render=False)]
for dep in [
"@chakra-ui/system@2.5.7",
"framer-motion@10.16.4",
Expand All @@ -53,35 +57,33 @@ class ChakraProvider(ChakraComponent):

tag = "ChakraProvider"

theme: rx.Var[str]
theme: Var[str]

@classmethod
def create(cls) -> rx.Component:
def create(cls) -> Component:
"""Create a new ChakraProvider component.
Returns:
A new ChakraProvider component.
"""
return super().create(
theme=rx.Var.create(
"extendTheme(theme)", _var_is_local=False, _var_is_string=False
),
theme=ImmutableVar.create("extendTheme(theme)"),
)

def add_imports(self) -> rx.utils.imports.ImportDict:
def add_imports(self) -> ImportDict:
"""Add imports for the ChakraProvider component.
Returns:
The import dict for the component.
"""
return {
self.library: rx.ImportVar(tag="extendTheme", is_default=False),
"/utils/theme.js": rx.ImportVar(tag="theme", is_default=True),
self.library: ImportVar(tag="extendTheme", is_default=False),
"/utils/theme.js": ImportVar(tag="theme", is_default=True),
}

@staticmethod
@lru_cache(maxsize=None)
def _get_app_wrap_components() -> dict[tuple[int, str], rx.Component]:
def _get_app_wrap_components() -> dict[tuple[int, str], Component]:
return {
(50, "ChakraColorModeProvider"): chakra_color_mode_provider,
}
Expand All @@ -90,7 +92,7 @@ def _get_app_wrap_components() -> dict[tuple[int, str], rx.Component]:
chakra_provider = ChakraProvider.create()


class ChakraColorModeProvider(rx.Component):
class ChakraColorModeProvider(Component):
"""Next-themes integration for chakra colorModeProvider."""

library = "/components/reflex/chakra_color_mode_provider.js"
Expand Down
122 changes: 46 additions & 76 deletions reflex_chakra/components/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from reflex.components.component import Component
from reflex.event import EventHandler, EventSpec
from reflex.style import Style
from reflex.utils.imports import ImportDict
from reflex.vars import BaseVar, Var
from reflex.vars import Var

class ChakraComponent(Component):
@overload
Expand All @@ -23,50 +23,40 @@ class ChakraComponent(Component):
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_blur: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_click: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_blur: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_click: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_context_menu: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_double_click: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_focus: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_mount: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mouse_down: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_enter: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_leave: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_move: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_out: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_over: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_up: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_scroll: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_unmount: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
**props,
) -> "ChakraComponent":
Expand Down Expand Up @@ -100,50 +90,40 @@ class ChakraProvider(ChakraComponent):
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_blur: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_click: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_blur: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_click: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_context_menu: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_double_click: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_focus: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_mount: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mouse_down: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_enter: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_leave: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_move: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_out: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_over: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_up: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_scroll: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_unmount: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
**props,
) -> "ChakraProvider":
Expand All @@ -170,50 +150,40 @@ class ChakraColorModeProvider(Component):
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_blur: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_click: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_blur: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_click: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_context_menu: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_double_click: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_focus: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_mount: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mouse_down: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_enter: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_leave: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_move: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_out: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_over: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_mouse_up: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
] = None,
on_scroll: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_unmount: Optional[
Union[EventHandler, EventSpec, list, Callable, BaseVar]
Union[EventHandler, EventSpec, list, Callable, Var]
] = None,
**props,
) -> "ChakraColorModeProvider":
Expand Down
6 changes: 3 additions & 3 deletions reflex_chakra/components/datadisplay/badge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Badge component."""

from reflex_chakra.components import ChakraComponent, LiteralVariant
import reflex as rx
from reflex.vars import Var


class Badge(ChakraComponent):
Expand All @@ -10,7 +10,7 @@ class Badge(ChakraComponent):
tag = "Badge"

# Variant of the badge ("solid" | "subtle" | "outline")
variant: rx.Var[LiteralVariant]
variant: Var[LiteralVariant]

# The color of the badge
color_scheme: rx.Var[str]
color_scheme: Var[str]
Loading

0 comments on commit 5431572

Please sign in to comment.