Skip to content

Commit 1bf4e23

Browse files
authored
add dropdown primitive props (#2521)
1 parent 5589cbb commit 1bf4e23

File tree

3 files changed

+319
-21
lines changed

3 files changed

+319
-21
lines changed
Lines changed: 180 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Interactive components provided by @radix-ui/themes."""
2-
from typing import Any, Dict, Literal
2+
from typing import Any, Dict, Literal, Union
33

44
from reflex.constants import EventTriggers
55
from reflex.vars import Var
@@ -9,18 +9,40 @@
99
RadixThemesComponent,
1010
)
1111

12+
LiteralDirType = Literal["ltr", "rtl"]
13+
14+
LiteralSizeType = Literal["1", "2"]
15+
16+
LiteralVariantType = Literal["solid", "soft"]
17+
18+
LiteralSideType = Literal["top", "right", "bottom", "left"]
19+
20+
LiteralAlignType = Literal["start", "center", "end"]
21+
22+
23+
LiteralStickyType = Literal[
24+
"partial",
25+
"always",
26+
]
27+
1228

1329
class DropdownMenuRoot(RadixThemesComponent):
14-
"""Trigger an action or event, such as submitting a form or displaying a dialog."""
30+
"""The Dropdown Menu Root Component."""
1531

1632
tag = "DropdownMenu.Root"
1733

34+
# The open state of the dropdown menu when it is initially rendered. Use when you do not need to control its open state.
35+
default_open: Var[bool]
36+
1837
# The controlled open state of the dropdown menu. Must be used in conjunction with onOpenChange.
1938
open: Var[bool]
2039

21-
# The modality of the dropdown menu. When set to true, interaction with outside elements will be disabled and only menu content will be visible to screen readers.
40+
# The modality of the dropdown menu. When set to true, interaction with outside elements will be disabled and only menu content will be visible to screen readers. Defaults to True.
2241
modal: Var[bool]
2342

43+
# The reading direction of submenus when applicable. If omitted, inherits globally from DirectionProvider or assumes LTR (left-to-right) reading mode.
44+
dir: Var[LiteralDirType]
45+
2446
def get_event_triggers(self) -> Dict[str, Any]:
2547
"""Get the events triggers signatures for the component.
2648
@@ -34,16 +56,67 @@ def get_event_triggers(self) -> Dict[str, Any]:
3456

3557

3658
class DropdownMenuTrigger(RadixThemesComponent):
37-
"""Trigger an action or event, such as submitting a form or displaying a dialog."""
59+
"""The button that toggles the dropdown menu."""
3860

3961
tag = "DropdownMenu.Trigger"
4062

63+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
64+
as_child: Var[bool]
65+
4166

4267
class DropdownMenuContent(RadixThemesComponent):
43-
"""Trigger an action or event, such as submitting a form or displaying a dialog."""
68+
"""The Dropdown Menu Content component that pops out when the dropdown menu is open."""
4469

4570
tag = "DropdownMenu.Content"
4671

72+
# Dropdown Menu Content size "1" - "2"
73+
size: Var[LiteralSizeType]
74+
75+
# Variant of Dropdown Menu Content: "solid" | "soft"
76+
variant: Var[LiteralVariantType]
77+
78+
# Override theme color for Dropdown Menu Content
79+
color_scheme: Var[LiteralAccentColor]
80+
81+
# Renders the Dropdown Menu Content in higher contrast
82+
high_contrast: Var[bool]
83+
84+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
85+
as_child: Var[bool]
86+
87+
# When True, keyboard navigation will loop from last item to first, and vice versa. Defaults to False.
88+
loop: Var[bool]
89+
90+
# Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
91+
force_mount: Var[bool]
92+
93+
# The preferred side of the trigger to render against when open. Will be reversed when collisions occur and `avoid_collisions` is enabled.The position of the tooltip. Defaults to "top".
94+
side: Var[LiteralSideType]
95+
96+
# The distance in pixels from the trigger. Defaults to 0.
97+
side_offset: Var[Union[float, int]]
98+
99+
# The preferred alignment against the trigger. May change when collisions occur. Defaults to "center".
100+
align: Var[LiteralAlignType]
101+
102+
# An offset in pixels from the "start" or "end" alignment options.
103+
align_offset: Var[Union[float, int]]
104+
105+
# When true, overrides the side and align preferences to prevent collisions with boundary edges. Defaults to True.
106+
avoid_collisions: Var[bool]
107+
108+
# The distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { "top": 20, "left": 20 }. Defaults to 0.
109+
collision_padding: Var[Union[float, int, Dict[str, Union[float, int]]]]
110+
111+
# The padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. Defaults to 0.
112+
arrow_padding: Var[Union[float, int]]
113+
114+
# The sticky behavior on the align axis. "partial" will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst "always" will keep the content in the boundary regardless. Defaults to "partial".
115+
sticky: Var[LiteralStickyType]
116+
117+
# Whether to hide the content when the trigger becomes fully occluded. Defaults to False.
118+
hide_when_detached: Var[bool]
119+
47120
def get_event_triggers(self) -> Dict[str, Any]:
48121
"""Get the events triggers signatures for the component.
49122
@@ -55,6 +128,7 @@ def get_event_triggers(self) -> Dict[str, Any]:
55128
EventTriggers.ON_CLOSE_AUTO_FOCUS: lambda e0: [e0],
56129
EventTriggers.ON_ESCAPE_KEY_DOWN: lambda e0: [e0],
57130
EventTriggers.ON_POINTER_DOWN_OUTSIDE: lambda e0: [e0],
131+
EventTriggers.ON_FOCUS_OUTSIDE: lambda e0: [e0],
58132
EventTriggers.ON_INTERACT_OUTSIDE: lambda e0: [e0],
59133
}
60134

@@ -64,44 +138,134 @@ class DropdownMenuSubTrigger(RadixThemesComponent):
64138

65139
tag = "DropdownMenu.SubTrigger"
66140

141+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
142+
as_child: Var[bool]
143+
144+
# When true, prevents the user from interacting with the item.
145+
disabled: Var[bool]
146+
147+
# Optional text used for typeahead purposes. By default the typeahead behavior will use the .textContent of the item. Use this when the content is complex, or you have non-textual content inside.
148+
text_value: Var[str]
149+
67150

68151
class DropdownMenuSub(RadixThemesComponent):
69-
"""Trigger an action or event, such as submitting a form or displaying a dialog."""
152+
"""Contains all the parts of a submenu."""
70153

71154
tag = "DropdownMenu.Sub"
72155

156+
# The controlled open state of the submenu. Must be used in conjunction with `on_open_change`.
157+
open: Var[bool]
158+
159+
# The open state of the submenu when it is initially rendered. Use when you do not need to control its open state.
160+
default_open: Var[bool]
161+
162+
def get_event_triggers(self) -> Dict[str, Any]:
163+
"""Get the events triggers signatures for the component.
164+
165+
Returns:
166+
The signatures of the event triggers.
167+
"""
168+
return {
169+
**super().get_event_triggers(),
170+
EventTriggers.ON_OPEN_CHANGE: lambda e0: [e0.target.value],
171+
}
172+
73173

74174
class DropdownMenuSubContent(RadixThemesComponent):
75-
"""Trigger an action or event, such as submitting a form or displaying a dialog."""
175+
"""The component that pops out when a submenu is open. Must be rendered inside DropdownMenuSub."""
76176

77177
tag = "DropdownMenu.SubContent"
78178

79-
# Button size "1" - "4"
80-
size: Var[Literal["1", "2"]]
179+
# Dropdown Menu Sub Content size "1" - "2"
180+
size: Var[LiteralSizeType]
81181

82-
# Variant of button: "solid" | "soft" | "outline" | "ghost"
83-
variant: Var[Literal["solid", "soft"]]
182+
# Variant of Dropdown Menu Sub Content: "solid" | "soft"
183+
variant: Var[LiteralVariantType]
84184

85-
# Override theme color for button
185+
# Override theme color for Dropdown Menu Sub Content
86186
color_scheme: Var[LiteralAccentColor]
87187

88-
# Whether to render the button with higher contrast color against background
188+
# Whether to render the component with higher contrast color against background
89189
high_contrast: Var[bool]
90190

191+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
192+
as_child: Var[bool]
193+
194+
# When True, keyboard navigation will loop from last item to first, and vice versa. Defaults to False.
195+
loop: Var[bool]
196+
197+
# Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
198+
force_mount: Var[bool]
199+
200+
# The distance in pixels from the trigger. Defaults to 0.
201+
side_offset: Var[Union[float, int]]
202+
203+
# An offset in pixels from the "start" or "end" alignment options.
204+
align_offset: Var[Union[float, int]]
205+
206+
# When true, overrides the side and align preferences to prevent collisions with boundary edges. Defaults to True.
207+
avoid_collisions: Var[bool]
208+
209+
# The distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { "top": 20, "left": 20 }. Defaults to 0.
210+
collision_padding: Var[Union[float, int, Dict[str, Union[float, int]]]]
211+
212+
# The padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. Defaults to 0.
213+
arrow_padding: Var[Union[float, int]]
214+
215+
# The sticky behavior on the align axis. "partial" will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst "always" will keep the content in the boundary regardless. Defaults to "partial".
216+
sticky: Var[LiteralStickyType]
217+
218+
# Whether to hide the content when the trigger becomes fully occluded. Defaults to False.
219+
hide_when_detached: Var[bool]
220+
221+
def get_event_triggers(self) -> Dict[str, Any]:
222+
"""Get the events triggers signatures for the component.
223+
224+
Returns:
225+
The signatures of the event triggers.
226+
"""
227+
return {
228+
**super().get_event_triggers(),
229+
EventTriggers.ON_ESCAPE_KEY_DOWN: lambda e0: [e0],
230+
EventTriggers.ON_POINTER_DOWN_OUTSIDE: lambda e0: [e0],
231+
EventTriggers.ON_FOCUS_OUTSIDE: lambda e0: [e0],
232+
EventTriggers.ON_INTERACT_OUTSIDE: lambda e0: [e0],
233+
}
234+
91235

92236
class DropdownMenuItem(RadixThemesComponent):
93-
"""Trigger an action or event, such as submitting a form or displaying a dialog."""
237+
"""The Dropdown Menu Item Component."""
94238

95239
tag = "DropdownMenu.Item"
96240

97-
# Override theme color for button
241+
# Override theme color for Dropdown Menu Item
98242
color_scheme: Var[LiteralAccentColor]
99243

100244
# Shortcut to render a menu item as a link
101245
shortcut: Var[str]
102246

247+
# Change the default rendered element for the one passed as a child, merging their props and behavior. Defaults to False.
248+
as_child: Var[bool]
249+
250+
# When true, prevents the user from interacting with the item.
251+
disabled: Var[bool]
252+
253+
# Optional text used for typeahead purposes. By default the typeahead behavior will use the .textContent of the item. Use this when the content is complex, or you have non-textual content inside.
254+
text_value: Var[str]
255+
256+
def get_event_triggers(self) -> Dict[str, Any]:
257+
"""Get the events triggers signatures for the component.
258+
259+
Returns:
260+
The signatures of the event triggers.
261+
"""
262+
return {
263+
**super().get_event_triggers(),
264+
EventTriggers.ON_SELECT: lambda e0: [e0.target.value],
265+
}
266+
103267

104268
class DropdownMenuSeparator(RadixThemesComponent):
105-
"""Trigger an action or event, such as submitting a form or displaying a dialog."""
269+
"""Dropdown Menu Separator Component. Used to visually separate items in the dropdown menu."""
106270

107271
tag = "DropdownMenu.Separator"

0 commit comments

Comments
 (0)