diff --git a/custom_components/reflex_resizable_panels/resizable_panels.py b/custom_components/reflex_resizable_panels/resizable_panels.py index d18ade0..b9c543c 100644 --- a/custom_components/reflex_resizable_panels/resizable_panels.py +++ b/custom_components/reflex_resizable_panels/resizable_panels.py @@ -4,27 +4,30 @@ from types import SimpleNamespace from typing import Any, Literal -import reflex as rx +import reflex as rx LiteralDirection = Literal["horizontal", "vertical"] -lib_name = "react-resizable-panels@^2.0.19" - class ResizablePanels(rx.Component): """ResizablePanels component.""" # The React library to wrap. - library = lib_name + library = "react-resizable-panels@^2.1.7" class PanelRoot(rx.el.Div): + """Root element for PanelGroup and Panel components.""" + def add_style(self) -> dict[str, Any] | None: + """Add style to the root element.""" return {"width": "100%", "height": "100%"} class PanelGroup(ResizablePanels): + """PanelGroup component.""" + tag = "PanelGroup" alias = "ResizablePanelGroup" @@ -42,6 +45,8 @@ class PanelGroup(ResizablePanels): class Panel(ResizablePanels): + """Panel component.""" + tag = "Panel" alias = "ResizablePanel" @@ -62,24 +67,27 @@ class Panel(ResizablePanels): min_size: rx.Var[int] # Event handlers triggered when the panel is collapsed - on_collapse: rx.EventHandler[lambda: []] + on_collapse: rx.EventHandler[rx.event.no_args_event_spec()] # Event handlers triggered when the panel is expanded - on_expand: rx.EventHandler[lambda: []] + on_expand: rx.EventHandler[rx.event.no_args_event_spec()] # Event handlers triggered when the panel is resized - on_resize: rx.EventHandler[lambda e0: [e0]] + on_resize: rx.EventHandler[rx.event.passthrough_event_spec(int)] # Order of the panel within the group order: rx.Var[int] class PanelResizeHandle(ResizablePanels): + """PanelResizeHandle component.""" + tag = "PanelResizeHandle" alias = "ResizablePanelResizeHandle" def add_style(self) -> dict[str, Any] | None: + """Add style to the root element.""" return { "width": "3px", "background": rx.color("accent", 9), @@ -87,6 +95,8 @@ def add_style(self) -> dict[str, Any] | None: class ResizablePanelsNamespace(SimpleNamespace): + """Namespace for ResizablePanels components.""" + group = staticmethod(PanelGroup.create) panel = staticmethod(Panel.create) handle = staticmethod(PanelResizeHandle.create) diff --git a/pyproject.toml b/pyproject.toml index c5d1f83..b347254 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,15 +4,15 @@ build-backend = "setuptools.build_meta" [project] name = "reflex-resizable-panels" -version = "0.0.1a1" +version = "0.0.2" description = "Reflex custom component resizable-panels" readme = "README.md" license = { text = "Apache-2.0" } -requires-python = ">=3.8" +requires-python = ">=3.10" authors = [{ name = "", email = "YOUREMAIL@domain.com" }] keywords = ["reflex","reflex-custom-components"] -dependencies = ["reflex>=0.4.2"] +dependencies = ["reflex>=0.7.0"] classifiers = ["Development Status :: 4 - Beta"] diff --git a/resizable_panels_demo/.gitignore b/resizable_panels_demo/.gitignore index eab0d4b..84a3ecc 100644 --- a/resizable_panels_demo/.gitignore +++ b/resizable_panels_demo/.gitignore @@ -1,4 +1,5 @@ +assets/external/ *.db *.py[cod] .web -__pycache__/ \ No newline at end of file +__pycache__/ diff --git a/resizable_panels_demo/resizable_panels_demo/resizable_panels_demo.py b/resizable_panels_demo/resizable_panels_demo/resizable_panels_demo.py index 09c982b..973a76b 100644 --- a/resizable_panels_demo/resizable_panels_demo/resizable_panels_demo.py +++ b/resizable_panels_demo/resizable_panels_demo/resizable_panels_demo.py @@ -41,6 +41,9 @@ def panels(): rx.container(lorem()), background_color=rx.color("gray", 10), min_size=30, + on_collapse=rx.toast("Panel collapsed"), + on_expand=rx.toast("Panel expanded"), + on_resize=lambda size: rx.toast(f"Panel resized to {size}%"), ), direction="horizontal", ), @@ -49,7 +52,7 @@ def panels(): ) -def index() -> rx.Component: +def index() -> tuple: return rx.box( panels(), height="100vh",