Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions custom_components/reflex_resizable_panels/resizable_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -42,6 +45,8 @@ class PanelGroup(ResizablePanels):


class Panel(ResizablePanels):
"""Panel component."""

tag = "Panel"

alias = "ResizablePanel"
Expand All @@ -62,31 +67,36 @@ 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),
}


class ResizablePanelsNamespace(SimpleNamespace):
"""Namespace for ResizablePanels components."""

group = staticmethod(PanelGroup.create)
panel = staticmethod(Panel.create)
handle = staticmethod(PanelResizeHandle.create)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
keywords = ["reflex","reflex-custom-components"]

dependencies = ["reflex>=0.4.2"]
dependencies = ["reflex>=0.7.0"]

classifiers = ["Development Status :: 4 - Beta"]

Expand Down
3 changes: 2 additions & 1 deletion resizable_panels_demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
assets/external/
*.db
*.py[cod]
.web
__pycache__/
__pycache__/
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
Expand All @@ -49,7 +52,7 @@ def panels():
)


def index() -> rx.Component:
def index() -> tuple:
return rx.box(
panels(),
height="100vh",
Expand Down