|
| 1 | +"""Interactive components provided by @radix-ui/react-dialog.""" |
| 2 | + |
| 3 | +from typing import Any |
| 4 | + |
| 5 | +from reflex.components.component import ComponentNamespace |
| 6 | +from reflex.components.el import elements |
| 7 | +from reflex.constants.compiler import MemoizationMode |
| 8 | +from reflex.event import EventHandler, no_args_event_spec, passthrough_event_spec |
| 9 | +from reflex.vars.base import Var |
| 10 | + |
| 11 | +from .base import RadixPrimitiveComponent, RadixPrimitiveTriggerComponent |
| 12 | + |
| 13 | + |
| 14 | +class DialogElement(RadixPrimitiveComponent): |
| 15 | + """Base class for all @radix-ui/react-dialog components.""" |
| 16 | + |
| 17 | + library = "@radix-ui/[email protected]" |
| 18 | + |
| 19 | + |
| 20 | +class DialogRoot(DialogElement): |
| 21 | + """Root component for Dialog.""" |
| 22 | + |
| 23 | + tag = "Root" |
| 24 | + alias = "RadixPrimitiveDialogRoot" |
| 25 | + |
| 26 | + # The controlled open state of the dialog. |
| 27 | + open: Var[bool] |
| 28 | + |
| 29 | + # Fired when the open state changes. |
| 30 | + on_open_change: EventHandler[passthrough_event_spec(bool)] |
| 31 | + |
| 32 | + # The open state of the dialog when it is initially rendered. Use when you do not need to control its open state. |
| 33 | + default_open: Var[bool] |
| 34 | + |
| 35 | + # The modality of the dialog. When set to true, interaction with outside elements will be disabled and only dialog content will be visible to screen readers. |
| 36 | + modal: Var[bool] |
| 37 | + |
| 38 | + |
| 39 | +class DialogPortal(DialogElement): |
| 40 | + """Portal component for Dialog.""" |
| 41 | + |
| 42 | + tag = "Portal" |
| 43 | + alias = "RadixPrimitiveDialogPortal" |
| 44 | + |
| 45 | + # Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. If used on this part, it will be inherited by Dialog.Overlay and Dialog.Content. |
| 46 | + force_mount: Var[bool] |
| 47 | + |
| 48 | + # Specify a container element to portal the content into. |
| 49 | + container: Var[Any] |
| 50 | + |
| 51 | + |
| 52 | +class DialogOverlay(DialogElement): |
| 53 | + """A layer that covers the inert portion of the view when the dialog is open.""" |
| 54 | + |
| 55 | + tag = "Overlay" |
| 56 | + alias = "RadixPrimitiveDialogOverlay" |
| 57 | + |
| 58 | + # Change the default rendered element for the one passed as a child, merging their props and behavior. |
| 59 | + as_child: Var[bool] |
| 60 | + |
| 61 | + # Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from Dialog.Portal. |
| 62 | + force_mount: Var[bool] |
| 63 | + |
| 64 | + |
| 65 | +class DialogTrigger(DialogElement, RadixPrimitiveTriggerComponent): |
| 66 | + """Trigger an action or event, to open a Dialog modal.""" |
| 67 | + |
| 68 | + tag = "Trigger" |
| 69 | + alias = "RadixPrimitiveDialogTrigger" |
| 70 | + |
| 71 | + # Change the default rendered element for the one passed as a child, merging their props and behavior. |
| 72 | + as_child: Var[bool] |
| 73 | + |
| 74 | + _memoization_mode = MemoizationMode(recursive=False) |
| 75 | + |
| 76 | + |
| 77 | +class DialogContent(elements.Div, DialogElement): |
| 78 | + """Content component to display inside a Dialog modal.""" |
| 79 | + |
| 80 | + tag = "Content" |
| 81 | + alias = "RadixPrimitiveDialogContent" |
| 82 | + |
| 83 | + # Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from Dialog.Portal. |
| 84 | + force_mount: Var[bool] |
| 85 | + |
| 86 | + # Change the default rendered element for the one passed as a child, merging their props and behavior. |
| 87 | + as_child: Var[bool] |
| 88 | + |
| 89 | + # Fired when the dialog is opened. |
| 90 | + on_open_auto_focus: EventHandler[no_args_event_spec] |
| 91 | + |
| 92 | + # Fired when the dialog is closed. |
| 93 | + on_close_auto_focus: EventHandler[no_args_event_spec] |
| 94 | + |
| 95 | + # Fired when the escape key is pressed. |
| 96 | + on_escape_key_down: EventHandler[no_args_event_spec] |
| 97 | + |
| 98 | + # Fired when the pointer is down outside the dialog. |
| 99 | + on_pointer_down_outside: EventHandler[no_args_event_spec] |
| 100 | + |
| 101 | + # Fired when the pointer interacts outside the dialog. |
| 102 | + on_interact_outside: EventHandler[no_args_event_spec] |
| 103 | + |
| 104 | + |
| 105 | +class DialogTitle(DialogElement): |
| 106 | + """Title component to display inside a Dialog modal.""" |
| 107 | + |
| 108 | + tag = "Title" |
| 109 | + alias = "RadixPrimitiveDialogTitle" |
| 110 | + |
| 111 | + # Change the default rendered element for the one passed as a child, merging their props and behavior. |
| 112 | + as_child: Var[bool] |
| 113 | + |
| 114 | + |
| 115 | +class DialogDescription(DialogElement): |
| 116 | + """Description component to display inside a Dialog modal.""" |
| 117 | + |
| 118 | + tag = "Description" |
| 119 | + alias = "RadixPrimitiveDialogDescription" |
| 120 | + |
| 121 | + # Change the default rendered element for the one passed as a child, merging their props and behavior. |
| 122 | + as_child: Var[bool] |
| 123 | + |
| 124 | + |
| 125 | +class DialogClose(DialogElement, RadixPrimitiveTriggerComponent): |
| 126 | + """Close button component to close an open Dialog modal.""" |
| 127 | + |
| 128 | + tag = "Close" |
| 129 | + alias = "RadixPrimitiveDialogClose" |
| 130 | + |
| 131 | + # Change the default rendered element for the one passed as a child, merging their props and behavior. |
| 132 | + as_child: Var[bool] |
| 133 | + |
| 134 | + |
| 135 | +class Dialog(ComponentNamespace): |
| 136 | + """Dialog components namespace.""" |
| 137 | + |
| 138 | + root = __call__ = staticmethod(DialogRoot.create) |
| 139 | + portal = staticmethod(DialogPortal.create) |
| 140 | + trigger = staticmethod(DialogTrigger.create) |
| 141 | + title = staticmethod(DialogTitle.create) |
| 142 | + overlay = staticmethod(DialogOverlay.create) |
| 143 | + content = staticmethod(DialogContent.create) |
| 144 | + description = staticmethod(DialogDescription.create) |
| 145 | + close = staticmethod(DialogClose.create) |
| 146 | + |
| 147 | + |
| 148 | +dialog = Dialog() |
0 commit comments