Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update overlay props #4261

Merged
merged 13 commits into from
Nov 1, 2024
Merged
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
45 changes: 33 additions & 12 deletions reflex/components/radix/primitives/drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,29 @@ class DrawerRoot(DrawerComponent):

alias = "Vaul" + tag

# The open state of the drawer when it is initially rendered. Use when you do not need to control its open state.
default_open: Var[bool]

# Whether the drawer is open or not.
open: Var[bool]

# Enable background scaling, it requires an element with [vaul-drawer-wrapper] data attribute to scale its background.
should_scale_background: Var[bool]
# Fires when the drawer is opened or closed.
on_open_change: EventHandler[identity_event(bool)]

# Number between 0 and 1 that determines when the drawer should be closed.
close_threshold: Var[float]
# When `False`, it allows interaction with elements outside of the drawer without closing it. Defaults to `True`.
modal: Var[bool]

# Direction of the drawer. This adjusts the animations and the drag direction. Defaults to `"bottom"`
direction: Var[LiteralDirectionType]

# Gets triggered after the open or close animation ends, it receives an open argument with the open state of the drawer by the time the function was triggered.
on_animation_end: EventHandler[identity_event(bool)]

# When `False`, dragging, clicking outside, pressing esc, etc. will not close the drawer. Use this in combination with the open prop, otherwise you won't be able to open/close the drawer.
dismissible: Var[bool]

# When `True`, dragging will only be possible by the handle.
handle_only: Var[bool]

# Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up. Should go from least visible. Also Accept px values, which doesn't take screen height into account.
snap_points: Optional[List[Union[str, float]]]
Expand All @@ -51,17 +66,14 @@ class DrawerRoot(DrawerComponent):
# Duration for which the drawer is not draggable after scrolling content inside of the drawer. Defaults to 500ms
scroll_lock_timeout: Var[int]

# When `False`, it allows to interact with elements outside of the drawer without closing it. Defaults to `True`.
modal: Var[bool]

# Direction of the drawer. Defaults to `"bottom"`
direction: Var[LiteralDirectionType]

# When `True`, it prevents scroll restoration. Defaults to `True`.
preventScrollRestoration: Var[bool]

# Fires when the drawer is opened or closed.
on_open_change: EventHandler[identity_event(bool)]
# Enable background scaling, it requires container element with `vaul-drawer-wrapper` attribute to scale its background.
should_scale_background: Var[bool]

# Number between 0 and 1 that determines when the drawer should be closed.
close_threshold: Var[float]


class DrawerTrigger(DrawerComponent):
Expand Down Expand Up @@ -263,6 +275,14 @@ def _get_style(self) -> dict:
return {"css": base_style}


class DrawerHandle(DrawerComponent):
"""A description for the drawer."""

tag = "Drawer.Handle"

alias = "Vaul" + tag


class Drawer(ComponentNamespace):
"""A namespace for Drawer components."""

Expand All @@ -274,6 +294,7 @@ class Drawer(ComponentNamespace):
close = staticmethod(DrawerClose.create)
title = staticmethod(DrawerTitle.create)
description = staticmethod(DrawerDescription.create)
handle = staticmethod(DrawerHandle.create)


