diff --git a/packages/reflex-components-internal/src/reflex_components_internal/components/base/drawer.py b/packages/reflex-components-internal/src/reflex_components_internal/components/base/drawer.py index 9ce7fc2e7ec..e286da33d70 100644 --- a/packages/reflex-components-internal/src/reflex_components_internal/components/base/drawer.py +++ b/packages/reflex-components-internal/src/reflex_components_internal/components/base/drawer.py @@ -3,12 +3,17 @@ from collections.abc import Sequence from typing import Literal +from reflex_components_core.el.elements.typography import Div + from reflex.components.component import Component, ComponentNamespace from reflex.event import EventHandler, passthrough_event_spec +from reflex.utils.imports import ImportVar from reflex.vars.base import Var -from reflex_components_internal.components.component import CoreComponent +from reflex_components_internal.components.base.button import button +from reflex_components_internal.components.base_ui import PACKAGE_NAME, BaseUIComponent +from reflex_components_internal.components.icons.hugeicon import hi -LiteralDirectionType = Literal["top", "bottom", "left", "right"] +LiteralSwipeDirectionType = Literal["up", "down", "left", "right"] class ClassNames: @@ -17,18 +22,30 @@ class ClassNames: ROOT = "" TRIGGER = "" PORTAL = "" - CONTENT = "fixed right-0 bottom-0 z-50 bg-secondary-1 max-w-96 border-l border-secondary-a4 size-full flex" - OVERLAY = "fixed inset-0 z-50 bg-black/50" - CLOSE = "" + BACKDROP = "fixed inset-0 bg-black opacity-40 transition-all duration-150 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 dark:opacity-80" + VIEWPORT = "fixed inset-0 flex items-end justify-center" + POPUP = "w-full max-h-[80vh] -mb-[3rem] rounded-t-2xl border border-secondary-a4 bg-secondary-1 px-6 pt-4 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px)+3rem)] text-secondary-12 overflow-y-auto overscroll-contain touch-auto [transform:translateY(var(--drawer-swipe-movement-y))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-[swiping]:select-none data-[ending-style]:[transform:translateY(calc(100%-3rem+2px))] data-[starting-style]:[transform:translateY(calc(100%-3rem+2px))] data-[ending-style]:duration-[calc(var(--drawer-swipe-strength)*400ms)]" + CONTENT = "mx-auto w-full max-w-[32rem]" TITLE = "text-2xl font-semibold text-secondary-12" DESCRIPTION = "text-sm text-secondary-11" - HANDLE = "" + CLOSE = "" + HANDLE = "w-12 h-1 mx-auto mb-4 rounded-full bg-secondary-a6" + HEADER = "flex flex-col gap-2 pb-4" + SWIPE_AREA = "" + PROVIDER = "" + INDENT_BACKGROUND = "" + INDENT = "" -class DrawerBaseComponent(CoreComponent): +class DrawerBaseComponent(BaseUIComponent): """Base component for drawer components.""" - library = "vaul-base@0.0.6" + library = f"{PACKAGE_NAME}/drawer" + + @property + def import_var(self): + """Return the import variable for the drawer component.""" + return ImportVar(tag="Drawer", package_path="", install=False) class DrawerRoot(DrawerBaseComponent): @@ -39,50 +56,35 @@ class DrawerRoot(DrawerBaseComponent): # 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. + # Whether the drawer is currently open. open: Var[bool] - # Fires when the drawer is opened or closed. - on_open_change: EventHandler[passthrough_event_spec(bool)] + # Event handler called when the drawer is opened or closed. + on_open_change: EventHandler[passthrough_event_spec(bool, dict)] - # When False, it allows interaction with elements outside of the drawer without closing it. Defaults to True. - modal: Var[bool] + # Direction of the swipe gesture to dismiss. Defaults to 'down'. + swipe_direction: Var[LiteralSwipeDirectionType] - # Direction of the drawer. This adjusts the animations and the drag direction. Defaults to "bottom" - direction: Var[LiteralDirectionType] + # Determines if the drawer enters a modal state when open. + modal: Var[bool | Literal["trap-focus"]] - # 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[passthrough_event_spec(bool)] + # Determines whether pointer dismissal (clicking outside) is disabled. Defaults to False. + disable_pointer_dismissal: Var[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] - - # Container element to render the portal into. Defaults to document.body. - container: Var[str] + # Event handler called after any animations complete when the drawer is opened or closed. + on_open_change_complete: EventHandler[passthrough_event_spec(bool)] - # Whether to reposition inputs when the drawer opens. Defaults to True. - reposition_inputs: 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. + # Array of snap points. Numbers between 0 and 1 represent fractions of the viewport height, and numbers greater than 1 are treated as pixel values. String values support `px` and `rem` units. snap_points: Sequence[str | float] | None # Current active snap point. - active_snap_point: Var[bool] - - # Function to set the active snap point. - set_active_snap_point: EventHandler[passthrough_event_spec(int)] - - # Index of a snap point from which the overlay fade should be applied. Defaults to the last snap point. - fade_from_index: Var[int] + snap_point: Var[str | float | None] - # Whether to snap to sequential points. - snap_to_sequential_point: Var[bool] + # Event handler called when the snap point changes. + on_snap_point_change: EventHandler[passthrough_event_spec(str | float | None)] @classmethod - def create(cls, *children, **props) -> Component: + def create(cls, *children, **props) -> BaseUIComponent: """Create the drawer root component. Returns: @@ -94,18 +96,18 @@ def create(cls, *children, **props) -> Component: class DrawerTrigger(DrawerBaseComponent): - """The button that opens the drawer.""" + """A button that opens the drawer. Renders a