dara-components 1.19.0__py3-none-any.whl → 1.19.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dara/components/common/__init__.py +3 -0
- dara/components/common/dropdown_menu.py +161 -0
- dara/components/umd/dara.components.umd.js +135873 -137266
- {dara_components-1.19.0.dist-info → dara_components-1.19.1.dist-info}/METADATA +3 -3
- {dara_components-1.19.0.dist-info → dara_components-1.19.1.dist-info}/RECORD +7 -6
- {dara_components-1.19.0.dist-info → dara_components-1.19.1.dist-info}/LICENSE +0 -0
- {dara_components-1.19.0.dist-info → dara_components-1.19.1.dist-info}/WHEEL +0 -0
|
@@ -39,6 +39,7 @@ from dara.components.common.component_select_list import (
|
|
|
39
39
|
ComponentSelectList,
|
|
40
40
|
)
|
|
41
41
|
from dara.components.common.datepicker import Datepicker
|
|
42
|
+
from dara.components.common.dropdown_menu import DropdownMenu, MenuItem
|
|
42
43
|
from dara.components.common.dropzone import UploadDropzone
|
|
43
44
|
from dara.components.common.form import Form
|
|
44
45
|
from dara.components.common.form_page import FormPage
|
|
@@ -87,6 +88,7 @@ __all__ = [
|
|
|
87
88
|
'ComponentItem',
|
|
88
89
|
'Datepicker',
|
|
89
90
|
'Direction',
|
|
91
|
+
'DropdownMenu',
|
|
90
92
|
'Form',
|
|
91
93
|
'FormPage',
|
|
92
94
|
'Grid',
|
|
@@ -100,6 +102,7 @@ __all__ = [
|
|
|
100
102
|
'ItemBadge',
|
|
101
103
|
'Label',
|
|
102
104
|
'ListSection',
|
|
105
|
+
'MenuItem',
|
|
103
106
|
'Markdown',
|
|
104
107
|
'Modal',
|
|
105
108
|
'Overlay',
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Optional, Union
|
|
2
|
+
|
|
3
|
+
from typing_extensions import TypedDict
|
|
4
|
+
|
|
5
|
+
from dara.components.common.base_component import BaseDashboardComponent
|
|
6
|
+
from dara.components.common.button import Button
|
|
7
|
+
from dara.core import Action, ComponentInstance, NonDataVariable
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MenuItem(TypedDict, total=False):
|
|
11
|
+
label: Union[str, ComponentInstance]
|
|
12
|
+
"""the label of the menu item"""
|
|
13
|
+
|
|
14
|
+
icon: Optional[str]
|
|
15
|
+
"""optional icon to show next to the label, use get_icon() helper"""
|
|
16
|
+
|
|
17
|
+
style: Optional[Dict[str, Any]]
|
|
18
|
+
"""optional style to apply to the menu item"""
|
|
19
|
+
|
|
20
|
+
prevent_close: Optional[bool]
|
|
21
|
+
"""optional flag to prevent the menu from closing when the item is clicked"""
|
|
22
|
+
|
|
23
|
+
before: Optional[ComponentInstance]
|
|
24
|
+
"""optional component to show before the label"""
|
|
25
|
+
|
|
26
|
+
after: Optional[ComponentInstance]
|
|
27
|
+
"""optional component to show after the label"""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class DropdownMenu(BaseDashboardComponent):
|
|
31
|
+
"""
|
|
32
|
+
A DropdownMenu component that displays a button which opens a dropdown menu with configurable menu items.
|
|
33
|
+
Menu items can be organized into sections and support icons, custom styling, and custom components.
|
|
34
|
+
|
|
35
|
+
A basic dropdown menu with simple text items:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from dara.core import action, ActionCtx
|
|
39
|
+
from dara.components import Button, DropdownMenu
|
|
40
|
+
|
|
41
|
+
@action
|
|
42
|
+
async def handle_menu_click(ctx: ActionCtx):
|
|
43
|
+
print(f"Clicked: {ctx.input['label']}")
|
|
44
|
+
|
|
45
|
+
DropdownMenu(
|
|
46
|
+
button=Button('Options'),
|
|
47
|
+
onclick=handle_menu_click(),
|
|
48
|
+
menu_items=[
|
|
49
|
+
[
|
|
50
|
+
MenuItem(label='Edit'),
|
|
51
|
+
MenuItem(label='Delete'),
|
|
52
|
+
]
|
|
53
|
+
]
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
A dropdown menu with icons and custom styling:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from dara.core import action, ActionCtx, get_icon
|
|
61
|
+
from dara.components import Button, DropdownMenu
|
|
62
|
+
|
|
63
|
+
@action
|
|
64
|
+
async def handle_menu_click(ctx: ActionCtx):
|
|
65
|
+
print(f"Clicked: {ctx.input['label']}")
|
|
66
|
+
|
|
67
|
+
DropdownMenu(
|
|
68
|
+
button=Button('Actions', icon=get_icon('chevron-down')),
|
|
69
|
+
onclick=handle_menu_click(),
|
|
70
|
+
menu_items=[
|
|
71
|
+
[
|
|
72
|
+
MenuItem(
|
|
73
|
+
label='Edit',
|
|
74
|
+
icon=get_icon('pen'),
|
|
75
|
+
style={'color': 'blue'}
|
|
76
|
+
),
|
|
77
|
+
MenuItem(
|
|
78
|
+
label='Delete',
|
|
79
|
+
icon=get_icon('trash'),
|
|
80
|
+
style={'color': 'red'}
|
|
81
|
+
),
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
MenuItem(label='Settings', icon=get_icon('gear'))
|
|
85
|
+
]
|
|
86
|
+
]
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
A dropdown menu with custom components and prevent close behavior:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from dara.core import action, ActionCtx, Variable
|
|
94
|
+
from dara.components import Button, DropdownMenu, Text, Stack
|
|
95
|
+
|
|
96
|
+
counter = Variable(0)
|
|
97
|
+
|
|
98
|
+
@action
|
|
99
|
+
async def handle_menu_click(ctx: ActionCtx, counter_value: int):
|
|
100
|
+
print(f"Clicked: {ctx.input['label']}")
|
|
101
|
+
|
|
102
|
+
if ctx.input['label'] == 'Increment':
|
|
103
|
+
await ctx.update(counter, counter_value + 1)
|
|
104
|
+
|
|
105
|
+
DropdownMenu(
|
|
106
|
+
button=Button('Custom Menu'),
|
|
107
|
+
onclick=handle_menu_click(counter),
|
|
108
|
+
menu_items=[
|
|
109
|
+
[
|
|
110
|
+
MenuItem(
|
|
111
|
+
label=Stack(Text('Counter: '), Text(counter)),
|
|
112
|
+
prevent_close=True
|
|
113
|
+
),
|
|
114
|
+
MenuItem(
|
|
115
|
+
label='Increment',
|
|
116
|
+
before=Text('→'),
|
|
117
|
+
after=Text('↑')
|
|
118
|
+
)
|
|
119
|
+
]
|
|
120
|
+
]
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
A dropdown menu with footer content at the bottom:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from dara.core import action, ActionCtx
|
|
128
|
+
from dara.components import Button, DropdownMenu, Text, Stack
|
|
129
|
+
|
|
130
|
+
@action
|
|
131
|
+
async def handle_menu_click(ctx: ActionCtx):
|
|
132
|
+
print(f"Clicked: {ctx.input['label']}")
|
|
133
|
+
|
|
134
|
+
DropdownMenu(
|
|
135
|
+
button=Button('Menu with Footer'),
|
|
136
|
+
onclick=handle_menu_click(),
|
|
137
|
+
menu_items=[
|
|
138
|
+
[
|
|
139
|
+
MenuItem(label='Option 1'),
|
|
140
|
+
MenuItem(label='Option 2'),
|
|
141
|
+
]
|
|
142
|
+
],
|
|
143
|
+
footer=Stack(
|
|
144
|
+
Text(
|
|
145
|
+
'Additional info or controls can go here',
|
|
146
|
+
raw_css={'padding': '8px', 'font-size': '0.8rem', 'color': 'gray'},
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
:param button: The button component that triggers the dropdown menu
|
|
153
|
+
:param onclick: Action triggered when a menu item is clicked, receives the clicked item as parameter
|
|
154
|
+
:param menu_items: List of menu item sections, where each section is a list of MenuItem objects
|
|
155
|
+
:param footer: Optional component to display at the bottom of the dropdown menu
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
button: Button
|
|
159
|
+
onclick: Action
|
|
160
|
+
menu_items: Union[List[List[MenuItem]], NonDataVariable]
|
|
161
|
+
footer: Optional[ComponentInstance] = None
|