drawer = Drawer()
105 changes: 85 additions & 20 deletions reflex/components/radix/primitives/drawer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,31 @@ class DrawerRoot(DrawerComponent):
def create( # type: ignore
cls,
*children,
default_open: Optional[Union[Var[bool], bool]] = None,
open: Optional[Union[Var[bool], bool]] = None,
should_scale_background: Optional[Union[Var[bool], bool]] = None,
close_threshold: Optional[Union[Var[float], float]] = None,
snap_points: Optional[List[Union[float, str]]] = None,
fade_from_index: Optional[Union[Var[int], int]] = None,
scroll_lock_timeout: Optional[Union[Var[int], int]] = None,
modal: Optional[Union[Var[bool], bool]] = None,
direction: Optional[
Union[
Literal["bottom", "left", "right", "top"],
Var[Literal["bottom", "left", "right", "top"]],
]
] = None,
dismissible: Optional[Union[Var[bool], bool]] = None,
handle_only: Optional[Union[Var[bool], bool]] = None,
snap_points: Optional[List[Union[float, str]]] = None,
fade_from_index: Optional[Union[Var[int], int]] = None,
scroll_lock_timeout: Optional[Union[Var[int], int]] = None,
preventScrollRestoration: Optional[Union[Var[bool], bool]] = None,
should_scale_background: Optional[Union[Var[bool], bool]] = None,
close_threshold: Optional[Union[Var[float], float]] = None,
as_child: Optional[Union[Var[bool], bool]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_animation_end: Optional[EventType[bool]] = None,
on_blur: Optional[EventType[[]]] = None,
on_click: Optional[EventType[[]]] = None,
on_context_menu: Optional[EventType[[]]] = None,
Expand All @@ -110,16 +114,20 @@ class DrawerRoot(DrawerComponent):

Args:
*children: The children of the component.
default_open: The open state of the drawer when it is initially rendered. Use when you do not need to control its open state.
open: Whether the drawer is open or not.
should_scale_background: Enable background scaling, it requires an element with [vaul-drawer-wrapper] data attribute to scale its background.
close_threshold: Number between 0 and 1 that determines when the drawer should be closed.
on_open_change: Fires when the drawer is opened or closed.
modal: When `False`, it allows interaction with elements outside of the drawer without closing it. Defaults to `True`.
direction: Direction of the drawer. This adjusts the animations and the drag direction. Defaults to `"bottom"`
on_animation_end: Gets triggered after the open or close animation ends, it receives an open argument with the open state of the drawer by the time the function was triggered.
dismissible: When `False`, dragging, clicking outside, pressing esc, etc. will not close the drawer. Use this in combination with the open prop, otherwise you won't be able to open/close the drawer.
handle_only: When `True`, dragging will only be possible by the handle.
snap_points: Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up. Should go from least visible. Also Accept px values, which doesn't take screen height into account.
fade_from_index: Index of a snapPoint from which the overlay fade should be applied. Defaults to the last snap point.
scroll_lock_timeout: Duration for which the drawer is not draggable after scrolling content inside of the drawer. Defaults to 500ms
modal: When `False`, it allows to interact with elements outside of the drawer without closing it. Defaults to `True`.
direction: Direction of the drawer. Defaults to `"bottom"`
preventScrollRestoration: When `True`, it prevents scroll restoration. Defaults to `True`.
on_open_change: Fires when the drawer is opened or closed.
should_scale_background: Enable background scaling, it requires container element with `vaul-drawer-wrapper` attribute to scale its background.
close_threshold: Number between 0 and 1 that determines when the drawer should be closed.
as_child: Change the default rendered element for the one passed as a child.
style: The style of the component.
key: A unique key for the component.
Expand Down Expand Up @@ -479,6 +487,54 @@ class DrawerDescription(DrawerComponent):
"""
...

class DrawerHandle(DrawerComponent):
@overload
@classmethod
def create( # type: ignore
cls,
*children,
as_child: Optional[Union[Var[bool], bool]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_blur: Optional[EventType[[]]] = None,
on_click: Optional[EventType[[]]] = None,
on_context_menu: Optional[EventType[[]]] = None,
on_double_click: Optional[EventType[[]]] = None,
on_focus: Optional[EventType[[]]] = None,
on_mount: Optional[EventType[[]]] = None,
on_mouse_down: Optional[EventType[[]]] = None,
on_mouse_enter: Optional[EventType[[]]] = None,
on_mouse_leave: Optional[EventType[[]]] = None,
on_mouse_move: Optional[EventType[[]]] = None,
on_mouse_out: Optional[EventType[[]]] = None,
on_mouse_over: Optional[EventType[[]]] = None,
on_mouse_up: Optional[EventType[[]]] = None,
on_scroll: Optional[EventType[[]]] = None,
on_unmount: Optional[EventType[[]]] = None,
**props,
) -> "DrawerHandle":
"""Create the component.

Args:
*children: The children of the component.
as_child: Change the default rendered element for the one passed as a child.
style: The style of the component.
key: A unique key for the component.
id: The id for the component.
class_name: The class name for the component.
autofocus: Whether the component should take the focus once the page is loaded
custom_attrs: custom attribute
**props: The props of the component.

Returns:
The component.
"""
...

class Drawer(ComponentNamespace):
root = staticmethod(DrawerRoot.create)
trigger = staticmethod(DrawerTrigger.create)
Expand All @@ -488,31 +544,36 @@ class Drawer(ComponentNamespace):
close = staticmethod(DrawerClose.create)
title = staticmethod(DrawerTitle.create)
description = staticmethod(DrawerDescription.create)
handle = staticmethod(DrawerHandle.create)

@staticmethod
def __call__(
*children,
default_open: Optional[Union[Var[bool], bool]] = None,
open: Optional[Union[Var[bool], bool]] = None,
should_scale_background: Optional[Union[Var[bool], bool]] = None,
close_threshold: Optional[Union[Var[float], float]] = None,
snap_points: Optional[List[Union[float, str]]] = None,
fade_from_index: Optional[Union[Var[int], int]] = None,
scroll_lock_timeout: Optional[Union[Var[int], int]] = None,
modal: Optional[Union[Var[bool], bool]] = None,
direction: Optional[
Union[
Literal["bottom", "left", "right", "top"],
Var[Literal["bottom", "left", "right", "top"]],
]
] = None,
dismissible: Optional[Union[Var[bool], bool]] = None,
handle_only: Optional[Union[Var[bool], bool]] = None,
snap_points: Optional[List[Union[float, str]]] = None,
fade_from_index: Optional[Union[Var[int], int]] = None,
scroll_lock_timeout: Optional[Union[Var[int], int]] = None,
preventScrollRestoration: Optional[Union[Var[bool], bool]] = None,
should_scale_background: Optional[Union[Var[bool], bool]] = None,
close_threshold: Optional[Union[Var[float], float]] = None,
as_child: Optional[Union[Var[bool], bool]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_animation_end: Optional[EventType[bool]] = None,
on_blur: Optional[EventType[[]]] = None,
on_click: Optional[EventType[[]]] = None,
on_context_menu: Optional[EventType[[]]] = None,
Expand All @@ -535,16 +596,20 @@ class Drawer(ComponentNamespace):

Args:
*children: The children of the component.
default_open: The open state of the drawer when it is initially rendered. Use when you do not need to control its open state.
open: Whether the drawer is open or not.
should_scale_background: Enable background scaling, it requires an element with [vaul-drawer-wrapper] data attribute to scale its background.
close_threshold: Number between 0 and 1 that determines when the drawer should be closed.
on_open_change: Fires when the drawer is opened or closed.
modal: When `False`, it allows interaction with elements outside of the drawer without closing it. Defaults to `True`.
direction: Direction of the drawer. This adjusts the animations and the drag direction. Defaults to `"bottom"`
on_animation_end: Gets triggered after the open or close animation ends, it receives an open argument with the open state of the drawer by the time the function was triggered.
dismissible: When `False`, dragging, clicking outside, pressing esc, etc. will not close the drawer. Use this in combination with the open prop, otherwise you won't be able to open/close the drawer.
handle_only: When `True`, dragging will only be possible by the handle.
snap_points: Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up. Should go from least visible. Also Accept px values, which doesn't take screen height into account.
fade_from_index: Index of a snapPoint from which the overlay fade should be applied. Defaults to the last snap point.
scroll_lock_timeout: Duration for which the drawer is not draggable after scrolling content inside of the drawer. Defaults to 500ms
modal: When `False`, it allows to interact with elements outside of the drawer without closing it. Defaults to `True`.
direction: Direction of the drawer. Defaults to `"bottom"`
preventScrollRestoration: When `True`, it prevents scroll restoration. Defaults to `True`.
on_open_change: Fires when the drawer is opened or closed.
should_scale_background: Enable background scaling, it requires container element with `vaul-drawer-wrapper` attribute to scale its background.
close_threshold: Number between 0 and 1 that determines when the drawer should be closed.
as_child: Change the default rendered element for the one passed as a child.
style: The style of the component.
key: A unique key for the component.
Expand Down
3 changes: 3 additions & 0 deletions reflex/components/radix/themes/components/alert_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class AlertDialogRoot(RadixThemesComponent):
# Fired when the open state changes.
on_open_change: EventHandler[identity_event(bool)]

# The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.
default_open: Var[bool]


class AlertDialogTrigger(RadixThemesTriggerComponent):
"""Wraps the control that will open the dialog."""
Expand Down
2 changes: 2 additions & 0 deletions reflex/components/radix/themes/components/alert_dialog.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AlertDialogRoot(RadixThemesComponent):
cls,
*children,
open: Optional[Union[Var[bool], bool]] = None,
default_open: Optional[Union[Var[bool], bool]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
Expand Down Expand Up @@ -56,6 +57,7 @@ class AlertDialogRoot(RadixThemesComponent):
*children: Child components.
open: The controlled open state of the dialog.
on_open_change: Fired when the open state changes.
default_open: The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.
style: The style of the component.
key: A unique key for the component.
id: The id for the component.
Expand Down
Loading
Loading